Gabriel Ilardi (gabrielilardi@hotmail.it)
[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
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 #ifdef RUN_PERF_PAGE
114 HANDLE hRefreshThread = NULL;
115 #endif
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 CloseHandle(hRefreshThread);
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(152, 205, 152)) ;
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(152, 215, 152)) ;
192 GraphCtrl_SetPlotColor(&PerformancePageMemUsageHistoryGraph, 0, RGB(255, 255, 0)) ;
193 /* Start our refresh thread */
194 #ifdef RUN_PERF_PAGE
195 hRefreshThread = CreateThread(NULL, 0, PerformancePageRefreshThread, NULL, 0, NULL);
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 /* Signal the event so that our refresh thread */
307 /* will wake up and refresh the performance page */
308 SetEvent(hPerformancePageEvent);
309 }
310
311 DWORD WINAPI PerformancePageRefreshThread(void *lpParameter)
312 {
313 ULONG CommitChargeTotal;
314 ULONG CommitChargeLimit;
315 ULONG CommitChargePeak;
316
317 ULONG CpuUsage;
318 ULONG CpuKernelUsage;
319
320 ULONG KernelMemoryTotal;
321 ULONG KernelMemoryPaged;
322 ULONG KernelMemoryNonPaged;
323
324 ULONG PhysicalMemoryTotal;
325 ULONG PhysicalMemoryAvailable;
326 ULONG PhysicalMemorySystemCache;
327
328 ULONG TotalHandles;
329 ULONG TotalThreads;
330 ULONG TotalProcesses;
331
332 WCHAR Text[260];
333 WCHAR szMemUsage[256];
334
335 /* Create the event */
336 hPerformancePageEvent = CreateEventW(NULL, TRUE, TRUE, NULL);
337
338 /* If we couldn't create the event then exit the thread */
339 if (!hPerformancePageEvent)
340 return 0;
341
342 LoadStringW(hInst, IDS_STATUS_MEMUSAGE, szMemUsage, 256);
343
344 while (1)
345 {
346 DWORD dwWaitVal;
347
348 int nBarsUsed1;
349 int nBarsUsed2;
350
351 /* Wait on the event */
352 dwWaitVal = WaitForSingleObject(hPerformancePageEvent, INFINITE);
353
354 /* If the wait failed then the event object must have been */
355 /* closed and the task manager is exiting so exit this thread */
356 if (dwWaitVal == WAIT_FAILED)
357 return 0;
358
359 if (dwWaitVal == WAIT_OBJECT_0)
360 {
361 /* Reset our event */
362 ResetEvent(hPerformancePageEvent);
363
364 /*
365 * Update the commit charge info
366 */
367 CommitChargeTotal = PerfDataGetCommitChargeTotalK();
368 CommitChargeLimit = PerfDataGetCommitChargeLimitK();
369 CommitChargePeak = PerfDataGetCommitChargePeakK();
370 _ultow(CommitChargeTotal, Text, 10);
371 SetWindowTextW(hPerformancePageCommitChargeTotalEdit, Text);
372 _ultow(CommitChargeLimit, Text, 10);
373 SetWindowTextW(hPerformancePageCommitChargeLimitEdit, Text);
374 _ultow(CommitChargePeak, Text, 10);
375 SetWindowTextW(hPerformancePageCommitChargePeakEdit, Text);
376 wsprintfW(Text, szMemUsage, CommitChargeTotal, CommitChargeLimit);
377 SendMessageW(hStatusWnd, SB_SETTEXT, 2, (LPARAM)Text);
378
379 /*
380 * Update the kernel memory info
381 */
382 KernelMemoryTotal = PerfDataGetKernelMemoryTotalK();
383 KernelMemoryPaged = PerfDataGetKernelMemoryPagedK();
384 KernelMemoryNonPaged = PerfDataGetKernelMemoryNonPagedK();
385 _ultow(KernelMemoryTotal, Text, 10);
386 SetWindowTextW(hPerformancePageKernelMemoryTotalEdit, Text);
387 _ultow(KernelMemoryPaged, Text, 10);
388 SetWindowTextW(hPerformancePageKernelMemoryPagedEdit, Text);
389 _ultow(KernelMemoryNonPaged, Text, 10);
390 SetWindowTextW(hPerformancePageKernelMemoryNonPagedEdit, Text);
391
392 /*
393 * Update the physical memory info
394 */
395 PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK();
396 PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK();
397 PhysicalMemorySystemCache = PerfDataGetPhysicalMemorySystemCacheK();
398 _ultow(PhysicalMemoryTotal, Text, 10);
399 SetWindowTextW(hPerformancePagePhysicalMemoryTotalEdit, Text);
400 _ultow(PhysicalMemoryAvailable, Text, 10);
401 SetWindowTextW(hPerformancePagePhysicalMemoryAvailableEdit, Text);
402 _ultow(PhysicalMemorySystemCache, Text, 10);
403 SetWindowTextW(hPerformancePagePhysicalMemorySystemCacheEdit, Text);
404
405 /*
406 * Update the totals info
407 */
408 TotalHandles = PerfDataGetSystemHandleCount();
409 TotalThreads = PerfDataGetTotalThreadCount();
410 TotalProcesses = PerfDataGetProcessCount();
411 _ultow(TotalHandles, Text, 10);
412 SetWindowTextW(hPerformancePageTotalsHandleCountEdit, Text);
413 _ultow(TotalThreads, Text, 10);
414 SetWindowTextW(hPerformancePageTotalsThreadCountEdit, Text);
415 _ultow(TotalProcesses, Text, 10);
416 SetWindowTextW(hPerformancePageTotalsProcessCountEdit, Text);
417
418 /*
419 * Redraw the graphs
420 */
421 InvalidateRect(hPerformancePageCpuUsageGraph, NULL, FALSE);
422 InvalidateRect(hPerformancePageMemUsageGraph, NULL, FALSE);
423
424 /*
425 * Get the CPU usage
426 */
427 CpuUsage = PerfDataGetProcessorUsage();
428 if (CpuUsage <= 0 ) CpuUsage = 0;
429 if (CpuUsage > 100) CpuUsage = 100;
430
431 if (TaskManagerSettings.ShowKernelTimes)
432 {
433 CpuKernelUsage = PerfDataGetProcessorSystemUsage();
434 if (CpuKernelUsage <= 0) CpuKernelUsage = 0;
435 if (CpuKernelUsage > 100) CpuKernelUsage = 100;
436 }
437 else
438 {
439 CpuKernelUsage = 0;
440 }
441 /*
442 * Get the memory usage
443 */
444 CommitChargeTotal = PerfDataGetCommitChargeTotalK();
445 CommitChargeLimit = PerfDataGetCommitChargeLimitK();
446 nBarsUsed1 = CommitChargeLimit ? ((CommitChargeTotal * 100) / CommitChargeLimit) : 0;
447
448 PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK();
449 PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK();
450 nBarsUsed2 = PhysicalMemoryTotal ? ((PhysicalMemoryAvailable * 100) / PhysicalMemoryTotal) : 0;
451
452
453
454 GraphCtrl_AppendPoint(&PerformancePageCpuUsageHistoryGraph, CpuUsage, CpuKernelUsage, 0.0, 0.0);
455 GraphCtrl_AppendPoint(&PerformancePageMemUsageHistoryGraph, nBarsUsed1, nBarsUsed2, 0.0, 0.0);
456 /* PerformancePageMemUsageHistoryGraph.SetRange(0.0, 100.0, 10) ; */
457 InvalidateRect(hPerformancePageMemUsageHistoryGraph, NULL, FALSE);
458 InvalidateRect(hPerformancePageCpuUsageHistoryGraph, NULL, FALSE);
459 }
460 }
461 return 0;
462 }
463
464 void PerformancePage_OnViewShowKernelTimes(void)
465 {
466 HMENU hMenu;
467 HMENU hViewMenu;
468
469 hMenu = GetMenu(hMainWnd);
470 hViewMenu = GetSubMenu(hMenu, 2);
471
472 /* Check or uncheck the show 16-bit tasks menu item */
473 if (GetMenuState(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND) & MF_CHECKED)
474 {
475 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_UNCHECKED);
476 TaskManagerSettings.ShowKernelTimes = FALSE;
477 }
478 else
479 {
480 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_CHECKED);
481 TaskManagerSettings.ShowKernelTimes = TRUE;
482 }
483
484 RefreshPerformancePage();
485 }
486
487 void PerformancePage_OnViewCPUHistoryOneGraphAll(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 = FALSE;
498 CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHALL, MF_BYCOMMAND);
499 }
500
501 void PerformancePage_OnViewCPUHistoryOneGraphPerCPU(void)
502 {
503 HMENU hMenu;
504 HMENU hViewMenu;
505 HMENU hCPUHistoryMenu;
506
507 hMenu = GetMenu(hMainWnd);
508 hViewMenu = GetSubMenu(hMenu, 2);
509 hCPUHistoryMenu = GetSubMenu(hViewMenu, 3);
510
511 TaskManagerSettings.CPUHistory_OneGraphPerCPU = TRUE;
512 CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, MF_BYCOMMAND);
513 }
514