Skip to content

Modify System_Requests_C report to account for # of CPU on the system#487

Open
PiJoCoder wants to merge 2 commits intomasterfrom
FixSystemRequestsCPUcount_pijocoder_032526
Open

Modify System_Requests_C report to account for # of CPU on the system#487
PiJoCoder wants to merge 2 commits intomasterfrom
FixSystemRequestsCPUcount_pijocoder_032526

Conversation

@PiJoCoder
Copy link
Collaborator

No description provided.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the System_Requests_C SSRS report definition to normalize reported CPU utilization by the system’s CPU core count, and adjusts report text/formatting to reflect the new meaning of “CPU %”.

Changes:

  • Added core-count lookup logic and normalized cpu_percent calculations by dividing by core count.
  • Updated report titles/labels/prompts and numeric formats to indicate normalized CPU%.
  • Added a report footer/info row to display CPU core count.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 10 comments.

File Description
sqlnexus/Reports/System_Requests_C.rdlC Normalizes CPU% by core count, updates UI text/formatting, and adds core-count display.
NexusReports/System_Requests_C.rdl Same report updates mirrored in the report project output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +179 to +182
OR runtime < prev_runtime
THEN NULL
ELSE DATEDIFF_BIG(ms, prev_runtime, runtime)
END AS elapsed_ms
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

elapsed_ms is computed via DATEDIFF_BIG(ms, ...) (bigint) and returned as delta_elapse_time. The RDL field for delta_elapse_time is still typed as System.Int32 (from the previous DATEDIFF(ms, ...)), which can overflow/truncate for larger gaps and cause render errors. Either cast elapsed_ms back to int or update the field type to System.Int64.

Copilot uses AI. Check for mistakes.
GROUP BY c2.command
HAVING
SUM(c2.delta_cpu) * 100.0
/ NULLIF(AVG(CONVERT(float, c2.elapsed_ms)), 0)
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command-threshold filter groups only by c2.command but computes CPU% using SUM(delta_cpu) / AVG(elapsed_ms). Over a multi-row time range this inflates CPU% roughly by the number of samples (since SUM/AVG scales with row count) and can cause incorrect filtering/ordering. Use a time-weighted denominator (e.g., SUM(elapsed_ms)) or reintroduce the prior grouping by (command, runtime) if the intent is per-sample thresholding.

Suggested change
/ NULLIF(AVG(CONVERT(float, c2.elapsed_ms)), 0)
/ NULLIF(SUM(CONVERT(float, c2.elapsed_ms)), 0)

Copilot uses AI. Check for mistakes.
<Paragraph>
<TextRuns>
<TextRun>
<Value>CPU Core Count </Value>
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The label CPU Core Count includes trailing spaces, which will render as extra padding/odd text in the report. Remove the trailing spaces from the textbox value.

Suggested change
<Value>CPU Core Count </Value>
<Value>CPU Core Count</Value>

Copilot uses AI. Check for mistakes.
Comment on lines +27 to +46
<DataSet Name="DataSet_CoreCount">
<Query>
<DataSourceName>DataSource1</DataSourceName>
<CommandText>
DECLARE @CoreCount INT = 1;
SELECT @CoreCount = COALESCE(
(SELECT CAST(PropertyValue AS INT) FROM [dbo].[tbl_ServerProperties] WHERE PropertyName = 'cpu_count'),
(SELECT MAX(cpu_count) FROM [dbo].[tbl_dm_os_sys_info]),
1
);
SELECT @CoreCount AS CoreCount;
</CommandText>
</Query>
<Fields>
<Field Name="CoreCount">
<DataField>CoreCount</DataField>
<rd:TypeName>System.Int32</rd:TypeName>
</Field>
</Fields>
</DataSet>
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DataSet_CoreCount appears to be unused (no other part of the report references it). This adds an extra query and duplicates the core-count logic already embedded in DataSet_System_Threads_Stats. Remove this dataset or wire the report to use it.

