[APPLICATIONS]
[reactos.git] / reactos / 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 SetWindowPos(hCntrl, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
95 }
96 InvalidateRect(hCntrl, NULL, TRUE);
97 }
98
99 static void AdjustControlPostion(HWND hCntrl, HWND hDlg, int nXDifference, int nYDifference)
100 {
101 AdjustFrameSize(hCntrl, hDlg, nXDifference, nYDifference, 0);
102 }
103
104 static void AdjustCntrlPos(int ctrl_id, HWND hDlg, int nXDifference, int nYDifference)
105 {
106 AdjustFrameSize(GetDlgItem(hDlg, ctrl_id), hDlg, nXDifference, nYDifference, 0);
107 }
108
109 INT_PTR CALLBACK
110 PerformancePageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
111 {
112 RECT rc;
113 int nXDifference;
114 int nYDifference;
115 /* HDC hdc; */
116 /* PAINTSTRUCT ps; */
117
118 switch (message) {
119 case WM_DESTROY:
120 GraphCtrl_Dispose(&PerformancePageCpuUsageHistoryGraph);
121 GraphCtrl_Dispose(&PerformancePageMemUsageHistoryGraph);
122 #ifdef RUN_PERF_PAGE
123 EndLocalThread(&hPerformanceThread, dwPerformanceThread);
124 #endif
125 break;
126
127 case WM_INITDIALOG:
128
129 /* Save the width and height */
130 GetClientRect(hDlg, &rc);
131 nPerformancePageWidth = rc.right;
132 nPerformancePageHeight = rc.bottom;
133
134 /* Update window position */
135 SetWindowPos(hDlg, NULL, 15, 30, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
136
137 /*
138 * Get handles to all the controls
139 */
140 hPerformancePageTotalsFrame = GetDlgItem(hDlg, IDC_TOTALS_FRAME);
141 hPerformancePageCommitChargeFrame = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_FRAME);
142 hPerformancePageKernelMemoryFrame = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_FRAME);
143 hPerformancePagePhysicalMemoryFrame = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_FRAME);
144
145 hPerformancePageCpuUsageFrame = GetDlgItem(hDlg, IDC_CPU_USAGE_FRAME);
146 hPerformancePageMemUsageFrame = GetDlgItem(hDlg, IDC_MEM_USAGE_FRAME);
147 hPerformancePageCpuUsageHistoryFrame = GetDlgItem(hDlg, IDC_CPU_USAGE_HISTORY_FRAME);
148 hPerformancePageMemUsageHistoryFrame = GetDlgItem(hDlg, IDC_MEMORY_USAGE_HISTORY_FRAME);
149
150 hPerformancePageCommitChargeTotalEdit = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_TOTAL);
151 hPerformancePageCommitChargeLimitEdit = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_LIMIT);
152 hPerformancePageCommitChargePeakEdit = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_PEAK);
153 hPerformancePageKernelMemoryTotalEdit = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_TOTAL);
154 hPerformancePageKernelMemoryPagedEdit = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_PAGED);
155 hPerformancePageKernelMemoryNonPagedEdit = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_NONPAGED);
156 hPerformancePagePhysicalMemoryTotalEdit = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_TOTAL);
157 hPerformancePagePhysicalMemoryAvailableEdit = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_AVAILABLE);
158 hPerformancePagePhysicalMemorySystemCacheEdit = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_SYSTEM_CACHE);
159 hPerformancePageTotalsHandleCountEdit = GetDlgItem(hDlg, IDC_TOTALS_HANDLE_COUNT);
160 hPerformancePageTotalsProcessCountEdit = GetDlgItem(hDlg, IDC_TOTALS_PROCESS_COUNT);
161 hPerformancePageTotalsThreadCountEdit = GetDlgItem(hDlg, IDC_TOTALS_THREAD_COUNT);
162
163 hPerformancePageCpuUsageGraph = GetDlgItem(hDlg, IDC_CPU_USAGE_GRAPH);
164 hPerformancePageMemUsageGraph = GetDlgItem(hDlg, IDC_MEM_USAGE_GRAPH);
165 hPerformancePageMemUsageHistoryGraph = GetDlgItem(hDlg, IDC_MEM_USAGE_HISTORY_GRAPH);
166 hPerformancePageCpuUsageHistoryGraph = GetDlgItem(hDlg, IDC_CPU_USAGE_HISTORY_GRAPH);
167
168 GetClientRect(hPerformancePageCpuUsageHistoryGraph, &rc);
169 /* create the control */
170 /* PerformancePageCpuUsageHistoryGraph.Create(0, rc, hDlg, IDC_CPU_USAGE_HISTORY_GRAPH); */
171 GraphCtrl_Create(&PerformancePageCpuUsageHistoryGraph, hPerformancePageCpuUsageHistoryGraph, hDlg, IDC_CPU_USAGE_HISTORY_GRAPH);
172 /* customize the control */
173 GraphCtrl_SetRange(&PerformancePageCpuUsageHistoryGraph, 0.0, 100.0, 10);
174 /* PerformancePageCpuUsageHistoryGraph.SetYUnits("Current") ; */
175 /* PerformancePageCpuUsageHistoryGraph.SetXUnits("Samples (Windows Timer: 100 msec)") ; */
176 /* PerformancePageCpuUsageHistoryGraph.SetBackgroundColor(RGB(0, 0, 64)) ; */
177 /* PerformancePageCpuUsageHistoryGraph.SetGridColor(RGB(192, 192, 255)) ; */
178 /* PerformancePageCpuUsageHistoryGraph.SetPlotColor(RGB(255, 255, 255)) ; */
179 GraphCtrl_SetBackgroundColor(&PerformancePageCpuUsageHistoryGraph, RGB(0, 0, 0)) ;
180 GraphCtrl_SetGridColor(&PerformancePageCpuUsageHistoryGraph, RGB(0, 128, 64));
181
182 GraphCtrl_SetPlotColor(&PerformancePageCpuUsageHistoryGraph, 0, RGB(0, 255, 0)) ;
183 GraphCtrl_SetPlotColor(&PerformancePageCpuUsageHistoryGraph, 1, RGB(255, 0, 0)) ;
184
185
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(0, 128, 64)) ;
191 GraphCtrl_SetPlotColor(&PerformancePageMemUsageHistoryGraph, 0, RGB(255, 255, 0)) ;
192 /* Start our refresh thread */
193 #ifdef RUN_PERF_PAGE
194 hPerformanceThread = CreateThread(NULL, 0, PerformancePageRefreshThread, NULL, 0, &dwPerformanceThread);
195 #endif
196
197 /*
198 * Subclass graph buttons
199 */
200 OldGraphWndProc = (WNDPROC)SetWindowLongPtrW(hPerformancePageCpuUsageGraph, GWLP_WNDPROC, (LONG_PTR)Graph_WndProc);
201 SetWindowLongPtrW(hPerformancePageMemUsageGraph, GWLP_WNDPROC, (LONG_PTR)Graph_WndProc);
202 OldGraphCtrlWndProc = (WNDPROC)SetWindowLongPtrW(hPerformancePageMemUsageHistoryGraph, GWLP_WNDPROC, (LONG_PTR)GraphCtrl_WndProc);
203 SetWindowLongPtrW(hPerformancePageCpuUsageHistoryGraph, GWLP_WNDPROC, (LONG_PTR)GraphCtrl_WndProc);
204 return TRUE;
205
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;
215
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;
226
227 if (wParam == SIZE_MINIMIZED)
228 return 0;
229
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);
237
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);
255
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);
268
269 nXDifference += lastX;
270 nYDifference += lastY;
271 lastX = lastY = 0;
272 if (nXDifference % 2) {
273 if (nXDifference > 0) {
274 nXDifference--;
275 lastX++;
276 } else {
277 nXDifference++;
278 lastX--;
279 }
280 }
281 if (nYDifference % 2) {
282 if (nYDifference > 0) {
283 nYDifference--;
284 lastY++;
285 } else {
286 nYDifference++;
287 lastY--;
288 }
289 }
290 AdjustFrameSize(hPerformancePageCpuUsageFrame, hDlg, nXDifference, nYDifference, 1);
291 AdjustFrameSize(hPerformancePageMemUsageFrame, hDlg, nXDifference, nYDifference, 2);
292 AdjustFrameSize(hPerformancePageCpuUsageHistoryFrame, hDlg, nXDifference, nYDifference, 3);
293 AdjustFrameSize(hPerformancePageMemUsageHistoryFrame, hDlg, nXDifference, nYDifference, 4);
294 AdjustFrameSize(hPerformancePageCpuUsageGraph, hDlg, nXDifference, nYDifference, 1);
295 AdjustFrameSize(hPerformancePageMemUsageGraph, hDlg, nXDifference, nYDifference, 2);
296 AdjustFrameSize(hPerformancePageCpuUsageHistoryGraph, hDlg, nXDifference, nYDifference, 3);
297 AdjustFrameSize(hPerformancePageMemUsageHistoryGraph, hDlg, nXDifference, nYDifference, 4);
298 break;
299 }
300 return 0;
301 }
302
303 void RefreshPerformancePage(void)
304 {
305 #ifdef RUN_PERF_PAGE
306 /* Signal the event so that our refresh thread */
307 /* will wake up and refresh the performance page */
308 PostThreadMessage(dwPerformanceThread, WM_TIMER, 0, 0);
309 #endif
310 }
311
312 DWORD WINAPI PerformancePageRefreshThread(void *lpParameter)
313 {
314 ULONG CommitChargeTotal;
315 ULONG CommitChargeLimit;
316 ULONG CommitChargePeak;
317
318 ULONG CpuUsage;
319 ULONG CpuKernelUsage;
320
321 ULONG KernelMemoryTotal;
322 ULONG KernelMemoryPaged;
323 ULONG KernelMemoryNonPaged;
324
325 ULONG PhysicalMemoryTotal;
326 ULONG PhysicalMemoryAvailable;
327 ULONG PhysicalMemorySystemCache;
328
329 ULONG TotalHandles;
330 ULONG TotalThreads;
331 ULONG TotalProcesses;
332
333 WCHAR Text[260];
334 WCHAR szMemUsage[256];
335
336 MSG msg;
337
338 LoadStringW(hInst, IDS_STATUS_MEMUSAGE, szMemUsage, 256);
339
340 while (1)
341 {
342 int nBarsUsed1;
343 int nBarsUsed2;
344
345 /* Wait for an the event or application close */
346 if (GetMessage(&msg, NULL, 0, 0) <= 0)
347 return 0;
348
349 if (msg.message == WM_TIMER)
350 {
351 /*
352 * Update the commit charge info
353 */
354 CommitChargeTotal = PerfDataGetCommitChargeTotalK();
355 CommitChargeLimit = PerfDataGetCommitChargeLimitK();
356 CommitChargePeak = PerfDataGetCommitChargePeakK();
357 _ultow(CommitChargeTotal, Text, 10);
358 SetWindowTextW(hPerformancePageCommitChargeTotalEdit, Text);
359 _ultow(CommitChargeLimit, Text, 10);
360 SetWindowTextW(hPerformancePageCommitChargeLimitEdit, Text);
361 _ultow(CommitChargePeak, Text, 10);
362 SetWindowTextW(hPerformancePageCommitChargePeakEdit, Text);
363 wsprintfW(Text, szMemUsage, CommitChargeTotal, CommitChargeLimit);
364 SendMessageW(hStatusWnd, SB_SETTEXT, 2, (LPARAM)Text);
365
366 /*
367 * Update the kernel memory info
368 */
369 KernelMemoryTotal = PerfDataGetKernelMemoryTotalK();
370 KernelMemoryPaged = PerfDataGetKernelMemoryPagedK();
371 KernelMemoryNonPaged = PerfDataGetKernelMemoryNonPagedK();
372 _ultow(KernelMemoryTotal, Text, 10);
373 SetWindowTextW(hPerformancePageKernelMemoryTotalEdit, Text);
374 _ultow(KernelMemoryPaged, Text, 10);
375 SetWindowTextW(hPerformancePageKernelMemoryPagedEdit, Text);
376 _ultow(KernelMemoryNonPaged, Text, 10);
377 SetWindowTextW(hPerformancePageKernelMemoryNonPagedEdit, Text);
378
379 /*
380 * Update the physical memory info
381 */
382 PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK();
383 PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK();
384 PhysicalMemorySystemCache = PerfDataGetPhysicalMemorySystemCacheK();
385 _ultow(PhysicalMemoryTotal, Text, 10);
386 SetWindowTextW(hPerformancePagePhysicalMemoryTotalEdit, Text);
387 _ultow(PhysicalMemoryAvailable, Text, 10);
388 SetWindowTextW(hPerformancePagePhysicalMemoryAvailableEdit, Text);
389 _ultow(PhysicalMemorySystemCache, Text, 10);
390 SetWindowTextW(hPerformancePagePhysicalMemorySystemCacheEdit, Text);
391
392 /*
393 * Update the totals info
394 */
395 TotalHandles = PerfDataGetSystemHandleCount();
396 TotalThreads = PerfDataGetTotalThreadCount();
397 TotalProcesses = PerfDataGetProcessCount();
398 _ultow(TotalHandles, Text, 10);
399 SetWindowTextW(hPerformancePageTotalsHandleCountEdit, Text);
400 _ultow(TotalThreads, Text, 10);
401 SetWindowTextW(hPerformancePageTotalsThreadCountEdit, Text);
402 _ultow(TotalProcesses, Text, 10);
403 SetWindowTextW(hPerformancePageTotalsProcessCountEdit, Text);
404
405 /*
406 * Redraw the graphs
407 */
408 InvalidateRect(hPerformancePageCpuUsageGraph, NULL, FALSE);
409 InvalidateRect(hPerformancePageMemUsageGraph, NULL, FALSE);
410
411 /*
412 * Get the CPU usage
413 */
414 CpuUsage = PerfDataGetProcessorUsage();
415 if (CpuUsage <= 0 ) CpuUsage = 0;
416 if (CpuUsage > 100) CpuUsage = 100;
417
418 if (TaskManagerSettings.ShowKernelTimes)
419 {
420 CpuKernelUsage = PerfDataGetProcessorSystemUsage();
421 if (CpuKernelUsage <= 0) CpuKernelUsage = 0;
422 if (CpuKernelUsage > 100) CpuKernelUsage = 100;
423 }
424 else
425 {
426 CpuKernelUsage = 0;
427 }
428 /*
429 * Get the memory usage
430 */
431 CommitChargeTotal = PerfDataGetCommitChargeTotalK();
432 CommitChargeLimit = PerfDataGetCommitChargeLimitK();
433 nBarsUsed1 = CommitChargeLimit ? ((CommitChargeTotal * 100) / CommitChargeLimit) : 0;
434
435 PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK();
436 PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK();
437 nBarsUsed2 = PhysicalMemoryTotal ? ((PhysicalMemoryAvailable * 100) / PhysicalMemoryTotal) : 0;
438
439 GraphCtrl_AppendPoint(&PerformancePageCpuUsageHistoryGraph, CpuUsage, CpuKernelUsage, 0.0, 0.0);
440 GraphCtrl_AppendPoint(&PerformancePageMemUsageHistoryGraph, nBarsUsed1, nBarsUsed2, 0.0, 0.0);
441 /* PerformancePageMemUsageHistoryGraph.SetRange(0.0, 100.0, 10) ; */
442 InvalidateRect(hPerformancePageMemUsageHistoryGraph, NULL, FALSE);
443 InvalidateRect(hPerformancePageCpuUsageHistoryGraph, NULL, FALSE);
444 }
445 }
446 return 0;
447 }
448
449 void PerformancePage_OnViewShowKernelTimes(void)
450 {
451 HMENU hMenu;
452 HMENU hViewMenu;
453
454 hMenu = GetMenu(hMainWnd);
455 hViewMenu = GetSubMenu(hMenu, 2);
456
457 /* Check or uncheck the show 16-bit tasks menu item */
458 if (GetMenuState(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND) & MF_CHECKED)
459 {
460 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_UNCHECKED);
461 TaskManagerSettings.ShowKernelTimes = FALSE;
462 }
463 else
464 {
465 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_CHECKED);
466 TaskManagerSettings.ShowKernelTimes = TRUE;
467 }
468
469 RefreshPerformancePage();
470 }
471
472 void PerformancePage_OnViewCPUHistoryOneGraphAll(void)
473 {
474 HMENU hMenu;
475 HMENU hViewMenu;
476 HMENU hCPUHistoryMenu;
477
478 hMenu = GetMenu(hMainWnd);
479 hViewMenu = GetSubMenu(hMenu, 2);
480 hCPUHistoryMenu = GetSubMenu(hViewMenu, 3);
481
482 TaskManagerSettings.CPUHistory_OneGraphPerCPU = FALSE;
483 CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHALL, MF_BYCOMMAND);
484 }
485
486 void PerformancePage_OnViewCPUHistoryOneGraphPerCPU(void)
487 {
488 HMENU hMenu;
489 HMENU hViewMenu;
490 HMENU hCPUHistoryMenu;
491
492 hMenu = GetMenu(hMainWnd);
493 hViewMenu = GetSubMenu(hMenu, 2);
494 hCPUHistoryMenu = GetSubMenu(hViewMenu, 3);
495
496 TaskManagerSettings.CPUHistory_OneGraphPerCPU = TRUE;
497 CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, MF_BYCOMMAND);
498 }
499