From 3c03459043c1e089f914cda95c6eee9e285c277e Mon Sep 17 00:00:00 2001 From: RobL Date: Thu, 7 Dec 2023 01:11:11 +0000 Subject: [PATCH] Quick fix for "undefined local variable or method `query_string (#597) * fix for undefined local variable or method `query_string' * Add spec/dependency for memory_profiler --- Gemfile | 1 + lib/mini_profiler/actions.rb | 2 +- spec/integration/mini_profiler_spec.rb | 28 ++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index c6286f89..f26e9fff 100644 --- a/Gemfile +++ b/Gemfile @@ -8,6 +8,7 @@ gemspec group :test do gem 'codecov', require: false gem 'stackprof', require: false + gem 'memory_profiler', require: false end group :development do diff --git a/lib/mini_profiler/actions.rb b/lib/mini_profiler/actions.rb index f53a084a..55ebc3cb 100644 --- a/lib/mini_profiler/actions.rb +++ b/lib/mini_profiler/actions.rb @@ -133,7 +133,7 @@ def serve_profile_memory(env, client_settings) ) end - query_params = Rack::Utils.parse_nested_query(query_string) + query_params = Rack::Utils.parse_nested_query(env['QUERY_STRING']) options = { ignore_files: query_params['memory_profiler_ignore_files'], allow_files: query_params['memory_profiler_allow_files'], diff --git a/spec/integration/mini_profiler_spec.rb b/spec/integration/mini_profiler_spec.rb index beccd9d8..ba16334a 100644 --- a/spec/integration/mini_profiler_spec.rb +++ b/spec/integration/mini_profiler_spec.rb @@ -141,6 +141,34 @@ def app end end + it 'works with memory_profiler' do + pid = fork do # Avoid polluting main process with stackprof + require 'memory_profiler' + + # Should store flamegraph for ?pp=profile-memory + Rack::MiniProfiler.config.enable_advanced_debugging_tools = true + get '/html?pp=profile-memory' + expect(last_response).to be_ok + expect(last_response.body).to match(/allocated memory by gem/) + expect(last_response.body).to match(/allocated memory by file/) + expect(last_response.body).to match(/allocated memory by location/) + expect(last_response.body).to match(/allocated memory by class/) + expect(last_response.body).to match(/allocated objects by gem/) + expect(last_response.body).to match(/allocated objects by file/) + expect(last_response.body).to match(/allocated objects by location/) + expect(last_response.body).to match(/allocated objects by class/) + expect(last_response.body).to match(/retained objects by gem/) + expect(last_response.body).to match(/retained objects by file/) + expect(last_response.body).to match(/retained objects by location/) + expect(last_response.body).to match(/retained objects by class/) + expect(last_response.body).to match(/Allocated String Report/) + expect(last_response.body).to match(/Retained String Report/) + end + + Process.wait(pid) + expect($?.exitstatus).to eq(0) + end + it 'works with async-flamegraph' do pid = fork do # Avoid polluting main process with stackprof require 'stackprof'