class ActionDispatch::ServerTiming

def self.unsubscribe # :nodoc:

:nodoc:
def self.unsubscribe # :nodoc:
  Subscriber.instance.unsubscribe
end

def call(env)

def call(env)
  response = nil
  events = @subscriber.collect_events do
    response = @app.call(env)
  end
  headers = response[1]
  header_info = events.group_by(&:name).map do |event_name, events_collection|
    "%s;dur=%.2f" % [event_name, events_collection.sum(&:duration)]
  end
  header_info.prepend(headers[SERVER_TIMING_HEADER]) if headers[SERVER_TIMING_HEADER].present?
  headers[SERVER_TIMING_HEADER] = header_info.join(", ")
  response
end

def initialize(app)

def initialize(app)
  @app = app
  @subscriber = Subscriber.instance
  @subscriber.ensure_subscribed
end