py-spy
py-spy copied to clipboard
Add --syscalls option for tracing syscalls (linux only)
This commit adds a new option (--syscalls/-S) to trace what time your python programm spends in kernel space. It is only supported on linux where current syscall can be determined using /proc/{pid}/task/{tid}/syscall. --syscalls implies --idle
Example output of top:
%Own %Total OwnTime TotalTime Function (filename:line)
99.00% 99.00% 67.60s 67.60s select syscall (<kernel>)
1.00% 1.00% 0.200s 0.200s write syscall (<kernel>)
0.00% 1.00% 0.130s 0.390s x (x.py:5)
0.00% 0.00% 0.060s 0.060s brk syscall (<kernel>)
0.00% 0.00% 0.010s 0.010s x (x.py:3)
0.00% 99.00% 0.000s 67.60s x (x.py:4)
0.00% 100.00% 0.000s 68.00s <module> (x.py:7)
Nice!
I had something similar in mind a while back - to add /proc/pid/stack entries as traces (so you have kernel stacks in addition to the Python stacks). It's simpler (because the kernel does symbolication for you) but requires root IIRC (unlike /proc/pid/syscall).
Also, I'm not sure it's useful unless you are in --nonblocking mode - otherwise, the kernel stack would be "stopped in ptrace".
Yes, my first idea was to add /proc/pid/stack, too, but then I thought that a programmer that only sees the python stacktrace (and not the c stacktrace of cpython) is probably barely interested in the internals of the kernel ;)
Hey, @benfred, let me know if there is anything in this pull request that I should change if you are not happy with the current state. :D
Hey, @benfred is there anything else I can do to have this merged?
Hey, @benfred, maybe you missed my last message. Is there anything else I can do to have this merged?