Files
sglang/python
minke.yu fec10023e0 observability: optional thread-CPU recording for detail phases
Adds an optional thread CPU clock next to the existing wall clock:

* detail_begin/end record time.thread_time_ns() only when detail is on and the
  loop is sampled; detail_add() accepts an explicit thread_cpu_ns for callers
  that already hold absolute start/end points (the prefill_batch_init parent).
* phase records carry [wall, count, start_wall, end_wall, cpu_sum, cpu_count].
  thread_cpu_ms and thread_cpu_measured_count are emitted whenever any
  occurrence was measured; non_cpu_ms only when every occurrence was, so a
  partial measurement never attributes unmeasured wall to non-CPU time. A
  phase whose CPU exceeds its wall keeps the clamped value, adds
  non_cpu_raw_ms and accounting_anomaly, and bumps a per-loop anomaly count.
* new detail_attr_sum()/detail_attr_setdefault() accumulate low-cardinality
  numeric loop attributes (eviction tokens, free-token snapshots).
* prefix_device_indices joins the attribute-only prefixes so per-request
  repeats never create spans.
* child spans carry phase_thread_cpu_ms / phase_cpu_measured_count /
  phase_non_cpu_ms, so the CPU split is visible without the loop attributes.

Default-off path is unchanged: no thread clock, no new dicts, no spans.
2026-11-12 10:30:29 +08:00
..