Skip to content
Browse files

Allow --node{count,fraction} parameters

  • Loading branch information...
1 parent fdaca6b commit f17e343011705e40d72b793b4016390f6101e9ee @ConradIrwin ConradIrwin committed with Jul 22, 2011
View
8 lib/rack/perftools_profiler/profiler.rb
@@ -84,10 +84,14 @@ def data(options = {})
printer = (options.fetch('printer') {@printer}).to_sym
ignore = options.fetch('ignore') { nil }
focus = options.fetch('focus') { nil }
+ nodecount = options.fetch('nodecount') { nil }
+ nodefraction = options.fetch('nodefraction') { nil }
if ::File.exists?(PROFILING_DATA_FILE)
args = ["--#{printer}"]
- args << " --ignore=#{ignore}" if ignore
- args << " --focus=#{focus}" if focus
+ args << "--ignore=#{ignore}" if ignore
+ args << "--focus=#{focus}" if focus
+ args << "--nodecount=#{nodecount}" if nodecount
+ args << "--nodefraction=#{nodefraction}" if nodefraction
args << PROFILING_DATA_FILE
cmd = ["pprof.rb"] + args
cmd = ["bundle", "exec"] + cmd if @bundler
View
11 test/multiple_request_profiling_test.rb
@@ -176,6 +176,17 @@ def profile_requests(profiled_app, requests, options = {})
end
+ context "when the nodefraction parameter is specified" do
+ should "call pprof.rb with nodefraction" do
+ status = stub_everything(:exitstatus => 0)
+ profiled_app = Rack::PerftoolsProfiler.new(@app)
+ custom_env = Rack::MockRequest.env_for('/method1', :params => 'profile=true&nodefraction=160')
+ Open4.expects(:popen4).with('pprof.rb', '--text', '--nodefraction=160', '/tmp/rack_perftools_profiler.prof').returns(status)
+ profiled_app.call(custom_env)
+ end
+ end
+
+
context "when overriding profiling mode" do
should "default to configured mode if mode is empty string" do
View
10 test/single_request_profiling_test.rb
@@ -123,6 +123,16 @@ def setup
end
+ context "when the nodecount parameter is specified" do
+ should "call pprof.rb with nodecount" do
+ status = stub_everything(:exitstatus => 0)
+ profiled_app = Rack::PerftoolsProfiler.new(@app)
+ custom_env = Rack::MockRequest.env_for('/method1', :params => 'profile=true&nodecount=160')
+ Open4.expects(:popen4).with('pprof.rb', '--text', '--nodecount=160', '/tmp/rack_perftools_profiler.prof').returns(status)
+ profiled_app.call(custom_env)
+ end
+ end
+
context "when overriding profiling mode" do
should "default to configured mode if mode is empty string" do

0 comments on commit f17e343

Please sign in to comment.
Something went wrong with that request. Please try again.