Ruby
#
Supported platformsLinux | macOS | Windows | Docker |
---|---|---|---|
✅ | ✅ | ✅ |
#
Profiling Ruby applicationsAdd the pyroscope
gem to your Gemfile:
bundle add pyroscope
#
Basic ConfigurationAdd the following code to your application. If you're using rails, put this into config/initializers
directory. This code will initialize pyroscope profiler and start profiling:
require 'pyroscope'
Pyroscope.configure do |config| config.application_name = "my.ruby.app" # replace this with some name for your application config.server_address = "http://my-pyroscope-server:4040" # replace this with the address of your pyroscope server # config.auth_token = "{YOUR_API_KEY}" # optionally, if authentication is enabled, specify the API keyend
#
TagsPyroscope ruby integration provides a number of ways to tag profiling data. For example, you can provide tags when you're initializing the profiler:
require 'pyroscope'
Pyroscope.configure do |config| config.application_name = "my.ruby.app" config.server_address = "http://my-pyroscope-server:4040"
config.tags = { "hostname" => ENV["HOSTNAME"], }end
or you can dynamically tag certain parts of your code:
Pyroscope.tag_wrapper({ "controller": "slow_controller_i_want_to_profile" }) do slow_codeend
#
Auto-Instrumentation#
RailsBy default, if you add pyroscope to a rails application it will automatically tag your actions with action="<controller_name>/<action_name>"
tag.
To disable rails autoinstrumentation, set autoinstrument_rails
to false
:
Pyroscope.configure do |config| config.autoinstrument_rails = false # more configurationend
#
Ruby profiling examplesCheck out the following resources to learn more about Ruby profiling:
- Ruby examples
- Ruby Demo showing Ruby example with tags
- Ruby blog post
Frame width represents CPU time per function