Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Profiler cleanup #24

Closed
wants to merge 2 commits into from

5 participants

@MasterLambaster

Some minor cleanup for profiler. Also added content type for missing html printer.

@masterkain

This fixes Rack::Profiler for me 100%, merge please?

@masterkain

News about this?

@rkh
Owner

Rebase please.

@mpalmer
Owner

I prefer the approach in #18 to this one. The addition of a content type for ::RubyProf::CallStackPrinter => 'text/html' in 95a895f is unique to this PR, though, so I'll leave it open for now until I or someone else splits that out separately.

@mpalmer mpalmer added the needs-work label
@jjb
Collaborator
jjb commented

we don't need the rubyprof namespace fix anymore

i don't have comprehension of what 95a895f is achieving. @MasterLambaster if you would still like that change, submit again in another PR, with explanation for why it's needed.

closing this PR.

@jjb jjb closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 12 deletions.
  1. +14 −12 lib/rack/contrib/profiler.rb
View
26 lib/rack/contrib/profiler.rb
@@ -16,13 +16,15 @@ class Profiler
gc_time
)
- DEFAULT_PRINTER = RubyProf::CallTreePrinter
- DEFAULT_CONTENT_TYPE = 'application/octet-stream'
+ RP = ::RubyProf
+ DEFAULT_PRINTER = RP::CallTreePrinter
+ DEFAULT_CONTENT_TYPE = 'application/octet-stream'
PRINTER_CONTENT_TYPE = {
- RubyProf::FlatPrinter => 'text/plain',
- RubyProf::GraphPrinter => 'text/plain',
- RubyProf::GraphHtmlPrinter => 'text/html'
+ RP::FlatPrinter => 'text/plain',
+ RP::GraphPrinter => 'text/plain',
+ RP::GraphHtmlPrinter => 'text/html',
+ RP::CallStackPrinter => 'text/html'
}
# Accepts a :printer => [:call_tree|:graph_html|:graph|:flat] option
@@ -43,10 +45,10 @@ def call(env)
private
def profiling?(env)
- unless RubyProf.running?
+ unless RP.running?
request = Rack::Request.new(env.clone)
if mode = request.params.delete('profile')
- if RubyProf.const_defined?(mode.upcase)
+ if RP.const_defined?(mode.upcase)
mode
else
env['rack.errors'].write "Invalid RubyProf measure_mode: " +
@@ -58,10 +60,10 @@ def profiling?(env)
end
def profile(env, mode)
- RubyProf.measure_mode = RubyProf.const_get(mode.upcase)
+ RP.measure_mode = RP.const_get(mode.upcase)
GC.enable_stats if GC.respond_to?(:enable_stats)
- result = RubyProf.profile do
+ result = RP.profile do
@times.times { @app.call(env) }
end
GC.disable_stats if GC.respond_to?(:disable_stats)
@@ -78,7 +80,7 @@ def print(printer, result)
def headers(printer, env, mode)
headers = { 'Content-Type' => PRINTER_CONTENT_TYPE[printer] || DEFAULT_CONTENT_TYPE }
- if printer == RubyProf::CallTreePrinter
+ if printer == RP::CallTreePrinter
filename = ::File.basename(env['PATH_INFO'])
headers['Content-Disposition'] =
%(attachment; filename="#{filename}.#{mode}.tree")
@@ -93,8 +95,8 @@ def parse_printer(printer)
printer
else
name = "#{camel_case(printer)}Printer"
- if RubyProf.const_defined?(name)
- RubyProf.const_get(name)
+ if RP.const_defined?(name)
+ RP.const_get(name)
else
DEFAULT_PRINTER
end
Something went wrong with that request. Please try again.