Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option for a time limit #265

Open
theimpostor opened this issue May 23, 2023 · 3 comments
Open

Option for a time limit #265

theimpostor opened this issue May 23, 2023 · 3 comments

Comments

@theimpostor
Copy link

theimpostor commented May 23, 2023

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.

@djc
Copy link
Contributor

djc commented May 24, 2023

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.)

@theimpostor
Copy link
Author

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

@djc
Copy link
Contributor

djc commented May 31, 2023

When you invoke flamegraph with -v it should print the full perf command, maybe that helps debug this?

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

No branches or pull requests

2 participants