rack-mini-profiler: a speed badge for Rack apps that depends on Gemfile order
Profiler for your development and production Ruby rack apps.
At a glance
- What is it?
- Rack middleware that stamps a timing badge on every HTML page, with SQL, flamegraph and memory views behind it. Most of the work in adopting it is load order and patch conflicts.
- Who is it for?
- Use it if you run a Rails, Sinatra or plain Rack app on Ruby 3.2+ and want per-request SQL, flamegraph and memory numbers in the browser. Skip it if your database layer is outside the Mysql2, Postgres, Oracle and Mongoid3 list.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 97 days ago.
- What is it written in?
- Mainly Ruby, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 26, 2026, and from our analysis. They are not legal advice.
Star history
- MiniProfiler/rack-mini-profiler3,906 ★ · +3
| Repository | 2026-10-08 | 2026-11-26 |
|---|---|---|
| MiniProfiler/rack-mini-profiler | 3.9k | 3.9k |
3 Stars in the last 49 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
A speed badge on every HTML page, with two optional gems behind the rest
rack-mini-profiler is middleware. Once it is in the stack, every HTML response carries a speed badge. Three kinds of data sit behind that badge: database profiling, call-stack profiling that draws flame graphs showing time spent by gem, and memory profiling with per-request memory usage, GC stats and global allocation metrics. The project says it is designed to work both in production and in development.
Installation is one line in the Gemfile, and the project asks for Ruby 3.2 or newer:
gem 'rack-mini-profiler'The flame graphs and memory views are off until you add their libraries:
# For memory profiling
gem 'memory_profiler'
# For call-stack profiling flamegraphs
gem 'stackprof'Without memory_profiler there is no memory view, and without stackprof there is no flamegraph. Nothing warns you about the gap, so a missing tab usually means a missing gem. On Rails, including the gem is enough for development. Production use needs extra steps from the project's notes, and they are not reproduced here, so read them before you enable the badge for real users.
SQL timings disappear when the gem loads before pg or mysql
Database profiling works by patching. At load time rack-mini-profiler looks at which ORM and driver gems are already loaded and inserts instrumentation for them. The supported list is Mysql2, Postgres, Oracle (oracle_enhanced ~> 1.5.0) and Mongoid3, with fallback support to ActiveRecord. A driver outside that list gets no query statistics.
The consequence of ordering is blunt. If rack-mini-profiler is required above the `pg` or `mysql` gems in the Gemfile, no SQL shows up in the badge, and the page still renders normally. The declaration order that works:
gem 'pg'
gem 'mongoid'
gem 'rack-mini-profiler'To override the detection, set the environment variable `RACK_MINI_PROFILER_PATCH`. The project shows three forms:
export RACK_MINI_PROFILER_PATCH="pg,mongoid"
# or
export RACK_MINI_PROFILER_PATCH="false"
# initializers/rack_profiler.rb: SqlPatches.patch %w(mongo)A list of names forces those patches, the string false turns SQL patching off, and the initializer line calls `SqlPatches.patch` directly with the names you give it. The values shown are the only ones documented, so a driver that is not named in the list has no override path.
Version 2.0.0 stopped patching Rails and moved to ActiveSupport::Notifications
Before 2.0.0, Mini Profiler patched various Rails methods to collect numbers such as template rendering time. From 2.0.0 on, it patches no Rails methods by default and reads what it needs from `ActiveSupport::Notifications`. An upgrade from an older version can therefore change which timings appear.
Teams that depended on the old behaviour can keep the patches by requiring `enable_rails_patches`. The exact gem line depends on whether you load the gem manually.
If you want Mini Profiler to be required manually:
gem 'rack-mini-profiler', require: ['enable_rails_patches']If you do not want to require it manually:
gem 'rack-mini-profiler', require: ['enable_rails_patches', 'rack-mini-profiler']The two lines differ only in whether the string `'rack-mini-profiler'` is inside the require array. Picking the wrong one either loads the gem twice in intent or leaves it unloaded, so match the line to how your Gemfile already treats the gem. Nothing in the project's notes says how the patched timings differ from the notification-based ones, so compare a page before and after switching.
Three stack-level-too-deep errors, one cause: a method patched by alias and by prepend
Ruby cannot safely mix two patching styles on one method. When one gem patches a method with module prepend and another uses method aliasing, the call loops and raises `SystemStackError`. See the linked Ruby issue 11120 for the underlying behaviour. rack-mini-profiler applies its patches by method aliasing by default, so a second library that prepends to the same method triggers the loop. The fix is to apply all patches the same way, which means switching Mini Profiler to prepend.
Three cases are documented, each with its own require key. For `Net::HTTP#request`:
gem 'rack-mini-profiler', require: ['prepend_net_http_patch', 'rack-mini-profiler']For peek-mysql2 on Rails 5 or later:
gem 'rack-mini-profiler', require: ['prepend_mysql2_patch', 'rack-mini-profiler']For pg:
gem 'rack-mini-profiler', require: ['prepend_pg_patch', 'rack-mini-profiler']If your Gemfile already has `require: false`, drop the `'rack-mini-profiler'` string from the array, so the line becomes `require: ['prepend_net_http_patch']` or `require: ['prepend_pg_patch']`. On Rails before 5, peek-mysql2 hooks into the mysql2 gem differently and no change is needed. A conflicting patch from a library not named here has no documented key, so you would be working it out yourself.
Manual initialization needs require: false or the Railtie loads first
Some apps must start Mini Profiler after every other gem, or run code before it loads. The Gemfile line for that is:
gem 'rack-mini-profiler', require: falseThe `require: false` part is mandatory. Leave it out and the Railtie loads straight away, and a later attempt to initialize the gem by hand raises an exception. After that, a generator sets up development use:
bundle exec rails g rack_mini_profiler:installOutside Rails there is no generator. In a Rack::Builder app you require the gem and add one line to the stack:
require 'rack-mini-profiler'
home = lambda { |env|
[200, {'Content-Type' => 'text/html'}, ["<html><body>hello!</body></html>"]]
}
builder = Rack::Builder.new do
use Rack::MiniProfiler
map('/') { run home }
end
run builderSinatra is the same idea, with `use Rack::MiniProfiler` inside a `Sinatra::Base` subclass. The badge appears only on HTML responses, so the lambda above returns an html body on purpose. A JSON-only API gets no badge from this setup.
Hanami partials are invisible until you profile Partial#render yourself
Hanami needs the rack integration plus one manual profiling hook. Partial rendering is not measured on its own, so the project asks you to register `Hanami::View::Rendering::Partial#render` in config.ru:
# config.ru
require 'rack-mini-profiler'
Rack::MiniProfiler.profile_method(Hanami::View::Rendering::Partial, :render) { "Render partial #{@options[:partial]}" }
use Rack::MiniProfiler`profile_method` takes a class, a method name and a block that returns the label shown in the profile. The block here builds the label from the partial option. Skip the call and template time lands in the surrounding request with no breakdown per partial.
The same call is the general escape hatch for code the patches do not reach. Nothing else about Hanami is covered, so database patching for a Hanami app falls back to the same Gemfile order and `RACK_MINI_PROFILER_PATCH` rules as everywhere else. Two other places hold hand-set behaviour. The Net::HTTP patch is applied by default, and you may want to turn it off with one variable:
export RACK_MINI_PROFILER_PATCH_NET_HTTP="false"Set it when another library already wraps `Net::HTTP`, which is the case behind the stack-level errors above.
The repository asks for triage help, and its last tagged release is 4.0.0
The last push to the master branch was on 2026-08-21, and the repository is not archived. The most recent releases are 4.0.0 on 2025-06-10, 3.3.1 on 2025-04-13 and 3.3.0 on 2023-12-07. A release gap of that size matters if you are waiting on a fix that landed after 4.0.0, since you would have to point Bundler at the master branch.
The maintainers also say they need help. They have decided to restructure so that a central UI repository exists and each language implementation has its own, and they ask volunteers to help triage issues through CodeTriage. Contributors are asked to open an issue and report progress. The repository still holds a `test_old/` directory and a `website/` directory next to `lib/` and `spec/`, which suggests the restructure is not finished.
The license is MIT and the primary language is Ruby. Community links point to community.miniprofiler.com, a RailsCast episode, and Sam Saffron's 2012 announcement and 2013 flame graph posts. Those posts predate the Ruby 3.2 requirement by a decade, so read them for the idea, not for current setup steps.
Editorial conclusion
Use it if you run a Rails, Sinatra or plain Rack app on Ruby 3.2+ and want per-request SQL, flamegraph and memory numbers in the browser. Skip it if your database layer is outside the Mysql2, Postgres, Oracle and Mongoid3 list. Before anything else, load a page in development and confirm that SQL timings appear, because a wrong Gemfile order is the failure that gives no error.
Frequently asked questions
What is a memory profiler in rack-mini-profiler?
In rack-mini-profiler, memory profiling reports per-request memory usage, GC stats and global allocation metrics. It needs the optional memory_profiler gem in your Gemfile.
Why does rack-mini-profiler show no SQL queries?
The gem instruments pg and mysql only if they are already loaded, so requiring rack-mini-profiler too early in the Gemfile leaves SQL out. Declare the database gem first.
How do I turn off the Net::HTTP patch in rack-mini-profiler?
Set the environment variable RACK_MINI_PROFILER_PATCH_NET_HTTP to "false". This is the documented way to disable the patch.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/miniprofiler-rack-mini-profiler)Star history chart for your README
[](https://hysenlabs.com/projects/miniprofiler-rack-mini-profiler)Was this useful?