Class: Rack::Bug::SpeedTracer
- Inherits:
-
Panel
- Object
- Panel
- Rack::Bug::SpeedTracer
- Includes:
- Rack::Bug::SpeedTrace::Render
- Defined in:
- lib/rack/bug/speedtracer/duck-puncher.rb,
lib/rack/bug/speedtracer.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #after(env, status, headers, body) ⇒ Object
- #before(env) ⇒ Object
- #content ⇒ Object
- #database ⇒ Object
- #heading ⇒ Object
-
#initialize(app) ⇒ SpeedTracer
constructor
A new instance of SpeedTracer.
- #name ⇒ Object
- #panel_app ⇒ Object
Constructor Details
#initialize(app) ⇒ SpeedTracer
Returns a new instance of SpeedTracer.
20 21 22 23 24 |
# File 'lib/rack/bug/speedtracer.rb', line 20 def initialize(app) @app = app @uuid = UUID.new super end |
Class Method Details
.database ⇒ Object
12 13 14 |
# File 'lib/rack/bug/speedtracer.rb', line 12 def self.database @db ||= {} end |
.safe_method_names(mod, method_names) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rack/bug/speedtracer/duck-puncher.rb', line 34 def safe_method_names(mod, method_names) unsafe_names = (mod.public_instance_methods(true) + mod.protected_instance_methods(true) + mod.private_instance_methods(true)).sort.uniq method_names.map do |name| name = name.to_s prefix = "0" hidden_name = ["_", prefix, name].join("_") while unsafe_names.include?(hidden_name) prefix = prefix.next hidden_name = ["_", prefix, name].join("_") end unsafe_names << hidden_name [name, hidden_name] end end |
Instance Method Details
#after(env, status, headers, body) ⇒ Object
50 51 52 53 54 |
# File 'lib/rack/bug/speedtracer.rb', line 50 def after(env, status, headers, body) env['st.tracer'].finish database[env['st.id']] = env['st.tracer'] headers['X-TraceUrl'] = '/speedtracer?id=' + env['st.id'] end |
#before(env) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/rack/bug/speedtracer.rb', line 42 def before(env) env['st.id'] = @uuid.generate tracer = SpeedTrace::Tracer.new(env['st.id'], env['REQUEST_METHOD'], env['REQUEST_URI']) env['st.tracer'] = tracer Thread::current['st.tracer'] = tracer end |
#content ⇒ Object
38 39 40 |
# File 'lib/rack/bug/speedtracer.rb', line 38 def content render_template "traces", :traces => database end |
#database ⇒ Object
16 17 18 |
# File 'lib/rack/bug/speedtracer.rb', line 16 def database self.class.database end |
#heading ⇒ Object
34 35 36 |
# File 'lib/rack/bug/speedtracer.rb', line 34 def heading "#{database.keys.length} traces" end |
#name ⇒ Object
30 31 32 |
# File 'lib/rack/bug/speedtracer.rb', line 30 def name "speedtracer" end |
#panel_app ⇒ Object
26 27 28 |
# File 'lib/rack/bug/speedtracer.rb', line 26 def panel_app return SpeedTrace::TraceApp.new(database) end |