|
| 1 | +#define YELLOW "\033[33m" |
| 2 | +#define NC "\033[0m" // No Color (resets the terminal color) |
| 3 | + |
| 4 | +// These are the official C API for enter/exiting a context, but is not called by the cpython |
| 5 | +// internals. Something like uvloop might use this. |
| 6 | +uprobe:/usr/lib/libpython3.13.so:PyContext_Enter { |
| 7 | + printf("%stid=%s%s %s %s\n", YELLOW, tid, NC, func, args); |
| 8 | +} |
| 9 | + |
| 10 | +uprobe:/usr/lib/libpython3.13.so:PyContext_Exit { |
| 11 | + printf("%stid=%s%s %s %s\n", YELLOW, tid, NC, func, args); |
| 12 | +} |
| 13 | + |
| 14 | +// This is the C implementation of contextvars.run() python function |
| 15 | +// https://github.com/python/cpython/blob/v3.13.9/Python/context.c#L648-L650. This plus the |
| 16 | +// PyContext_Enter/PyContext_Exit is probably the most reliable. |
| 17 | +uprobe:/usr/lib/libpython3.13.so:context_run* { |
| 18 | + printf("%stid=%s%s %s %s\n", YELLOW, tid, NC, func, args); |
| 19 | +} |
| 20 | +uretprobe:/usr/lib/libpython3.13.so:context_run* { |
| 21 | + printf("%stid=%s%s return %s\n", YELLOW, tid, NC, func); |
| 22 | +} |
| 23 | + |
| 24 | +// ----------- |
| 25 | + |
| 26 | +// These might be useful for tracking parentage of new Context objects |
| 27 | +/** |
| 28 | +uretprobe:/usr/lib/libpython3.13.so:PyContext_CopyCurrent { |
| 29 | + printf("%s retval = %#x\n", func, retval); |
| 30 | +} |
| 31 | +uretprobe:/usr/lib/libpython3.13.so:PyContext_Copy { |
| 32 | + printf("%s retval = %#x\n", func, retval); |
| 33 | +} |
| 34 | +*/ |
| 35 | + |
| 36 | +// These might be useful for watching the trace context for OTel python instrumented code |
| 37 | +/* |
| 38 | +uprobe:/usr/lib/libpython3.13.so:PyContextVar_Get { |
| 39 | + printf("%s %s\n", func, args); |
| 40 | +} |
| 41 | +uprobe:/usr/lib/libpython3.13.so:PyContextVar_Set { |
| 42 | + printf("%s %s\n", func, args); |
| 43 | +} |
| 44 | +*/ |
| 45 | + |
| 46 | +// These are called by PyContext_Enter/PyContext_Exit and context_run internally. It seems to |
| 47 | +// get inlined in many production builds of python (e.g. on Debian and uv managed python), so |
| 48 | +// might not be reliable. |
| 49 | +// |
| 50 | +// See https://github.com/python/cpython/blob/v3.13.9/Python/context.c#L112-L113 |
| 51 | +/* |
| 52 | +uprobe:/usr/lib/libpython3.13.so:_PyContext_Enter { |
| 53 | + printf("tid=%s %s %s\n", tid, func, args); |
| 54 | +} |
| 55 | +uprobe:/usr/lib/libpython3.13.so:_PyContext_Exit { |
| 56 | + printf("tid=%s %s %s\n", tid, func, args); |
| 57 | +} |
| 58 | +*/ |
0 commit comments