|
| 1 | +## Running |
| 2 | + |
| 3 | +```console |
| 4 | +docker compose up --remove-orphans --build |
| 5 | +``` |
| 6 | + |
| 7 | +## Sample output |
| 8 | + |
| 9 | +```console |
| 10 | +bpftrace-1 | Trying to attach probe: uretprobe:/usr/lib/libpython3.13.so:context_run* |
| 11 | +bpftrace-1 | Attaching to 1 functions |
| 12 | +bpftrace-1 | /usr/lib/libpython3.13.so:context_run |
| 13 | +bpftrace-1 | Trying to attach probe: uprobe:/usr/lib/libpython3.13.so:context_run* |
| 14 | +bpftrace-1 | Attaching to 1 functions |
| 15 | +bpftrace-1 | /usr/lib/libpython3.13.so:context_run |
| 16 | +bpftrace-1 | Trying to attach probe: uprobe:/usr/lib/libpython3.13.so:PyContext_Exit |
| 17 | +bpftrace-1 | Trying to attach probe: uprobe:/usr/lib/libpython3.13.so:PyContext_Enter |
| 18 | +bpftrace-1 | Attached 4 probes |
| 19 | +bpftrace-1 | tid=3062951 context_run { .self = 0x7fdd35f88900, .args = 0x7fdd36158a98, .nargs = 3, .kwnames = 0x0 } |
| 20 | +bpftrace-1 | tid=3062951 return context_run |
| 21 | +bpftrace-1 | tid=3062951 context_run { .self = 0x7fdd36188240, .args = 0x7fdd35f37098, .nargs = 2, .kwnames = 0x0 } |
| 22 | +bpftrace-1 | tid=3062951 return context_run |
| 23 | +bpftrace-1 | tid=3062958 context_run { .self = 0x7fdd35f88900, .args = 0x7fdd3722e938, .nargs = 1, .kwnames = 0x0 } |
| 24 | +python-1 | 200 |
| 25 | +bpftrace-1 | tid=3062958 return context_run |
| 26 | +bpftrace-1 | tid=3062951 context_run { .self = 0x7fdd35f8b740, .args = 0x7fdd35ff7758, .nargs = 3, .kwnames = 0x0 } |
| 27 | +bpftrace-1 | tid=3062951 return context_run |
| 28 | +bpftrace-1 | tid=3062951 context_run { .self = 0x7fdd364f40c0, .args = 0x7fdd3600d588, .nargs = 1, .kwnames = 0x0 } |
| 29 | +bpftrace-1 | tid=3062951 return context_run |
| 30 | +bpftrace-1 | tid=3062951 context_run { .self = 0x7fdd364320c0, .args = 0x7fdd35f36118, .nargs = 2, .kwnames = 0x0 } |
| 31 | +bpftrace-1 | tid=3062951 return context_run |
| 32 | +bpftrace-1 | tid=3062951 context_run { .self = 0x7fdd36188240, .args = 0x7fdd35f36118, .nargs = 2, .kwnames = 0x0 } |
| 33 | +bpftrace-1 | tid=3062951 return context_run |
| 34 | +bpftrace-1 | tid=3062951 context_run { .self = 0x7fdd35f88900, .args = 0x7fdd36158a98, .nargs = 3, .kwnames = 0x0 } |
| 35 | +bpftrace-1 | tid=3062951 return context_run |
| 36 | +bpftrace-1 | tid=3062951 context_run { .self = 0x7fdd36188240, .args = 0x7fdd35f36118, .nargs = 2, .kwnames = 0x0 } |
| 37 | +bpftrace-1 | tid=3062951 return context_run |
| 38 | +bpftrace-1 | tid=3062958 context_run { .self = 0x7fdd35f88900, .args = 0x7fdd3722e938, .nargs = 1, .kwnames = 0x0 } |
| 39 | +bpftrace-1 | tid=3062958 return context_run |
| 40 | +bpftrace-1 | tid=3062951 context_run { .self = 0x7fdd35f8b740, .args = 0x7fdd35ff7758, .nargs = 3, .kwnames = 0x0 } |
| 41 | +bpftrace-1 | tid=3062951 return context_run |
| 42 | +bpftrace-1 | tid=3062951 context_run { .self = 0x7fdd364f40c0, .args = 0x7fdd3600d738, .nargs = 1, .kwnames = 0x0 } |
| 43 | +bpftrace-1 | tid=3062951 return context_run |
| 44 | +bpftrace-1 | tid=3062951 context_run { .self = 0x7fdd364320c0, .args = 0x7fdd35fbaf58, .nargs = 2, .kwnames = 0x0 } |
| 45 | +bpftrace-1 | tid=3062951 return context_run |
| 46 | +bpftrace-1 | tid=3062951 context_run { .self = 0x7fdd36188240, .args = 0x7fdd35fbaf58, .nargs = 2, .kwnames = 0x0 } |
| 47 | +python-1 | 200 |
| 48 | +``` |
| 49 | + |
| 50 | +In this example `3062951` is the main event loop thread and `3062958` is a thread pool worker, |
| 51 | +given work by `asyncio.to_thread()`. When work is run in the thread pool, asyncio wraps that in |
| 52 | +`context_run()` so you can track which thread started the work. The [self |
| 53 | +argument](https://github.com/python/cpython/blob/v3.13.9/Python/context.c#L649) is a pointer to |
| 54 | +the [Context object](https://docs.python.org/3/library/contextvars.html#contextvars.Context). |
| 55 | + |
| 56 | +In the above example, Context `0x7fdd35f88900` moves between the two threads. |
| 57 | +```console |
| 58 | +bpftrace-1 | tid=3062951 context_run { .self = 0x7fdd35f88900, .args = 0x7fdd36158a98, .nargs = 3, .kwnames = 0x0 } |
| 59 | +... |
| 60 | +bpftrace-1 | tid=3062958 context_run { .self = 0x7fdd35f88900, .args = 0x7fdd3722e938, .nargs = 1, .kwnames = 0x0 } |
| 61 | +... |
| 62 | +bpftrace-1 | tid=3062951 context_run { .self = 0x7fdd35f88900, .args = 0x7fdd36158a98, .nargs = 3, .kwnames = 0x0 } |
| 63 | +... |
| 64 | +bpftrace-1 | tid=3062958 context_run { .self = 0x7fdd35f88900, .args = 0x7fdd3722e938, .nargs = 1, .kwnames = 0x0 } |
| 65 | +``` |
0 commit comments