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

How to trace all functions with USDT in Python? #5074

Open
nurdann opened this issue Aug 10, 2024 · 2 comments
Open

How to trace all functions with USDT in Python? #5074

nurdann opened this issue Aug 10, 2024 · 2 comments

Comments

@nurdann
Copy link
Contributor

nurdann commented Aug 10, 2024

I have the following Python code

# sample.py
from time import sleep
def foo():
    ...
    
def main():
    while True:
        with open("sample.py") as f:
            content = f.read()
        print("fooo")
        foo()
        sleep(3)

main()

Running the script

$ python3 sample.py > /dev/null &
[1] 270606

And run uflow.py

$ sudo python3 ~/bcc/tools/lib/uflow.py -l python 270606

Tracing method calls in python process 270606... Ctrl-C to quit.
CPU PID    TID    TIME(us) METHOD
12  270606 270606 12.130   -> /usr/lib/python3.10/codecs.py.__init__
12  270606 270606 12.131     -> /usr/lib/python3.10/codecs.py.__init__
12  270606 270606 12.131     <- /usr/lib/python3.10/codecs.py.__init__
12  270606 270606 12.131   <- /usr/lib/python3.10/codecs.py.__init__
12  270606 270606 12.131   -> /usr/lib/python3.10/codecs.py.decode 
12  270606 270606 12.131   <- /usr/lib/python3.10/codecs.py.decode 
12  270606 270606 12.131   -> /home/foo/Downloads/sample.py.foo
12  270606 270606 12.131   <- /home/foo/Downloads/sample.py.foo

The only function I see is the one defined in the script. I would expect that calls for open() and print() to show up.

  1. How to trace all function invocations?
  2. Can you build stack trace for specific functions? From the above sample output, it's not clear which class is calling __init__ in /usr/lib/python3.10/codecs.py.
@ZhangYet
Copy link
Contributor

I think this is because print and open are builtin functions, when they are called, function_entry usdt won't be called.

@nurdann
Copy link
Contributor Author

nurdann commented Aug 16, 2024

For __init__() can you tell which class it belongs to?

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

No branches or pull requests

2 participants