Sha256: fb8d777d23de300848cfabf4c1e9a254577d9d4d3ad9c13e15231193ccfa3153

Contents?: true

Size: 648 Bytes

Versions: 1

Compression:

Stored size: 648 Bytes

Contents

require "rack_gc_profiler/version"

module RackGcProfiler
  class Middleware

    GC_TIME_FORMAT = "%0.6f".freeze
    GC_TIME_HEADER = "GC-Time".freeze
    GC_RUNS_HEADER = "GC-Runs".freeze

    attr_reader :profiler

    def initialize(app, profiler = GC::Profiler)
      @app = app
      @profiler = profiler
    end

    def call(env)
      @profiler.enable

      status, headers, body = @app.call(env)

      headers[GC_TIME_HEADER] = GC_TIME_FORMAT % @profiler.total_time
      headers[GC_RUNS_HEADER] = @profiler.raw_data.size.to_s

      [status, headers, body]

    ensure
      @profiler.disable
      @profiler.clear

    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rack_gc_profiler-0.1.0 lib/rack_gc_profiler.rb