[TASKMGR] Clamp the values returned from PerfDataGetProcessorUsage() and PerfDataGetProcessorSystemUsage() inside these functions.

It's necessary to make this clamping there so that returned values are
always used consistently in taskmgr, including in places where the
values are directly fetched into other functions.

This is a free adaptation from
Wine commit
a9742b3210c4cec67aca3c0012f3b9504a4368cf
From: Gerald Pfeifer <gerald@pfeifer.com>

taskmgr: Move out-of-domain checking into
PerfDataGetProcessorUsage() and PerfDataGetProcessorSystemUsage().
This commit is contained in:
Hermès Bélusca-Maïto 2021-12-18 03:10:26 +01:00
parent 7b53126375
commit 0b4c8bdd1c
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
3 changed files with 3 additions and 14 deletions

View file

@ -148,8 +148,6 @@ void Graph_DrawCpuUsageGraph(HDC hDC, HWND hWnd)
* Get the CPU usage
*/
CpuUsage = PerfDataGetProcessorUsage();
if (CpuUsage <= 0) CpuUsage = 0;
if (CpuUsage > 100) CpuUsage = 100;
wsprintfW(Text, L"%d%%", (int)CpuUsage);
@ -179,8 +177,6 @@ void Graph_DrawCpuUsageGraph(HDC hDC, HWND hWnd)
if (TaskManagerSettings.ShowKernelTimes)
{
CpuKernelUsage = PerfDataGetProcessorSystemUsage();
if (CpuKernelUsage <= 0) CpuKernelUsage = 0;
if (CpuKernelUsage >= 100) CpuKernelUsage = 100;
nBarsUsedKernel = (nBars * CpuKernelUsage) / 100;
}
else

View file

@ -458,7 +458,7 @@ ULONG PerfDataGetProcessorUsage(void)
{
ULONG Result;
EnterCriticalSection(&PerfDataCriticalSection);
Result = (ULONG)dbIdleTime;
Result = (ULONG)min(max(dbIdleTime, 0.), 100.);
LeaveCriticalSection(&PerfDataCriticalSection);
return Result;
}
@ -467,7 +467,7 @@ ULONG PerfDataGetProcessorSystemUsage(void)
{
ULONG Result;
EnterCriticalSection(&PerfDataCriticalSection);
Result = (ULONG)dbKernelTime;
Result = (ULONG)min(max(dbKernelTime, 0.), 100.);
LeaveCriticalSection(&PerfDataCriticalSection);
return Result;
}

View file

@ -422,8 +422,7 @@ DWORD WINAPI PerformancePageRefreshThread(PVOID Parameter)
* Get the CPU usage
*/
CpuUsage = PerfDataGetProcessorUsage();
if (CpuUsage <= 0 ) CpuUsage = 0;
if (CpuUsage > 100) CpuUsage = 100;
CpuKernelUsage = PerfDataGetProcessorSystemUsage();
if (!bInMenuLoop)
{
@ -431,12 +430,6 @@ DWORD WINAPI PerformancePageRefreshThread(PVOID Parameter)
SendMessageW(hStatusWnd, SB_SETTEXT, 1, (LPARAM)Text);
}
CpuKernelUsage = PerfDataGetProcessorSystemUsage();
if (CpuKernelUsage <= 0)
CpuKernelUsage = 0;
else if (CpuKernelUsage > 100)
CpuKernelUsage = 100;
/*
* Get the memory usage
*/