Class: State

Inherits:
Object
  • Object
show all
Defined in:
lib/debugtrace/state.rb

Overview

Contains the trace state for a thread

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(thread_id) ⇒ State

Initializes this object.

Parameters:

  • thread_id (Integer)

    the object id of the thread



15
16
17
18
# File 'lib/debugtrace/state.rb', line 15

def initialize(thread_id)
  @thread_id = Common.check_type('thread_id', thread_id, Integer)
  reset()
end

Instance Attribute Details

#nest_levelObject (readonly)

Returns the value of attribute nest_level.



9
10
11
# File 'lib/debugtrace/state.rb', line 9

def nest_level
  @nest_level
end

#previous_nest_levelObject (readonly)

Returns the value of attribute previous_nest_level.



10
11
12
# File 'lib/debugtrace/state.rb', line 10

def previous_nest_level
  @previous_nest_level
end

#thread_idObject (readonly)

Returns the value of attribute thread_id.



8
9
10
# File 'lib/debugtrace/state.rb', line 8

def thread_id
  @thread_id
end

Instance Method Details

#down_nestFloat

Downs the nest level.

Returns:

  • (Float)

    The time when the corresponding up_nest method was invoked



46
47
48
49
50
# File 'lib/debugtrace/state.rb', line 46

def down_nest
    @previous_nest_level = @nest_level
    @nest_level -= 1
    return @times.length > 0 ? @times.pop() : Time.now
end

#resetObject

Resets this object



21
22
23
24
25
# File 'lib/debugtrace/state.rb', line 21

def reset
  @nest_level = 0
  @previous_nest_level = 0
  @times = []
end

#to_sString

Returns a string representation of this object.

Returns:

  • (String)

    A string representation of this object



30
31
32
# File 'lib/debugtrace/state.rb', line 30

def to_s()
    return "(State){thread_id: #{@thread_id}, nest_level: #{@nest_level}, previous_nest_level: #{@previous_nest_level}, times: #{@times}}"
end

#up_nestObject

Ups the nest level.



35
36
37
38
39
40
41
# File 'lib/debugtrace/state.rb', line 35

def up_nest
    @previous_nest_level = @nest_level
    if (@nest_level >= 0)
        @times.push(Time.now)
    end
    @nest_level += 1
end