Class: Gitlab::Middleware::MemoryReport

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ MemoryReport

Returns a new instance of MemoryReport.


6
7
8
# File 'lib/gitlab/middleware/memory_report.rb', line 6

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gitlab/middleware/memory_report.rb', line 10

def call(env)
  request = ActionDispatch::Request.new(env)

  return @app.call(env) unless rendering_memory_profiler?(request)

  begin
    require 'memory_profiler'

    report = MemoryProfiler.report do
      @app.call(env)
    end

    report = report_to_string(report)
    headers = { 'Content-Type' => 'text/plain' }

    [200, headers, [report]]
  rescue StandardError => e
    ::Gitlab::ErrorTracking.track_exception(e)
    [500, { 'Content-Type' => 'text/plain' }, ["Could not generate memory report: #{e}"]]
  end
end