Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --syscalls option for tracing syscalls (linux only) #421

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

manuels
Copy link

@manuels manuels commented Jul 14, 2021

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

@manuels manuels force-pushed the master branch 3 times, most recently from 4fa5e97 to 4d6d859 Compare July 14, 2021 16:44
@manuels manuels changed the title Add --syscalls option (linux only) Add --syscalls option for tracing syscalls (linux only) Jul 14, 2021
@manuels
Copy link
Author

manuels commented Jul 14, 2021

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)

@Jongy
Copy link
Contributor

Jongy commented Jul 14, 2021

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".

@manuels
Copy link
Author

manuels commented Jul 14, 2021

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 ;)

Copy link
Owner

@benfred benfred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

src/config.rs Outdated Show resolved Hide resolved
src/python_spy.rs Outdated Show resolved Hide resolved
@manuels
Copy link
Author

manuels commented Jul 25, 2021

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

@manuels
Copy link
Author

manuels commented Sep 22, 2021

Hey, @benfred is there anything else I can do to have this merged?

src/config.rs Outdated Show resolved Hide resolved
@manuels
Copy link
Author

manuels commented Mar 29, 2022

Hey, @benfred, maybe you missed my last message. Is there anything else I can do to have this merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants