Class: Rack::PerftoolsProfiler

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/rack/contrib/perftools_profiler.rb

Constant Summary collapse

PRINTER_CONTENT_TYPE =
{
  :text => 'text/plain',
  :gif => 'image/gif',
  :pdf => 'application/pdf'
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ PerftoolsProfiler

Returns a new instance of PerftoolsProfiler.



96
97
98
99
# File 'lib/rack/contrib/perftools_profiler.rb', line 96

def initialize(app, options = {})
  @app = app
  @profiler = Profiler.new(@app, options.clone)
end

Class Method Details

.clear_dataObject



86
87
88
# File 'lib/rack/contrib/perftools_profiler.rb', line 86

def self.clear_data
  Profiler.clear_data
end

.with_profiling_off(app, options = {}) ⇒ Object



90
91
92
93
94
# File 'lib/rack/contrib/perftools_profiler.rb', line 90

def self.with_profiling_off(app, options = {})
  instance = self.new(app, options)
  instance.force_stop
  instance
end

Instance Method Details

#call(env) ⇒ Object



101
102
103
104
105
# File 'lib/rack/contrib/perftools_profiler.rb', line 101

def call(env)
  action = Action.for_env(env.clone, @profiler, self)
  action.act
  action.response
end

#call_app(env) ⇒ Object



107
108
109
# File 'lib/rack/contrib/perftools_profiler.rb', line 107

def call_app(env)
  @app.call(env)
end

#force_stopObject



111
112
113
# File 'lib/rack/contrib/perftools_profiler.rb', line 111

def force_stop
  @profiler.stop
end

#profiler_data_response(profiling_data) ⇒ Object



115
116
117
118
119
120
121
122
# File 'lib/rack/contrib/perftools_profiler.rb', line 115

def profiler_data_response(profiling_data)
  format, body = profiling_data
  if format==:none
    [404, {'Content-Type' => 'text/plain'}, ['No profiling data available.']] 
  else
    [200, headers(format, body), Array(body)]
   end
end