-
Notifications
You must be signed in to change notification settings - Fork 479
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
python function tracing for both python2 and python3 #680
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I'd like to see python3 support for |
Sure. I will do that. |
honggyukim
force-pushed
the
review/python3-tracing-v1
branch
5 times, most recently
from
October 7, 2019 00:23
b586a61
to
eb87857
Compare
The trace_python module implement 'trace' function to be set by sys.settrace(). It will call uftrace (i.e. libmcount) to save trace info along with the interpreter. But C extension module cannot be used by it so also added misc/uftrace.py module just as a loader. Signed-off-by: Namhyung Kim <namhyung@gmail.com>
It needs to map python function name to an address so that uftrace can deal with it like C functions. As lowest address won't be used by native programs, just use simple counter (from 1) to save symbol address. The symbol table will be written as "python-symtab.sym" in the data directory. Signed-off-by: Namhyung Kim <namhyung@gmail.com>
If it finds the python symbol table, it'll add a map so that uftrace can find its address. For now, it assumes having up to 4k symbols. Signed-off-by: Namhyung Kim <namhyung@gmail.com>
$ cat hello.py #!/usr/bin/env python2 def b(arg): return arg+1 def a(): return b(0) print a() $ u --python hello.py 1 # DURATION TID FUNCTION [ 560] | <module>() { [ 560] | a() { 0.958 us [ 560] | b(); 3.751 us [ 560] | } /* a */ 10.769 us [ 560] | } /* <module> */ 6.969 us [ 560] | _remove(); 2.099 us [ 560] | _remove(); Signed-off-by: Namhyung Kim <namhyung@gmail.com>
Convert module initializer from "<module>" to "<module:name>". Signed-off-by: Namhyung Kim <namhyung@gmail.com>
misc/uftrace.py indirectly executes the given python script, but it shouldn't be passed as the first argument in sys.argv. This patch also changes execfile() to exec() to make it work in both python2 and python3. In "What’s New In Python 3.0": "Removed execfile(). Instead of execfile(fn) use exec(open(fn).read())." Link: http://docs.python.org/3.3/whatsnew/3.0.html?highlight=execfile#builtins Signed-off-by: Honggyu Kim <honggyu.kp@gmail.com>
Since python-config provides a way to get the correct cflags and ldflags, it's better to use it to avoid using version specific header path. Signed-off-by: Honggyu Kim <honggyu.kp@gmail.com>
In order to support both python2 and python3, this patch adds a new "trace-python2.c" file, which contains only python2 specific code. "trace-python.c" only contains common code for both python2 and python3. Signed-off-by: Honggyu Kim <honggyu.kp@gmail.com>
This patch changes the name of python2 shared object from "python_trace.so" to "python_trace2.so". This is a preparation phase for additional python3 support. Signed-off-by: Honggyu Kim <honggyu.kp@gmail.com>
This adds a new file "misc/trace-python3.c" to support python3 script tracing. It only contains the code so build script change will be followed in the next commit. Signed-off-by: Honggyu Kim <honggyu.kp@gmail.com>
This patch adds a build rule to generate "trace-python3.so" for python3 tracing support. Signed-off-by: Honggyu Kim <honggyu.kp@gmail.com>
misc/uftrace.py is a middle layer before calling the target python script, so it can check the python version before tracing. Based on the python version, it can decide whether to import "trace_python2.so" or "trace_python3.so". Signed-off-by: Honggyu Kim <honggyu.kp@gmail.com>
honggyukim
force-pushed
the
review/python3-tracing-v1
branch
from
October 7, 2019 07:52
eb87857
to
c9f4e80
Compare
Signed-off-by: Honggyu Kim <honggyu.kp@gmail.com>
This PR isn't properly updated so opened a new PR in #934. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is based on review/python-tracing-v3.
Related issue: #436