1 year ago
#337105
David Owens
How to kill perf record with python subprocess?
I am attempting to use the perf utility to monitor my system.
It will be started and killed within a python script. I have created a sandbox like so:
extra_params = ["-F", "99", "-g", "-a", "--"]
record_args = ["sudo", "perf", "record", "-o", "/path/perf.data", *extra_params]
print(f"Starting perf w/ args: {record_args}")
proc = subprocess.Popen(
args=record_args,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
print(proc.pid)
time.sleep(2)
subprocess.check_output(["sudo", "kill", "-2", str(proc.pid)])
This fails to properly kill the process resulting in perf
not correctly flushing its data. I do not get the Captured and wrote
success message. Eventually my Flamegraph states:
Unrecognized line: Was the 'perf record' command properly terminated? at stackcollapse-perf.pl line 424, <> line
If I open another terminal and run the exact same sudo kill -2 $pid
command, perf
exits correctly and the downstream FlameGraph
executables work correctly.
I have referenced the following resources, all which fail to fix the issue:
- perf report failing with error "data field size is 0 which is unexpected. Was 'perf record' command properly terminated?"
- https://www.spinics.net/lists/linux-perf-users/msg08375.html
- https://serverfault.com/questions/967054/how-to-gracefully-kill-linux-perf-tool-process
Thank you!
python
performance
monitoring
perf
flamegraph
0 Answers
Your Answer