From db73adf551740f195e5d479ee88ce1a663b309a5 Mon Sep 17 00:00:00 2001 From: "Jason R. Clark" Date: Tue, 17 Jun 2014 10:19:08 -0700 Subject: [PATCH] Respect existing GC::Profiler.enabled? state Currently peek-gc will enable and disable GC::Profiler before every request. This has unfortunate side-effects if anyone else has set `GC::Profiler.enable` and assumes the setting won't be changed under them. newrelic_rpm was making this assumption (which we're fixing in the upcoming release), but I thought others might benefit from being a little more cautious here. Note that there's still an issue here related to different conflicting code calling `GC::Profiler.clear`, but I don't have a good solution to that. At the very least preserving the existing setting on this seemed less likely to cause suprises. --- lib/peek/views/gc.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/peek/views/gc.rb b/lib/peek/views/gc.rb index 1efcd63..5bdd791 100644 --- a/lib/peek/views/gc.rb +++ b/lib/peek/views/gc.rb @@ -51,13 +51,14 @@ def parse_result def setup_subscribers # Reset each counter when a new request starts before_request do |name, start, finish, id, payload| - ::GC::Profiler.enable + @previously_enabled = ::GC::Profiler.enabled? + ::GC::Profiler.enable unless @previously_enabled ::GC::Profiler.clear end # Once the action is finished subscribe 'process_action.action_controller' do |name, start, finish, id, payload| - ::GC::Profiler.disable + ::GC::Profiler.disable unless @previously_enabled ::GC::Profiler.clear end end