b2bea988dccdc843e5202445a50208a5f0e72609
[reactos.git] / reactos / subsys / system / 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
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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
55 static int nPerformancePageWidth;
56 static int nPerformancePageHeight;
57 static int lastX, lastY;
58 static HANDLE hPerformancePageEvent = NULL; /* When this event becomes signaled then we refresh the performance page */
59 DWORD WINAPI PerformancePageRefreshThread(void *lpParameter);
60
61 void AdjustFrameSize(HWND hCntrl, HWND hDlg, int nXDifference, int nYDifference, int pos)
62 {
63 RECT rc;
64 int cx, cy, sx, sy;
65
66 GetClientRect(hCntrl, &rc);
67 MapWindowPoints(hCntrl, hDlg, (LPPOINT)(PRECT)(&rc), (sizeof(RECT)/sizeof(POINT)));
68 if (pos) {
69 cx = rc.left;
70 cy = rc.top;
71 sx = rc.right - rc.left;
72 switch (pos) {
73 case 1:
74 break;
75 case 2:
76 cy += nYDifference / 2;
77 break;
78 case 3:
79 sx += nXDifference;
80 break;
81 case 4:
82 cy += nYDifference / 2;
83 sx += nXDifference;
84 break;
85 }
86 sy = rc.bottom - rc.top + nYDifference / 2;
87 SetWindowPos(hCntrl, NULL, cx, cy, sx, sy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER);
88 } else {
89 cx = rc.left + nXDifference;
90 cy = rc.top + nYDifference;
91 sx = sy = 0;
92 SetWindowPos(hCntrl, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
93 }
94 InvalidateRect(hCntrl, NULL, TRUE);
95 }
96
97 void AdjustControlPostion(HWND hCntrl, HWND hDlg, int nXDifference, int nYDifference)
98 {
99 AdjustFrameSize(hCntrl, hDlg, nXDifference, nYDifference, 0);
100 }
101
102 void AdjustCntrlPos(int ctrl_id, HWND hDlg, int nXDifference, int nYDifference)
103 {
104 AdjustFrameSize(GetDlgItem(hDlg, ctrl_id), hDlg, nXDifference, nYDifference, 0);
105 }
106
107 INT_PTR CALLBACK
108 PerformancePageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
109 {
110 RECT rc;
111 int nXDifference;
112 int nYDifference;
113
114 /* HDC hdc; */
115 /* PAINTSTRUCT ps; */
116
117 switch (message) {
118 case WM_INITDIALOG:
119
120 /* Save the width and height */
121 GetClientRect(hDlg, &rc);
122 nPerformancePageWidth = rc.right;
123 nPerformancePageHeight = rc.bottom;
124
125 /* Update window position */
126 SetWindowPos(hDlg, NULL, 15, 30, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
127
128 /*
129 * Get handles to all the controls
130 */
131 hPerformancePageTotalsFrame = GetDlgItem(hDlg, IDC_TOTALS_FRAME);
132 hPerformancePageCommitChargeFrame = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_FRAME);
133 hPerformancePageKernelMemoryFrame = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_FRAME);
134 hPerformancePagePhysicalMemoryFrame = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_FRAME);
135
136 hPerformancePageCpuUsageFrame = GetDlgItem(hDlg, IDC_CPU_USAGE_FRAME);
137 hPerformancePageMemUsageFrame = GetDlgItem(hDlg, IDC_MEM_USAGE_FRAME);
138 hPerformancePageCpuUsageHistoryFrame = GetDlgItem(hDlg, IDC_CPU_USAGE_HISTORY_FRAME);
139 hPerformancePageMemUsageHistoryFrame = GetDlgItem(hDlg, IDC_MEMORY_USAGE_HISTORY_FRAME);
140
141 hPerformancePageCommitChargeTotalEdit = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_TOTAL);
142 hPerformancePageCommitChargeLimitEdit = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_LIMIT);
143 hPerformancePageCommitChargePeakEdit = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_PEAK);
144 hPerformancePageKernelMemoryTotalEdit = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_TOTAL);
145 hPerformancePageKernelMemoryPagedEdit = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_PAGED);
146 hPerformancePageKernelMemoryNonPagedEdit = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_NONPAGED);
147 hPerformancePagePhysicalMemoryTotalEdit = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_TOTAL);
148 hPerformancePagePhysicalMemoryAvailableEdit = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_AVAILABLE);
149 hPerformancePagePhysicalMemorySystemCacheEdit = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_SYSTEM_CACHE);
150 hPerformancePageTotalsHandleCountEdit = GetDlgItem(hDlg, IDC_TOTALS_HANDLE_COUNT);
151 hPerformancePageTotalsProcessCountEdit = GetDlgItem(hDlg, IDC_TOTALS_PROCESS_COUNT);
152 hPerformancePageTotalsThreadCountEdit = GetDlgItem(hDlg, IDC_TOTALS_THREAD_COUNT);
153
154 hPerformancePageCpuUsageGraph = GetDlgItem(hDlg, IDC_CPU_USAGE_GRAPH);
155 hPerformancePageMemUsageGraph = GetDlgItem(hDlg, IDC_MEM_USAGE_GRAPH);
156 hPerformancePageMemUsageHistoryGraph = GetDlgItem(hDlg, IDC_MEM_USAGE_HISTORY_GRAPH);
157 hPerformancePageCpuUsageHistoryGraph = GetDlgItem(hDlg, IDC_CPU_USAGE_HISTORY_GRAPH);
158
159 GetClientRect(hPerformancePageCpuUsageHistoryGraph, &rc);
160 /* create the control */
161 /* PerformancePageCpuUsageHistoryGraph.Create(0, rc, hDlg, IDC_CPU_USAGE_HISTORY_GRAPH); */
162 GraphCtrl_Create(&PerformancePageCpuUsageHistoryGraph, hPerformancePageCpuUsageHistoryGraph, hDlg, IDC_CPU_USAGE_HISTORY_GRAPH);
163 /* customize the control */
164 GraphCtrl_SetRange(&PerformancePageCpuUsageHistoryGraph, 0.0, 100.0, 10);
165 /* PerformancePageCpuUsageHistoryGraph.SetYUnits("Current") ; */
166 /* PerformancePageCpuUsageHistoryGraph.SetXUnits("Samples (Windows Timer: 100 msec)") ; */
167 /* PerformancePageCpuUsageHistoryGraph.SetBackgroundColor(RGB(0, 0, 64)) ; */
168 /* PerformancePageCpuUsageHistoryGraph.SetGridColor(RGB(192, 192, 255)) ; */
169 /* PerformancePageCpuUsageHistoryGraph.SetPlotColor(RGB(255, 255, 255)) ; */
170 GraphCtrl_SetBackgroundColor(&PerformancePageCpuUsageHistoryGraph, RGB(0, 0, 0)) ;
171 GraphCtrl_SetGridColor(&PerformancePageCpuUsageHistoryGraph, RGB(152, 205, 152)) ;
172 GraphCtrl_SetPlotColor(&PerformancePageCpuUsageHistoryGraph, 0, RGB(255, 0, 0)) ;
173 GraphCtrl_SetPlotColor(&PerformancePageCpuUsageHistoryGraph, 1, RGB(0, 255, 0)) ;
174
175 GetClientRect(hPerformancePageMemUsageHistoryGraph, &rc);
176 GraphCtrl_Create(&PerformancePageMemUsageHistoryGraph, hPerformancePageMemUsageHistoryGraph, hDlg, IDC_MEM_USAGE_HISTORY_GRAPH);
177 GraphCtrl_SetRange(&PerformancePageMemUsageHistoryGraph, 0.0, 100.0, 10) ;
178 GraphCtrl_SetBackgroundColor(&PerformancePageMemUsageHistoryGraph, RGB(0, 0, 0)) ;
179 GraphCtrl_SetGridColor(&PerformancePageMemUsageHistoryGraph, RGB(152, 215, 152)) ;
180 GraphCtrl_SetPlotColor(&PerformancePageMemUsageHistoryGraph, 0, RGB(255, 255, 0)) ;
181 /* Start our refresh thread */
182 #ifdef RUN_PERF_PAGE
183 CreateThread(NULL, 0, PerformancePageRefreshThread, NULL, 0, NULL);
184 #endif
185
186 /*
187 * Subclass graph buttons
188 */
189 OldGraphWndProc = SetWindowLongPtr(hPerformancePageCpuUsageGraph, GWL_WNDPROC, (DWORD_PTR)Graph_WndProc);
190 SetWindowLongPtr(hPerformancePageMemUsageGraph, GWL_WNDPROC, (DWORD_PTR)Graph_WndProc);
191 OldGraphCtrlWndProc = SetWindowLongPtr(hPerformancePageMemUsageHistoryGraph, GWL_WNDPROC, (DWORD_PTR)GraphCtrl_WndProc);
192 SetWindowLongPtr(hPerformancePageCpuUsageHistoryGraph, GWL_WNDPROC, (DWORD_PTR)GraphCtrl_WndProc);
193 return TRUE;
194
195 case WM_COMMAND:
196 break;
197 #if 0
198 case WM_NCPAINT:
199 hdc = GetDC(hDlg);
200 GetClientRect(hDlg, &rc);
201 Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
202 ReleaseDC(hDlg, hdc);
203 break;
204
205 case WM_PAINT:
206 hdc = BeginPaint(hDlg, &ps);
207 GetClientRect(hDlg, &rc);
208 Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
209 EndPaint(hDlg, &ps);
210 break;
211 #endif
212 case WM_SIZE:
213 do {
214 int cx, cy;
215
216 if (wParam == SIZE_MINIMIZED)
217 return 0;
218
219 cx = LOWORD(lParam);
220 cy = HIWORD(lParam);
221 nXDifference = cx - nPerformancePageWidth;
222 nYDifference = cy - nPerformancePageHeight;
223 nPerformancePageWidth = cx;
224 nPerformancePageHeight = cy;
225 } while (0);
226
227 /* Reposition the performance page's controls */
228 AdjustFrameSize(hPerformancePageTotalsFrame, hDlg, 0, nYDifference, 0);
229 AdjustFrameSize(hPerformancePageCommitChargeFrame, hDlg, 0, nYDifference, 0);
230 AdjustFrameSize(hPerformancePageKernelMemoryFrame, hDlg, 0, nYDifference, 0);
231 AdjustFrameSize(hPerformancePagePhysicalMemoryFrame, hDlg, 0, nYDifference, 0);
232 AdjustCntrlPos(IDS_COMMIT_CHARGE_TOTAL, hDlg, 0, nYDifference);
233 AdjustCntrlPos(IDS_COMMIT_CHARGE_LIMIT, hDlg, 0, nYDifference);
234 AdjustCntrlPos(IDS_COMMIT_CHARGE_PEAK, hDlg, 0, nYDifference);
235 AdjustCntrlPos(IDS_KERNEL_MEMORY_TOTAL, hDlg, 0, nYDifference);
236 AdjustCntrlPos(IDS_KERNEL_MEMORY_PAGED, hDlg, 0, nYDifference);
237 AdjustCntrlPos(IDS_KERNEL_MEMORY_NONPAGED, hDlg, 0, nYDifference);
238 AdjustCntrlPos(IDS_PHYSICAL_MEMORY_TOTAL, hDlg, 0, nYDifference);
239 AdjustCntrlPos(IDS_PHYSICAL_MEMORY_AVAILABLE, hDlg, 0, nYDifference);
240 AdjustCntrlPos(IDS_PHYSICAL_MEMORY_SYSTEM_CACHE, hDlg, 0, nYDifference);
241 AdjustCntrlPos(IDS_TOTALS_HANDLE_COUNT, hDlg, 0, nYDifference);
242 AdjustCntrlPos(IDS_TOTALS_PROCESS_COUNT, hDlg, 0, nYDifference);
243 AdjustCntrlPos(IDS_TOTALS_THREAD_COUNT, hDlg, 0, nYDifference);
244
245 AdjustControlPostion(hPerformancePageCommitChargeTotalEdit, hDlg, 0, nYDifference);
246 AdjustControlPostion(hPerformancePageCommitChargeLimitEdit, hDlg, 0, nYDifference);
247 AdjustControlPostion(hPerformancePageCommitChargePeakEdit, hDlg, 0, nYDifference);
248 AdjustControlPostion(hPerformancePageKernelMemoryTotalEdit, hDlg, 0, nYDifference);
249 AdjustControlPostion(hPerformancePageKernelMemoryPagedEdit, hDlg, 0, nYDifference);
250 AdjustControlPostion(hPerformancePageKernelMemoryNonPagedEdit, hDlg, 0, nYDifference);
251 AdjustControlPostion(hPerformancePagePhysicalMemoryTotalEdit, hDlg, 0, nYDifference);
252 AdjustControlPostion(hPerformancePagePhysicalMemoryAvailableEdit, hDlg, 0, nYDifference);
253 AdjustControlPostion(hPerformancePagePhysicalMemorySystemCacheEdit, hDlg, 0, nYDifference);
254 AdjustControlPostion(hPerformancePageTotalsHandleCountEdit, hDlg, 0, nYDifference);
255 AdjustControlPostion(hPerformancePageTotalsProcessCountEdit, hDlg, 0, nYDifference);
256 AdjustControlPostion(hPerformancePageTotalsThreadCountEdit, hDlg, 0, nYDifference);
257
258 nXDifference += lastX;
259 nYDifference += lastY;
260 lastX = lastY = 0;
261 if (nXDifference % 2) {
262 if (nXDifference > 0) {
263 nXDifference--;
264 lastX++;
265 } else {
266 nXDifference++;
267 lastX--;
268 }
269 }
270 if (nYDifference % 2) {
271 if (nYDifference > 0) {
272 nYDifference--;
273 lastY++;
274 } else {
275 nYDifference++;
276 lastY--;
277 }
278 }
279 AdjustFrameSize(hPerformancePageCpuUsageFrame, hDlg, nXDifference, nYDifference, 1);
280 AdjustFrameSize(hPerformancePageMemUsageFrame, hDlg, nXDifference, nYDifference, 2);
281 AdjustFrameSize(hPerformancePageCpuUsageHistoryFrame, hDlg, nXDifference, nYDifference, 3);
282 AdjustFrameSize(hPerformancePageMemUsageHistoryFrame, hDlg, nXDifference, nYDifference, 4);
283 AdjustFrameSize(hPerformancePageCpuUsageGraph, hDlg, nXDifference, nYDifference, 1);
284 AdjustFrameSize(hPerformancePageMemUsageGraph, hDlg, nXDifference, nYDifference, 2);
285 AdjustFrameSize(hPerformancePageCpuUsageHistoryGraph, hDlg, nXDifference, nYDifference, 3);
286 AdjustFrameSize(hPerformancePageMemUsageHistoryGraph, hDlg, nXDifference, nYDifference, 4);
287 break;
288 }
289 return 0;
290 }
291
292 void RefreshPerformancePage(void)
293 {
294 /* Signal the event so that our refresh thread */
295 /* will wake up and refresh the performance page */
296 SetEvent(hPerformancePageEvent);
297 }
298
299 DWORD WINAPI PerformancePageRefreshThread(void *lpParameter)
300 {
301 ULONG CommitChargeTotal;
302 ULONG CommitChargeLimit;
303 ULONG CommitChargePeak;
304
305 ULONG CpuUsage;
306 ULONG CpuKernelUsage;
307
308 ULONG KernelMemoryTotal;
309 ULONG KernelMemoryPaged;
310 ULONG KernelMemoryNonPaged;
311
312 ULONG PhysicalMemoryTotal;
313 ULONG PhysicalMemoryAvailable;
314 ULONG PhysicalMemorySystemCache;
315
316 ULONG TotalHandles;
317 ULONG TotalThreads;
318 ULONG TotalProcesses;
319
320 TCHAR Text[260];
321 TCHAR szMemUsage[256];
322
323 /* Create the event */
324 hPerformancePageEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
325
326 /* If we couldn't create the event then exit the thread */
327 if (!hPerformancePageEvent)
328 return 0;
329
330 LoadString(hInst, IDS_STATUS_MEMUSAGE, szMemUsage, 256);
331
332 while (1)
333 {
334 DWORD dwWaitVal;
335
336 int nBarsUsed1;
337 int nBarsUsed2;
338
339 /* Wait on the event */
340 dwWaitVal = WaitForSingleObject(hPerformancePageEvent, INFINITE);
341
342 /* If the wait failed then the event object must have been */
343 /* closed and the task manager is exiting so exit this thread */
344 if (dwWaitVal == WAIT_FAILED)
345 return 0;
346
347 if (dwWaitVal == WAIT_OBJECT_0)
348 {
349 /* Reset our event */
350 ResetEvent(hPerformancePageEvent);
351
352 /*
353 * Update the commit charge info
354 */
355 CommitChargeTotal = PerfDataGetCommitChargeTotalK();
356 CommitChargeLimit = PerfDataGetCommitChargeLimitK();
357 CommitChargePeak = PerfDataGetCommitChargePeakK();
358 _ultot(CommitChargeTotal, Text, 10);
359 SetWindowText(hPerformancePageCommitChargeTotalEdit, Text);
360 _ultot(CommitChargeLimit, Text, 10);
361 SetWindowText(hPerformancePageCommitChargeLimitEdit, Text);
362 _ultot(CommitChargePeak, Text, 10);
363 SetWindowText(hPerformancePageCommitChargePeakEdit, Text);
364 wsprintf(Text, szMemUsage, CommitChargeTotal, CommitChargeLimit);
365 SendMessage(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 _ultot(KernelMemoryTotal, Text, 10);
374 SetWindowText(hPerformancePageKernelMemoryTotalEdit, Text);
375 _ultot(KernelMemoryPaged, Text, 10);
376 SetWindowText(hPerformancePageKernelMemoryPagedEdit, Text);
377 _ultot(KernelMemoryNonPaged, Text, 10);
378 SetWindowText(hPerformancePageKernelMemoryNonPagedEdit, Text);
379
380 /*
381 * Update the physical memory info
382 */
383 PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK();
384 PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK();
385 PhysicalMemorySystemCache = PerfDataGetPhysicalMemorySystemCacheK();
386 _ultot(PhysicalMemoryTotal, Text, 10);
387 SetWindowText(hPerformancePagePhysicalMemoryTotalEdit, Text);
388 _ultot(PhysicalMemoryAvailable, Text, 10);
389 SetWindowText(hPerformancePagePhysicalMemoryAvailableEdit, Text);
390 _ultot(PhysicalMemorySystemCache, Text, 10);
391 SetWindowText(hPerformancePagePhysicalMemorySystemCacheEdit, Text);
392
393 /*
394 * Update the totals info
395 */
396 TotalHandles = PerfDataGetSystemHandleCount();
397 TotalThreads = PerfDataGetTotalThreadCount();
398 TotalProcesses = PerfDataGetProcessCount();
399 _ultot(TotalHandles, Text, 10);
400 SetWindowText(hPerformancePageTotalsHandleCountEdit, Text);
401 _ultot(TotalThreads, Text, 10);
402 SetWindowText(hPerformancePageTotalsThreadCountEdit, Text);
403 _ultot(TotalProcesses, Text, 10);
404 SetWindowText(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 CpuKernelUsage = PerfDataGetProcessorSystemUsage();
417 if (CpuUsage < 0 ) CpuUsage = 0;
418 if (CpuUsage > 100) CpuUsage = 100;
419 if (CpuKernelUsage < 0) CpuKernelUsage = 0;
420 if (CpuKernelUsage > 100) CpuKernelUsage = 100;
421
422 /*
423 * Get the memory usage
424 */
425 CommitChargeTotal = (ULONGLONG)PerfDataGetCommitChargeTotalK();
426 CommitChargeLimit = (ULONGLONG)PerfDataGetCommitChargeLimitK();
427 nBarsUsed1 = CommitChargeLimit ? ((CommitChargeTotal * 100) / CommitChargeLimit) : 0;
428
429 PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK();
430 PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK();
431 nBarsUsed2 = PhysicalMemoryTotal ? ((PhysicalMemoryAvailable * 100) / PhysicalMemoryTotal) : 0;
432
433
434 GraphCtrl_AppendPoint(&PerformancePageCpuUsageHistoryGraph, CpuUsage, CpuKernelUsage, 0.0, 0.0);
435 GraphCtrl_AppendPoint(&PerformancePageMemUsageHistoryGraph, nBarsUsed1, nBarsUsed2, 0.0, 0.0);
436 /* PerformancePageMemUsageHistoryGraph.SetRange(0.0, 100.0, 10) ; */
437 InvalidateRect(hPerformancePageMemUsageHistoryGraph, NULL, FALSE);
438 InvalidateRect(hPerformancePageCpuUsageHistoryGraph, NULL, FALSE);
439 }
440 }
441 return 0;
442 }
443
444 void PerformancePage_OnViewShowKernelTimes(void)
445 {
446 HMENU hMenu;
447 HMENU hViewMenu;
448
449 hMenu = GetMenu(hMainWnd);
450 hViewMenu = GetSubMenu(hMenu, 2);
451
452 /* Check or uncheck the show 16-bit tasks menu item */
453 if (GetMenuState(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND) & MF_CHECKED)
454 {
455 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_UNCHECKED);
456 TaskManagerSettings.ShowKernelTimes = FALSE;
457 }
458 else
459 {
460 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_CHECKED);
461 TaskManagerSettings.ShowKernelTimes = TRUE;
462 }
463
464 RefreshPerformancePage();
465 }
466
467 void PerformancePage_OnViewCPUHistoryOneGraphAll(void)
468 {
469 HMENU hMenu;
470 HMENU hViewMenu;
471 HMENU hCPUHistoryMenu;
472
473 hMenu = GetMenu(hMainWnd);
474 hViewMenu = GetSubMenu(hMenu, 2);
475 hCPUHistoryMenu = GetSubMenu(hViewMenu, 3);
476
477 TaskManagerSettings.CPUHistory_OneGraphPerCPU = FALSE;
478 CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHALL, MF_BYCOMMAND);
479 }
480
481 void PerformancePage_OnViewCPUHistoryOneGraphPerCPU(void)
482 {
483 HMENU hMenu;
484 HMENU hViewMenu;
485 HMENU hCPUHistoryMenu;
486
487 hMenu = GetMenu(hMainWnd);
488 hViewMenu = GetSubMenu(hMenu, 2);
489 hCPUHistoryMenu = GetSubMenu(hViewMenu, 3);
490
491 TaskManagerSettings.CPUHistory_OneGraphPerCPU = TRUE;
492 CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, MF_BYCOMMAND);
493 }
494