Python call subprocess in background

broken image
broken image

you need to capture stderr as perf sends its output to stderr (at least in my version).to terminate perf and make it output the gathered performance stats you need to send it the SIGINT signal (try it out with sudo perf stat -p mypid: ctrl-\ will print nothing whereas ctrl-c will).If you really want to call perf from within python then you'll face some tricky problems: First: I advise against calling perf from within your python process (as you see in the complexity of the task below), but instead use is from the command line: sudo perf stat - python test.py

broken image