chore: profiler overhead metrics #22209
All Vouch review confidence checks passed
Residual risk 0.25 = Change Risk (0.48) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.48 · 523 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.375
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #22209"
general
weight: 0.35
gyuheon0h
Description
Previously, we only embedded profiler stats as JSON metadata inside pprof uploads to the profiling backend. This change also routes them through the telemetry intake.
These metrics are emitted once per flush cycle and give visibility into the profiler's resource consumption without requiring access to individual profile payloads.
ddup_collect_stats_json()which is a cpp function that reads the nativeProfilerStatsunder the profile lock and returns them as JSON and its exposed to Python with a cython bindingScheduler.flush()to collect stats before upload (since upload swaps/resets them), measure snapshot and upload wall times separately, and callemit_profiler_telemetry()after each flushHere are the metrics added:
Flush timing
| Metric | Type | Description |
|--------|------|-------------|
|
flush.wall_time_ms| distribution | Total wall time of the flush cycle (snapshot + upload) ||
flush.snapshot_wall_time_ms| distribution | Wall time of the collector snapshot phase ||
flush.upload_wall_time_ms| distribution | Wall time of the serialization + network upload phase |Stack sampler (from native
ProfilerStats)| Metric | Type | Description |
|--------|------|-------------|
|
stack.capture_cpu_time_us| count | CPU time spent by the sampler thread capturing samples ||
stack.sample_count| count | Number of stack samples collected (one per thread per cycle) ||
stack.sampling_event_count| count | Number of sampling cycles ||
stack.sampling_interval_us| gauge | Current adaptive sampling interval ||
stack.string_table_count| gauge | Echion frame cache entries (memory footprint proxy) ||
stack.asyncio_task_count| gauge | Peak asyncio tasks seen per cycle (more tasks = more sampling work) ||
stack.greenlet_count| gauge | Tracked greenlets (more greenlets = more sampling work) |Memory allocation profiler
| Metric | Type | Description |
|--------|------|-------------|
|
memalloc.heap.tracker_size| gauge | Number of tracked allocations in the heap tracker ||
memalloc.snapshot_wall_time_ms| distribution | Wall time of the heap snapshot export |Lock profiler
| Metric | Type | Description |
|--------|------|-------------|
|
lock.events_sampled| count | Lock acquire + release events that produced a sample ||
lock.avg_acquire_overhead_ns| gauge | Average instrumentation time per sampled acquire (ns) |Exception profiler
| Metric | Type | Description |
|--------|------|-------------|
|
exception.events_seen| count | Totalsys.monitoring.RAISEcallback invocations (before filtering) ||
exception.events_sampled| count | Callbacks that captured a stack sample |countfor metrics where sum matters -- accumulationgaugefor point in time snapshotsdistributionfor metrics where the spread mattersTesting
Doe results with this config
language=python, runtime_version=3.12, framework=fastapi, event_loop=asyncio,archetype=idle, workers=2, profiling=true, tracing=false, agent=false,
lock_ops=53, lock_type=Lock, exception_mode=handled, exceptions_num=10,
duration=300s, n=3
The overhead added here is
ddup.collect_stats_json()call that acquires profile lock, reads stats, returns JSONjson.loads()on a ~200 byte stringtelemetry_writer.add_gauge_metric()/add_distribution_metric()in mem queue writes, cheaptime.monotonic_ns()calls, also cheapAnd all this happens only once per flush cycle
| Run | Branch | Latency p50 | Latency p99 |
|-----|---------|-------------|-------------|
| 1 | main | 12.89 ms | 13.98 ms |
| 2 | main | 12.88 ms | 13.51 ms |
| 3 | main | 12.87 ms | 13.74 ms |
| 1 | feature | 12.86 ms | 13.78 ms |
| 2 | feature | 12.86 ms | 13.61 ms |
| 3 | feature | 12.86 ms | 13.86 ms |
| | Main (avg) | Feature (avg) | Delta |
|-------------|------------|---------------|----------|
| Latency p50 | 12.88 ms | 12.86 ms | -0.02 ms |
| Latency p99 | 13.74 ms | 13.75 ms | +0.01 ms |