jonhoo/inferno

cargo flamegraph

spacejam opened this issue · 13 comments

Hey! As a very heavy flamegraph user I've long been thinking about a cargo flamegraph command, but have been wary of including the bundle of perl scripts in the popular implementation. Is something like cargo flamegraph a priority of this project? I can imagine that it could support that use case in a more clean way.

Glad to see effort in the rust + flamegraph space :]

Ooooh, that'd be excellent! We're not directly pushing towards cargo flamegraph, but that's certainly something this library enables. The tricky part will be to also do the profiling. I think what you'd want is some notion of a profiling "driver" (like perf or bpftrace), and cargo flamegraph would be ~ equivalent to cargo run --release wrapped in that driver. It'd then feed the resulting output file to the appropriate inferno collapser and then to inferno::flamegraph to produce the final flamegraph.

I sadly don't have time myself to work on this, but would be happy to help such a project along and review PRs!

Relatedly, profiling will become so nice once we get the ability to do performance profiling like this:

# bpftrace -e 'profile:hz:499 /pid == 1234/ { @[kstack(folded), ustack(folded)]++ } interval:s:30 { exit() }' | flamegraph > out.svg
sanga commented

Stumbled upon this https://github.com/nokia/not-perf that may be of use in this regard? Looks like that already have the perf data collection part under cargo

@sanga ahh! the missing piece :] it doesn't seem to work on osx, but for linux machines may be a nice way to reduce dependencies

I've got something pretty basic going that seems to work on linux but it relies on the new collapse::Folder that was added since 0.3 was released. @jonhoo would it be possible to do a release to crates.io to get access to that?

@spacejam done! 0.4.0 released now.

@jonhoo woohoo thanks :] I'll push it quite soon!

whipped up this little cargo subcommand https://crates.io/crates/flamegraph

it's quite brittle as-is but far more maintainable than the junk shellscripts I've been relying on so far :]

feel free to use it as a basis for anything you use in this repo, etc... I'd like to update it when more collapsing options are available in inferno too since I'm also a big dtrace user!

@spacejam that's awesome! I'd be happy to look at a PR for adding DTrace support ;) We may also want some command-line flags to customize the resulting flame graph eventually. One thing that may be worth looking into is integrating with @koute's not-perf!

You should post that to /r/rust!

koute commented

Reusing https://github.com/nokia/not-perf in another project should be relatively simple; I'd just have to massage it a little into a proper library. @spacejam Hit me up if you're interested and I'll be happy to help out.

I put a dtrace collapser in #78 :)

flamegraph 0.1.4 now uses @Licenser 's dtrace collapser by default on non-linux systems :]