Class: RailsMemoryProfiler::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_memory_profiler/middleware.rb

Overview

Rack middleware that profiles each request and pushes a report into ReportStore. Registered automatically by the Engine initializer; you do not need to add it to the middleware stack manually.

Profiling is skipped when:

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.

Parameters:

  • app (#call)

    the next Rack application in the stack



12
13
14
15
16
17
# File 'lib/rails_memory_profiler/middleware.rb', line 12

def initialize(app)
  @app            = app
  @request_count  = 0
  @detailed_count = 0
  @mutex          = Mutex.new
end

Instance Method Details

#call(env) ⇒ Array

Profiles the request if applicable and delegates to the inner app.

Parameters:

  • env (Hash)

    Rack environment

Returns:

  • (Array)

    Rack response triplet



23
24
25
26
27
28
29
# File 'lib/rails_memory_profiler/middleware.rb', line 23

def call(env)
  return @app.call(env) unless RailsMemoryProfiler.config.enabled
  return @app.call(env) if ignored_path?(env["PATH_INFO"])
  return @app.call(env) unless sample?

  profile(env)
end