Next-generation Ruby 3.2.1+ sampling profiler. Tracks multiple threads, GVL activity, GC pauses, idle time, and more.
![Screenshot 2024-02-29 at 22 47 43](https://private-user-images.githubusercontent.com/131752/309185639-aa995a41-d74f-405f-8ada-2522dd72c2c8.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg4OTY2MzYsIm5iZiI6MTczODg5NjMzNiwicGF0aCI6Ii8xMzE3NTIvMzA5MTg1NjM5LWFhOTk1YTQxLWQ3NGYtNDA1Zi04YWRhLTI1MjJkZDcyYzJjOC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjA3JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIwN1QwMjQ1MzZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT00NDhjMDViOTU3NTYyMTFjMjZkZTNmYjhiNzg0ZmEyYTk3YmZhMmUyZDA4ODhjOGRlZGM5YzE2MzFhZTQzODA5JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.oN4kx_VrCWgKyJxULvOR_PwlfvoBjT9ICDlH0VgNtP0)
Livestreamed demo: Pairin' with Aaron (YouTube)
Sidekiq jobs from Mastodon (time, threded) : https://share.firefox.dev/44jZRf3
Puma web requests from Mastodon (time, threded) : https://share.firefox.dev/48FOTnF
Rails benchmark - lobste.rs (time) : https://share.firefox.dev/3Ld89id
require "irb"
(retained memory)
: https://share.firefox.dev/3DhLsFa
Vernier requires Ruby version 3.2.1 or greater
gem "vernier", "~> 1.0"
The output can be viewed in the web app at https://vernier.prof or locally using the profile-viewer
gem (both are lightly customized versions of the firefox profiler frontend, which profiles are also compatible with).
- 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.
- Stack Chart: Shows the stack at each sample with the x-axis representing time and can be read left-to-right.
The easiest way to record a program or script is via the CLI
$ vernier run -- ruby -e 'sleep 1'
starting profiler with interval 500
#<Vernier::Result 1.001589 seconds, 1 threads, 2002 samples, 1 unique>
written to /tmp/profile20240328-82441-gkzffc.vernier.json
Vernier.run(out: "time_profile.json") do
some_slow_method
end
Record a flamegraph of all retained allocations from loading irb
.
ruby -r vernier -e 'Vernier.trace_retained(out: "irb_profile.json") { require "irb" }'
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.
After 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.
To 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.
Bug 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://profiler.firefox.com/docs/#/
- https://github.com/firefox-devtools/profiler/tree/main/docs-developer
- https://github.com/tmm1/stackprof
- ruby/ruby#5500
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Vernier project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.