{"id":13878844,"url":"https://github.com/hschne/rails-mini-profiler","last_synced_at":"2025-10-04T21:31:13.571Z","repository":{"id":37801742,"uuid":"360794368","full_name":"hschne/rails-mini-profiler","owner":"hschne","description":"Performance profiling for Rails, made simple 🦔","archived":false,"fork":false,"pushed_at":"2024-07-27T16:13:35.000Z","size":4154,"stargazers_count":411,"open_issues_count":17,"forks_count":22,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-09-25T13:14:12.625Z","etag":null,"topics":["performance","profiling","rails","ruby","ruby-on-rails","rubygems"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hschne.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-23T07:05:43.000Z","updated_at":"2024-09-21T12:08:03.000Z","dependencies_parsed_at":"2024-03-18T12:59:10.603Z","dependency_job_id":"a71dec71-0066-4c84-beca-db6957438f69","html_url":"https://github.com/hschne/rails-mini-profiler","commit_stats":{"total_commits":379,"total_committers":10,"mean_commits":37.9,"dds":0.3192612137203166,"last_synced_commit":"b6d7c62459d6b95add831464ad3fefc997b8c239"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hschne%2Frails-mini-profiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hschne%2Frails-mini-profiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hschne%2Frails-mini-profiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hschne%2Frails-mini-profiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hschne","download_url":"https://codeload.github.com/hschne/rails-mini-profiler/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219876760,"owners_count":16554786,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["performance","profiling","rails","ruby","ruby-on-rails","rubygems"],"created_at":"2024-08-06T08:02:01.734Z","updated_at":"2025-10-04T21:31:13.564Z","avatar_url":"https://github.com/hschne.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n# Rails Mini Profiler\n\n\u003cimg alt=\"logo\" src=\"docs/images/logo.png\" width=\"300px\" height=\"auto\"\u003e\n\n### Performance profiling for Rails, made simple.\n\n[![Gem Version](https://badge.fury.io/rb/rails_mini_profiler.svg)](https://badge.fury.io/rb/rails_mini_profiler)\n[![Main](https://github.com/hschne/rails-mini-profiler/actions/workflows/main.yml/badge.svg)](https://github.com/hschne/rails-mini-profiler/actions/workflows/main.yml)\n[![License](https://img.shields.io/github/license/hschne/rails-mini-profiler)](https://img.shields.io/github/license/hschne/rails-mini-profiler)\n\n[![Maintainability](https://api.codeclimate.com/v1/badges/1fcc2f4d01ab5bf7a260/maintainability)](https://codeclimate.com/github/hschne/rails-mini-profiler/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/1fcc2f4d01ab5bf7a260/test_coverage)](https://codeclimate.com/github/hschne/rails-mini-profiler/test_coverage)\n\n\u003c/div\u003e\n\n## What's this?\n\nRails Mini Profiler is an easy-to-use performance profiler for your Rails applications. It is heavily inspired by [Rack Mini Profiler](https://github.com/MiniProfiler/rack-mini-profiler) and other APM tools. To find out how it stacks up against those check out [Why Rails Mini Profiler](#why-rails-mini-profiler)?\n\nTo see it in action view the preview below:\n\n\u003cdiv align=\"center\"\u003e\n\n[![Rails Mini Profiler Preview](http://img.youtube.com/vi/fSR8fCcsO8Q/0.jpg)](https://www.youtube.com/watch?v=fSR8fCcsO8Q)\n\n\u003c/div\u003e\n\n## Getting Started\n\nAdd Rails Mini Profiler to your Gemfile:\n\n```ruby\ngem 'rails_mini_profiler'\n```\n\nInstall the gem and run the installer:\n\n```bash\nbundle install\nrails rails_mini_profiler:install\n```\n\nInspect the generated migration in `db/migrate` and run it:\n\n```\nrails db:migrate\n```\n\nStart your Rails application and perform some requests. You can either click the little hedgehog 🦔 on the top\nleft or navigate to `/rails_mini_profiler` to view collected performance metrics.\n\n## Usage\n\nRails Mini Profiler provides detailed information about your requests to help you figure out why certain requests perform poorly.\n\nInstalling it will generate a new initializer `config/initializers/rails_mini_profiler.rb` and add a new\nroute:\n\n```ruby\n# routes.rb\nRails.application.routes.draw do\n  mount RailsMiniProfiler::Engine =\u003e '/rails_mini_profiler'\nend\n```\n\nOnce you perform requests against your applications you can inspect them using that route, or by clicking the badge on the\ntop right that is injected into your pages.\n\n### Request Overview\n\n![overview](docs/images/overview.png)\n\nRequests to your application will be profiled automatically. You can view and search all stored requests by navigating to `yourapp/rails_mini_profiler/profiled_requests`.\n\n### Request Details\n\n\u003cp align=\"center\"\u003e\n  \u003cimg alt=\"Light\" src=\"docs/images/trace.png\" width=\"45%\"\u003e\n\u0026nbsp; \u0026nbsp; \u0026nbsp; \u0026nbsp;\n  \u003cimg alt=\"Dark\" src=\"docs/images/trace-details.png\" width=\"45%\"\u003e\n\u003c/p\u003e\n\nThis view shows you how your requests spend their time. How much of it is spent in the DB, how much in rendering views?\nMay can filter and clicking on individual traces to gain deeper insights and see detailed information.\n\n### Flamegraphs\n\nRails Mini Profiler automatically records Flamegraphs for profiled requests. To enable this feature, add [Stackprof](https://github.com/tmm1/stackprof)\nto your Gemfile:\n\n```ruby\ngem 'stackprof'\n```\n\nFor convenience, Flamegraphs are recorded for every request. This may incur a significant performance penalty. To change the default behavior see [Configuration](#Configuration).\n\nFlamegraphs are rendered using [Speedscope](https://github.com/jlfwong/speedscope). See [Troubleshooting](#Troubleshooting) if Flamegraphs are not rendering correctly.\n\n## Configuration\n\nRails Mini Profiler provides a wide array of configuration options. You can find details below. For an example configuration check `initializers/rails_mini_profiler.rb` (or [the template file](https://github.com/hschne/rails-mini-profiler/blob/main/lib/generators/rails_mini_profiler/templates/rails_mini_profiler.rb.erb)).\n\n| Name                     | Default                      | Description                                                                 |\n| ------------------------ | ---------------------------- | --------------------------------------------------------------------------- |\n| `enabled`                | `true` (dev)/ `false` (prod) | Whether or not RMP is enabled                                               |\n| `flamegraph_enabled`     | `true`                       | Should flamegraphs be recorded automatically?                               |\n| `flamegraph_sample_rate` | `0.5`                        | The flamegraph sample rate. How many snapshots per millisecond are created. |\n| `skip_paths`             | `[]`                         | An array of request paths that should not be profiled. Regex allowed.       |\n| `storage`                | `Storage.new`                | Storage configuration. See [Storage](#Storage).                             |\n| `ui`                     | `UserInterface.new`          | UI configuration. See [UI](#UI).                                            |\n| `user_provider`          | `Rack::Request.new(env).ip`  | How to identify users. See [Authorization](#Authorization)                  |\n\n### Storage\n\nRails Mini Profiler stores profiling information in your database per default. You can configure various details of how\ntraces and requests are stored.\n\n| Name                      | Default                 | Description                                                                                               |\n| ------------------------- | ----------------------- | --------------------------------------------------------------------------------------------------------- |\n| `database`                | `nil`                   | Set a custom database to be used for storing profiler information. Uses `connect_to` for profiler records |\n| `profiled_requests_table` | `rmp_profiled_requests` | The table to be used to store profiled requests.                                                          |\n| `flamegraphs_table`       | `rmp_flamegraphs`       | The table to be used to store flamegraphs.                                                                |\n| `traces_table`            | `rmp_traces`            | The table to be used to store traces.                                                                     |\n\nRails Mini Profiler does not offer an automatic way to clean up old profiling information. It is recommended you add a sweeper job to clean up old profiled requests periodically (e.g. using [clockwork](https://github.com/adamwiggins/clockwork). For example, with ActiveJob:\n\n```ruby\n# Clockwork\nevery(1.month, 'purge rails mini profiler') do\n    ProfiledRequestCleanupJob.perform_later\nend\n\n# ActiveJob\nclass ProfiledRequestCleanupJob \u003c ApplicationJob\n  queue_as :default\n\n  def perform\n    RailsMiniProfiler::ProfiledRequest.where('created_at \u003c ?', 1.month.ago).destroy_all\n  end\nend\n```\n\n### UI\n\nRails Mini Profiler allows you to configure various UI features.\n\n| Name              | Default                 | Description                                                                                     |\n| ----------------- | ----------------------- | ----------------------------------------------------------------------------------------------- |\n| `badge_enabled`   | `true`                  | Should the hedgehog 🦔 badge be injected into pages?                                            |\n| `badge_position`  | `'top-left'`            | Where to display the badge. Options are `'top-left', 'top-right', 'bottom-left, 'bottom-right'` |\n| `base_controller` | `ApplicationController` | Which controller UI controllers should inherit from.                                            |\n| `page_size`       | `25`                    | The page size for lists shown in the UI.                                                        |\n\n### Request Configuration\n\nYou may override static configuration on a per-request by attaching request parameters. For example, `https://myapp.com/api/mydata?rmp_flamegraph=false`\n\n| Name             | Description                                                                                  |\n| ---------------- | -------------------------------------------------------------------------------------------- |\n| `rmp_flamegraph` | Overrides `flamegraph_enabled` If set to `true` will redirect to the flamegraph immediately. |\n\n### Authorization\n\nProfiling information is segregated by user ID. That means users cannot see each other's profiled requests. Per default, individual users are identified by their IP adress.\n\nYou may change this by setting a custom user provider:\n\n```ruby\nconfig.user_provider = proc { |env| Rack::Request.new(env).ip }\n```\n\nYou may also explicitly set the user by modifying your application controller (or the controller you have configured as UI base controller):\n\n```ruby\nclass ApplicationController \u003c ActionController::Base\n  before_action do\n    RailsMiniProfiler::User.authorize(current_user.id)\n  end\nend\n```\n\n`ApplicationController` is used as the default base class for UI controllers. To change it, you may use `configuration.ui.base_controller`.\n\n### Profiling in Production\n\nRails Mini Profiler is not intended for performance monitoring. There are other tools for that ( [RorVsWild](https://www.rorvswild.com/), [AppSignal](https://www.appsignal.com/), [Skylight](https://www.skylight.io/),\n[New Relic](https://newrelic.com/), [DataDog](https://www.datadoghq.com/)...). But you can still use RMP in production to profile specific requests.\n\nPer default, _no requests will be profiled_ in production, and the Rails Mini Profiler UI will be inaccessible.\n\n#### Enabling Profiling\n\nSince profiling impacts performance, it is recommended that you limit which requests are being profiled:\n\n```ruby\nRailsMiniProfiler.configure do |config|\n  config.enabled = proc { |env| env.headers['RMP_ENABLED'].present? }\nend\n```\n\n#### Authorizing Users\n\nYou must explicitly authorize profiling for users, as well as authenticate them to the UI:\n\n```ruby\nclass ApplicationController \u003c ActionController::Base\n  before_action do\n    RailsMiniProfiler::User.authorize(current_user.id) # Requests by this user will now be profiled, and they get access to the UI\n  end\nend\n```\n\n## Why Rails Mini Profiler?\n\nImproving the performance of any application is a 3-step process. You have to answer these questions:\n\n1. What is slow?\n2. Why is it slow?\n3. Did my solution fix the slowness?\n\nI'm a huge fan of [rack-mini-profiler](https://github.com/MiniProfiler/rack-mini-profiler), and APM tools such as [Skylight](https://www.skylight.io/) or [Scout APM](https://scoutapm.com). Each of these tools has its own areas where it succeeds.\n\nAPM tools are excellent for profiling your app in production - aka. they show you what is slow - and offer _some_ hints as to what causes the slowdown. `rack-mini-profiler` can do some sampling in production, but excels at providing detailed insight into _why_ something is slow by providing Flamegraphs and detailed query information.\n\nRails Mini Profiler improves upon `rack-mini-profiler` in the latter regard. It is a developer tool, rather than a monitoring tool, and sets a big focus on developer experience. Simply put, it aims to be the best tool available to help you figure out _why_ specific requests are slow.\n\nAs such, compared to `rack-mini-profiler`, it does not support non-Rails apps (e.g. Sinatra) or production sampling, but provides a much better user experience and better support for API-only applications.\n\n## Troubleshooting\n\n### Upgrading\n\nRails Mini Profiler is in early development. As such, breaking changes may still be introduced on a regular basis. While Rails Mini Profiler is in pre-release we do not offer upgrade migrations.\n\nIf an upgrade to Rails Mini Profiler breaks your application, we recommend that you clean house and start over. Re-run the initializer and overwrite existing files:\n\n```bash\nrails rails_mini_profiler:install\n```\n\nIf only the DB schema is out of date, drop the offending tables and re-run migrations for the latest version:\n\n```\nrails rails_mini_profiler:install:migrations\nrails db:migrate\n```\n\n### Support for API-Only Apps\n\nRails Mini Profiler supports API-only apps, but you have to make some small adjustments to use it. Modify `application.rb`:\n\n```ruby\nmodule ApiOnly\n  class Application \u003c Rails::Application\n\n    config.api_only = true # Either set this to false\n    config.middleware.use ActionDispatch::Flash # Or add this\n  end\nend\n```\n\n### No Flamegraphs are being recored?\n\nMake sure you have added [StackProf](https://github.com/tmm1/stackprof) to your Gemfile.\n\n```ruby\ngem 'stackprof'\n```\n\n### Flamegraphs are not rendering?\n\nFlamegraphs are loaded into [Speedscope](https://github.com/jlfwong/speedscope) using an Iframe and URI Encoded blobs (see [source](https://github.com/hschne/rails-mini-profiler/blob/main/app/views/rails_mini_profiler/flamegraphs/show.html.erb))\nIf your browser gives you warnings about blocking content due to CSP you _must_ enable `blob` as default source:\n\n```ruby\nRails.application.config.content_security_policy do |policy|\n    policy.default_src :self, :blob\n    ...\nend\n```\n\n### Some requests have no Flamegraphs attached?\n\n[StackProf](https://github.com/tmm1/stackprof), which is used for recording Flamegraphs, does not work on concurrent requests.\nBecause of this, concurrent requests may skip recording a Flamegraph.\n\nIt is recommended that you resend _only_ the request you wish to build a Flamegraph for.\n\n## Credit\n\nThis project was heavily inspired by projects such as [rack-mini-profiler](https://github.com/MiniProfiler/rack-mini-profiler) and\n[rack-profiler](https://github.com/dawanda/rack-profiler). [Skylight](https://www.skylight.io/) was also a huge influence.\n\n[Lena Schnedlitz](https://github.com/LenaSchnedlitz) designed the Logo and provided great support. Without her supreme CSS skills this project would not have been possible 🙌\n\n## Contributing\n\nSee [Contributing](CONTRIBUTING.md)\n\n## License\n\nThis gem is available as open source under the terms of the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhschne%2Frails-mini-profiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhschne%2Frails-mini-profiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhschne%2Frails-mini-profiler/lists"}