1
0
Fork 0
forked from OpenNeo/impress

Add mini profiler to each page

It shows up in development always, and if you're logged in as Me
Specifically in production!

I'm using this to poke at memory usage for pages that seem suspicious.
I don't know why our app reliably grows so large in RAM, but my hunch is
that maybe there are some pages that just use a truly large amount to
begin with - and I've learned Ruby doesn't release memory back after
it's GC'd, it just grows the process and keeps the free space to itself
in its own heap!

So I'm just eyeing pages that I know *can* have a lot going on, and
seeing what I find!
This commit is contained in:
Emi Matchu 2023-10-27 19:38:49 -07:00
parent 2d1443da4f
commit c496e33c37
7 changed files with 22 additions and 0 deletions

View file

@ -65,3 +65,8 @@ gem 'record_tag_helper', '~> 1.0', '>= 1.0.1'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '~> 1.16', require: false
# For investigating performance issues.
gem "rack-mini-profiler", "~> 3.1"
gem "memory_profiler", "~> 1.0"
gem "stackprof", "~> 0.2.25"

View file

@ -154,6 +154,7 @@ GEM
net-pop
net-smtp
marcel (1.0.2)
memory_profiler (1.0.1)
mime-types (3.4.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2023.0218.1)
@ -189,6 +190,8 @@ GEM
rack (2.2.8)
rack-attack (6.7.0)
rack (>= 1.0, < 4)
rack-mini-profiler (3.1.1)
rack (>= 1.2.0)
rack-session (1.0.1)
rack (< 3)
rack-test (2.1.0)
@ -273,6 +276,7 @@ GEM
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
stackprof (0.2.25)
stringio (3.0.8)
temple (0.8.2)
terser (1.1.17)
@ -314,11 +318,13 @@ DEPENDENCIES
httparty (~> 0.21.0)
jsbundling-rails (~> 1.1)
letter_opener (~> 1.8, >= 1.8.1)
memory_profiler (~> 1.0)
mysql2 (~> 0.5.5)
nokogiri (~> 1.15, >= 1.15.3)
parallel (~> 1.23)
puma (~> 6.3, >= 6.3.1)
rack-attack (~> 6.7)
rack-mini-profiler (~> 3.1)
rails (~> 7.1, >= 7.1.1)
rails-i18n (~> 7.0, >= 7.0.7)
rdiscount (~> 2.2, >= 2.2.7.1)
@ -328,6 +334,7 @@ DEPENDENCIES
sanitize (~> 6.0, >= 6.0.2)
sass-rails (~> 6.0)
sprockets (~> 4.2)
stackprof (~> 0.2.25)
terser (~> 1.1, >= 1.1.17)
web-console (~> 4.2)
will_paginate (~> 4.0)

View file

@ -13,6 +13,13 @@ class ApplicationController < ActionController::Base
before_action :save_return_to_path,
if: ->(c) { c.controller_name == 'sessions' && c.action_name == 'new' }
# Enable profiling tools if logged in as admin.
before_action do
if current_user && current_user.admin?
Rack::MiniProfiler.authorize_request
end
end
def authenticate_user!
redirect_to(new_auth_user_session_path) unless user_signed_in?
end

View file

@ -0,0 +1,3 @@
Rails.configuration.to_prepare do
Rack::MiniProfiler.config.enable_advanced_debugging_tools = true
end

BIN
vendor/cache/memory_profiler-1.0.1.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/stackprof-0.2.25.gem vendored Normal file

Binary file not shown.