Class: Insight::SpeedTracer::Tracer
- Inherits:
-
Object
- Object
- Insight::SpeedTracer::Tracer
- Defined in:
- lib/insight/panels/speedtracer_panel/tracer.rb
Instance Method Summary (collapse)
- - (Object) after_detect(method_call, timing, arguments, result)
- - (Object) before_detect(method_call, arguments)
-
- (Tracer) initialize(table)
constructor
A new instance of Tracer.
- - (Object) make_string_of(array)
- - (Object) request_finish(env, status, headers, body, timing)
- - (Object) request_start(env, start)
- - (Object) short_string(item, max_per_elem = 50)
Constructor Details
- (Tracer) initialize(table)
A new instance of Tracer
4 5 6 7 8 |
# File 'lib/insight/panels/speedtracer_panel/tracer.rb', line 4 def initialize(table) @pstack = [] @table = table @event_id = 0 end |
Instance Method Details
- (Object) after_detect(method_call, timing, arguments, result)
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/insight/panels/speedtracer_panel/tracer.rb', line 29 def after_detect(method_call, timing, arguments, result) event = @pstack.pop if event.nil? else event.finish unless (parent = @pstack.last).nil? parent.children.push event else @children.push event end end end |
- (Object) before_detect(method_call, arguments)
19 20 21 22 23 24 25 26 27 |
# File 'lib/insight/panels/speedtracer_panel/tracer.rb', line 19 def before_detect(method_call, arguments) @event_id += 1 #arguments_string = make_string_of(arguments) arguments_string = "" #XXX ServerEvent use method call... event = ServerEvent.new(method_call, arguments_string) @pstack.push event end |
- (Object) make_string_of(array)
43 44 45 46 47 |
# File 'lib/insight/panels/speedtracer_panel/tracer.rb', line 43 def make_string_of(array) array.map do |item| short_string(item) end.join(",") end |
- (Object) request_finish(env, status, headers, body, timing)
15 16 17 |
# File 'lib/insight/panels/speedtracer_panel/tracer.rb', line 15 def request_finish(env, status, headers, body, timing) env["insight.speedtracer-record"] = @pstack.pop end |
- (Object) request_start(env, start)
10 11 12 13 |
# File 'lib/insight/panels/speedtracer_panel/tracer.rb', line 10 def request_start(env, start) id, method, uri = env.values_at("insight.speedtracer-id", "REQUEST_METHOD", "PATH_INFO") @pstack.push RequestRecord.new(id, method, uri) end |
- (Object) short_string(item, max_per_elem = 50)
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/insight/panels/speedtracer_panel/tracer.rb', line 49 def short_string(item, max_per_elem = 50) begin string = item.inspect if string.length > max_per_elem case item when NilClass "nil" when Hash "{ " + item.map do |key, value| short_string(key, 15) + "=>" + short_string(value, 30) end.join(", ") + " }" when find_constant("ActionView::Base") tmpl = item.template if tmpl.nil? item.path.inspect else [tmpl.base_path, tmpl.name].join("/") end when find_constant("ActiveRecord::Base") string = "#{item.class.name}(#{item.id})" else string = item.class.name end else string end rescue Exception => ex "..." end end |