I have some Python code that I want to debug with perf. For that purpose I want to use subprocess. The following command returns instruction-related information of a process
Use subprocess.Popen to run perf. Then, use pipe.communicate() to send input and get the process's output.
After you've done, call pipe.terminate() to terminate the process.
For example:
pipe = subprocess.Popen(["perf","stat","-p",str(GetMyProcessID())], stdout=PIPE)
pipe.terminate()
stdout, stderr = pipe.communicate()
print stdout