Option for a time limit
theimpostor opened this issue · comments
Sometimes I want to profile a running application for only a short while. With perf what I'll typically do is something like this:
sudo perf record -p <pid> -g -F 999 -- sleep 60
It's not obvious to me how I would do the same thing with flamegraph. It would be cool if there was an option to add a time limit, or even use a signal to stop profiling and write out the svg.
The -c
option will let you write a custom perf
command. Does that help? I'd also be open to reviewing a PR to add this. (In the end, flamegraph is a pretty thin wrapper over running perf
-- at least on Linux.)
Hmm, it doesn't seem to like the way I'm supplying a command to perf. Here I'm trying to grab a trace from pid 11736 for 60 seconds:
❯ flamegraph -c 'sudo perf record -p 11736 -g -F 999 -- sleep 60'
Error: no workload given to generate a flamegraph for
✖1 ❯ flamegraph -p 11736 -c 'sudo perf record -p 11736 -g -F 999 -- sleep 60'
perf: 'sudo' is not a perf-command. See 'perf --help'.
failed to sample program
✖1 ❯ flamegraph -p 11736 -c 'perf record -p 11736 -g -F 999 -- sleep 60' --root
perf: 'perf' is not a perf-command. See 'perf --help'.
failed to sample program
✖1 ❯ flamegraph -p 11736 -c 'record -p 11736 -g -F 999 -- sleep 60' --root
Couldn't synthesize bpf events.
sleep: invalid option -- 'p'
Try 'sleep --help' for more information.
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.133 MB perf.data (366 samples) ]
failed to sample program
✖1 ❯ flamegraph -p 11736 -c 'record -g -F 999 -- sleep 60' --root
Couldn't synthesize bpf events.
sleep: invalid option -- 'p'
Try 'sleep --help' for more information.
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.011 MB perf.data (8 samples) ]
failed to sample program
When you invoke flamegraph
with -v
it should print the full perf
command, maybe that helps debug this?