Ported the ReactOS taskmgr written by Brian Palmer.
[wine.git] / programs / taskmgr / perfpage.c
blob0653ab852603e6d23eeb60ab7de5f3818db658dc
1 /*
2 * ReactOS Task Manager
4 * perfpage.c
6 * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
24 #include <windows.h>
25 #include <commctrl.h>
26 #include <stdlib.h>
27 #include <malloc.h>
28 #include <memory.h>
29 #include <tchar.h>
30 #include <stdio.h>
31 #include <winnt.h>
33 #include "taskmgr.h"
34 #include "perfdata.h"
35 #include "graphctl.h"
37 TGraphCtrl PerformancePageCpuUsageHistoryGraph;
38 TGraphCtrl PerformancePageMemUsageHistoryGraph;
40 HWND hPerformancePage; /* Performance Property Page */
41 HWND hPerformancePageCpuUsageGraph; /* CPU Usage Graph */
42 HWND hPerformancePageMemUsageGraph; /* MEM Usage Graph */
43 HWND hPerformancePageCpuUsageHistoryGraph; /* CPU Usage History Graph */
44 HWND hPerformancePageMemUsageHistoryGraph; /* Memory Usage History Graph */
45 HWND hPerformancePageTotalsFrame; /* Totals Frame */
46 HWND hPerformancePageCommitChargeFrame; /* Commit Charge Frame */
47 HWND hPerformancePageKernelMemoryFrame; /* Kernel Memory Frame */
48 HWND hPerformancePagePhysicalMemoryFrame; /* Physical Memory Frame */
49 HWND hPerformancePageCpuUsageFrame;
50 HWND hPerformancePageMemUsageFrame;
51 HWND hPerformancePageCpuUsageHistoryFrame;
52 HWND hPerformancePageMemUsageHistoryFrame;
53 HWND hPerformancePageCommitChargeTotalEdit; /* Commit Charge Total Edit Control */
54 HWND hPerformancePageCommitChargeLimitEdit; /* Commit Charge Limit Edit Control */
55 HWND hPerformancePageCommitChargePeakEdit; /* Commit Charge Peak Edit Control */
56 HWND hPerformancePageKernelMemoryTotalEdit; /* Kernel Memory Total Edit Control */
57 HWND hPerformancePageKernelMemoryPagedEdit; /* Kernel Memory Paged Edit Control */
58 HWND hPerformancePageKernelMemoryNonPagedEdit; /* Kernel Memory NonPaged Edit Control */
59 HWND hPerformancePagePhysicalMemoryTotalEdit; /* Physical Memory Total Edit Control */
60 HWND hPerformancePagePhysicalMemoryAvailableEdit; /* Physical Memory Available Edit Control */
61 HWND hPerformancePagePhysicalMemorySystemCacheEdit; /* Physical Memory System Cache Edit Control */
62 HWND hPerformancePageTotalsHandleCountEdit; /* Total Handles Edit Control */
63 HWND hPerformancePageTotalsProcessCountEdit; /* Total Processes Edit Control */
64 HWND hPerformancePageTotalsThreadCountEdit; /* Total Threads Edit Control */
67 static int nPerformancePageWidth;
68 static int nPerformancePageHeight;
69 static HANDLE hPerformancePageEvent = NULL; /* When this event becomes signaled then we refresh the performance page */
70 DWORD WINAPI PerformancePageRefreshThread(void *lpParameter);
72 void AdjustFrameSize(HWND hCntrl, HWND hDlg, int nXDifference, int nYDifference, int pos)
74 RECT rc;
75 int cx, cy, sx, sy;
77 GetClientRect(hCntrl, &rc);
78 MapWindowPoints(hCntrl, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT)));
79 if (pos) {
80 cx = rc.left;
81 cy = rc.top;
82 sx = rc.right - rc.left;
83 switch (pos) {
84 case 1:
85 break;
86 case 2:
87 cy += nYDifference / 2;
88 break;
89 case 3:
90 sx += nXDifference;
91 break;
92 case 4:
93 cy += nYDifference / 2;
94 sx += nXDifference;
95 break;
97 sy = rc.bottom - rc.top + nYDifference / 2;
98 SetWindowPos(hCntrl, NULL, cx, cy, sx, sy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER);
99 } else {
100 cx = rc.left + nXDifference;
101 cy = rc.top + nYDifference;
102 sx = sy = 0;
103 SetWindowPos(hCntrl, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
105 InvalidateRect(hCntrl, NULL, TRUE);
108 void AdjustControlPostion(HWND hCntrl, HWND hDlg, int nXDifference, int nYDifference)
110 AdjustFrameSize(hCntrl, hDlg, nXDifference, nYDifference, 0);
113 void AdjustCntrlPos(int ctrl_id, HWND hDlg, int nXDifference, int nYDifference)
115 AdjustFrameSize(GetDlgItem(hDlg, ctrl_id), hDlg, nXDifference, nYDifference, 0);
118 LRESULT CALLBACK PerformancePageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
120 RECT rc;
121 int nXDifference;
122 int nYDifference;
124 /* HDC hdc; */
125 /* PAINTSTRUCT ps; */
127 switch (message) {
128 case WM_INITDIALOG:
130 /* Save the width and height */
131 GetClientRect(hDlg, &rc);
132 nPerformancePageWidth = rc.right;
133 nPerformancePageHeight = rc.bottom;
135 /* Update window position */
136 SetWindowPos(hDlg, NULL, 15, 30, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
139 * Get handles to all the controls
141 hPerformancePageTotalsFrame = GetDlgItem(hDlg, IDC_TOTALS_FRAME);
142 hPerformancePageCommitChargeFrame = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_FRAME);
143 hPerformancePageKernelMemoryFrame = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_FRAME);
144 hPerformancePagePhysicalMemoryFrame = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_FRAME);
146 hPerformancePageCpuUsageFrame = GetDlgItem(hDlg, IDC_CPU_USAGE_FRAME);
147 hPerformancePageMemUsageFrame = GetDlgItem(hDlg, IDC_MEM_USAGE_FRAME);
148 hPerformancePageCpuUsageHistoryFrame = GetDlgItem(hDlg, IDC_CPU_USAGE_HISTORY_FRAME);
149 hPerformancePageMemUsageHistoryFrame = GetDlgItem(hDlg, IDC_MEMORY_USAGE_HISTORY_FRAME);
151 hPerformancePageCommitChargeTotalEdit = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_TOTAL);
152 hPerformancePageCommitChargeLimitEdit = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_LIMIT);
153 hPerformancePageCommitChargePeakEdit = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_PEAK);
154 hPerformancePageKernelMemoryTotalEdit = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_TOTAL);
155 hPerformancePageKernelMemoryPagedEdit = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_PAGED);
156 hPerformancePageKernelMemoryNonPagedEdit = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_NONPAGED);
157 hPerformancePagePhysicalMemoryTotalEdit = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_TOTAL);
158 hPerformancePagePhysicalMemoryAvailableEdit = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_AVAILABLE);
159 hPerformancePagePhysicalMemorySystemCacheEdit = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_SYSTEM_CACHE);
160 hPerformancePageTotalsHandleCountEdit = GetDlgItem(hDlg, IDC_TOTALS_HANDLE_COUNT);
161 hPerformancePageTotalsProcessCountEdit = GetDlgItem(hDlg, IDC_TOTALS_PROCESS_COUNT);
162 hPerformancePageTotalsThreadCountEdit = GetDlgItem(hDlg, IDC_TOTALS_THREAD_COUNT);
164 hPerformancePageCpuUsageGraph = GetDlgItem(hDlg, IDC_CPU_USAGE_GRAPH);
165 hPerformancePageMemUsageGraph = GetDlgItem(hDlg, IDC_MEM_USAGE_GRAPH);
166 hPerformancePageMemUsageHistoryGraph = GetDlgItem(hDlg, IDC_MEM_USAGE_HISTORY_GRAPH);
167 hPerformancePageCpuUsageHistoryGraph = GetDlgItem(hDlg, IDC_CPU_USAGE_HISTORY_GRAPH);
169 GetClientRect(hPerformancePageCpuUsageHistoryGraph, &rc);
170 /* create the control */
171 /* PerformancePageCpuUsageHistoryGraph.Create(0, rc, hDlg, IDC_CPU_USAGE_HISTORY_GRAPH); */
172 GraphCtrl_Create(&PerformancePageCpuUsageHistoryGraph, hPerformancePageCpuUsageHistoryGraph, hDlg, IDC_CPU_USAGE_HISTORY_GRAPH);
173 /* customize the control */
174 GraphCtrl_SetRange(&PerformancePageCpuUsageHistoryGraph, 0.0, 100.0, 10);
175 /* PerformancePageCpuUsageHistoryGraph.SetYUnits("Current") ; */
176 /* PerformancePageCpuUsageHistoryGraph.SetXUnits("Samples (Windows Timer: 100 msec)") ; */
177 /* PerformancePageCpuUsageHistoryGraph.SetBackgroundColor(RGB(0, 0, 64)) ; */
178 /* PerformancePageCpuUsageHistoryGraph.SetGridColor(RGB(192, 192, 255)) ; */
179 /* PerformancePageCpuUsageHistoryGraph.SetPlotColor(RGB(255, 255, 255)) ; */
180 GraphCtrl_SetBackgroundColor(&PerformancePageCpuUsageHistoryGraph, RGB(0, 0, 0)) ;
181 GraphCtrl_SetGridColor(&PerformancePageCpuUsageHistoryGraph, RGB(152, 205, 152)) ;
182 GraphCtrl_SetPlotColor(&PerformancePageCpuUsageHistoryGraph, 0, RGB(255, 0, 0)) ;
183 GraphCtrl_SetPlotColor(&PerformancePageCpuUsageHistoryGraph, 1, RGB(0, 255, 0)) ;
185 GetClientRect(hPerformancePageMemUsageHistoryGraph, &rc);
186 GraphCtrl_Create(&PerformancePageMemUsageHistoryGraph, hPerformancePageMemUsageHistoryGraph, hDlg, IDC_MEM_USAGE_HISTORY_GRAPH);
187 GraphCtrl_SetRange(&PerformancePageMemUsageHistoryGraph, 0.0, 100.0, 10) ;
188 GraphCtrl_SetBackgroundColor(&PerformancePageMemUsageHistoryGraph, RGB(0, 0, 0)) ;
189 GraphCtrl_SetGridColor(&PerformancePageMemUsageHistoryGraph, RGB(152, 215, 152)) ;
190 GraphCtrl_SetPlotColor(&PerformancePageMemUsageHistoryGraph, 0, RGB(255, 255, 0)) ;
191 /* Start our refresh thread */
192 #ifdef RUN_PERF_PAGE
193 CreateThread(NULL, 0, PerformancePageRefreshThread, NULL, 0, NULL);
194 #endif
197 * Subclass graph buttons
199 OldGraphWndProc = SetWindowLong(hPerformancePageCpuUsageGraph, GWL_WNDPROC, (LONG)Graph_WndProc);
200 SetWindowLong(hPerformancePageMemUsageGraph, GWL_WNDPROC, (LONG)Graph_WndProc);
201 OldGraphCtrlWndProc = SetWindowLong(hPerformancePageMemUsageHistoryGraph, GWL_WNDPROC, (LONG)GraphCtrl_WndProc);
202 SetWindowLong(hPerformancePageCpuUsageHistoryGraph, GWL_WNDPROC, (LONG)GraphCtrl_WndProc);
203 return TRUE;
205 case WM_COMMAND:
206 break;
207 #if 0
208 case WM_NCPAINT:
209 hdc = GetDC(hDlg);
210 GetClientRect(hDlg, &rc);
211 Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
212 ReleaseDC(hDlg, hdc);
213 break;
215 case WM_PAINT:
216 hdc = BeginPaint(hDlg, &ps);
217 GetClientRect(hDlg, &rc);
218 Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
219 EndPaint(hDlg, &ps);
220 break;
221 #endif
222 case WM_SIZE:
223 do {
224 int cx, cy;
226 if (wParam == SIZE_MINIMIZED)
227 return 0;
229 cx = LOWORD(lParam);
230 cy = HIWORD(lParam);
231 nXDifference = cx - nPerformancePageWidth;
232 nYDifference = cy - nPerformancePageHeight;
233 nPerformancePageWidth = cx;
234 nPerformancePageHeight = cy;
235 } while (0);
237 /* Reposition the performance page's controls */
238 AdjustFrameSize(hPerformancePageTotalsFrame, hDlg, 0, nYDifference, 0);
239 AdjustFrameSize(hPerformancePageCommitChargeFrame, hDlg, 0, nYDifference, 0);
240 AdjustFrameSize(hPerformancePageKernelMemoryFrame, hDlg, 0, nYDifference, 0);
241 AdjustFrameSize(hPerformancePagePhysicalMemoryFrame, hDlg, 0, nYDifference, 0);
242 AdjustCntrlPos(IDS_COMMIT_CHARGE_TOTAL, hDlg, 0, nYDifference);
243 AdjustCntrlPos(IDS_COMMIT_CHARGE_LIMIT, hDlg, 0, nYDifference);
244 AdjustCntrlPos(IDS_COMMIT_CHARGE_PEAK, hDlg, 0, nYDifference);
245 AdjustCntrlPos(IDS_KERNEL_MEMORY_TOTAL, hDlg, 0, nYDifference);
246 AdjustCntrlPos(IDS_KERNEL_MEMORY_PAGED, hDlg, 0, nYDifference);
247 AdjustCntrlPos(IDS_KERNEL_MEMORY_NONPAGED, hDlg, 0, nYDifference);
248 AdjustCntrlPos(IDS_PHYSICAL_MEMORY_TOTAL, hDlg, 0, nYDifference);
249 AdjustCntrlPos(IDS_PHYSICAL_MEMORY_AVAILABLE, hDlg, 0, nYDifference);
250 AdjustCntrlPos(IDS_PHYSICAL_MEMORY_SYSTEM_CACHE, hDlg, 0, nYDifference);
251 AdjustCntrlPos(IDS_TOTALS_HANDLE_COUNT, hDlg, 0, nYDifference);
252 AdjustCntrlPos(IDS_TOTALS_PROCESS_COUNT, hDlg, 0, nYDifference);
253 AdjustCntrlPos(IDS_TOTALS_THREAD_COUNT, hDlg, 0, nYDifference);
255 AdjustControlPostion(hPerformancePageCommitChargeTotalEdit, hDlg, 0, nYDifference);
256 AdjustControlPostion(hPerformancePageCommitChargeLimitEdit, hDlg, 0, nYDifference);
257 AdjustControlPostion(hPerformancePageCommitChargePeakEdit, hDlg, 0, nYDifference);
258 AdjustControlPostion(hPerformancePageKernelMemoryTotalEdit, hDlg, 0, nYDifference);
259 AdjustControlPostion(hPerformancePageKernelMemoryPagedEdit, hDlg, 0, nYDifference);
260 AdjustControlPostion(hPerformancePageKernelMemoryNonPagedEdit, hDlg, 0, nYDifference);
261 AdjustControlPostion(hPerformancePagePhysicalMemoryTotalEdit, hDlg, 0, nYDifference);
262 AdjustControlPostion(hPerformancePagePhysicalMemoryAvailableEdit, hDlg, 0, nYDifference);
263 AdjustControlPostion(hPerformancePagePhysicalMemorySystemCacheEdit, hDlg, 0, nYDifference);
264 AdjustControlPostion(hPerformancePageTotalsHandleCountEdit, hDlg, 0, nYDifference);
265 AdjustControlPostion(hPerformancePageTotalsProcessCountEdit, hDlg, 0, nYDifference);
266 AdjustControlPostion(hPerformancePageTotalsThreadCountEdit, hDlg, 0, nYDifference);
269 static int lastX, lastY;
271 nXDifference += lastX;
272 nYDifference += lastY;
273 lastX = lastY = 0;
274 if (nXDifference % 2) {
275 if (nXDifference > 0) {
276 nXDifference--;
277 lastX++;
278 } else {
279 nXDifference++;
280 lastX--;
283 if (nYDifference % 2) {
284 if (nYDifference > 0) {
285 nYDifference--;
286 lastY++;
287 } else {
288 nYDifference++;
289 lastY--;
294 AdjustFrameSize(hPerformancePageCpuUsageFrame, hDlg, nXDifference, nYDifference, 1);
295 AdjustFrameSize(hPerformancePageMemUsageFrame, hDlg, nXDifference, nYDifference, 2);
296 AdjustFrameSize(hPerformancePageCpuUsageHistoryFrame, hDlg, nXDifference, nYDifference, 3);
297 AdjustFrameSize(hPerformancePageMemUsageHistoryFrame, hDlg, nXDifference, nYDifference, 4);
298 AdjustFrameSize(hPerformancePageCpuUsageGraph, hDlg, nXDifference, nYDifference, 1);
299 AdjustFrameSize(hPerformancePageMemUsageGraph, hDlg, nXDifference, nYDifference, 2);
300 AdjustFrameSize(hPerformancePageCpuUsageHistoryGraph, hDlg, nXDifference, nYDifference, 3);
301 AdjustFrameSize(hPerformancePageMemUsageHistoryGraph, hDlg, nXDifference, nYDifference, 4);
302 break;
304 return 0;
307 void RefreshPerformancePage(void)
309 /* Signal the event so that our refresh thread */
310 /* will wake up and refresh the performance page */
311 SetEvent(hPerformancePageEvent);
314 DWORD WINAPI PerformancePageRefreshThread(void *lpParameter)
316 ULONG CommitChargeTotal;
317 ULONG CommitChargeLimit;
318 ULONG CommitChargePeak;
320 ULONG KernelMemoryTotal;
321 ULONG KernelMemoryPaged;
322 ULONG KernelMemoryNonPaged;
324 ULONG PhysicalMemoryTotal;
325 ULONG PhysicalMemoryAvailable;
326 ULONG PhysicalMemorySystemCache;
328 ULONG TotalHandles;
329 ULONG TotalThreads;
330 ULONG TotalProcesses;
332 TCHAR Text[260];
334 /* Create the event */
335 hPerformancePageEvent = CreateEvent(NULL, TRUE, TRUE, _T("Performance Page Event"));
337 /* If we couldn't create the event then exit the thread */
338 if (!hPerformancePageEvent)
339 return 0;
341 while (1)
343 DWORD dwWaitVal;
345 /* Wait on the event */
346 dwWaitVal = WaitForSingleObject(hPerformancePageEvent, INFINITE);
348 /* If the wait failed then the event object must have been */
349 /* closed and the task manager is exiting so exit this thread */
350 if (dwWaitVal == WAIT_FAILED)
351 return 0;
353 if (dwWaitVal == WAIT_OBJECT_0)
355 ULONG CpuUsage;
356 ULONG CpuKernelUsage;
357 int nBarsUsed1;
358 int nBarsUsed2;
360 /* Reset our event */
361 ResetEvent(hPerformancePageEvent);
364 * Update the commit charge info
366 CommitChargeTotal = PerfDataGetCommitChargeTotalK();
367 CommitChargeLimit = PerfDataGetCommitChargeLimitK();
368 CommitChargePeak = PerfDataGetCommitChargePeakK();
369 _ultoa(CommitChargeTotal, Text, 10);
370 SetWindowText(hPerformancePageCommitChargeTotalEdit, Text);
371 _ultoa(CommitChargeLimit, Text, 10);
372 SetWindowText(hPerformancePageCommitChargeLimitEdit, Text);
373 _ultoa(CommitChargePeak, Text, 10);
374 SetWindowText(hPerformancePageCommitChargePeakEdit, Text);
375 wsprintf(Text, _T("Mem Usage: %dK / %dK"), CommitChargeTotal, CommitChargeLimit);
376 SendMessage(hStatusWnd, SB_SETTEXT, 2, (LPARAM)Text);
379 * Update the kernel memory info
381 KernelMemoryTotal = PerfDataGetKernelMemoryTotalK();
382 KernelMemoryPaged = PerfDataGetKernelMemoryPagedK();
383 KernelMemoryNonPaged = PerfDataGetKernelMemoryNonPagedK();
384 _ultoa(KernelMemoryTotal, Text, 10);
385 SetWindowText(hPerformancePageKernelMemoryTotalEdit, Text);
386 _ultoa(KernelMemoryPaged, Text, 10);
387 SetWindowText(hPerformancePageKernelMemoryPagedEdit, Text);
388 _ultoa(KernelMemoryNonPaged, Text, 10);
389 SetWindowText(hPerformancePageKernelMemoryNonPagedEdit, Text);
392 * Update the physical memory info
394 PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK();
395 PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK();
396 PhysicalMemorySystemCache = PerfDataGetPhysicalMemorySystemCacheK();
397 _ultoa(PhysicalMemoryTotal, Text, 10);
398 SetWindowText(hPerformancePagePhysicalMemoryTotalEdit, Text);
399 _ultoa(PhysicalMemoryAvailable, Text, 10);
400 SetWindowText(hPerformancePagePhysicalMemoryAvailableEdit, Text);
401 _ultoa(PhysicalMemorySystemCache, Text, 10);
402 SetWindowText(hPerformancePagePhysicalMemorySystemCacheEdit, Text);
405 * Update the totals info
407 TotalHandles = PerfDataGetSystemHandleCount();
408 TotalThreads = PerfDataGetTotalThreadCount();
409 TotalProcesses = PerfDataGetProcessCount();
410 _ultoa(TotalHandles, Text, 10);
411 SetWindowText(hPerformancePageTotalsHandleCountEdit, Text);
412 _ultoa(TotalThreads, Text, 10);
413 SetWindowText(hPerformancePageTotalsThreadCountEdit, Text);
414 _ultoa(TotalProcesses, Text, 10);
415 SetWindowText(hPerformancePageTotalsProcessCountEdit, Text);
418 * Redraw the graphs
420 InvalidateRect(hPerformancePageCpuUsageGraph, NULL, FALSE);
421 InvalidateRect(hPerformancePageMemUsageGraph, NULL, FALSE);
424 * Get the CPU usage
426 CpuUsage = PerfDataGetProcessorUsage();
427 CpuKernelUsage = PerfDataGetProcessorSystemUsage();
428 if (CpuUsage < 0 ) CpuUsage = 0;
429 if (CpuUsage > 100) CpuUsage = 100;
430 if (CpuKernelUsage < 0) CpuKernelUsage = 0;
431 if (CpuKernelUsage > 100) CpuKernelUsage = 100;
434 * Get the memory usage
436 CommitChargeTotal = (ULONGLONG)PerfDataGetCommitChargeTotalK();
437 CommitChargeLimit = (ULONGLONG)PerfDataGetCommitChargeLimitK();
438 nBarsUsed1 = CommitChargeLimit ? ((CommitChargeTotal * 100) / CommitChargeLimit) : 0;
440 PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK();
441 PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK();
442 nBarsUsed2 = PhysicalMemoryTotal ? ((PhysicalMemoryAvailable * 100) / PhysicalMemoryTotal) : 0;
445 GraphCtrl_AppendPoint(&PerformancePageCpuUsageHistoryGraph, CpuUsage, CpuKernelUsage, 0.0, 0.0);
446 GraphCtrl_AppendPoint(&PerformancePageMemUsageHistoryGraph, nBarsUsed1, nBarsUsed2, 0.0, 0.0);
447 /* PerformancePageMemUsageHistoryGraph.SetRange(0.0, 100.0, 10) ; */
448 InvalidateRect(hPerformancePageMemUsageHistoryGraph, NULL, FALSE);
449 InvalidateRect(hPerformancePageCpuUsageHistoryGraph, NULL, FALSE);
452 return 0;
455 void PerformancePage_OnViewShowKernelTimes(void)
457 HMENU hMenu;
458 HMENU hViewMenu;
460 hMenu = GetMenu(hMainWnd);
461 hViewMenu = GetSubMenu(hMenu, 2);
463 /* Check or uncheck the show 16-bit tasks menu item */
464 if (GetMenuState(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND) & MF_CHECKED)
466 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_UNCHECKED);
467 TaskManagerSettings.ShowKernelTimes = FALSE;
469 else
471 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_CHECKED);
472 TaskManagerSettings.ShowKernelTimes = TRUE;
475 RefreshPerformancePage();
478 void PerformancePage_OnViewCPUHistoryOneGraphAll(void)
480 HMENU hMenu;
481 HMENU hViewMenu;
482 HMENU hCPUHistoryMenu;
484 hMenu = GetMenu(hMainWnd);
485 hViewMenu = GetSubMenu(hMenu, 2);
486 hCPUHistoryMenu = GetSubMenu(hViewMenu, 3);
488 TaskManagerSettings.CPUHistory_OneGraphPerCPU = FALSE;
489 CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHALL, MF_BYCOMMAND);
492 void PerformancePage_OnViewCPUHistoryOneGraphPerCPU(void)
494 HMENU hMenu;
495 HMENU hViewMenu;
496 HMENU hCPUHistoryMenu;
498 hMenu = GetMenu(hMainWnd);
499 hViewMenu = GetSubMenu(hMenu, 2);
500 hCPUHistoryMenu = GetSubMenu(hViewMenu, 3);
502 TaskManagerSettings.CPUHistory_OneGraphPerCPU = TRUE;
503 CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, MF_BYCOMMAND);