pylow 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. pylow-0.1.0/PKG-INFO +457 -0
  2. pylow-0.1.0/README.md +435 -0
  3. pylow-0.1.0/pyproject.toml +41 -0
  4. pylow-0.1.0/setup.cfg +4 -0
  5. pylow-0.1.0/src/api/cli/controller.py +329 -0
  6. pylow-0.1.0/src/pylow.egg-info/PKG-INFO +457 -0
  7. pylow-0.1.0/src/pylow.egg-info/SOURCES.txt +46 -0
  8. pylow-0.1.0/src/pylow.egg-info/dependency_links.txt +1 -0
  9. pylow-0.1.0/src/pylow.egg-info/entry_points.txt +2 -0
  10. pylow-0.1.0/src/pylow.egg-info/requires.txt +16 -0
  11. pylow-0.1.0/src/pylow.egg-info/top_level.txt +4 -0
  12. pylow-0.1.0/src/pytrace_features/attach/index.py +4 -0
  13. pylow-0.1.0/src/pytrace_features/attach/ports.py +14 -0
  14. pylow-0.1.0/src/pytrace_features/attach/service.py +37 -0
  15. pylow-0.1.0/src/pytrace_features/diff/index.py +3 -0
  16. pylow-0.1.0/src/pytrace_features/diff/service.py +100 -0
  17. pylow-0.1.0/src/pytrace_features/flame/service.py +48 -0
  18. pylow-0.1.0/src/pytrace_features/flow/index.py +3 -0
  19. pylow-0.1.0/src/pytrace_features/flow/service.py +112 -0
  20. pylow-0.1.0/src/pytrace_features/io/service.py +44 -0
  21. pylow-0.1.0/src/pytrace_features/malloc/service.py +48 -0
  22. pylow-0.1.0/src/pytrace_features/pyanomaly/service.py +89 -0
  23. pylow-0.1.0/src/pytrace_features/pyargs/service.py +46 -0
  24. pylow-0.1.0/src/pytrace_features/pyasync/service.py +72 -0
  25. pylow-0.1.0/src/pytrace_features/pycall/service.py +52 -0
  26. pylow-0.1.0/src/pytrace_features/pycpu/service.py +55 -0
  27. pylow-0.1.0/src/pytrace_features/pydash/service.py +75 -0
  28. pylow-0.1.0/src/pytrace_features/pyexcept/service.py +43 -0
  29. pylow-0.1.0/src/pytrace_features/pyframe/service.py +49 -0
  30. pylow-0.1.0/src/pytrace_features/pygil/service.py +48 -0
  31. pylow-0.1.0/src/pytrace_features/pygraph/service.py +141 -0
  32. pylow-0.1.0/src/pytrace_features/pyiowait/service.py +50 -0
  33. pylow-0.1.0/src/pytrace_features/pyleak/service.py +46 -0
  34. pylow-0.1.0/src/pytrace_features/pynplus1/service.py +57 -0
  35. pylow-0.1.0/src/pytrace_features/pyreq/service.py +58 -0
  36. pylow-0.1.0/src/pytrace_features/pysingle/service.py +159 -0
  37. pylow-0.1.0/src/pytrace_features/pysyscall/service.py +72 -0
  38. pylow-0.1.0/src/pytrace_features/pythread/service.py +116 -0
  39. pylow-0.1.0/src/pytrace_features/sched/service.py +45 -0
  40. pylow-0.1.0/src/pytrace_features/slow/index.py +3 -0
  41. pylow-0.1.0/src/pytrace_features/slow/service.py +129 -0
  42. pylow-0.1.0/src/pytrace_features/stitch/index.py +3 -0
  43. pylow-0.1.0/src/pytrace_features/stitch/service.py +101 -0
  44. pylow-0.1.0/src/pytrace_features/syscall/service.py +47 -0
  45. pylow-0.1.0/src/pytrace_features/tcp/service.py +43 -0
  46. pylow-0.1.0/src/pytrace_features/timeline/service.py +128 -0
  47. pylow-0.1.0/src/pytrace_infra/adapters/sqlite_store.py +143 -0
  48. pylow-0.1.0/src/pytrace_infra/adapters/trace_collector_adapter.py +173 -0