Suggested change
<DataSet Name="DataSet_CoreCount">
<Query>
<DataSourceName>DataSource1</DataSourceName>
<CommandText>
DECLARE @CoreCount INT = 1;
SELECT @CoreCount = COALESCE(
(SELECT CAST(PropertyValue AS INT) FROM [dbo].[tbl_ServerProperties] WHERE PropertyName = 'cpu_count'),
(SELECT MAX(cpu_count) FROM [dbo].[tbl_dm_os_sys_info]),
1
);
SELECT @CoreCount AS CoreCount;
</CommandText>
</Query>
<Fields>
<Field Name="CoreCount">
<DataField>CoreCount</DataField>
<rd:TypeName>System.Int32</rd:TypeName>
</Field>
</Fields>
</DataSet>

Copilot uses AI. Check for mistakes.
<Paragraph>
<TextRuns>
<TextRun>
<Value>CPU Core Count </Value>
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The label CPU Core Count includes trailing spaces, which will render as extra padding/odd text in the report. Remove the trailing spaces from the textbox value.

Suggested change
<Value>CPU Core Count </Value>
<Value>CPU Core Count</Value>

Copilot uses AI. Check for mistakes.
Comment on lines +179 to +182
OR runtime &lt; prev_runtime
THEN NULL
ELSE DATEDIFF_BIG(ms, prev_runtime, runtime)
END AS elapsed_ms
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

elapsed_ms is computed via DATEDIFF_BIG(ms, ...) (bigint) and returned as delta_elapse_time. The RDL field for delta_elapse_time is still typed as System.Int32 (from the previous DATEDIFF(ms, ...)), which can overflow/truncate for larger gaps and cause render errors. Either cast elapsed_ms back to int or update the field type to System.Int64.

Copilot uses AI. Check for mistakes.
Comment on lines +27 to +46
<DataSet Name="DataSet_CoreCount">
<Query>
<DataSourceName>DataSource1</DataSourceName>
<CommandText>
DECLARE @CoreCount INT = 1;
SELECT @CoreCount = COALESCE(
(SELECT CAST(PropertyValue AS INT) FROM [dbo].[tbl_ServerProperties] WHERE PropertyName = 'cpu_count'),
(SELECT MAX(cpu_count) FROM [dbo].[tbl_dm_os_sys_info]),
1
);
SELECT @CoreCount AS CoreCount;
</CommandText>
</Query>
<Fields>
<Field Name="CoreCount">
<DataField>CoreCount</DataField>
<rd:TypeName>System.Int32</rd:TypeName>
</Field>
</Fields>
</DataSet>
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DataSet_CoreCount appears to be unused (no other part of the report references it). This adds an extra query and duplicates the core-count logic already embedded in DataSet_System_Threads_Stats. Remove this dataset or wire the report to use it.

Suggested change
<DataSet Name="DataSet_CoreCount">
<Query>
<DataSourceName>DataSource1</DataSourceName>
<CommandText>
DECLARE @CoreCount INT = 1;
SELECT @CoreCount = COALESCE(
(SELECT CAST(PropertyValue AS INT) FROM [dbo].[tbl_ServerProperties] WHERE PropertyName = 'cpu_count'),
(SELECT MAX(cpu_count) FROM [dbo].[tbl_dm_os_sys_info]),
1
);
SELECT @CoreCount AS CoreCount;
</CommandText>
</Query>
<Fields>
<Field Name="CoreCount">
<DataField>CoreCount</DataField>
<rd:TypeName>System.Int32</rd:TypeName>
</Field>
</Fields>
</DataSet>

Copilot uses AI. Check for mistakes.
GROUP BY c2.command
HAVING
SUM(c2.delta_cpu) * 100.0
/ NULLIF(AVG(CONVERT(float, c2.elapsed_ms)), 0)
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command-threshold filter groups only by c2.command but computes CPU% using SUM(delta_cpu) / AVG(elapsed_ms). Over a multi-row time range this inflates CPU% roughly by the number of samples (since SUM/AVG scales with row count) and can cause incorrect filtering/ordering. Use a time-weighted denominator (e.g., SUM(elapsed_ms)) or reintroduce the prior grouping by (command, runtime) if the intent is per-sample thresholding.

Suggested change
/ NULLIF(AVG(CONVERT(float, c2.elapsed_ms)), 0)
/ NULLIF(SUM(CONVERT(float, c2.elapsed_ms)), 0)

Copilot uses AI. Check for mistakes.
@PiJoCoder PiJoCoder changed the title Modify System_Requests_C to account for CPU count on the system Modify System_Requests_C report to account for # of CPU on the system Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants