Class: Rack::MemProf::Middleware
- Inherits:
-
Object
- Object
- Rack::MemProf::Middleware
- Defined in:
- lib/rack/mem_prof/middleware.rb
Constant Summary collapse
- REPEXT =
'.txt'.freeze
- REPDIR =
'rack_mem_prof'.freeze
- UNSLUGGABLE =
'stub_for_unslaggable_requests'.freeze
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, options = {}) ⇒ Middleware
Returns a new instance of Middleware.
13 14 15 16 17 |
# File 'lib/rack/mem_prof/middleware.rb', line 13 def initialize(app, = {}) @app = app @path = [:path] || "/tmp" @scale_bytes = [:scale_bytes] || true end |
Instance Method Details
#call(env) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rack/mem_prof/middleware.rb', line 19 def call(env) report_path, report_filename = build_report_path(env) path_with_file = ::File.join(report_path, report_filename) if ::File.exists?(path_with_file) status, headers, body = @app.call(env) else FileUtils.mkdir_p report_path MemoryProfiler.start status, headers, body = @app.call(env) write_report(MemoryProfiler.stop, path_with_file) end [status, headers, body] rescue => e MemoryProfiler.stop raise e end |