# server_proc.pid - содержит PID некоторого процесса,
# который мы запустили и хотим попрофилировать
perf = "sudo perf record -g -p " + str(server_proc.pid) + " -o perf.data"
perf_proc = subprocess.Popen(shlex.split(perf), stderr=subprocess.STDOUT)
# делаем что-то полезное, тем временем perf измеряет происходящее
perf_proc.send_signal(signal.SIGINT) # посылаем ctrl-c
# ок, можно обрабатывать perf.data
bob@homepc:~$ sudo apt install linux-tools-common
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
linux-tools-common is already the newest version (5.15.0-119.129).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
bob@homepc:~$ perf
WARNING: perf not found for kernel 5.15.153.1-microsoft
You may need to install the following packages for this specific kernel:
linux-tools-5.15.153.1-microsoft-standard-WSL2
linux-cloud-tools-5.15.153.1-microsoft-standard-WSL2
You may also want to install one of the following packages to keep up to date:
linux-tools-standard-WSL2
linux-cloud-tools-standard-WSL2
$ sudo apt install linux-tools-5.15.153.1-microsoft-standard-WSL2
...
E: Unable to locate package linux-tools-5.15.153.1-microsoft-standard-WSL2
sudo apt update && sudo apt upgrade