Class: Rack::PerftoolsProfiler::ProfilerMiddleware
- Inherits:
-
Object
- Object
- Rack::PerftoolsProfiler::ProfilerMiddleware
- Includes:
- Utils
- Defined in:
- lib/rack/perftools_profiler/profiler_middleware.rb
Constant Summary collapse
- PRINTER_CONTENT_TYPE =
{ :text => 'text/plain', :gif => 'image/gif', :pdf => 'application/pdf' }
- PRINTERS =
PRINTER_CONTENT_TYPE.keys
Instance Method Summary collapse
- #call(env) ⇒ Object
- #call_app(env) ⇒ Object
- #force_stop ⇒ Object
-
#initialize(app, options = {}) ⇒ ProfilerMiddleware
constructor
A new instance of ProfilerMiddleware.
- #profiler_data_response(profiling_data) ⇒ Object
Constructor Details
#initialize(app, options = {}) ⇒ ProfilerMiddleware
Returns a new instance of ProfilerMiddleware.
16 17 18 19 |
# File 'lib/rack/perftools_profiler/profiler_middleware.rb', line 16 def initialize(app, = {}) @app = app @profiler = Profiler.new(@app, .clone) end |
Instance Method Details
#call(env) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rack/perftools_profiler/profiler_middleware.rb', line 21 def call(env) @env = env.clone action = Action.for_env(@env, @profiler, self) action.act action.response rescue ProfilerArgumentError => err @env['rack.errors'].write(err.) [400, {'Content-Type' => 'text/plain'}, [err.]] rescue ProfilingError => err @env['rack.errors'].write(err. + "\n" + err.stderr) [500, {'Content-Type' => 'text/plain'}, [err.+"\n\n", "Standard error:\n"+err.stderr+"\n"]] end |
#call_app(env) ⇒ Object
34 35 36 |
# File 'lib/rack/perftools_profiler/profiler_middleware.rb', line 34 def call_app(env) @app.call(env) end |
#force_stop ⇒ Object
38 39 40 |
# File 'lib/rack/perftools_profiler/profiler_middleware.rb', line 38 def force_stop @profiler.stop end |
#profiler_data_response(profiling_data) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rack/perftools_profiler/profiler_middleware.rb', line 42 def profiler_data_response(profiling_data) format, body = profiling_data body = Array(body) if format==:none = 'No profiling data available. Visit /__stop__ and then visit /__data__' [404, {'Content-Type' => 'text/plain'}, []] else [200, headers(format, body), Array(body)] end end |