Skip to content

Conversation

@jhawthorn
Copy link
Contributor

@jhawthorn jhawthorn commented May 15, 2020

This PR makes flamegraph generation significantly faster. The main change is to create cursor objects pointing into the raw buffer instead of slicing arrays out of the raw buffer.

Before

jhawthorn@guardian:~/src/stackprof (master ) [ruby 2.8.0]
$ time ruby -Ilib bin/stackprof --flamegraph stackprof-test-boot.dump > /dev/null
31.52s user 0.24s system 99% cpu 31.891 total

After

jhawthorn@guardian:~/src/stackprof (faster_reporting ) [ruby 2.8.0]
$ time ruby -Ilib bin/stackprof --flamegraph stackprof-test-boot.dump > /dev/null
6.69s user 0.16s system 99% cpu 6.875 total

I found this using stackprof on its own reporting 😆 ♻️

# frozen_string_literal: true

require "stackprof"

report = StackProf::Report.new(Marshal.load(IO.binread(ARGV[0])))

output = File.open("/dev/null", "wb")
StackProf.run(mode: :wall, out: 'stackprof-stackprof.dump') do
  report.print_timeline_flamegraph(output)
end

jhawthorn added 3 commits May 2, 2020 21:58
This makes generating flamegraph HTML faster by avoid copying data and
instead creating objects to track the windows inside the buffer.
frames is sorted and we can avoid calculating it for a few formats
@tmm1 tmm1 merged commit ae980e1 into tmm1:master Jul 5, 2020
@tmm1
Copy link
Owner

tmm1 commented Jul 5, 2020

This is really clever. Great use of stackprof!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants