RailsMemoryProfiler

CI Gem Version Gem Downloads Ruby Rails codecov

Per-request memory allocation reports with a mountable dashboard UI. Fills the gap between the memory_profiler gem (terminal-only output, manual block wrapping) and having nowhere useful to browse results in a Rails app.

A Rack middleware captures object allocations for every request using GC.stat diffs. Results are stored in a thread-safe ring buffer and served through a mountable engine with a sortable, filterable dashboard.


Table of Contents


Installation

Add to your Gemfile:

gem "rails_memory_profiler", group: :development

Run the install generator:

bundle exec rails generate rails_memory_profiler:install

This creates config/initializers/rails_memory_profiler.rb with all options documented and prints mount instructions.

Mount the dashboard in config/routes.rb:

mount RailsMemoryProfiler::Engine, at: "/rails/memory"

Then visit /rails/memory/reports to see per-request allocation data.

↑ Back to top


Dashboard

The index view shows a sortable table of captured requests. Click any row to open the detail view for that request.

Columns: Path, Controller#Action, Allocated Objects (colour-coded), Retained Objects, Duration (ms), Recorded At.

Use the controller filter to narrow the table down to a specific controller without a page reload.

↑ Back to top


Configuration

All options and their defaults:

Option Default Description
enabled true in development Enable/disable request profiling
sample_rate 1 Profile every Nth request (1 = every request)
store_size 100 Max reports in the ring buffer; oldest are evicted when full
dashboard_enabled true in development Enable the dashboard endpoint
min_allocated_objects 0 Skip requests that allocate fewer objects than this
ignore_paths [] Paths to skip — strings (prefix) or regexes
ignore_controllers [] Controller names to skip (e.g. "rails/health")

Example:

RailsMemoryProfiler.configure do |config|
  config.sample_rate           = 5
  config.min_allocated_objects = 1_000
  config.ignore_paths          = ["/rails/memory", "/up"]
  config.ignore_controllers    = ["rails/health"]
end

↑ Back to top


Contributing

Bug reports and pull requests are welcome on GitHub.

↑ Back to top


License

The gem is available as open source under the terms of the MIT License.

↑ Back to top