flamegraph icon indicating copy to clipboard operation
flamegraph copied to clipboard

extend flamegraph to take an optional pid and timespan

Open papertigers opened this issue 6 years ago • 11 comments

Adding a timeout to flamegraph would be nice for long running commands.

Example of a command printing output once per second forever: # flamegraph -o example.svg vfsstat 1

In this scenario being able to pass a 30s timeout value that results in tick-30s { exit(0) }' would be great. # flamegraph -t 30s -o example.svg vfsstat 1

Additionally being able to run flamegraph against an already running process by specifying a pid and timeout would be nice. flamegraph -p $(pgrep my-server) -t 30s -o server.svg

papertigers avatar Mar 13 '19 21:03 papertigers

Another useful argument would be to defer collection until a certain amount of time has passed, to avoid having a big flamegraph of your application starting up followed by a short section you're actually interested in.

estebank avatar Mar 13 '19 22:03 estebank

I'm quite in-favor of adding this flag. Also, once it is in place, this library can easily allow applications to generate flamegraphs targeting themselves through the library API.

spacejam avatar Mar 14 '19 14:03 spacejam

having it as a -p option is a bad idea, since the package selection in the workspace of the original cargo command is done with this flag. having it available via --pid is fine

Stunkymonkey avatar Mar 05 '20 22:03 Stunkymonkey

FWIW I use the pid argument of py-spy all the time: https://github.com/benfred/py-spy

Massively helpful for profiling long-running service applications

willstott101 avatar Sep 22 '20 13:09 willstott101

+1 to add --pid please, I would love to be able to profile something that is already running for an interval

ckcr4lyf avatar Jul 12 '22 05:07 ckcr4lyf

The flamegraph binary already exposes --pid. I suppose this issue is only still open because we don't support a time span (or delay) yet.

djc avatar Jul 25 '22 08:07 djc

The flamegraph binary already exposes --pid. I suppose this issue is only still open because we don't support a time span (or delay) yet.

I never tried it, but if so, would be nice to add to the documentation as well (https://github.com/flamegraph-rs/flamegraph#usage) . I will test the pid feature tonight

ckcr4lyf avatar Jul 25 '22 10:07 ckcr4lyf

Would be great if you can submit a PR to clarify the existence of this option in the README.

djc avatar Jul 25 '22 11:07 djc

Tested, it works. Will make a PR!

ckcr4lyf avatar Jul 25 '22 15:07 ckcr4lyf

Looks like this was accidentally closed? A way to stop recording before the process ends would be nice to have.

fenhl avatar Sep 07 '24 11:09 fenhl

I won't be able to work on that myself, but would be happy to review a PR.

djc avatar Sep 07 '24 11:09 djc