55

I'm using rack mini profiler in rails just fine, but during some coding sessions especially where I'm working on a lot of different client side code, it gets in the way. (mainly in my client side debugging tools network graphs, etc.)

I'm trying to turn it off with a before filter, that also serves to see if the user is authorized to see the profile anyway, but "deauthorize" doesn't seem to do anything for me. Here's my code called as a before filter:

def miniprofiler  
 off = true
 if off || !current_user
  Rack::MiniProfiler.deauthorize_request
  return
 elsif current_user.role_symbols.include?(:view_page_profiles)    
  Rack::MiniProfiler.authorize_request
  return
 end
 Rack::MiniProfiler.deauthorize_request
end

I also know there is a setting "Rack::MiniProfiler.config.authorization_mode" but I can't find docs on what the possible settings are, and not seeing it used in the code? Right now its telling me :allow_all, but :allow_none doesn't do anything either.

Even if I can just temporarily set a value in the dev environment file and restart the server, that would serve my purposes.

3 Answers 3

104

Get latest and type:

http://mysite.com?pp=disable

When you are done type

http://mysite.com?pp=enable

See ?pp=help for all the options:

Append the following to your query string:

  pp=help : display this screen
  pp=env : display the rack environment
  pp=skip : skip mini profiler for this request
  pp=no-backtrace : don't collect stack traces from all the SQL executed (sticky, use pp=normal-backtrace to enable)
  pp=normal-backtrace (*) : collect stack traces from all the SQL executed and filter normally
  pp=full-backtrace : enable full backtraces for SQL executed (use pp=normal-backtrace to disable) 
  pp=sample : sample stack traces and return a report isolating heavy usage (experimental works best with the stacktrace gem)
  pp=disable : disable profiling for this session 
  pp=enable : enable profiling for this session (if previously disabled)
  pp=profile-gc: perform gc profiling on this request, analyzes ObjectSpace generated by request (ruby 1.9.3 only)
  pp=profile-gc-time: perform built-in gc profiling on this request (ruby 1.9.3 only)
3
  • @DaveSanders no worries, feel free to make any feature requests etc on community.miniprofiler.com Sep 21, 2012 at 4:28
  • @SamSaffron Is there a way to disable it initially until I do pp=enable explicitly?
    – mxgrn
    Oct 1, 2013 at 11:05
  • @SamSaffron I am trying to build a switch on my front end that will either disable or enable MiniProfiler. How can I detect if it is currently disabled or enabled?
    – Tintin81
    Jun 18, 2014 at 15:36
51

You can also use Alt + p to toggle on Windows/Linux and Option + p on MacOS.

6
  • 1
    Particularly useful, when the start_hidden option is used!!
    – Eero
    Feb 1, 2016 at 16:13
  • Super useful answer.
    – csalmeida
    Dec 28, 2020 at 0:00
  • 1
    Thanks for this. For those on Mac, it's option + p
    – dace
    May 15, 2022 at 11:17
  • Cool, thanks, I updated the answer to include that.
    – lobati
    May 16, 2022 at 17:29
  • this made my chrome window freeze May 19, 2022 at 13:32
4

If you want the profiler to be disabled initially, and then activate on demand... add a pre-authorize callback in an initializer file like:

Rack::MiniProfiler.config.pre_authorize_cb = lambda {|env| ENV['RACK_MINI_PROFILER'] == 'on'}

then in your application controller, add a before_filter that looks for the pp param

before_filter :activate_profiler
def activate_profiler
  ENV['RACK_MINI_PROFILER'] = 'on' if params['pp']
  ENV['RACK_MINI_PROFILER'] = 'off' if params['pp'] == 'disabled'
end

your environment will not have RACK_MINI_PROFILER set initially, but if you want to turn it on, you can tack ?pp=enabled onto your url. Then you can disable again later (the pp=disabled will only turn it off for the current session, but setting the ENV variable to off will kill it entirely until you force it back on).

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.