https://git.reactos.org/?p=reactos.git;a=commitdiff;h=0b4c8bdd1cb4cf1a50c107...
commit 0b4c8bdd1cb4cf1a50c1076c7ded19ee7e9f9198 Author: Hermès Bélusca-Maïto hermes.belusca-maito@reactos.org AuthorDate: Sat Dec 18 03:10:26 2021 +0100 Commit: Hermès Bélusca-Maïto hermes.belusca-maito@reactos.org CommitDate: Thu Jun 15 12:44:21 2023 +0200
[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(). --- base/applications/taskmgr/graph.c | 4 ---- base/applications/taskmgr/perfdata.c | 4 ++-- base/applications/taskmgr/perfpage.c | 9 +-------- 3 files changed, 3 insertions(+), 14 deletions(-)
diff --git a/base/applications/taskmgr/graph.c b/base/applications/taskmgr/graph.c index 3962e976fb5..0b30e1ffbbc 100644 --- a/base/applications/taskmgr/graph.c +++ b/base/applications/taskmgr/graph.c @@ -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 diff --git a/base/applications/taskmgr/perfdata.c b/base/applications/taskmgr/perfdata.c index 573021d5f89..c4e80d5832a 100644 --- a/base/applications/taskmgr/perfdata.c +++ b/base/applications/taskmgr/perfdata.c @@ -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; } diff --git a/base/applications/taskmgr/perfpage.c b/base/applications/taskmgr/perfpage.c index df36c918859..62668e059c0 100644 --- a/base/applications/taskmgr/perfpage.c +++ b/base/applications/taskmgr/perfpage.c @@ -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 */