From fe5a6057708fdfeb5453fa0d40eb03a56451510c Mon Sep 17 00:00:00 2001 From: merely Date: Tue, 1 Oct 2024 01:59:16 -0300 Subject: [PATCH] respect flamegraph_mode --- lib/mini_profiler.rb | 4 ++-- spec/lib/profiler_spec.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/mini_profiler.rb b/lib/mini_profiler.rb index cccbce90..1236da43 100644 --- a/lib/mini_profiler.rb +++ b/lib/mini_profiler.rb @@ -296,8 +296,8 @@ def call(env) mode_match_data = action_parameters(env)['flamegraph_mode'] - if mode_match_data && [:cpu, :wall, :object, :custom].include?(mode_match_data[1].to_sym) - mode = mode_match_data[1].to_sym + if mode_match_data && [:cpu, :wall, :object, :custom].include?(mode_match_data.to_sym) + mode = mode_match_data.to_sym else mode = config.flamegraph_mode end diff --git a/spec/lib/profiler_spec.rb b/spec/lib/profiler_spec.rb index 6f93b706..ce69629a 100644 --- a/spec/lib/profiler_spec.rb +++ b/spec/lib/profiler_spec.rb @@ -228,5 +228,13 @@ def self.bar(baz, boo) ensure Rack::MiniProfiler.config.enable_advanced_debugging_tools = original_enable_advanced_debugging_tools end + + it 'passes flamegraph_mode parameter to StackProf.run' do + stackprof = double + stub_const('StackProf', stackprof) + expect(stackprof).to receive(:respond_to?).with(:run).and_return(true) + expect(stackprof).to receive(:run).with(hash_including(mode: :cpu)).and_return({}) + profiler.call({ "PATH_INFO" => "/", "QUERY_STRING" => "pp=flamegraph&flamegraph_mode=cpu" }) + end end end