{"id":13395118,"url":"https://github.com/bhb/rack-perftools_profiler","last_synced_at":"2025-05-16T15:07:24.449Z","repository":{"id":875821,"uuid":"618085","full_name":"bhb/rack-perftools_profiler","owner":"bhb","description":"Middleware for profiling Rack-compatible apps using perftools.rb","archived":false,"fork":false,"pushed_at":"2022-02-02T08:53:13.000Z","size":118,"stargazers_count":330,"open_issues_count":4,"forks_count":28,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-05-14T11:28:35.469Z","etag":null,"topics":[],"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/bhb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-04-19T16:41:07.000Z","updated_at":"2024-10-16T04:59:23.000Z","dependencies_parsed_at":"2022-07-30T22:07:57.508Z","dependency_job_id":null,"html_url":"https://github.com/bhb/rack-perftools_profiler","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhb%2Frack-perftools_profiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhb%2Frack-perftools_profiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhb%2Frack-perftools_profiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhb%2Frack-perftools_profiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bhb","download_url":"https://codeload.github.com/bhb/rack-perftools_profiler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254227581,"owners_count":22035664,"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":[],"created_at":"2024-07-30T17:01:42.630Z","updated_at":"2025-05-16T15:07:24.417Z","avatar_url":"https://github.com/bhb.png","language":"Ruby","funding_links":[],"categories":["Ruby","Middlewares"],"sub_categories":[],"readme":"# DEPRECATED\n\nAccording to [this perftools.rb issue](https://github.com/tmm1/perftools.rb/issues/80), \"perftools isn't working or needed on rubies newer than 2.1. You should use stackprof or rblineprof\"\n\n\n# Rack::PerftoolsProfiler\n\nMiddleware for profiling Rack-compatible apps using [perftools.rb](http://github.com/tmm1/perftools.rb)\n\n## Quick start\n\nAssuming your application is using Rails 3 (and you have installed the requirements in the next section), add the following code:\n\nGemfile:\n\n    gem 'rack-perftools_profiler', :require =\u003e 'rack/perftools_profiler'\n\nconfig/application.rb:\n\n    config.middleware.use ::Rack::PerftoolsProfiler, :default_printer =\u003e 'gif', :bundler =\u003e true\n\nThe visit the page you want to profile:\n\n    http://localhost:3000/some_action?profile=true\n\n## Requirements\n\nYou'll need graphviz to generate call graphs using dot (for the GIF printer):\n\n    sudo port install graphviz     # OS X\n    brew install graphviz          # Homebrew\n    sudo apt-get install graphviz  # Debian/Ubuntu\n\nYou'll need ps2pdf to generate PDFs (On OS X, ps2pdf comes is installed as part of Ghostscript)\n\n    sudo port install ghostscript    # OSX\n    brew install ghostscript         # Homebrew\n    sudo apt-get install ghostscript # Debian/Ubuntu\n\n## Configuration\n\nInstall the gem\n\n    gem install rack-perftools_profiler\n\nInclude the middleware\n\n    require 'rack/perftools_profiler'\n\nFor Rails 2, add the following to `config/environment.rb`\n\n    config.gem 'rack-perftools_profiler', :lib =\u003e 'rack/perftools_profiler'\n    require 'rack/perftools_profiler'\n    config.middleware.use ::Rack::PerftoolsProfiler, :default_printer =\u003e 'gif'\n\nFor Rails 3, add the following to your Gemfile\n\n    gem 'rack-perftools_profiler', :require =\u003e 'rack/perftools_profiler'\n\nand add the following to config/application.rb\n\n    config.middleware.use ::Rack::PerftoolsProfiler, :default_printer =\u003e 'gif', :bundler =\u003e true\n\nFor Sinatra, call `use` inside a configure block, like so:\n\n    configure do\n      use ::Rack::PerftoolsProfiler, :default_printer =\u003e 'gif'\n    end\n\nFor Rack::Builder, call `use` inside the Builder constructor block\n\n    Rack::Builder.new do\n      use ::Rack::PerftoolsProfiler, :default_printer =\u003e 'gif'\n    end\n\n## Options\n\n* `:default_printer` - can be set to 'text', 'gif', or 'pdf'. Default is 'text'.\n* `:mode`            - can be set to 'cputime', 'methods', 'objects', 'walltime'. Default is :cputime. See the 'Profiling Modes' section below.\n* `:frequency`       - in :cputime mode, the number of times per second the app will be sampled. Default is 100 (times/sec).\n* `:bundler`         - run the profiler binary using 'bundle' if set to true. Default is false.\n* `:gemfile_dir`     - directory with Gemfile. Default is the current directory.\n* `:password`        - password-protect profiling.\n\n## Usage\n\nThere are two ways to profile your app: with a single request or with multiple requests.\n\nTo profile with a single request, visit the URL you want to profile, but add the `profile` and (optionally) the `times` GET params (which will rerun the action the specified number of times).\n\nExample:\n\n    curl http://localhost:3000/foobar?profile=true\u0026times=3\n\nNote that this will change the status, body, and headers of the response (you'll get\nback the profiling data, NOT the original response).\n\nYou can also profile your application using multiple requests. When you profile using this method, all responses are normal. You must visit `__stop__`  to complete profiling and then you can view the profiling data by visiting `__data__`.\n\nExample:\n\n    curl http://localhost:3000/__start__\n    curl http://localhost:3000/foobar\n    curl http://localhost:3000/foobaz\n    curl http://localhost:3000/__stop__\n    curl http://localhost:3000/__data__\n\n## Profiling Data Options\n\nRegardless of how you profile your application, you can add additional params to change how the\ndata is displayed. When using a single request, these params are just added to the URL being profiled.\nWhen using multiple requests, they are added to the `__data__` URL.\n\n* printer - overrides the default_printer option (see above)\n* ignore  - a regular expression of the area of code to ignore\n* focus   - a regular expression of the area of code to solely focus on.\n\n(for 'ignore' and 'focus', please see http://google-perftools.googlecode.com/svn/trunk/doc/cpuprofile.html#pprof\nfor more details)\n\n## Profiling Modes\n\nperftools.rb (and therefore, the Rack middleware) can be put into three different profiling modes.\n\n* CPU time mode            - Reports how many CPU cycles are spent in each section of code. This is the default and can be enabled by setting `:mode =\u003e :cputime`\n* Method call mode         - Report how many method calls are made inside each method. Enable by setting `:mode =\u003e :methods`\n* Object allocation mode   - Reports the percentage of object allocations performed in each section of code. Enable by setting `:mode =\u003e :objects`\n* Wall time mode           - Reports the amount of time (as in, wall clock time) spent in each section of code. Enable by setting `:mode =\u003e :walltime`\n\nFor example, consider the following Sinatra application:\n\n    require 'sinatra'\n    require 'rack/perftools_profiler'\n\n    configure do\n      use ::Rack::PerftoolsProfiler, :default_printer =\u003e 'gif', :mode =\u003e :cputime\n    end\n\n    get \"/slow\" do\n      sleep(3)\n      \"hello\"\n    end\n\nIn the default mode, there will be no profiling data for the 'slow' route, because it uses few CPU cycles (You'll see the message 'No nodes to print').\n\nIf you change the mode to `:walltime`, you'll get profiling data, since the call to `sleep` causes the code to spend several seconds of wall time in the block.\n\n## Overriding the Profiling mode\n\nYou can also switch the profiling mode on a per-request basis, but ONLY if you are switching to 'methods' or 'objects' mode. Due to the implementation of perftools.rb, it is NOT possible to switch to 'walltime' or 'cputime' modes.\n\nTo switch to another mode, provide the 'mode' option. When profiling with a single request, add the option to the URL profiled:\n\n    curl http://localhost:3000/foobar?profile=true\u0026mode=objects\n\nWhen profiling using multiple requests, add the option when visiting `__start__` :\n\n    curl http://localhost:3000/__start__?mode=objects\n\nIf the 'mode' option is omitted, the middleware will default to the mode specified at configuration.\n\n## Profiling in production\n\nIt is recommended that you always profile your application in the 'production' environment (using `rails server -e production` or an equivalent), since there can be important differences between 'development' and 'production' that may affect performance.\n\nHowever, it is recommended that you profile your application on a development or staging machine rather than on a production machine. This is because profiling with multiple requests *will not* work if your app is running in multiple Ruby server processes.\n\nProfiling a single request will work if there are multiple server processes. If your staging machine is publicly accessible, you can password-protect single-request profiling by using the `:password` option and then using the `profile` GET parameter to provide the password:\n\n    curl http://localhost:3000/foobar?profile=PASSWORD\n\n## Changing behavior with environment variables\n\nThe mode and frequency settings are enabled by setting environment variables. Some of these environment variables must be set before 'perftools' is required. If you only require 'rack/perftools_profiler', it will do the right thing (require 'perftools' after setting the environment variables).\n\nIf you need to require 'perftools' before 'rack/perftools_profiler' (or you have other problems changing the mode or frequency), try using these environment variables yourself.\n\nSetting the frequency:\n\n    CPUPROFILE_FREQUENCY=500 ruby your_app.rb\n\nSetting the mode to 'wall time'\n\n    CPUPROFILE_REALTIME=1 ruby your_app.rb\n\nSetting the mode to 'object allocation'\n\n    CPUPROFILE_OBJECTS=1 ruby your_app.rb\n\n## Acknowledgments\n\nA huge thanks to Aman Gupta for the awesome perftools.rb gem.\n\nThe basic idea and initial implementation of the middleware was heavily influenced by Rack::Profiler from rack-contrib.\n\n## Notes on bugs\n\nThis project depends on the awesome perftools.rb gem. Before submitting a bug, please determine if the bug is with perftools.rb or with this middleware. For instance, if you are having a problem with installation, make sure `gem install perftools.rb` works. If it does not, please submit a bug report [here](https://github.com/tmm1/perftools.rb/issues).\n\n## Note on Patches/Pull Requests\n\n* Fork the project.\n* Make your feature addition or bug fix.\n* Add tests for it. This is important so I don't break it in a future version unintentionally.\n* Commit, do not mess with rakefile, version, or history (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull).\n* Send me a pull request. Bonus points for topic branches.\n\n## Copyright\n\nCopyright (c) 2010-2018 Ben Brinckerhoff. See LICENSE for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbhb%2Frack-perftools_profiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbhb%2Frack-perftools_profiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbhb%2Frack-perftools_profiler/lists"}