Class: Rack::Insight::SpeedTracer::Tracer
- Inherits:
-
Object
- Object
- Rack::Insight::SpeedTracer::Tracer
- Defined in:
- lib/rack/insight/panels/speedtracer_panel/tracer.rb
Instance Method Summary collapse
- #after_detect(method_call, timing, arguments, result) ⇒ Object
- #before_detect(method_call, arguments) ⇒ Object
-
#initialize(table) ⇒ Tracer
constructor
A new instance of Tracer.
- #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) ⇒ Object
Constructor Details
#initialize(table) ⇒ Tracer
Returns a new instance of Tracer.
4 5 6 7 8 |
# File 'lib/rack/insight/panels/speedtracer_panel/tracer.rb', line 4 def initialize(table) @pstack = [] @table = table @event_id = 0 end |
Instance Method Details
#after_detect(method_call, timing, arguments, result) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rack/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 |
#before_detect(method_call, arguments) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/rack/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 |
#make_string_of(array) ⇒ Object
43 44 45 46 47 |
# File 'lib/rack/insight/panels/speedtracer_panel/tracer.rb', line 43 def make_string_of(array) array.map do |item| short_string(item) end.join(",") end |
#request_finish(env, status, headers, body, timing) ⇒ Object
15 16 17 |
# File 'lib/rack/insight/panels/speedtracer_panel/tracer.rb', line 15 def request_finish(env, status, headers, body, timing) env["rack-insight.speedtracer-record"] = @pstack.pop end |
#request_start(env, start) ⇒ Object
10 11 12 13 |
# File 'lib/rack/insight/panels/speedtracer_panel/tracer.rb', line 10 def request_start(env, start) id, method, uri = env.values_at("rack-insight.speedtracer-id", "REQUEST_METHOD", "PATH_INFO") @pstack.push RequestRecord.new(id, method, uri) end |
#short_string(item, max_per_elem = 50) ⇒ Object
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/rack/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 |