Class: FrameBuilder
- Inherits:
-
Object
- Object
- FrameBuilder
- Defined in:
- lib/agent/frame_builder.rb
Overview
Ruby version of the Java FrameBuilder Contructs a tree of frames through calls to enter and exit. One FrameBuilder is maintained per thread.
Instance Attribute Summary collapse
-
#depth ⇒ Object
Returns the value of attribute depth.
-
#last ⇒ Object
Returns the value of attribute last.
Class Method Summary collapse
Instance Method Summary collapse
- #createFrame(id, operation, startTime, endTime, children = []) ⇒ Object
- #enter(operation, time = Time.now) ⇒ Object
- #exit(time = Time.now, addTrace = true) ⇒ Object
-
#initialize ⇒ FrameBuilder
constructor
A new instance of FrameBuilder.
- #lastStart ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize ⇒ FrameBuilder
Returns a new instance of FrameBuilder.
7 8 9 10 11 12 |
# File 'lib/agent/frame_builder.rb', line 7 def initialize() @id = 0 @depth = 0 @current = nil @parent = nil end |
Instance Attribute Details
#depth ⇒ Object
Returns the value of attribute depth.
14 15 16 |
# File 'lib/agent/frame_builder.rb', line 14 def depth @depth end |
#last ⇒ Object
Returns the value of attribute last.
14 15 16 |
# File 'lib/agent/frame_builder.rb', line 14 def last @last end |
Class Method Details
.instance ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/agent/frame_builder.rb', line 16 def self.instance instance = Thread.current['instance'] if instance == nil instance = Thread.current['instance'] = FrameBuilder.new puts "Creating new instance of frame builder for thread " + Thread.current.object_id.to_s end return instance end |
Instance Method Details
#createFrame(id, operation, startTime, endTime, children = []) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/agent/frame_builder.rb', line 26 def createFrame(id, operation, startTime, endTime, children = []) startTimeNanos = startTime.to_f * 1000000000 endTimeNanos = endTime.to_f * 1000000000 if endTimeNanos.to_i <= startTimeNanos.to_i endTimeNanos = startTimeNanos + 1000 end Frame.new(id, startTimeNanos, endTimeNanos, operation, nil, children) end |
#enter(operation, time = Time.now) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/agent/frame_builder.rb', line 35 def enter(operation, time = Time.now ) startTimeNanos = time.to_f * 1000000000 @id += 1 @depth += 1 @parent = @current initialEndTime = startTimeNanos + 1000 @current = Frame.new(@id, startTimeNanos, initialEndTime, operation, @parent, []) end |
#exit(time = Time.now, addTrace = true) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/agent/frame_builder.rb', line 44 def exit(time = Time.now, addTrace = true) endTimeNanos = time.to_f * 1000000000 @depth -= 1 @current.endNanos = endTimeNanos if @current.endNanos < @current.startNanos raise "end time less than or equal to start time for frame " + @current.operation.label + "StartNanos " + ("%d" % @current.startNanos) + " must be less than EndNanos " + ("%d" % @current.endNanos) end # At root already if @parent == nil trace = TraceBuilder.instance.createTrace(@current) if addTrace TraceQueue.instance.addTrace(trace) end @last = @current reset trace else @parent.children << @current @current = @parent @parent = @current.parent nil end end |
#lastStart ⇒ Object
78 79 80 81 82 |
# File 'lib/agent/frame_builder.rb', line 78 def lastStart if last != null @last.startNanos / 1000000 end end |
#reset ⇒ Object
70 71 72 73 74 75 |
# File 'lib/agent/frame_builder.rb', line 70 def reset() @id = 0 @depth = 0 @current = nil @parent = nil end |