Skip to content

Importing from stackprof (ruby)

Jamie Wong edited this page Feb 15, 2019 · 2 revisions

stackprof is a sampling call-stack profiler for Ruby.

To record a profile, wrap your code in a StackProf.run block with raw: true, then save the JSON encoded version of the profile to a file. You'll need to be running stackprof >= 0.2.11.

require 'json'
require 'stackprof'

profile = StackProf.run(mode: :wall, raw: true) do
  # Do your thing here
end

File.write('stackprof.json', JSON.generate(profile))

Then drop the resulting stackprof.json into https://www.speedscope.app/

To view it offline, you'll need to install speedscope via npm:

npm install -g speedscope

Then you should be able to open it like so:

speedscope stackprof.json