Class: Rack::Bug::SpeedTrace::TraceRecord

Inherits:
Object
  • Object
show all
Includes:
Render
Defined in:
lib/rack/bug/panels/speedtracer_panel/tracer.rb

Direct Known Subclasses

ServerEvent, Tracer

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Render

#compiled_source

Methods included from Render

#compile, #compile!, #compiled_source, #method_name, #method_name_without_locals, #render_template, #signed_params

Constructor Details

#initialize(id) ⇒ TraceRecord

Returns a new instance of TraceRecord.



5
6
7
8
9
# File 'lib/rack/bug/panels/speedtracer_panel/tracer.rb', line 5

def initialize(id)
  @id = id
  @start = Time.now
  @children = []
end

Instance Attribute Details

#startObject (readonly)

Returns the value of attribute start.



11
12
13
# File 'lib/rack/bug/panels/speedtracer_panel/tracer.rb', line 11

def start
  @start
end

Instance Method Details

#durationObject



23
24
25
# File 'lib/rack/bug/panels/speedtracer_panel/tracer.rb', line 23

def duration
  ((@finish - @start) * 1000).to_i
end

#finishObject



13
14
15
# File 'lib/rack/bug/panels/speedtracer_panel/tracer.rb', line 13

def finish
  @finish ||= Time.now
end

#time_in_childrenObject



17
18
19
20
21
# File 'lib/rack/bug/panels/speedtracer_panel/tracer.rb', line 17

def time_in_children
  @children.inject(0) do |time, child|
    time + child.duration
  end
end

#to_jsonObject



27
28
29
# File 'lib/rack/bug/panels/speedtracer_panel/tracer.rb', line 27

def to_json
  Yajl::Encoder.encode(hash_representation, :pretty => true, :indent => '  ')
end