[CMAKE]
[reactos.git] / base / applications / taskmgr / perfpage.c
1 /*
2 * ReactOS Task Manager
3 *
4 * perfpage.c
5 *
6 * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program 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
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23 #include <precomp.h>
24
25 TGraphCtrl PerformancePageCpuUsageHistoryGraph;
26 TGraphCtrl PerformancePageMemUsageHistoryGraph;
27
28 HWND hPerformancePage; /* Performance Property Page */
29 HWND hPerformancePageCpuUsageGraph; /* CPU Usage Graph */
30 HWND hPerformancePageMemUsageGraph; /* MEM Usage Graph */
31 HWND hPerformancePageCpuUsageHistoryGraph; /* CPU Usage History Graph */
32 HWND hPerformancePageMemUsageHistoryGraph; /* Memory Usage History Graph */
33 HWND hPerformancePageTotalsFrame; /* Totals Frame */
34 HWND hPerformancePageCommitChargeFrame; /* Commit Charge Frame */
35 HWND hPerformancePageKernelMemoryFrame; /* Kernel Memory Frame */
36 HWND hPerformancePagePhysicalMemoryFrame; /* Physical Memory Frame */
37 HWND hPerformancePageCpuUsageFrame;
38 HWND hPerformancePageMemUsageFrame;
39 HWND hPerformancePageCpuUsageHistoryFrame;
40 HWND hPerformancePageMemUsageHistoryFrame;
41 HWND hPerformancePageCommitChargeTotalEdit; /* Commit Charge Total Edit Control */
42 HWND hPerformancePageCommitChargeLimitEdit; /* Commit Charge Limit Edit Control */
43 HWND hPerformancePageCommitChargePeakEdit; /* Commit Charge Peak Edit Control */
44 HWND hPerformancePageKernelMemoryTotalEdit; /* Kernel Memory Total Edit Control */
45 HWND hPerformancePageKernelMemoryPagedEdit; /* Kernel Memory Paged Edit Control */
46 HWND hPerformancePageKernelMemoryNonPagedEdit; /* Kernel Memory NonPaged Edit Control */
47 HWND hPerformancePagePhysicalMemoryTotalEdit; /* Physical Memory Total Edit Control */
48 HWND hPerformancePagePhysicalMemoryAvailableEdit; /* Physical Memory Available Edit Control */
49 HWND hPerformancePagePhysicalMemorySystemCacheEdit; /* Physical Memory System Cache Edit Control */
50 HWND hPerformancePageTotalsHandleCountEdit; /* Total Handles Edit Control */
51 HWND hPerformancePageTotalsProcessCountEdit; /* Total Processes Edit Control */
52 HWND hPerformancePageTotalsThreadCountEdit; /* Total Threads Edit Control */
53
54 #ifdef RUN_PERF_PAGE
55 static HANDLE hPerformanceThread = NULL;
56 static DWORD dwPerformanceThread;
57 #endif
58
59 static int nPerformancePageWidth;
60 static int nPerformancePageHeight;
61 static int lastX, lastY;
62 DWORD WINAPI PerformancePageRefreshThread(void *lpParameter);
63
64 void AdjustFrameSize(HWND hCntrl, HWND hDlg, int nXDifference, int nYDifference, int pos)
65 {
66 RECT rc;
67 int cx, cy, sx, sy;
68
69 GetClientRect(hCntrl, &rc);
70 MapWindowPoints(hCntrl, hDlg, (LPPOINT)(PRECT)(&rc), (sizeof(RECT)/sizeof(POINT)));
71 if (pos) {
72 cx = rc.left;
73 cy = rc.top;
74 sx = rc.right - rc.left;
75 switch (pos) {
76 case 1:
77 break;
78 case 2:
79 cy += nYDifference / 2;
80 break;
81 case 3:
82 sx += nXDifference;
83 break;
84 case 4:
85 cy += nYDifference / 2;
86 sx += nXDifference;
87 break;
88 }
89 sy = rc.bottom - rc.top + nYDifference / 2;
90 SetWindowPos(hCntrl, NULL, cx, cy, sx, sy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER);
91 } else {
92 cx = rc.left + nXDifference;
93 cy = rc.top + nYDifference;
94 sx = sy = 0;
95 SetWindowPos(hCntrl, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
96 }
97 InvalidateRect(hCntrl, NULL, TRUE);
98 }
99
100 static void AdjustControlPostion(HWND hCntrl, HWND hDlg, int nXDifference, int nYDifference)
101 {
102 AdjustFrameSize(hCntrl, hDlg, nXDifference, nYDifference, 0);
103 }
104
105 static void AdjustCntrlPos(int ctrl_id, HWND hDlg, int nXDifference, int nYDifference)
106 {
107 AdjustFrameSize(GetDlgItem(hDlg, ctrl_id), hDlg, nXDifference, nYDifference, 0);
108 }
109
110 INT_PTR CALLBACK
111 PerformancePageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
112 {
113 RECT rc;
114 int nXDifference;
115 int nYDifference;
116 /* HDC hdc; */
117 /* PAINTSTRUCT ps; */
118
119 switch (message) {
120 case WM_DESTROY:
121 GraphCtrl_Dispose(&PerformancePageCpuUsageHistoryGraph);
122 GraphCtrl_Dispose(&PerformancePageMemUsageHistoryGraph);
123 #ifdef RUN_PERF_PAGE
124 EndLocalThread(&hPerformanceThread, dwPerformanceThread);
125 #endif
126 break;
127
128 case WM_INITDIALOG:
129
130 /* Save the width and height */
131 GetClientRect(hDlg, &rc);
132 nPerformancePageWidth = rc.right;
133 nPerformancePageHeight = rc.bottom;
134
135 /* Update window position */
136 SetWindowPos(hDlg, NULL, 15, 30, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
137
138 /*
139 * Get handles to all the controls
140 */
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);
145
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);
150
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);
163
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);
168
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(0, 128, 64));
182
183 GraphCtrl_SetPlotColor(&PerformancePageCpuUsageHistoryGraph, 0, RGB(0, 255, 0)) ;
184 GraphCtrl_SetPlotColor(&PerformancePageCpuUsageHistoryGraph, 1, RGB(255, 0, 0)) ;
185
186
187 GetClientRect(hPerformancePageMemUsageHistoryGraph, &rc);
188 GraphCtrl_Create(&PerformancePageMemUsageHistoryGraph, hPerformancePageMemUsageHistoryGraph, hDlg, IDC_MEM_USAGE_HISTORY_GRAPH);
189 GraphCtrl_SetRange(&PerformancePageMemUsageHistoryGraph, 0.0, 100.0, 10) ;
190 GraphCtrl_SetBackgroundColor(&PerformancePageMemUsageHistoryGraph, RGB(0, 0, 0)) ;
191 GraphCtrl_SetGridColor(&PerformancePageMemUsageHistoryGraph, RGB(0, 128, 64)) ;
192 GraphCtrl_SetPlotColor(&PerformancePageMemUsageHistoryGraph, 0, RGB(255, 255, 0)) ;
193 /* Start our refresh thread */
194 #ifdef RUN_PERF_PAGE
195 hPerformanceThread = CreateThread(NULL, 0, PerformancePageRefreshThread, NULL, 0, &dwPerformanceThread);
196 #endif
197
198 /*
199 * Subclass graph buttons
200 */
201 OldGraphWndProc = (WNDPROC)(LONG_PTR) SetWindowLongPtrW(hPerformancePageCpuUsageGraph, GWL_WNDPROC, (LONG_PTR)Graph_WndProc);
202 SetWindowLongPtrW(hPerformancePageMemUsageGraph, GWL_WNDPROC, (LONG_PTR)Graph_WndProc);
203 OldGraphCtrlWndProc = (WNDPROC)(LONG_PTR) SetWindowLongPtrW(hPerformancePageMemUsageHistoryGraph, GWL_WNDPROC, (LONG_PTR)GraphCtrl_WndProc);
204 SetWindowLongPtrW(hPerformancePageCpuUsageHistoryGraph, GWL_WNDPROC, (LONG_PTR)GraphCtrl_WndProc);
205 return TRUE;
206
207 case WM_COMMAND:
208 break;
209 #if 0
210 case WM_NCPAINT:
211 hdc = GetDC(hDlg);
212 GetClientRect(hDlg, &rc);
213 Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
214 ReleaseDC(hDlg, hdc);
215 break;
216
217 case WM_PAINT:
218 hdc = BeginPaint(hDlg, &ps);
219 GetClientRect(hDlg, &rc);
220 Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
221 EndPaint(hDlg, &ps);
222 break;
223 #endif
224 case WM_SIZE:
225 do {
226 int cx, cy;
227
228 if (wParam == SIZE_MINIMIZED)
229 return 0;
230
231 cx = LOWORD(lParam);
232 cy = HIWORD(lParam);
233 nXDifference = cx - nPerformancePageWidth;
234 nYDifference = cy - nPerformancePageHeight;
235 nPerformancePageWidth = cx;
236 nPerformancePageHeight = cy;
237 } while (0);
238
239 /* Reposition the performance page's controls */
240 AdjustFrameSize(hPerformancePageTotalsFrame, hDlg, 0, nYDifference, 0);
241 AdjustFrameSize(hPerformancePageCommitChargeFrame, hDlg, 0, nYDifference, 0);
242 AdjustFrameSize(hPerformancePageKernelMemoryFrame, hDlg, 0, nYDifference, 0);
243 AdjustFrameSize(hPerformancePagePhysicalMemoryFrame, hDlg, 0, nYDifference, 0);
244 AdjustCntrlPos(IDS_COMMIT_CHARGE_TOTAL, hDlg, 0, nYDifference);
245 AdjustCntrlPos(IDS_COMMIT_CHARGE_LIMIT, hDlg, 0, nYDifference);
246 AdjustCntrlPos(IDS_COMMIT_CHARGE_PEAK, hDlg, 0, nYDifference);
247 AdjustCntrlPos(IDS_KERNEL_MEMORY_TOTAL, hDlg, 0, nYDifference);
248 AdjustCntrlPos(IDS_KERNEL_MEMORY_PAGED, hDlg, 0, nYDifference);
249 AdjustCntrlPos(IDS_KERNEL_MEMORY_NONPAGED, hDlg, 0, nYDifference);
250 AdjustCntrlPos(IDS_PHYSICAL_MEMORY_TOTAL, hDlg, 0, nYDifference);
251 AdjustCntrlPos(IDS_PHYSICAL_MEMORY_AVAILABLE, hDlg, 0, nYDifference);
252 AdjustCntrlPos(IDS_PHYSICAL_MEMORY_SYSTEM_CACHE, hDlg, 0, nYDifference);
253 AdjustCntrlPos(IDS_TOTALS_HANDLE_COUNT, hDlg, 0, nYDifference);
254 AdjustCntrlPos(IDS_TOTALS_PROCESS_COUNT, hDlg, 0, nYDifference);
255 AdjustCntrlPos(IDS_TOTALS_THREAD_COUNT, hDlg, 0, nYDifference);
256
257 AdjustControlPostion(hPerformancePageCommitChargeTotalEdit, hDlg, 0, nYDifference);
258 AdjustControlPostion(hPerformancePageCommitChargeLimitEdit, hDlg, 0, nYDifference);
259 AdjustControlPostion(hPerformancePageCommitChargePeakEdit, hDlg, 0, nYDifference);
260 AdjustControlPostion(hPerformancePageKernelMemoryTotalEdit, hDlg, 0, nYDifference);
261 AdjustControlPostion(hPerformancePageKernelMemoryPagedEdit, hDlg, 0, nYDifference);
262 AdjustControlPostion(hPerformancePageKernelMemoryNonPagedEdit, hDlg, 0, nYDifference);
263 AdjustControlPostion(hPerformancePagePhysicalMemoryTotalEdit, hDlg, 0, nYDifference);
264 AdjustControlPostion(hPerformancePagePhysicalMemoryAvailableEdit, hDlg, 0, nYDifference);
265 AdjustControlPostion(hPerformancePagePhysicalMemorySystemCacheEdit, hDlg, 0, nYDifference);
266 AdjustControlPostion(hPerformancePageTotalsHandleCountEdit, hDlg, 0, nYDifference);
267 AdjustControlPostion(hPerformancePageTotalsProcessCountEdit, hDlg, 0, nYDifference);
268 AdjustControlPostion(hPerformancePageTotalsThreadCountEdit, hDlg, 0, nYDifference);
269
270 nXDifference += lastX;
271 nYDifference += lastY;
272 lastX = lastY = 0;
273 if (nXDifference % 2) {
274 if (nXDifference > 0) {
275 nXDifference--;
276 lastX++;
277 } else {
278 nXDifference++;
279 lastX--;
280 }
281 }
282 if (nYDifference % 2) {
283 if (nYDifference > 0) {
284 nYDifference--;
285 lastY++;
286 } else {
287 nYDifference++;
288 lastY--;
289 }
290 }
291 AdjustFrameSize(hPerformancePageCpuUsageFrame, hDlg, nXDifference, nYDifference, 1);
292 AdjustFrameSize(hPerformancePageMemUsageFrame, hDlg, nXDifference, nYDifference, 2);
293 AdjustFrameSize(hPerformancePageCpuUsageHistoryFrame, hDlg, nXDifference, nYDifference, 3);
294 AdjustFrameSize(hPerformancePageMemUsageHistoryFrame, hDlg, nXDifference, nYDifference, 4);
295 AdjustFrameSize(hPerformancePageCpuUsageGraph, hDlg, nXDifference, nYDifference, 1);
296 AdjustFrameSize(hPerformancePageMemUsageGraph, hDlg, nXDifference, nYDifference, 2);
297 AdjustFrameSize(hPerformancePageCpuUsageHistoryGraph, hDlg, nXDifference, nYDifference, 3);
298 AdjustFrameSize(hPerformancePageMemUsageHistoryGraph, hDlg, nXDifference, nYDifference, 4);
299 break;
300 }
301 return 0;
302 }
303
304 void RefreshPerformancePage(void)
305 {
306 #ifdef RUN_PERF_PAGE
307 /* Signal the event so that our refresh thread */
308 /* will wake up and refresh the performance page */
309 PostThreadMessage(dwPerformanceThread, WM_TIMER, 0, 0);
310 #endif
311 }
312
313 DWORD WINAPI PerformancePageRefreshThread(void *lpParameter)
314 {
315 ULONG CommitChargeTotal;
316 ULONG CommitChargeLimit;
317 ULONG CommitChargePeak;
318
319 ULONG CpuUsage;
320 ULONG CpuKernelUsage;
321
322 ULONG KernelMemoryTotal;
323 ULONG KernelMemoryPaged;
324 ULONG KernelMemoryNonPaged;
325
326 ULONG PhysicalMemoryTotal;
327 ULONG PhysicalMemoryAvailable;
328 ULONG PhysicalMemorySystemCache;
329
330 ULONG TotalHandles;
331 ULONG TotalThreads;
332 ULONG TotalProcesses;
333
334 WCHAR Text[260];
335 WCHAR szMemUsage[256];
336
337 MSG msg;
338
339 LoadStringW(hInst, IDS_STATUS_MEMUSAGE, szMemUsage, 256);
340
341 while (1)
342 {
343 int nBarsUsed1;
344 int nBarsUsed2;
345
346 /* Wait for an the event or application close */
347 if (GetMessage(&msg, NULL, 0, 0) <= 0)
348 return 0;
349
350 if (msg.message == WM_TIMER)
351 {
352 /*
353 * Update the commit charge info
354 */
355 CommitChargeTotal = PerfDataGetCommitChargeTotalK();
356 CommitChargeLimit = PerfDataGetCommitChargeLimitK();
357 CommitChargePeak = PerfDataGetCommitChargePeakK();
358 _ultow(CommitChargeTotal, Text, 10);
359 SetWindowTextW(hPerformancePageCommitChargeTotalEdit, Text);
360 _ultow(CommitChargeLimit, Text, 10);
361 SetWindowTextW(hPerformancePageCommitChargeLimitEdit, Text);
362 _ultow(CommitChargePeak, Text, 10);
363 SetWindowTextW(hPerformancePageCommitChargePeakEdit, Text);
364 wsprintfW(Text, szMemUsage, CommitChargeTotal, CommitChargeLimit);
365 SendMessageW(hStatusWnd, SB_SETTEXT, 2, (LPARAM)Text);
366
367 /*
368 * Update the kernel memory info
369 */
370 KernelMemoryTotal = PerfDataGetKernelMemoryTotalK();
371 KernelMemoryPaged = PerfDataGetKernelMemoryPagedK();
372 KernelMemoryNonPaged = PerfDataGetKernelMemoryNonPagedK();
373 _ultow(KernelMemoryTotal, Text, 10);
374 SetWindowTextW(hPerformancePageKernelMemoryTotalEdit, Text);
375 _ultow(KernelMemoryPaged, Text, 10);
376 SetWindowTextW(hPerformancePageKernelMemoryPagedEdit, Text);
377 _ultow(KernelMemoryNonPaged, Text, 10);
378 SetWindowTextW(hPerformancePageKernelMemoryNonPagedEdit, Text);
379
380 /*
381 * Update the physical memory info
382 */
383 PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK();
384 PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK();
385 PhysicalMemorySystemCache = PerfDataGetPhysicalMemorySystemCacheK();
386 _ultow(PhysicalMemoryTotal, Text, 10);
387 SetWindowTextW(hPerformancePagePhysicalMemoryTotalEdit, Text);
388 _ultow(PhysicalMemoryAvailable, Text, 10);
389 SetWindowTextW(hPerformancePagePhysicalMemoryAvailableEdit, Text);
390 _ultow(PhysicalMemorySystemCache, Text, 10);
391 SetWindowTextW(hPerformancePagePhysicalMemorySystemCacheEdit, Text);
392
393 /*
394 * Update the totals info
395 */
396 TotalHandles = PerfDataGetSystemHandleCount();
397 TotalThreads = PerfDataGetTotalThreadCount();
398 TotalProcesses = PerfDataGetProcessCount();
399 _ultow(TotalHandles, Text, 10);
400 SetWindowTextW(hPerformancePageTotalsHandleCountEdit, Text);
401 _ultow(TotalThreads, Text, 10);
402 SetWindowTextW(hPerformancePageTotalsThreadCountEdit, Text);
403 _ultow(TotalProcesses, Text, 10);
404 SetWindowTextW(hPerformancePageTotalsProcessCountEdit, Text);
405
406 /*
407 * Redraw the graphs
408 */
409 InvalidateRect(hPerformancePageCpuUsageGraph, NULL, FALSE);
410 InvalidateRect(hPerformancePageMemUsageGraph, NULL, FALSE);
411
412 /*
413 * Get the CPU usage
414 */
415 CpuUsage = PerfDataGetProcessorUsage();
416 if (CpuUsage <= 0 ) CpuUsage = 0;
417 if (CpuUsage > 100) CpuUsage = 100;
418
419 if (TaskManagerSettings.ShowKernelTimes)
420 {
421 CpuKernelUsage = PerfDataGetProcessorSystemUsage();
422 if (CpuKernelUsage <= 0) CpuKernelUsage = 0;
423 if (CpuKernelUsage > 100) CpuKernelUsage = 100;
424 }
425 else
426 {
427 CpuKernelUsage = 0;
428 }
429 /*
430 * Get the memory usage
431 */
432 CommitChargeTotal = PerfDataGetCommitChargeTotalK();
433 CommitChargeLimit = PerfDataGetCommitChargeLimitK();
434 nBarsUsed1 = CommitChargeLimit ? ((CommitChargeTotal * 100) / CommitChargeLimit) : 0;
435
436 PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK();
437 PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK();
438 nBarsUsed2 = PhysicalMemoryTotal ? ((PhysicalMemoryAvailable * 100) / PhysicalMemoryTotal) : 0;
439
440 GraphCtrl_AppendPoint(&PerformancePageCpuUsageHistoryGraph, CpuUsage, CpuKernelUsage, 0.0, 0.0);
441 GraphCtrl_AppendPoint(&PerformancePageMemUsageHistoryGraph, nBarsUsed1, nBarsUsed2, 0.0, 0.0);
442 /* PerformancePageMemUsageHistoryGraph.SetRange(0.0, 100.0, 10) ; */
443 InvalidateRect(hPerformancePageMemUsageHistoryGraph, NULL, FALSE);
444 InvalidateRect(hPerformancePageCpuUsageHistoryGraph, NULL, FALSE);
445 }
446 }
447 return 0;
448 }
449
450 void PerformancePage_OnViewShowKernelTimes(void)
451 {
452 HMENU hMenu;
453 HMENU hViewMenu;
454
455 hMenu = GetMenu(hMainWnd);
456 hViewMenu = GetSubMenu(hMenu, 2);
457
458 /* Check or uncheck the show 16-bit tasks menu item */
459 if (GetMenuState(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND) & MF_CHECKED)
460 {
461 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_UNCHECKED);
462 TaskManagerSettings.ShowKernelTimes = FALSE;
463 }
464 else
465 {
466 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_CHECKED);
467 TaskManagerSettings.ShowKernelTimes = TRUE;
468 }
469
470 RefreshPerformancePage();
471 }
472
473 void PerformancePage_OnViewCPUHistoryOneGraphAll(void)
474 {
475 HMENU hMenu;
476 HMENU hViewMenu;
477 HMENU hCPUHistoryMenu;
478
479 hMenu = GetMenu(hMainWnd);
480 hViewMenu = GetSubMenu(hMenu, 2);
481 hCPUHistoryMenu = GetSubMenu(hViewMenu, 3);
482
483 TaskManagerSettings.CPUHistory_OneGraphPerCPU = FALSE;
484 CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHALL, MF_BYCOMMAND);
485 }
486
487 void PerformancePage_OnViewCPUHistoryOneGraphPerCPU(void)
488 {
489 HMENU hMenu;
490 HMENU hViewMenu;
491 HMENU hCPUHistoryMenu;
492
493 hMenu = GetMenu(hMainWnd);
494 hViewMenu = GetSubMenu(hMenu, 2);
495 hCPUHistoryMenu = GetSubMenu(hViewMenu, 3);
496
497 TaskManagerSettings.CPUHistory_OneGraphPerCPU = TRUE;
498 CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, MF_BYCOMMAND);
499 }
500