Skip to content

Commit a46dbce

Browse files
committed
Add cpu saturation/queue count to cpu topology latency
1 parent b1f3d3e commit a46dbce

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

ProcessHacker/include/procprv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ extern SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION PhCpuTotals;
1919
extern ULONG PhTotalProcesses;
2020
extern ULONG PhTotalThreads;
2121
extern ULONG PhTotalHandles;
22+
extern ULONG PhTotalCpuQueueLength;
2223

2324
extern ULONG64 PhCpuTotalCycleDelta;
2425
extern PLARGE_INTEGER PhCpuIdleCycleTime; // cycle time for Idle

ProcessHacker/procprv.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION PhCpuTotals;
181181
ULONG PhTotalProcesses = 0;
182182
ULONG PhTotalThreads = 0;
183183
ULONG PhTotalHandles = 0;
184+
ULONG PhTotalCpuQueueLength = 0;
184185

185186
PSYSTEM_PROCESS_INFORMATION PhDpcsProcessInformation = NULL;
186187
PSYSTEM_PROCESS_INFORMATION PhInterruptsProcessInformation = NULL;
@@ -1843,17 +1844,20 @@ VOID PhpGetProcessThreadInformation(
18431844
_In_ PSYSTEM_PROCESS_INFORMATION Process,
18441845
_Out_opt_ PBOOLEAN IsSuspended,
18451846
_Out_opt_ PBOOLEAN IsPartiallySuspended,
1846-
_Out_opt_ PULONG ContextSwitches
1847+
_Out_opt_ PULONG ContextSwitches,
1848+
_Out_opt_ PULONG ReadyThreads
18471849
)
18481850
{
18491851
ULONG i;
18501852
BOOLEAN isSuspended;
18511853
BOOLEAN isPartiallySuspended;
18521854
ULONG contextSwitches;
1855+
ULONG threadQueueCount;
18531856

18541857
isSuspended = PH_IS_REAL_PROCESS_ID(Process->UniqueProcessId);
18551858
isPartiallySuspended = FALSE;
18561859
contextSwitches = 0;
1860+
threadQueueCount = 0;
18571861

18581862
for (i = 0; i < Process->NumberOfThreads; i++)
18591863
{
@@ -1867,6 +1871,11 @@ VOID PhpGetProcessThreadInformation(
18671871
isPartiallySuspended = TRUE;
18681872
}
18691873

1874+
if (Process->Threads[i].ThreadState == Ready)
1875+
{
1876+
threadQueueCount++;
1877+
}
1878+
18701879
contextSwitches += Process->Threads[i].ContextSwitches;
18711880
}
18721881

@@ -1883,6 +1892,8 @@ VOID PhpGetProcessThreadInformation(
18831892
*IsPartiallySuspended = isPartiallySuspended;
18841893
if (ContextSwitches)
18851894
*ContextSwitches = contextSwitches;
1895+
if (ReadyThreads)
1896+
*ReadyThreads = threadQueueCount;
18861897
}
18871898

18881899
VOID PhProcessProviderUpdate(
@@ -1953,6 +1964,7 @@ VOID PhProcessProviderUpdate(
19531964
PhTotalProcesses = 0;
19541965
PhTotalThreads = 0;
19551966
PhTotalHandles = 0;
1967+
PhTotalCpuQueueLength = 0;
19561968

19571969
if (!NT_SUCCESS(PhEnumProcesses(&processes)))
19581970
return;
@@ -2177,6 +2189,7 @@ VOID PhProcessProviderUpdate(
21772189
BOOLEAN isSuspended;
21782190
BOOLEAN isPartiallySuspended;
21792191
ULONG contextSwitches;
2192+
ULONG readyThreads;
21802193

21812194
// Create the process item and fill in basic information.
21822195
processItem = PhCreateProcessItem(process->UniqueProcessId);
@@ -2188,8 +2201,9 @@ VOID PhProcessProviderUpdate(
21882201
PhpAddProcessRecord(processRecord);
21892202
processItem->Record = processRecord;
21902203

2191-
PhpGetProcessThreadInformation(process, &isSuspended, &isPartiallySuspended, &contextSwitches);
2204+
PhpGetProcessThreadInformation(process, &isSuspended, &isPartiallySuspended, &contextSwitches, &readyThreads);
21922205
PhpUpdateDynamicInfoProcessItem(processItem, process);
2206+
PhTotalCpuQueueLength += readyThreads;
21932207

21942208
// Initialize the deltas.
21952209
PhUpdateDelta(&processItem->CpuKernelDelta, process->KernelTime.QuadPart);
@@ -2249,13 +2263,15 @@ VOID PhProcessProviderUpdate(
22492263
BOOLEAN isSuspended;
22502264
BOOLEAN isPartiallySuspended;
22512265
ULONG contextSwitches;
2266+
ULONG readyThreads;
22522267
FLOAT newCpuUsage;
22532268
FLOAT kernelCpuUsage;
22542269
FLOAT userCpuUsage;
22552270

2256-
PhpGetProcessThreadInformation(process, &isSuspended, &isPartiallySuspended, &contextSwitches);
2271+
PhpGetProcessThreadInformation(process, &isSuspended, &isPartiallySuspended, &contextSwitches, &readyThreads);
22572272
PhpUpdateDynamicInfoProcessItem(processItem, process);
22582273
PhpFillProcessItemExtension(processItem, process);
2274+
PhTotalCpuQueueLength += readyThreads;
22592275

22602276
// Update the deltas.
22612277
PhUpdateDelta(&processItem->CpuKernelDelta, process->KernelTime.QuadPart);

ProcessHacker/syssccpu.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,13 +1123,15 @@ VOID PhSipUpdateCpuPanel(
11231123
performanceCounterTicks.QuadPart = 0;
11241124

11251125
PhInitFormatI64UGroupDigits(&format[0], performanceCounterTicks.QuadPart);
1126+
PhInitFormatS(&format[1], L" | ");
1127+
PhInitFormatI64UGroupDigits(&format[2], PhTotalCpuQueueLength);
11261128

1127-
if (PhFormatToBuffer(format, 1, formatBuffer, sizeof(formatBuffer), NULL))
1129+
if (PhFormatToBuffer(format, 3, formatBuffer, sizeof(formatBuffer), NULL))
11281130
PhSetWindowText(CpuPanelLatencyLabel, formatBuffer);
11291131
else
11301132
PhSetWindowText(CpuPanelLatencyLabel, PhaFormatUInt64(performanceCounterTicks.QuadPart, TRUE)->Buffer);
11311133
#else
1132-
PhSetWindowText(CpuPanelLatencyLabel, L"N/A");
1134+
PhSetWindowText(CpuPanelLatencyLabel, PhaFormatUInt64(PhTotalCpuQueueLength, TRUE)->Buffer);
11331135
#endif
11341136
}
11351137

0 commit comments

Comments
 (0)