wrc: Integer ids can be used for control labels instead of strings.
[wine/multimedia.git] / programs / taskmgr / perfpage.c
blob6c06557424443d645c8cdd85f90d62a11d562953
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 static 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 static void AdjustControlPostion(HWND hCntrl, HWND hDlg, int nXDifference, int nYDifference)
110 AdjustFrameSize(hCntrl, hDlg, nXDifference, nYDifference, 0);
113 static void AdjustCntrlPos(int ctrl_id, HWND hDlg, int nXDifference, int nYDifference)
115 AdjustFrameSize(GetDlgItem(hDlg, ctrl_id), hDlg, nXDifference, nYDifference, 0);
118 INT_PTR CALLBACK
119 PerformancePageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
121 RECT rc;
122 int nXDifference;
123 int nYDifference;
125 /* HDC hdc; */
126 /* PAINTSTRUCT ps; */
128 switch (message) {
129 case WM_INITDIALOG:
131 /* Save the width and height */
132 GetClientRect(hDlg, &rc);
133 nPerformancePageWidth = rc.right;
134 nPerformancePageHeight = rc.bottom;
136 /* Update window position */
137 SetWindowPos(hDlg, NULL, 15, 30, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
140 * Get handles to all the controls
142 hPerformancePageTotalsFrame = GetDlgItem(hDlg, IDC_TOTALS_FRAME);
143 hPerformancePageCommitChargeFrame = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_FRAME);
144 hPerformancePageKernelMemoryFrame = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_FRAME);
145 hPerformancePagePhysicalMemoryFrame = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_FRAME);
147 hPerformancePageCpuUsageFrame = GetDlgItem(hDlg, IDC_CPU_USAGE_FRAME);
148 hPerformancePageMemUsageFrame = GetDlgItem(hDlg, IDC_MEM_USAGE_FRAME);
149 hPerformancePageCpuUsageHistoryFrame = GetDlgItem(hDlg, IDC_CPU_USAGE_HISTORY_FRAME);
150 hPerformancePageMemUsageHistoryFrame = GetDlgItem(hDlg, IDC_MEMORY_USAGE_HISTORY_FRAME);
152 hPerformancePageCommitChargeTotalEdit = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_TOTAL);
153 hPerformancePageCommitChargeLimitEdit = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_LIMIT);
154 hPerformancePageCommitChargePeakEdit = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_PEAK);
155 hPerformancePageKernelMemoryTotalEdit = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_TOTAL);
156 hPerformancePageKernelMemoryPagedEdit = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_PAGED);
157 hPerformancePageKernelMemoryNonPagedEdit = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_NONPAGED);
158 hPerformancePagePhysicalMemoryTotalEdit = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_TOTAL);
159 hPerformancePagePhysicalMemoryAvailableEdit = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_AVAILABLE);
160 hPerformancePagePhysicalMemorySystemCacheEdit = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_SYSTEM_CACHE);
161 hPerformancePageTotalsHandleCountEdit = GetDlgItem(hDlg, IDC_TOTALS_HANDLE_COUNT);
162 hPerformancePageTotalsProcessCountEdit = GetDlgItem(hDlg, IDC_TOTALS_PROCESS_COUNT);
163 hPerformancePageTotalsThreadCountEdit = GetDlgItem(hDlg, IDC_TOTALS_THREAD_COUNT);
165 hPerformancePageCpuUsageGraph = GetDlgItem(hDlg, IDC_CPU_USAGE_GRAPH);
166 hPerformancePageMemUsageGraph = GetDlgItem(hDlg, IDC_MEM_USAGE_GRAPH);
167 hPerformancePageMemUsageHistoryGraph = GetDlgItem(hDlg, IDC_MEM_USAGE_HISTORY_GRAPH);
168 hPerformancePageCpuUsageHistoryGraph = GetDlgItem(hDlg, IDC_CPU_USAGE_HISTORY_GRAPH);
170 GetClientRect(hPerformancePageCpuUsageHistoryGraph, &rc);
171 /* create the control */
172 /* PerformancePageCpuUsageHistoryGraph.Create(0, rc, hDlg, IDC_CPU_USAGE_HISTORY_GRAPH); */
173 GraphCtrl_Create(&PerformancePageCpuUsageHistoryGraph, hPerformancePageCpuUsageHistoryGraph, hDlg, IDC_CPU_USAGE_HISTORY_GRAPH);
174 /* customize the control */
175 GraphCtrl_SetRange(&PerformancePageCpuUsageHistoryGraph, 0.0, 100.0, 10);
176 /* PerformancePageCpuUsageHistoryGraph.SetYUnits("Current") ; */
177 /* PerformancePageCpuUsageHistoryGraph.SetXUnits("Samples (Windows Timer: 100 msec)") ; */
178 /* PerformancePageCpuUsageHistoryGraph.SetBackgroundColor(RGB(0, 0, 64)) ; */
179 /* PerformancePageCpuUsageHistoryGraph.SetGridColor(RGB(192, 192, 255)) ; */
180 /* PerformancePageCpuUsageHistoryGraph.SetPlotColor(RGB(255, 255, 255)) ; */
181 GraphCtrl_SetBackgroundColor(&PerformancePageCpuUsageHistoryGraph, RGB(0, 0, 0)) ;
182 GraphCtrl_SetGridColor(&PerformancePageCpuUsageHistoryGraph, RGB(152, 205, 152)) ;
183 GraphCtrl_SetPlotColor(&PerformancePageCpuUsageHistoryGraph, 0, RGB(255, 0, 0)) ;
184 GraphCtrl_SetPlotColor(&PerformancePageCpuUsageHistoryGraph, 1, RGB(0, 255, 0)) ;
186 GetClientRect(hPerformancePageMemUsageHistoryGraph, &rc);
187 GraphCtrl_Create(&PerformancePageMemUsageHistoryGraph, hPerformancePageMemUsageHistoryGraph, hDlg, IDC_MEM_USAGE_HISTORY_GRAPH);
188 GraphCtrl_SetRange(&PerformancePageMemUsageHistoryGraph, 0.0, 100.0, 10) ;
189 GraphCtrl_SetBackgroundColor(&PerformancePageMemUsageHistoryGraph, RGB(0, 0, 0)) ;
190 GraphCtrl_SetGridColor(&PerformancePageMemUsageHistoryGraph, RGB(152, 215, 152)) ;
191 GraphCtrl_SetPlotColor(&PerformancePageMemUsageHistoryGraph, 0, RGB(255, 255, 0)) ;
192 /* Start our refresh thread */
193 #ifdef RUN_PERF_PAGE
194 CreateThread(NULL, 0, PerformancePageRefreshThread, NULL, 0, NULL);
195 #endif
198 * Subclass graph buttons
200 OldGraphWndProc = (WNDPROC)SetWindowLongPtr(hPerformancePageCpuUsageGraph, GWLP_WNDPROC, (LONG_PTR)Graph_WndProc);
201 SetWindowLongPtr(hPerformancePageMemUsageGraph, GWLP_WNDPROC, (LONG_PTR)Graph_WndProc);
202 OldGraphCtrlWndProc = (WNDPROC)SetWindowLongPtr(hPerformancePageMemUsageHistoryGraph, GWLP_WNDPROC, (LONG_PTR)GraphCtrl_WndProc);
203 SetWindowLongPtr(hPerformancePageCpuUsageHistoryGraph, GWLP_WNDPROC, (LONG_PTR)GraphCtrl_WndProc);
204 return TRUE;
206 case WM_COMMAND:
207 break;
208 #if 0
209 case WM_NCPAINT:
210 hdc = GetDC(hDlg);
211 GetClientRect(hDlg, &rc);
212 Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
213 ReleaseDC(hDlg, hdc);
214 break;
216 case WM_PAINT:
217 hdc = BeginPaint(hDlg, &ps);
218 GetClientRect(hDlg, &rc);
219 Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
220 EndPaint(hDlg, &ps);
221 break;
222 #endif
223 case WM_SIZE:
224 do {
225 int cx, cy;
227 if (wParam == SIZE_MINIMIZED)
228 return 0;
230 cx = LOWORD(lParam);
231 cy = HIWORD(lParam);
232 nXDifference = cx - nPerformancePageWidth;
233 nYDifference = cy - nPerformancePageHeight;
234 nPerformancePageWidth = cx;
235 nPerformancePageHeight = cy;
236 } while (0);
238 /* Reposition the performance page's controls */
239 AdjustFrameSize(hPerformancePageTotalsFrame, hDlg, 0, nYDifference, 0);
240 AdjustFrameSize(hPerformancePageCommitChargeFrame, hDlg, 0, nYDifference, 0);
241 AdjustFrameSize(hPerformancePageKernelMemoryFrame, hDlg, 0, nYDifference, 0);
242 AdjustFrameSize(hPerformancePagePhysicalMemoryFrame, hDlg, 0, nYDifference, 0);
243 AdjustCntrlPos(IDS_COMMIT_CHARGE_TOTAL, hDlg, 0, nYDifference);
244 AdjustCntrlPos(IDS_COMMIT_CHARGE_LIMIT, hDlg, 0, nYDifference);
245 AdjustCntrlPos(IDS_COMMIT_CHARGE_PEAK, hDlg, 0, nYDifference);
246 AdjustCntrlPos(IDS_KERNEL_MEMORY_TOTAL, hDlg, 0, nYDifference);
247 AdjustCntrlPos(IDS_KERNEL_MEMORY_PAGED, hDlg, 0, nYDifference);
248 AdjustCntrlPos(IDS_KERNEL_MEMORY_NONPAGED, hDlg, 0, nYDifference);
249 AdjustCntrlPos(IDS_PHYSICAL_MEMORY_TOTAL, hDlg, 0, nYDifference);
250 AdjustCntrlPos(IDS_PHYSICAL_MEMORY_AVAILABLE, hDlg, 0, nYDifference);
251 AdjustCntrlPos(IDS_PHYSICAL_MEMORY_SYSTEM_CACHE, hDlg, 0, nYDifference);
252 AdjustCntrlPos(IDS_TOTALS_HANDLE_COUNT, hDlg, 0, nYDifference);
253 AdjustCntrlPos(IDS_TOTALS_PROCESS_COUNT, hDlg, 0, nYDifference);
254 AdjustCntrlPos(IDS_TOTALS_THREAD_COUNT, hDlg, 0, nYDifference);
256 AdjustControlPostion(hPerformancePageCommitChargeTotalEdit, hDlg, 0, nYDifference);
257 AdjustControlPostion(hPerformancePageCommitChargeLimitEdit, hDlg, 0, nYDifference);
258 AdjustControlPostion(hPerformancePageCommitChargePeakEdit, hDlg, 0, nYDifference);
259 AdjustControlPostion(hPerformancePageKernelMemoryTotalEdit, hDlg, 0, nYDifference);
260 AdjustControlPostion(hPerformancePageKernelMemoryPagedEdit, hDlg, 0, nYDifference);
261 AdjustControlPostion(hPerformancePageKernelMemoryNonPagedEdit, hDlg, 0, nYDifference);
262 AdjustControlPostion(hPerformancePagePhysicalMemoryTotalEdit, hDlg, 0, nYDifference);
263 AdjustControlPostion(hPerformancePagePhysicalMemoryAvailableEdit, hDlg, 0, nYDifference);
264 AdjustControlPostion(hPerformancePagePhysicalMemorySystemCacheEdit, hDlg, 0, nYDifference);
265 AdjustControlPostion(hPerformancePageTotalsHandleCountEdit, hDlg, 0, nYDifference);
266 AdjustControlPostion(hPerformancePageTotalsProcessCountEdit, hDlg, 0, nYDifference);
267 AdjustControlPostion(hPerformancePageTotalsThreadCountEdit, hDlg, 0, nYDifference);
270 static int lastX, lastY;
272 nXDifference += lastX;
273 nYDifference += lastY;
274 lastX = lastY = 0;
275 if (nXDifference % 2) {
276 if (nXDifference > 0) {
277 nXDifference--;
278 lastX++;
279 } else {
280 nXDifference++;
281 lastX--;
284 if (nYDifference % 2) {
285 if (nYDifference > 0) {
286 nYDifference--;
287 lastY++;
288 } else {
289 nYDifference++;
290 lastY--;
295 AdjustFrameSize(hPerformancePageCpuUsageFrame, hDlg, nXDifference, nYDifference, 1);
296 AdjustFrameSize(hPerformancePageMemUsageFrame, hDlg, nXDifference, nYDifference, 2);
297 AdjustFrameSize(hPerformancePageCpuUsageHistoryFrame, hDlg, nXDifference, nYDifference, 3);
298 AdjustFrameSize(hPerformancePageMemUsageHistoryFrame, hDlg, nXDifference, nYDifference, 4);
299 AdjustFrameSize(hPerformancePageCpuUsageGraph, hDlg, nXDifference, nYDifference, 1);
300 AdjustFrameSize(hPerformancePageMemUsageGraph, hDlg, nXDifference, nYDifference, 2);
301 AdjustFrameSize(hPerformancePageCpuUsageHistoryGraph, hDlg, nXDifference, nYDifference, 3);
302 AdjustFrameSize(hPerformancePageMemUsageHistoryGraph, hDlg, nXDifference, nYDifference, 4);
303 break;
305 return 0;
308 void RefreshPerformancePage(void)
310 /* Signal the event so that our refresh thread */
311 /* will wake up and refresh the performance page */
312 SetEvent(hPerformancePageEvent);
315 DWORD WINAPI PerformancePageRefreshThread(void *lpParameter)
317 ULONG CommitChargeTotal;
318 ULONG CommitChargeLimit;
319 ULONG CommitChargePeak;
321 ULONG KernelMemoryTotal;
322 ULONG KernelMemoryPaged;
323 ULONG KernelMemoryNonPaged;
325 ULONG PhysicalMemoryTotal;
326 ULONG PhysicalMemoryAvailable;
327 ULONG PhysicalMemorySystemCache;
329 ULONG TotalHandles;
330 ULONG TotalThreads;
331 ULONG TotalProcesses;
333 TCHAR Text[260];
335 /* Create the event */
336 hPerformancePageEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
338 /* If we couldn't create the event then exit the thread */
339 if (!hPerformancePageEvent)
340 return 0;
342 while (1)
344 DWORD dwWaitVal;
346 /* Wait on the event */
347 dwWaitVal = WaitForSingleObject(hPerformancePageEvent, INFINITE);
349 /* If the wait failed then the event object must have been */
350 /* closed and the task manager is exiting so exit this thread */
351 if (dwWaitVal == WAIT_FAILED)
352 return 0;
354 if (dwWaitVal == WAIT_OBJECT_0)
356 ULONG CpuUsage;
357 ULONG CpuKernelUsage;
358 int nBarsUsed1;
359 int nBarsUsed2;
361 /* Reset our event */
362 ResetEvent(hPerformancePageEvent);
365 * Update the commit charge info
367 CommitChargeTotal = PerfDataGetCommitChargeTotalK();
368 CommitChargeLimit = PerfDataGetCommitChargeLimitK();
369 CommitChargePeak = PerfDataGetCommitChargePeakK();
370 _ultoa(CommitChargeTotal, Text, 10);
371 SetWindowText(hPerformancePageCommitChargeTotalEdit, Text);
372 _ultoa(CommitChargeLimit, Text, 10);
373 SetWindowText(hPerformancePageCommitChargeLimitEdit, Text);
374 _ultoa(CommitChargePeak, Text, 10);
375 SetWindowText(hPerformancePageCommitChargePeakEdit, Text);
376 wsprintf(Text, _T("Mem Usage: %dK / %dK"), CommitChargeTotal, CommitChargeLimit);
377 SendMessage(hStatusWnd, SB_SETTEXT, 2, (LPARAM)Text);
380 * Update the kernel memory info
382 KernelMemoryTotal = PerfDataGetKernelMemoryTotalK();
383 KernelMemoryPaged = PerfDataGetKernelMemoryPagedK();
384 KernelMemoryNonPaged = PerfDataGetKernelMemoryNonPagedK();
385 _ultoa(KernelMemoryTotal, Text, 10);
386 SetWindowText(hPerformancePageKernelMemoryTotalEdit, Text);
387 _ultoa(KernelMemoryPaged, Text, 10);
388 SetWindowText(hPerformancePageKernelMemoryPagedEdit, Text);
389 _ultoa(KernelMemoryNonPaged, Text, 10);
390 SetWindowText(hPerformancePageKernelMemoryNonPagedEdit, Text);
393 * Update the physical memory info
395 PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK();
396 PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK();
397 PhysicalMemorySystemCache = PerfDataGetPhysicalMemorySystemCacheK();
398 _ultoa(PhysicalMemoryTotal, Text, 10);
399 SetWindowText(hPerformancePagePhysicalMemoryTotalEdit, Text);
400 _ultoa(PhysicalMemoryAvailable, Text, 10);
401 SetWindowText(hPerformancePagePhysicalMemoryAvailableEdit, Text);
402 _ultoa(PhysicalMemorySystemCache, Text, 10);
403 SetWindowText(hPerformancePagePhysicalMemorySystemCacheEdit, Text);
406 * Update the totals info
408 TotalHandles = PerfDataGetSystemHandleCount();
409 TotalThreads = PerfDataGetTotalThreadCount();
410 TotalProcesses = PerfDataGetProcessCount();
411 _ultoa(TotalHandles, Text, 10);
412 SetWindowText(hPerformancePageTotalsHandleCountEdit, Text);
413 _ultoa(TotalThreads, Text, 10);
414 SetWindowText(hPerformancePageTotalsThreadCountEdit, Text);
415 _ultoa(TotalProcesses, Text, 10);
416 SetWindowText(hPerformancePageTotalsProcessCountEdit, Text);
419 * Redraw the graphs
421 InvalidateRect(hPerformancePageCpuUsageGraph, NULL, FALSE);
422 InvalidateRect(hPerformancePageMemUsageGraph, NULL, FALSE);
425 * Get the CPU usage
427 CpuUsage = PerfDataGetProcessorUsage();
428 CpuKernelUsage = PerfDataGetProcessorSystemUsage();
429 if (CpuUsage < 0 ) CpuUsage = 0;
430 if (CpuUsage > 100) CpuUsage = 100;
431 if (CpuKernelUsage < 0) CpuKernelUsage = 0;
432 if (CpuKernelUsage > 100) CpuKernelUsage = 100;
435 * Get the memory usage
437 CommitChargeTotal = (ULONGLONG)PerfDataGetCommitChargeTotalK();
438 CommitChargeLimit = (ULONGLONG)PerfDataGetCommitChargeLimitK();
439 nBarsUsed1 = CommitChargeLimit ? ((CommitChargeTotal * 100) / CommitChargeLimit) : 0;
441 PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK();
442 PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK();
443 nBarsUsed2 = PhysicalMemoryTotal ? ((PhysicalMemoryAvailable * 100) / PhysicalMemoryTotal) : 0;
446 GraphCtrl_AppendPoint(&PerformancePageCpuUsageHistoryGraph, CpuUsage, CpuKernelUsage, 0.0, 0.0);
447 GraphCtrl_AppendPoint(&PerformancePageMemUsageHistoryGraph, nBarsUsed1, nBarsUsed2, 0.0, 0.0);
448 /* PerformancePageMemUsageHistoryGraph.SetRange(0.0, 100.0, 10) ; */
449 InvalidateRect(hPerformancePageMemUsageHistoryGraph, NULL, FALSE);
450 InvalidateRect(hPerformancePageCpuUsageHistoryGraph, NULL, FALSE);
453 return 0;
456 void PerformancePage_OnViewShowKernelTimes(void)
458 HMENU hMenu;
459 HMENU hViewMenu;
461 hMenu = GetMenu(hMainWnd);
462 hViewMenu = GetSubMenu(hMenu, 2);
464 /* Check or uncheck the show 16-bit tasks menu item */
465 if (GetMenuState(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND) & MF_CHECKED)
467 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_UNCHECKED);
468 TaskManagerSettings.ShowKernelTimes = FALSE;
470 else
472 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_CHECKED);
473 TaskManagerSettings.ShowKernelTimes = TRUE;
476 RefreshPerformancePage();
479 void PerformancePage_OnViewCPUHistoryOneGraphAll(void)
481 HMENU hMenu;
482 HMENU hViewMenu;
483 HMENU hCPUHistoryMenu;
485 hMenu = GetMenu(hMainWnd);
486 hViewMenu = GetSubMenu(hMenu, 2);
487 hCPUHistoryMenu = GetSubMenu(hViewMenu, 3);
489 TaskManagerSettings.CPUHistory_OneGraphPerCPU = FALSE;
490 CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHALL, MF_BYCOMMAND);
493 void PerformancePage_OnViewCPUHistoryOneGraphPerCPU(void)
495 HMENU hMenu;
496 HMENU hViewMenu;
497 HMENU hCPUHistoryMenu;
499 hMenu = GetMenu(hMainWnd);
500 hViewMenu = GetSubMenu(hMenu, 2);
501 hCPUHistoryMenu = GetSubMenu(hViewMenu, 3);
503 TaskManagerSettings.CPUHistory_OneGraphPerCPU = TRUE;
504 CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, MF_BYCOMMAND);