Skip to content

Report unattributed CPU on the top-queries reads — ranked-query CPU vs the box's measured CPU-seconds #2320

Description

@erikdarlingdata

The last unshipped item from #2235's wishlist, split out on that issue's close.

The ask: get_top_queries_by_cpu (and the procedures twin) should report what fraction of the instance's actually-consumed CPU the ranking explains: sum the returned rows' windowed CPU, divide by measured CPU-seconds for the same window (cpu_utilization is already collected — SQL-process % × core count × window), and return both the numerator and the ratio, e.g. attributed_cpu_ratio: 0.32 with a one-line note when it's low.

Why it earns its place, twice over from #2235:

  1. Pre-Credit a newly compiled plan's counter instead of discarding it (#2235) #2290, the reads explained ~10% of the box and nothing said so — a caller assumed the ranking explained everything and chased the visible 10%. Post-fix the top-10 explains roughly a third; still worth surfacing, since plan-cache attribution can never reach 100% (evictions between snapshots, zero-cost rows, non-query CPU).
  2. It is exactly the number that catches an impossible claim at a glance: the Datadog comparison died the moment someone divided its worker_time sum by the box's available CPU-seconds and got 137%. Our own tools should hand the caller that denominator instead of leaving it to be re-derived.

Sketch: the window's CPU-seconds comes from the existing cpu_utilization series (avg sql_server_cpu% over the window × cores × seconds); cores from server_properties. Both stores hold all three pieces. Denominator gaps (cpu_utilization missing for part of the window) should degrade to omitting the ratio, never to a made-up one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions