Skip to content

Commit e85bb0b

Browse files
tgxworldonyxblade
andcommitted
respect flamegraph_mode in query string
Currently, parameters like `?flamegraph_mode=cpu` are not correctly passed to StackProf. Instead, `config.flamegraph_mode` will always be used. Co-authored-by: merely <[email protected]>
1 parent 3d3d72e commit e85bb0b

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
## Unreleased
44

55
- [BREAKING CHANGE] Ruby version 3.1.0 or later is required. [#632](https://github.com/MiniProfiler/rack-mini-profiler/pull/632)
6-
- [FIX] Truncate long profiler name in profiler popup. [#634](https://github.com/MiniProfiler/rack-mini-profiler/pull/634)
6+
- [FIX] Truncate long profiler name in profiler popup. [#634](https://github.com/MiniProfiler/rack-mini-profiler/pull/634)
7+
- [FIX] `flamegraph_mode` query param having no effect. [#635](https://github.com/MiniProfiler/rack-mini-profiler/pull/635)
78

89
## 3.3.1 - 2024-02-15
910
- [FEATURE] Support dynamic `config.content_security_policy_nonce` [#609](https://github.com/MiniProfiler/rack-mini-profiler/pull/609)

lib/mini_profiler.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ def call(env)
296296

297297
mode_match_data = action_parameters(env)['flamegraph_mode']
298298

299-
if mode_match_data && [:cpu, :wall, :object, :custom].include?(mode_match_data[1].to_sym)
300-
mode = mode_match_data[1].to_sym
299+
if mode_match_data && [:cpu, :wall, :object, :custom].include?(mode_match_data.to_sym)
300+
mode = mode_match_data.to_sym
301301
else
302302
mode = config.flamegraph_mode
303303
end

spec/lib/profiler_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,5 +230,13 @@ def self.bar(baz, boo)
230230
ensure
231231
Rack::MiniProfiler.config.enable_advanced_debugging_tools = original_enable_advanced_debugging_tools
232232
end
233+
234+
it 'passes flamegraph_mode parameter to StackProf.run' do
235+
stackprof = double
236+
stub_const('StackProf', stackprof)
237+
expect(stackprof).to receive(:respond_to?).with(:run).and_return(true)
238+
expect(stackprof).to receive(:run).with(hash_including(mode: :cpu)).and_return({})
239+
profiler.call({ "PATH_INFO" => "/", "QUERY_STRING" => "pp=flamegraph&flamegraph_mode=cpu" })
240+
end
233241
end
234242
end

0 commit comments

Comments
 (0)