pylow-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,457 @@
1
+ Metadata-Version: 2.4
2
+ Name: pylow
3
+ Version: 0.1.0
4
+ Summary: One CLI. Zero code changes. Full system flow visibility for any Python service or distributed system.
5
+ Requires-Python: >=3.10
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: pydantic>=2.0.0
8
+ Requires-Dist: fastapi>=0.110.0
9
+ Requires-Dist: uvicorn>=0.22.0
10
+ Requires-Dist: opentelemetry-api>=1.24.0
11
+ Requires-Dist: opentelemetry-sdk>=1.24.0
12
+ Requires-Dist: opentelemetry-exporter-otlp>=1.24.0
13
+ Requires-Dist: opentelemetry-instrumentation-fastapi>=0.45b0
14
+ Requires-Dist: httpx>=0.27.0
15
+ Requires-Dist: argcomplete>=3.0.0
16
+ Provides-Extra: dev
17
+ Requires-Dist: pytest>=8.0; extra == "dev"
18
+ Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
19
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
20
+ Requires-Dist: mypy>=1.8.0; extra == "dev"
21
+ Requires-Dist: ruff>=0.2.0; extra == "dev"
22
+
23
+
24
+
25
+
26
+ # pytrace
27
+
28
+ One CLI. Zero code changes. Full system flow visibility for any Python service or distributed system.
29
+
30
+ ## How it works under the hood
31
+ Three layers working together:
32
+ - **Layer 1** → OTel auto-instrumentation (HTTP, DB, gRPC, queues — zero code changes)
33
+ - **Layer 2** → bpftrace USDT (Python function call tree, syscalls)
34
+ - **Layer 3** → pytrace CLI (stitches both, renders the flow)
35
+
36
+ ---
37
+
38
+ ## Complete CLI Command Reference & Outputs
39
+
40
+ Here is the usage documentation and sample outputs for every command in the `pytrace` tool:
41
+
42
+ ### 1. `pytrace attach <pid>`
43
+ Attach to any running Python process and start collecting trace logs immediately.
44
+ ```bash
45
+ pytrace attach 4821
46
+ ```
47
+ **Output:**
48
+ ```text
49
+ ✓ Attached to process 4821. Monitoring execution events...
50
+ ```
51
+
52
+ ### 2. `pytrace flow`
53
+ Renders the complete execution flow tree (local/distributed spans & events) from the trace repository.
54
+ ```bash
55
+ pytrace flow --last
56
+ ```
57
+ **Output:**
58
+ ```text
59
+ handle_request 450ms
60
+ ├── authenticate_user 20ms
61
+ │ └── [redis GET session_id] 15ms
62
+ └── call_llm_chain 410ms
63
+ └── [POST api.openai.com/v1/chat/completions] 400ms
64
+ └── waiting (epoll_wait) 390ms ← bottleneck
65
+ ```
66
+
67
+ ### 3. `pytrace stitch`
68
+ Stitch distributed traces together across service boundaries using traceparent headers.
69
+ ```bash
70
+ pytrace stitch --services api,worker,ml-service
71
+ ```
72
+ **Output:**
73
+ ```text
74
+ REQUEST trace-id: t_demo_flow_123
75
+
76
+ api-gateway 450ms handle_request
77
+ └── api-gateway 20ms authenticate_user
78
+ └── api-gateway 15ms redis GET session_id
79
+ └── api-gateway 410ms call_llm_chain
80
+ └── api-gateway 400ms POST api.openai.com/v1/chat/completions
81
+ └── api-gateway 390ms waiting (epoll_wait)
82
+ ```
83
+
84
+ ### 4. `pytrace slow`
85
+ Continuously daemonize/monitor and surface slow execution paths exceeding a latency threshold.
86
+ ```bash
87
+ pytrace slow --threshold 200ms --watch
88
+ ```
89
+ **Output:**
90
+ ```text
91
+ Continuous monitoring daemon started. Threshold: 200ms, Watch: False
92
+ SLOW PATHS detected (last 5 min):
93
+
94
+ #1 handle_request → call_llm_chain → POST api.openai.com/v1/chat/completions → [waiting (epoll_wait)]
95
+ avg: 390ms occurrences: 1
96
+ root cause: epoll_wait 310ms — network latency to openai
97
+ ```
98
+
99
+ ### 5. `pytrace diff`
100
+ Compare execution flow metrics between versions or releases to detect regressions.
101
+ ```bash
102
+ pytrace diff --before deploy-v1.2 --after deploy-v1.3
103
+ ```
104
+ **Output:**
105
+ ```text
106
+ Comparing before v1.2 vs after v1.3...
107
+
108
+ REGRESSIONS:
109
+
110
+ handle_request +150ms avg (was 200ms, now 350ms)
111
+ call_llm +140ms avg (was 180ms, now 320ms)
112
+ serialize +12ms avg (was 3ms, now 15ms)
113
+
114
+ NEW CALLS in v1.3:
115
+ validate_schema 8ms (added input validation)
116
+
117
+ REMOVED in v1.3:
118
+ legacy_cache_check (removed)
119
+ ```
120
+
121
+ ### 6. `pytrace syscall <pid>`
122
+ Trace syscall counts and histogram latency patterns for the target process.
123
+ ```bash
124
+ pytrace syscall 4821
125
+ ```
126
+ **Output:**
127
+ ```text
128
+ Attaching syscall counter to PID 4821...
129
+ ✓ Attached. Monitoring syscall events... Ctrl+C to stop.
130
+
131
+ --- BPF Map: @sys_counts ---
132
+ sys_enter_read: 231
133
+ sys_enter_write: 184
134
+ sys_enter_epoll_wait: 42
135
+ ```
136
+
137
+ ### 7. `pytrace malloc <pid>`
138
+ Profile allocations and heap sizing metrics.
139
+ ```bash
140
+ pytrace malloc 4821
141
+ ```
142
+ **Output:**
143
+ ```text
144
+ Attaching allocator profile to PID 4821...
145
+ ✓ Attached. Monitoring memory allocations... Ctrl+C to stop.
146
+
147
+ --- BPF Map: @alloc_sizes (bytes allocated) ---
148
+ [64, 127] 45 |@@@@@@@@@@@ |
149
+ [512, 1023] 120 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
150
+ [4096, 8191] 18 |@@@@ |
151
+ ```
152
+
153
+ ### 8. `pytrace tcp <pid>`
154
+ Trace outbound TCP latency.
155
+ ```bash
156
+ pytrace tcp 4821
157
+ ```
158
+ **Output:**
159
+ ```text
160
+ Attaching TCP latency tracer to PID 4821...
161
+ ✓ Attached. Monitoring TCP sendmsg... Ctrl+C to stop.
162
+
163
+ --- BPF Map: @tcp_send_us (ns delay) ---
164
+ [100000, 200000] 21 |@@@@@@@@@@ |
165
+ ```
166
+
167
+ ### 9. `pytrace io <pid>`
168
+ Trace Block and File I/O read/write latencies.
169
+ ```bash
170
+ pytrace io 4821
171
+ ```
172
+ **Output:**
173
+ ```text
174
+ Attaching File I/O latency tracer to PID 4821...
175
+ ✓ Attached. Collecting block I/O events... Ctrl+C to stop.
176
+
177
+ --- BPF Map: @read_lat (ns) ---
178
+ [4096, 8191] 150 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
179
+ [16384, 32767] 23 |@@@@@ |
180
+ ```
181
+
182
+ ### 10. `pytrace flame <pid>`
183
+ Generate sampling-based user/kernel stack flame graphs.
184
+ ```bash
185
+ pytrace flame 4821 --duration 5
186
+ ```
187
+ **Output:**
188
+ ```text
189
+ Attaching kernel profile sampler to PID 4821 for 5s...
190
+ ✓ Attached. Sampling for 5s...
191
+ ✓ Saved flame graph to flamegraph.svg
192
+ ```
193
+
194
+ ### 11. `pytrace sched <pid>`
195
+ Monitor runqueue latency and scheduling delays.
196
+ ```bash
197
+ pytrace sched 4821
198
+ ```
199
+ **Output:**
200
+ ```text
201
+ Attaching scheduler delay tracer to PID 4821...
202
+ ✓ Attached. Collecting scheduler runqueue events... Ctrl+C to stop.
203
+
204
+ --- BPF Map: @runq_latency_us (us delay) ---
205
+ [1, 2] 98 |@@@@@@@@@@@@@@@@@@@@@@@@ |
206
+ [4, 8] 142 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@|
207
+ ```
208
+
209
+ ### 12. `pytrace pycall <pid>`
210
+ Profile Python `PyObject_Call` execution timings.
211
+ ```bash
212
+ pytrace pycall 4821
213
+ ```
214
+ **Output:**
215
+ ```text
216
+ Attaching Python function call timer to PID 4821...
217
+ ✓ Attached. Collecting PyObject_Call events... Ctrl+C to stop.
218
+
219
+ --- BPF Map: @latency (time spent per function in us) ---
220
+ SLOW execute_query took 12400us
221
+ SLOW process_job took 1850us
222
+ ```
223
+
224
+ ### 13. `pytrace pyframe <pid>`
225
+ Log Python execution contexts at the frame level (file, function, line).
226
+ ```bash
227
+ pytrace pyframe 4821
228
+ ```
229
+ **Output:**
230
+ ```text
231
+ Attaching Python frame USDT tracer to PID 4821...
232
+ ✓ Attached. Collecting USDT frame events... Ctrl+C to stop.
233
+
234
+ ENTER execute_query() @ db/models.py:142
235
+ slow_query() @ db/models.py:142 — p99: 340ms
236
+ ```
237
+
238
+ ### 14. `pytrace pycpu <pid>`
239
+ Identify CPU hotspots in Python runtime execution stacks.
240
+ ```bash
241
+ pytrace pycpu 4821
242
+ ```
243
+ **Output:**
244
+ ```text
245
+ Attaching CPU hotspot sampler to PID 4821...
246
+ ✓ Attached. Sampling CPU stacks... Ctrl+C to stop.
247
+
248
+ --- BPF Map: @stacks ---
249
+ [0x7f3b821034bc, 0x7f3b821035dc]: 145
250
+ -> Resolved: call_llm_chain @ gateway/orchestrator.py:120
251
+ ```
252
+
253
+ ### 15. `pytrace pyexcept <pid>`
254
+ Trace raised and caught exceptions within Python virtual machine.
255
+ ```bash
256
+ pytrace pyexcept 4821
257
+ ```
258
+ **Output:**
259
+ ```text
260
+ Attaching Python exception tracer to PID 4821...
261
+ ✓ Attached. Monitoring exceptions... Ctrl+C to stop.
262
+
263
+ EXCEPTION KeyError @ tid=10234
264
+ [ustack]:
265
+ get_user_context @ db/client.py:48
266
+ ```
267
+
268
+ ### 16. `pytrace pyiowait <pid>`
269
+ Trace Python code blocked waiting on blocking I/O calls.
270
+ ```bash
271
+ pytrace pyiowait 4821
272
+ ```
273
+ **Output:**
274
+ ```text
275
+ Attaching I/O Wait blocking call tracer to PID 4821...
276
+ ✓ Attached. Monitoring blocking sys_read calls... Ctrl+C to stop.
277
+
278
+ BLOCKING READ 12ms
279
+ [ustack]:
280
+ fetch_metadata @ db/client.py:54
281
+ ```
282
+
283
+ ### 17. `pytrace pygil <pid>`
284
+ Profile GIL lock acquisition delays and thread contention.
285
+ ```bash
286
+ pytrace pygil 4821
287
+ ```
288
+ **Output:**
289
+ ```text
290
+ Attaching GIL lock contention tracer to PID 4821...
291
+ ✓ Attached. Monitoring GIL wait states... Ctrl+C to stop.
292
+
293
+ GIL WAIT 1250us tid=10234 stack:
294
+ [ustack]:
295
+ calculate_features @ ml/engine.py:89
296
+ ```
297
+
298
+ ### 18. `pytrace pyleak <pid>`
299
+ Profile heap allocations to detect memory leak patterns.
300
+ ```bash
301
+ pytrace pyleak 4821
302
+ ```
303
+ **Output:**
304
+ ```text
305
+ Attaching memory leak tracer to PID 4821...
306
+ ✓ Attached. Collecting memory allocation metrics... Ctrl+C to stop.
307
+
308
+ === TOP ALLOCATORS ===
309
+ @allocs[0x7f3b821034bc]: 10485760 bytes
310
+ -> allocating callsite: load_dataset @ ml/data.py:12
311
+ ```
312
+
313
+ ### 19. `pytrace pyreq <pid>`
314
+ Measure end-to-end request lifecycle breakdown.
315
+ ```bash
316
+ pytrace pyreq 4821
317
+ ```
318
+ **Output:**
319
+ ```text
320
+ Attaching Request Lifecycle timer to PID 4821...
321
+ ✓ Attached. Collecting Request Latency counts... Ctrl+C to stop.
322
+
323
+ REQ START tid=10234
324
+ REQ DONE total=340ms db=310ms other=30ms
325
+ ```
326
+
327
+ ### 20. `pytrace timeline <pid>`
328
+ Trace absolute chronological timeline call graph.
329
+ ```bash
330
+ pytrace timeline 4821 --duration 5.0 --threshold 2.0
331
+ ```
332
+ **Output:**
333
+ ```text
334
+ [ 0.000ms] → handle_request() server.py:45
335
+ [ 0.040ms] → parse_headers() http.py:12
336
+ [ 0.051ms] ← parse_headers() [0.011ms]
337
+ [ 0.055ms] → execute_query() db.py:88
338
+ [ 91.230ms] ← execute_query() [91.175ms] ⚠️ SLOW
339
+ ```
340
+
341
+ ### 21. `pytrace pythread <pid>`
342
+ Trace thread-aware function call timelines with self-time.
343
+ ```bash
344
+ pytrace pythread 4821
345
+ ```
346
+ **Output:**
347
+ ```text
348
+ Attaching thread-aware tracer to PID 4821...
349
+ ✓ Attached. Collecting threaded events... Ctrl+C to stop.
350
+
351
+ --- Thread ID: 10001 ---
352
+ parse_headers() spent 0.00ms (Self time: 0.00ms)
353
+ ```
354
+
355
+ ### 22. `pytrace pyasync <pid>`
356
+ Trace async await coroutine metrics and yields.
357
+ ```bash
358
+ pytrace pyasync 4821
359
+ ```
360
+ **Output:**
361
+ ```text
362
+ Attaching async/coroutine tracer to PID 4821...
363
+ ✓ Attached. Monitoring coroutine suspends/resumes... Ctrl+C to stop.
364
+
365
+ --- Coroutine: 0x7f3b821034bc ---
366
+ Suspended counts: 2
367
+ Total CPU Time: 80us
368
+ ```
369
+
370
+ ### 23. `pytrace pyargs <pid>`
371
+ Profile Python function call argument types and layout.
372
+ ```bash
373
+ pytrace pyargs 4821
374
+ ```
375
+ **Output:**
376
+ ```text
377
+ Attaching argument Layout layout-tracer to PID 4821...
378
+ ✓ Attached. Dereferencing Python structs... Ctrl+C to stop.
379
+
380
+ 1000 CALL obj=0x7f3b821034bc args=0x7f3b821051fa
381
+ ```
382
+
383
+ ### 24. `pytrace pysyscall <pid>`
384
+ Profile syscalls attributed directly to Python frames.
385
+ ```bash
386
+ pytrace pysyscall 4821
387
+ ```
388
+ **Output:**
389
+ ```text
390
+ Attaching syscall-to-Python attribution tracer to PID 4821...
391
+ ✓ Attached. Monitoring slow read and futex syscalls... Ctrl+C to stop.
392
+
393
+ === SLOW READ fd=4 dur=12ms ===
394
+ [ustack]:
395
+ fetch_metadata @ db/client.py:54
396
+ ```
397
+
398
+ ### 25. `pytrace pynplus1 <pid>`
399
+ Detect potential ORM loop-driven N+1 query patterns.
400
+ ```bash
401
+ pytrace pynplus1 4821
402
+ ```
403
+ **Output:**
404
+ ```text
405
+ Attaching N+1 query loop detector to PID 4821...
406
+ ✓ Attached. Monitoring ORM execute loops... Ctrl+C to stop.
407
+
408
+ ⚠️ N+1 CANDIDATE: db/models.py:142
409
+ Called 15x in 5s (3.0/s)
410
+ ```
411
+
412
+ ### 26. `pytrace pygraph <pid>`
413
+ Trace hierarchical call relationships.
414
+ ```bash
415
+ pytrace pygraph 4821
416
+ ```
417
+ **Output:**
418
+ ```text
419
+ handle_request() calls=1 avg=0.00ms (server.py:45)
420
+ execute_query() calls=1 avg=0.00ms (db.py:88)
421
+ ```
422
+
423
+ ### 27. `pytrace pyanomaly <pid>`
424
+ Identify slow function calls using statistical baselines.
425
+ ```bash
426
+ pytrace pyanomaly 4821
427
+ ```
428
+ **Output:**
429
+ ```text
430
+ [BASELINE] execute_query(): mean=10.33ms stddev=0.76ms
431
+ 🚨 ANOMALY execute_query(): 45.00ms vs baseline 10.33ms
432
+ ```
433
+
434
+ ### 28. `pytrace pydash <pid>`
435
+ Stream traces directly to live curses dashboard.
436
+ ```bash
437
+ pytrace pydash 4821
438
+ ```
439
+ **Output:**
440
+ ```text
441
+ Attaching curses dashboard to PID 4821...
442
+ === LIVE FUNCTION TRACER ===
443
+ RECENT CALLS:
444
+ handle_request() 120.40ms
445
+ ```
446
+
447
+ ### 29. `pytrace pysingle <pid> <target_func>`
448
+ Trace single request / execution call tree with self time.
449
+ ```bash
450
+ pytrace pysingle 4821 handle_request
451
+ ```
452
+ **Output:**
453
+ ```text
454
+ [ 0.000ms] → handle_request() server.py:45
455
+ [ 0.011ms] → validate_token() auth.py:12
456
+ [ 0.015ms] ← validate_token() total=0.004ms self=0.003ms
457
+ ```