← Back to Pull requests

chore: profiler overhead metrics #22209

Open
unknown opened this pull request with 523 lines diff across 6 files
View on GitHub
unknown unknown commented on Nov 30, 2026 20:19 UTC
Author

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.

  • added ddup_collect_stats_json() which is a cpp function that reads the native ProfilerStats under the profile lock and returns them as JSON and its exposed to Python with a cython binding

  • modified Scheduler.flush() to collect stats before upload (since upload swaps/resets them), measure snapshot and upload wall times separately, and call emit_profiler_telemetry() after each flush
  • Here 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 | Total sys.monitoring.RAISE callback invocations (before filtering) |
    | exception.events_sampled | count | Callbacks that captured a stack sample |

    count for metrics where sum matters -- accumulation
    gauge for point in time snapshots
    distribution for metrics where the spread matters

    Testing


    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 JSON

  • json.loads() on a ~200 byte string

  • telemetry_writer.add_gauge_metric() / add_distribution_metric() in mem queue writes, cheap

  • time.monotonic_ns() calls, also cheap
  • And 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 |

    Diff: 523 lines (+392 / -131) across 6 files Reviewer: gyuheon0h Review duration: 1417m
    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
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.8% (MEDIUM) · Higher = larger blast radius
    47.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 25.5% · Safe to merge
    25.5%