{"id":13878100,"url":"https://github.com/jhawthorn/vernier","last_synced_at":"2025-05-13T22:02:28.561Z","repository":{"id":57676065,"uuid":"485962904","full_name":"jhawthorn/vernier","owner":"jhawthorn","description":"📏 next generation CRuby profiler","archived":false,"fork":false,"pushed_at":"2025-05-07T13:42:15.000Z","size":570,"stargazers_count":983,"open_issues_count":20,"forks_count":24,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-05-07T14:47:39.422Z","etag":null,"topics":["cpu-profiler","flamegraph","memory-profiler","profiler","ruby"],"latest_commit_sha":null,"homepage":"https://vernier.prof/","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/jhawthorn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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,"zenodo":null}},"created_at":"2022-04-26T22:10:32.000Z","updated_at":"2025-05-07T13:42:21.000Z","dependencies_parsed_at":"2023-11-13T23:25:41.988Z","dependency_job_id":"c4ca515a-8278-4d4c-a30e-ba8d2f7bbad7","html_url":"https://github.com/jhawthorn/vernier","commit_stats":{"total_commits":394,"total_committers":16,"mean_commits":24.625,"dds":"0.20558375634517767","last_synced_commit":"243c9d40ebc597467b2e7cb1f9d45dc40b273007"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhawthorn%2Fvernier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhawthorn%2Fvernier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhawthorn%2Fvernier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhawthorn%2Fvernier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jhawthorn","download_url":"https://codeload.github.com/jhawthorn/vernier/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254036807,"owners_count":22003652,"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":["cpu-profiler","flamegraph","memory-profiler","profiler","ruby"],"created_at":"2024-08-06T08:01:39.829Z","updated_at":"2025-05-13T22:02:28.540Z","avatar_url":"https://github.com/jhawthorn.png","language":"Ruby","funding_links":[],"categories":["Ruby","Ruby specific"],"sub_categories":[],"readme":"# Vernier\n\nNext-generation Ruby 3.2.1+ sampling profiler. Tracks multiple threads, GVL activity, GC pauses, idle time, and more.\n\n\u003cimg width=\"500\" alt=\"Screenshot 2024-02-29 at 22 47 43\" src=\"https://github.com/jhawthorn/vernier/assets/131752/aa995a41-d74f-405f-8ada-2522dd72c2c8\"\u003e\n\n## Demos and Examples\n\n[Livestreamed demo: Pairin' with Aaron (YouTube)](https://www.youtube.com/watch?v=9nvX3OHykGQ#t=27m40)\n\n[Overview at RubyKaigi 2024 (YouTube)](https://youtu.be/QSjN-H4hGsM)\n\nSidekiq jobs from Mastodon (time, threaded)\n: https://share.firefox.dev/44jZRf3\n\nPuma web requests from Mastodon (time, threaded)\n: https://share.firefox.dev/48FOTnF\n\nRails benchmark - lobste.rs (time)\n: https://share.firefox.dev/3Ld89id\n\n`require \"irb\"` (retained memory)\n: https://share.firefox.dev/3DhLsFa\n\n## Installation\n\nVernier requires Ruby version 3.2.1 or greater and a Unix-like operating system.\n\n```ruby\ngem \"vernier\", \"~\u003e 1.0\"\n```\n\n## Usage\n\nThe output can be viewed in the web app at https://vernier.prof, locally using the [`profile-viewer` gem](https://github.com/tenderlove/profiler/tree/ruby) (both lightly customized versions of the firefox profiler frontend which profiles are compatible with), or by using the `vernier view` command in the CLI.\n\n- **Flame Graph**: Shows proportionally how much time is spent within particular stack frames. Frames are grouped together, which means that x-axis / left-to-right order is not meaningful.\n- **Stack Chart**: Shows the stack at each sample with the x-axis representing time and can be read left-to-right.\n\n### Time and Allocations\n\n#### Command line\n\nThe easiest way to record a program or script is via the CLI:\n\n```sh\n$ vernier run -- ruby -e 'sleep 1'\nstarting profiler with interval 500 and allocation interval 0\n#\u003cVernier::Result 1.001589 seconds, 1 threads, 1 samples, 1 unique\u003e\nwritten to /tmp/profile20240328-82441-gkzffc.vernier.json.gz\n```\n\n```sh\n$ vernier run --interval 100 --allocation-interval 10 -- ruby -e '10.times { Object.new }'\nstarting profiler with interval 100 and allocation interval 10\n#\u003cVernier::Result 0.00067 seconds, 1 threads, 1 samples, 1 unique\u003e\nwritten to /tmp/profile20241029-26525-dalmym.vernier.json.gz\n```\n\n#### Block of code\n\n``` ruby\nVernier.profile(out: \"time_profile.json\") do\n  some_slow_method\nend\n```\n\n``` ruby\nVernier.profile(out: \"time_profile.json\", interval: 100, allocation_interval: 10) do\n  some_slow_method\nend\n```\n\nAlternatively you can use the aliases `Vernier.run` and `Vernier.trace`.\n\n#### Start and stop\n\n```ruby\nVernier.start_profile(out: \"time_profile.json\", interval: 10_000, allocation_interval: 100_000)\n\nsome_slow_method\n\n# some other file\n\nsome_other_slow_method\n\nVernier.stop_profile\n```\n\n#### Rack middleware\n\nYou can also use `Vernier::Middleware` to profile a Rack application:\n\n```ruby\n# config.ru\n\nrequire \"vernier\"\n\nuse Vernier::Middleware\n\nrun -\u003e(env) { [200, { \"Content-Type\" =\u003e \"text/plain\" }, [\"Hello, Profiling World!\"]] }\n```\n\nIf you're using Rails, you can add the middleware to your `config/application.rb`:\n\n```ruby\nconfig.middleware.use Vernier::Middleware, permit: -\u003e(env) { env[\"PATH_INFO\"].start_with?(\"/api\") }\n```\n\nYou can then enable profiling and configure options with query parameters:\n\n```sh\ncurl http://localhost:3000?vernier=true\u0026vernier_interval=100\u0026vernier_allocation_interval=10\n```\n\n### Retained memory\n\n#### Block of code\n\nRecord a flamegraph of all **retained** allocations from loading `irb`:\n\n```sh\nruby -r vernier -e 'Vernier.trace_retained(out: \"irb_profile.json\") { require \"irb\" }'\n```\n\n\u003e [!NOTE]\n\u003e Retained-memory flamegraphs must be interpreted a little differently than a typical profiling flamegraph. In a retained-memory flamegraph, the x-axis represents a proportion of memory in bytes,  _not time or samples_ The topmost boxes on the y-axis represent the retained objects, with their stacktrace below; their width represents the percentage of overall retained memory each object occupies.\n\n### Options\n\n| Option                | Middleware Param              | Description                                                   | Default (Middleware Default) |\n|-----------------------|-------------------------------|---------------------------------------------------------------|------------------------------|\n| `mode`                | N/A                           | Sampling mode: `:wall`, `:retained`, or `:custom`.            | `:wall` (`:wall`)            |\n| `out`                 | N/A                           | File to write the profile to.                                 | N/A (Auto-generated)         |\n| `interval`            | `vernier_interval`            | Sampling interval (µs). Only in `:wall` mode.                 | `500` (`200`)                |\n| `allocation_interval` | `vernier_allocation_interval` | Allocation sampling interval. Only in `:wall` mode.           | `0`/disabled (`200`)       |\n| `gc`                  | N/A                           | Run full GC cycle before profiling. Only in `:retained` mode. | `true` (N/A)                 |\n| `metadata`            | N/A                           | Metadata key-value pairs to include in the profile.           | `{}` (N/A)                   |\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/jhawthorn/vernier. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/jhawthorn/vernier/blob/main/CODE_OF_CONDUCT.md).\n\n### Resources\n\n* https://profiler.firefox.com/docs/#/\n* https://github.com/firefox-devtools/profiler/tree/main/docs-developer\n* https://github.com/tmm1/stackprof\n* https://github.com/ruby/ruby/pull/5500\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Vernier project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/jhawthorn/vernier/blob/main/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjhawthorn%2Fvernier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjhawthorn%2Fvernier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjhawthorn%2Fvernier/lists"}