Skip to content

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

Closed

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.

Activity

  1. erikdarlingdata commented on Aug 18, 2026

    @erikdarlingdata
    OwnerAuthor

    Shipped in 2ceaaa9 (#2330): get_top_queries_by_cpu and get_top_procedures_by_cpu (both SKUs) now return cpu_attribution — the returned rows' summed CPU-seconds, the SQL process's measured CPU-seconds for the window (avg cpu_utilization × core count × window), and attributed_cpu_ratio. Under half, the note explains where unattributable CPU goes; above the process's own measured consumption it flags the impossible claim (the 137% marker). The degrade rule is exactly as specified: missing CPU series, missing core count, or coverage under 90% of the window omits the ratio rather than inventing one. One computation in PerformanceMonitor.Common, decision-table pinned identically in both test projects. In the next nightly; rides the upcoming release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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