Reputation: 4128
I have some intermittent performance issues that I want to capture via perf top
. The issue is intermittent, so I want to write a script that runs perf top
when the issue is occurring so that I can save the data and view it at a later time.
I can't seem to figure out how to get perf top
to put its output in a file, it seems to demand to be run interactively. Here is what I've tried so far:
# timeout 10 perf top --stdio -E 20 > 'perf-top'
This does not kill perf, just leaves it running in the background forever until I create another console session, find the PID, and kill it.
# timeout --signal=9 10 perf top --stdio -E 20 > 'perf-top'
This kills perf in the expected 10 seconds, but the output is not written to the file that I specified.
Is there some special way that this command needs to be run? It works if I run it from an interactive ssh session, but I'd really like to be able to run it from a script. I'm trying to put it into an ansible task with a few other metrics-gathering programs.
Upvotes: 1
Views: 1358
Reputation: 364238
SIGKILL (9
) isn't catchable, so it's impossible for perf
to flush any buffered output.
Use any another signal so perf
can clean up after receiving the signal and write output.
If the default SIGTERM
doesn't work, then maybe try SIGHUP, SIGINT, or others.
timeout --signal=INT
timeout 10 perf top --stdio -E 20 > perf-top
(with the default SIGTERM) works for me (as non-root) on my Arch Linux desktop. perf version 5.0.g1c163f4
Upvotes: 4