341931d9b976b0a864d3d4053e0c830eae423778
[reactos.git] / rosapps / taskmgr / PerformancePage.cpp
1 /*
2 * ReactOS Task Manager
3 *
4 * performancepage.cpp
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 #ifdef _MSC_VER
24 #include "stdafx.h"
25 #else
26 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
27 #include <windows.h>
28 #include <commctrl.h>
29 #include <stdlib.h>
30 #include <malloc.h>
31 #include <memory.h>
32 #include <tchar.h>
33 #include <process.h>
34 #include <stdio.h>
35 #endif
36
37 #include "TaskMgr.h"
38 #include "PerformancePage.h"
39 #include "perfdata.h"
40
41 #include "graph.h"
42 #include "GraphCtrl.h"
43
44 TGraphCtrl PerformancePageCpuUsageHistoryGraph;
45 TGraphCtrl PerformancePageMemUsageHistoryGraph;
46
47 HWND hPerformancePage; // Performance Property Page
48
49 HWND hPerformancePageCpuUsageGraph; // CPU Usage Graph
50 HWND hPerformancePageMemUsageGraph; // MEM Usage Graph
51 HWND hPerformancePageCpuUsageHistoryGraph; // CPU Usage History Graph
52 HWND hPerformancePageMemUsageHistoryGraph; // Memory Usage History Graph
53
54 HWND hPerformancePageTotalsFrame; // Totals Frame
55 HWND hPerformancePageCommitChargeFrame; // Commit Charge Frame
56 HWND hPerformancePageKernelMemoryFrame; // Kernel Memory Frame
57 HWND hPerformancePagePhysicalMemoryFrame; // Physical Memory Frame
58
59 HWND hPerformancePageCpuUsageFrame;
60 HWND hPerformancePageMemUsageFrame;
61 HWND hPerformancePageCpuUsageHistoryFrame;
62 HWND hPerformancePageMemUsageHistoryFrame;
63
64 HWND hPerformancePageCommitChargeTotalEdit; // Commit Charge Total Edit Control
65 HWND hPerformancePageCommitChargeLimitEdit; // Commit Charge Limit Edit Control
66 HWND hPerformancePageCommitChargePeakEdit; // Commit Charge Peak Edit Control
67
68 HWND hPerformancePageKernelMemoryTotalEdit; // Kernel Memory Total Edit Control
69 HWND hPerformancePageKernelMemoryPagedEdit; // Kernel Memory Paged Edit Control
70 HWND hPerformancePageKernelMemoryNonPagedEdit; // Kernel Memory NonPaged Edit Control
71
72 HWND hPerformancePagePhysicalMemoryTotalEdit; // Physical Memory Total Edit Control
73 HWND hPerformancePagePhysicalMemoryAvailableEdit; // Physical Memory Available Edit Control
74 HWND hPerformancePagePhysicalMemorySystemCacheEdit; // Physical Memory System Cache Edit Control
75
76 HWND hPerformancePageTotalsHandleCountEdit; // Total Handles Edit Control
77 HWND hPerformancePageTotalsProcessCountEdit; // Total Processes Edit Control
78 HWND hPerformancePageTotalsThreadCountEdit; // Total Threads Edit Control
79
80
81 static int nPerformancePageWidth;
82 static int nPerformancePageHeight;
83
84 static HANDLE hPerformancePageEvent = NULL; // When this event becomes signaled then we refresh the performance page
85
86 void PerformancePageRefreshThread(void *lpParameter);
87
88 void AdjustFrameSize(HWND hCntrl, HWND hDlg, int nXDifference, int nYDifference, int pos)
89 {
90 RECT rc;
91 int cx, cy, sx, sy;
92 GetClientRect(hCntrl, &rc);
93 MapWindowPoints(hCntrl, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT)));
94 if (pos) {
95 cx = rc.left;
96 cy = rc.top;
97 sx = rc.right - rc.left;
98 switch (pos) {
99 case 1:
100 break;
101 case 2:
102 cy += nYDifference / 2;
103 break;
104 case 3:
105 sx += nXDifference / 2;
106 break;
107 case 4:
108 cy += nYDifference / 2;
109 sx += nXDifference / 2;
110 break;
111 }
112 sy = rc.bottom - rc.top + nYDifference / 2;
113 SetWindowPos(hCntrl, NULL, cx, cy, sx, sy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER);
114 } else {
115 cx = rc.left + nXDifference;
116 cy = rc.top + nYDifference;
117 sx = sy = 0;
118 SetWindowPos(hCntrl, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
119 }
120 InvalidateRect(hCntrl, NULL, TRUE);
121 }
122
123 void AdjustControlPostion(HWND hCntrl, HWND hDlg, int nXDifference, int nYDifference)
124 {
125 AdjustFrameSize(hCntrl, hDlg, nXDifference, nYDifference, 0);
126 }
127
128 void AdjustCntrlPos(int ctrl_id, HWND hDlg, int nXDifference, int nYDifference)
129 {
130 AdjustFrameSize(GetDlgItem(hDlg, ctrl_id), hDlg, nXDifference, nYDifference, 0);
131 }
132
133 LRESULT CALLBACK PerformancePageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
134 {
135 RECT rc;
136 int nXDifference;
137 int nYDifference;
138
139 HDC hdc;
140 PAINTSTRUCT ps;
141
142 switch (message)
143 {
144 case WM_INITDIALOG:
145
146 // Save the width and height
147 GetClientRect(hDlg, &rc);
148 nPerformancePageWidth = rc.right;
149 nPerformancePageHeight = rc.bottom;
150
151 // Update window position
152 SetWindowPos(hDlg, NULL, 15, 30, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
153
154 //
155 // Get handles to all the controls
156 //
157 hPerformancePageTotalsFrame = GetDlgItem(hDlg, IDC_TOTALS_FRAME);
158 hPerformancePageCommitChargeFrame = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_FRAME);
159 hPerformancePageKernelMemoryFrame = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_FRAME);
160 hPerformancePagePhysicalMemoryFrame = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_FRAME);
161
162 hPerformancePageCpuUsageFrame = GetDlgItem(hDlg, IDC_CPU_USAGE_FRAME);
163 hPerformancePageMemUsageFrame = GetDlgItem(hDlg, IDC_MEM_USAGE_FRAME);
164 hPerformancePageCpuUsageHistoryFrame = GetDlgItem(hDlg, IDC_CPU_USAGE_HISTORY_FRAME);
165 hPerformancePageMemUsageHistoryFrame = GetDlgItem(hDlg, IDC_MEMORY_USAGE_HISTORY_FRAME);
166
167 hPerformancePageCommitChargeTotalEdit = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_TOTAL);
168 hPerformancePageCommitChargeLimitEdit = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_LIMIT);
169 hPerformancePageCommitChargePeakEdit = GetDlgItem(hDlg, IDC_COMMIT_CHARGE_PEAK);
170 hPerformancePageKernelMemoryTotalEdit = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_TOTAL);
171 hPerformancePageKernelMemoryPagedEdit = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_PAGED);
172 hPerformancePageKernelMemoryNonPagedEdit = GetDlgItem(hDlg, IDC_KERNEL_MEMORY_NONPAGED);
173 hPerformancePagePhysicalMemoryTotalEdit = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_TOTAL);
174 hPerformancePagePhysicalMemoryAvailableEdit = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_AVAILABLE);
175 hPerformancePagePhysicalMemorySystemCacheEdit = GetDlgItem(hDlg, IDC_PHYSICAL_MEMORY_SYSTEM_CACHE);
176 hPerformancePageTotalsHandleCountEdit = GetDlgItem(hDlg, IDC_TOTALS_HANDLE_COUNT);
177 hPerformancePageTotalsProcessCountEdit = GetDlgItem(hDlg, IDC_TOTALS_PROCESS_COUNT);
178 hPerformancePageTotalsThreadCountEdit = GetDlgItem(hDlg, IDC_TOTALS_THREAD_COUNT);
179
180 hPerformancePageCpuUsageGraph = GetDlgItem(hDlg, IDC_CPU_USAGE_GRAPH);
181 hPerformancePageMemUsageGraph = GetDlgItem(hDlg, IDC_MEM_USAGE_GRAPH);
182 hPerformancePageMemUsageHistoryGraph = GetDlgItem(hDlg, IDC_MEM_USAGE_HISTORY_GRAPH);
183 hPerformancePageCpuUsageHistoryGraph = GetDlgItem(hDlg, IDC_CPU_USAGE_HISTORY_GRAPH);
184
185 GetClientRect(hPerformancePageCpuUsageHistoryGraph, &rc);
186 // create the control
187 //PerformancePageCpuUsageHistoryGraph.Create(0, rc, hDlg, IDC_CPU_USAGE_HISTORY_GRAPH);
188 PerformancePageCpuUsageHistoryGraph.Create(hPerformancePageCpuUsageHistoryGraph, hDlg, IDC_CPU_USAGE_HISTORY_GRAPH);
189 // customize the control
190 PerformancePageCpuUsageHistoryGraph.SetRange(0.0, 100.0, 10) ;
191 // PerformancePageCpuUsageHistoryGraph.SetYUnits("Current") ;
192 // PerformancePageCpuUsageHistoryGraph.SetXUnits("Samples (Windows Timer: 100 msec)") ;
193 // PerformancePageCpuUsageHistoryGraph.SetBackgroundColor(RGB(0, 0, 64)) ;
194 // PerformancePageCpuUsageHistoryGraph.SetGridColor(RGB(192, 192, 255)) ;
195 // PerformancePageCpuUsageHistoryGraph.SetPlotColor(RGB(255, 255, 255)) ;
196 PerformancePageCpuUsageHistoryGraph.SetBackgroundColor(RGB(0, 0, 0)) ;
197 PerformancePageCpuUsageHistoryGraph.SetGridColor(RGB(152, 205, 152)) ;
198 PerformancePageCpuUsageHistoryGraph.SetPlotColor(0, RGB(255, 0, 0)) ;
199 PerformancePageCpuUsageHistoryGraph.SetPlotColor(1, RGB(0, 255, 0)) ;
200
201 GetClientRect(hPerformancePageMemUsageHistoryGraph, &rc);
202 PerformancePageMemUsageHistoryGraph.Create(hPerformancePageMemUsageHistoryGraph, hDlg, IDC_MEM_USAGE_HISTORY_GRAPH);
203 PerformancePageMemUsageHistoryGraph.SetRange(0.0, 100.0, 10) ;
204 PerformancePageMemUsageHistoryGraph.SetBackgroundColor(RGB(0, 0, 0)) ;
205 PerformancePageMemUsageHistoryGraph.SetGridColor(RGB(152, 215, 152)) ;
206 PerformancePageMemUsageHistoryGraph.SetPlotColor(0, RGB(255, 255, 0)) ;
207
208 // Start our refresh thread
209 #ifdef RUN_PERF_PAGE
210 _beginthread(PerformancePageRefreshThread, 0, NULL);
211 #endif
212 //
213 // Subclass graph buttons
214 //
215 OldGraphWndProc = SetWindowLong(hPerformancePageCpuUsageGraph, GWL_WNDPROC, (LONG)Graph_WndProc);
216 SetWindowLong(hPerformancePageMemUsageGraph, GWL_WNDPROC, (LONG)Graph_WndProc);
217 // SetWindowLong(hPerformancePageMemUsageHistoryGraph, GWL_WNDPROC, (LONG)Graph_WndProc);
218
219 // OldGraphCtrlWndProc = SetWindowLong(hPerformancePageCpuUsageGraph, GWL_WNDPROC, (LONG)GraphCtrl_WndProc);
220 // SetWindowLong(hPerformancePageMemUsageGraph, GWL_WNDPROC, (LONG)GraphCtrl_WndProc);
221 OldGraphCtrlWndProc = SetWindowLong(hPerformancePageMemUsageHistoryGraph, GWL_WNDPROC, (LONG)GraphCtrl_WndProc);
222 SetWindowLong(hPerformancePageCpuUsageHistoryGraph, GWL_WNDPROC, (LONG)GraphCtrl_WndProc);
223
224 return TRUE;
225
226 case WM_COMMAND:
227 break;
228 #if 0
229 case WM_NCPAINT:
230 hdc = GetDC(hDlg);
231 //GetClientRect(hDlg, &rc);
232 //Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
233 ReleaseDC(hDlg, hdc);
234 break;
235
236 case WM_PAINT:
237 hdc = BeginPaint(hDlg, &ps);
238
239 //GetClientRect(hDlg, &rc);
240 //Draw3dRect(hdc, rc.left, rc.top, rc.right, rc.top + 2, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));
241 EndPaint(hDlg, &ps);
242 break;
243 #endif
244 case WM_SIZE:
245 int cx, cy;
246
247 if (wParam == SIZE_MINIMIZED)
248 return 0;
249
250 cx = LOWORD(lParam);
251 cy = HIWORD(lParam);
252 nXDifference = cx - nPerformancePageWidth;
253 nYDifference = cy - nPerformancePageHeight;
254 nPerformancePageWidth = cx;
255 nPerformancePageHeight = cy;
256 // SetWindowPos(hPerformancePageMemUsageHistoryGraph, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
257 // SetWindowPos(hPerformancePageCpuUsageHistoryGraph, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
258
259 // Reposition the performance page's controls
260 AdjustFrameSize(hPerformancePageTotalsFrame, hDlg, 0, nYDifference, 0);
261 AdjustFrameSize(hPerformancePageCommitChargeFrame, hDlg, 0, nYDifference, 0);
262 AdjustFrameSize(hPerformancePageKernelMemoryFrame, hDlg, 0, nYDifference, 0);
263 AdjustFrameSize(hPerformancePagePhysicalMemoryFrame, hDlg, 0, nYDifference, 0);
264 AdjustCntrlPos(IDS_COMMIT_CHARGE_TOTAL, hDlg, 0, nYDifference);
265 AdjustCntrlPos(IDS_COMMIT_CHARGE_LIMIT, hDlg, 0, nYDifference);
266 AdjustCntrlPos(IDS_COMMIT_CHARGE_PEAK, hDlg, 0, nYDifference);
267 AdjustCntrlPos(IDS_KERNEL_MEMORY_TOTAL, hDlg, 0, nYDifference);
268 AdjustCntrlPos(IDS_KERNEL_MEMORY_PAGED, hDlg, 0, nYDifference);
269 AdjustCntrlPos(IDS_KERNEL_MEMORY_NONPAGED, hDlg, 0, nYDifference);
270 AdjustCntrlPos(IDS_PHYSICAL_MEMORY_TOTAL, hDlg, 0, nYDifference);
271 AdjustCntrlPos(IDS_PHYSICAL_MEMORY_AVAILABLE, hDlg, 0, nYDifference);
272 AdjustCntrlPos(IDS_PHYSICAL_MEMORY_SYSTEM_CACHE, hDlg, 0, nYDifference);
273 AdjustCntrlPos(IDS_TOTALS_HANDLE_COUNT, hDlg, 0, nYDifference);
274 AdjustCntrlPos(IDS_TOTALS_PROCESS_COUNT, hDlg, 0, nYDifference);
275 AdjustCntrlPos(IDS_TOTALS_THREAD_COUNT, hDlg, 0, nYDifference);
276
277 AdjustControlPostion(hPerformancePageCommitChargeTotalEdit, hDlg, 0, nYDifference);
278 AdjustControlPostion(hPerformancePageCommitChargeLimitEdit, hDlg, 0, nYDifference);
279 AdjustControlPostion(hPerformancePageCommitChargePeakEdit, hDlg, 0, nYDifference);
280 AdjustControlPostion(hPerformancePageKernelMemoryTotalEdit, hDlg, 0, nYDifference);
281 AdjustControlPostion(hPerformancePageKernelMemoryPagedEdit, hDlg, 0, nYDifference);
282 AdjustControlPostion(hPerformancePageKernelMemoryNonPagedEdit, hDlg, 0, nYDifference);
283 AdjustControlPostion(hPerformancePagePhysicalMemoryTotalEdit, hDlg, 0, nYDifference);
284 AdjustControlPostion(hPerformancePagePhysicalMemoryAvailableEdit, hDlg, 0, nYDifference);
285 AdjustControlPostion(hPerformancePagePhysicalMemorySystemCacheEdit, hDlg, 0, nYDifference);
286 AdjustControlPostion(hPerformancePageTotalsHandleCountEdit, hDlg, 0, nYDifference);
287 AdjustControlPostion(hPerformancePageTotalsProcessCountEdit, hDlg, 0, nYDifference);
288 AdjustControlPostion(hPerformancePageTotalsThreadCountEdit, hDlg, 0, nYDifference);
289
290 static int lastX, lastY;
291
292 nXDifference += lastX;
293 nYDifference += lastY;
294 lastX = lastY = 0;
295 if (nXDifference % 2) {
296 if (nXDifference > 0) {
297 nXDifference--;
298 lastX++;
299 } else {
300 nXDifference++;
301 lastX--;
302 }
303 }
304 if (nYDifference % 2) {
305 if (nYDifference > 0) {
306 nYDifference--;
307 lastY++;
308 } else {
309 nYDifference++;
310 lastY--;
311 }
312 }
313 AdjustFrameSize(hPerformancePageCpuUsageFrame, hDlg, nXDifference, nYDifference, 1);
314 AdjustFrameSize(hPerformancePageMemUsageFrame, hDlg, nXDifference, nYDifference, 2);
315 AdjustFrameSize(hPerformancePageCpuUsageHistoryFrame, hDlg, nXDifference, nYDifference, 3);
316 AdjustFrameSize(hPerformancePageMemUsageHistoryFrame, hDlg, nXDifference, nYDifference, 4);
317 /*
318 AdjustFrameSize(hPerformancePageCpuUsageGraph, hDlg, nXDifference, nYDifference, 1);
319 AdjustFrameSize(hPerformancePageMemUsageGraph, hDlg, nXDifference, nYDifference, 2);
320 AdjustFrameSize(hPerformancePageMemUsageHistoryGraph, hDlg, nXDifference, nYDifference, 3);
321 AdjustFrameSize(hPerformancePageCpuUsageHistoryGraph, hDlg, nXDifference, nYDifference, 4);
322 */
323 break;
324 }
325
326 return 0;
327 }
328
329 void RefreshPerformancePage(void)
330 {
331 // Signal the event so that our refresh thread
332 // will wake up and refresh the performance page
333 SetEvent(hPerformancePageEvent);
334 }
335
336 void PerformancePageRefreshThread(void *lpParameter)
337 {
338 ULONG CommitChargeTotal;
339 ULONG CommitChargeLimit;
340 ULONG CommitChargePeak;
341
342 ULONG KernelMemoryTotal;
343 ULONG KernelMemoryPaged;
344 ULONG KernelMemoryNonPaged;
345
346 ULONG PhysicalMemoryTotal;
347 ULONG PhysicalMemoryAvailable;
348 ULONG PhysicalMemorySystemCache;
349
350 ULONG TotalHandles;
351 ULONG TotalThreads;
352 ULONG TotalProcesses;
353
354 TCHAR Text[260];
355
356 // Create the event
357 hPerformancePageEvent = CreateEvent(NULL, TRUE, TRUE, "Performance Page Event");
358
359 // If we couldn't create the event then exit the thread
360 if (!hPerformancePageEvent)
361 return;
362
363 while (1)
364 {
365 DWORD dwWaitVal;
366
367 // Wait on the event
368 dwWaitVal = WaitForSingleObject(hPerformancePageEvent, INFINITE);
369
370 // If the wait failed then the event object must have been
371 // closed and the task manager is exiting so exit this thread
372 if (dwWaitVal == WAIT_FAILED)
373 return;
374
375 if (dwWaitVal == WAIT_OBJECT_0)
376 {
377 // Reset our event
378 ResetEvent(hPerformancePageEvent);
379
380 //
381 // Update the commit charge info
382 //
383 CommitChargeTotal = PerfDataGetCommitChargeTotalK();
384 CommitChargeLimit = PerfDataGetCommitChargeLimitK();
385 CommitChargePeak = PerfDataGetCommitChargePeakK();
386 _ultot(CommitChargeTotal, Text, 10);
387 SetWindowText(hPerformancePageCommitChargeTotalEdit, Text);
388 _ultot(CommitChargeLimit, Text, 10);
389 SetWindowText(hPerformancePageCommitChargeLimitEdit, Text);
390 _ultot(CommitChargePeak, Text, 10);
391 SetWindowText(hPerformancePageCommitChargePeakEdit, Text);
392 wsprintf(Text, _T("Mem Usage: %dK / %dK"), CommitChargeTotal, CommitChargeLimit);
393 SendMessage(hStatusWnd, SB_SETTEXT, 2, (LPARAM)Text);
394
395 //
396 // Update the kernel memory info
397 //
398 KernelMemoryTotal = PerfDataGetKernelMemoryTotalK();
399 KernelMemoryPaged = PerfDataGetKernelMemoryPagedK();
400 KernelMemoryNonPaged = PerfDataGetKernelMemoryNonPagedK();
401 _ultot(KernelMemoryTotal, Text, 10);
402 SetWindowText(hPerformancePageKernelMemoryTotalEdit, Text);
403 _ultot(KernelMemoryPaged, Text, 10);
404 SetWindowText(hPerformancePageKernelMemoryPagedEdit, Text);
405 _ultot(KernelMemoryNonPaged, Text, 10);
406 SetWindowText(hPerformancePageKernelMemoryNonPagedEdit, Text);
407
408 //
409 // Update the physical memory info
410 //
411 PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK();
412 PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK();
413 PhysicalMemorySystemCache = PerfDataGetPhysicalMemorySystemCacheK();
414 _ultot(PhysicalMemoryTotal, Text, 10);
415 SetWindowText(hPerformancePagePhysicalMemoryTotalEdit, Text);
416 _ultot(PhysicalMemoryAvailable, Text, 10);
417 SetWindowText(hPerformancePagePhysicalMemoryAvailableEdit, Text);
418 _ultot(PhysicalMemorySystemCache, Text, 10);
419 SetWindowText(hPerformancePagePhysicalMemorySystemCacheEdit, Text);
420
421 //
422 // Update the totals info
423 //
424 TotalHandles = PerfDataGetSystemHandleCount();
425 TotalThreads = PerfDataGetTotalThreadCount();
426 TotalProcesses = PerfDataGetProcessCount();
427 _ultot(TotalHandles, Text, 10);
428 SetWindowText(hPerformancePageTotalsHandleCountEdit, Text);
429 _ultot(TotalThreads, Text, 10);
430 SetWindowText(hPerformancePageTotalsThreadCountEdit, Text);
431 _ultot(TotalProcesses, Text, 10);
432 SetWindowText(hPerformancePageTotalsProcessCountEdit, Text);
433
434 //
435 // Redraw the graphs
436 //
437 InvalidateRect(hPerformancePageCpuUsageGraph, NULL, FALSE);
438 InvalidateRect(hPerformancePageMemUsageGraph, NULL, FALSE);
439
440 //
441
442 ULONG CpuUsage;
443 ULONG CpuKernelUsage;
444 ULONGLONG CommitChargeTotal;
445 ULONGLONG CommitChargeLimit;
446 ULONG PhysicalMemoryTotal;
447 ULONG PhysicalMemoryAvailable;
448 int nBarsUsed1;
449 int nBarsUsed2;
450
451 //
452 // Get the CPU usage
453 //
454 CpuUsage = PerfDataGetProcessorUsage();
455 CpuKernelUsage = PerfDataGetProcessorSystemUsage();
456 if (CpuUsage < 0 ) CpuUsage = 0;
457 if (CpuUsage > 100) CpuUsage = 100;
458 if (CpuKernelUsage < 0) CpuKernelUsage = 0;
459 if (CpuKernelUsage > 100) CpuKernelUsage = 100;
460
461 //
462 // Get the memory usage
463 //
464 CommitChargeTotal = (ULONGLONG)PerfDataGetCommitChargeTotalK();
465 CommitChargeLimit = (ULONGLONG)PerfDataGetCommitChargeLimitK();
466 nBarsUsed1 = ((CommitChargeTotal * 100) / CommitChargeLimit);
467
468 PhysicalMemoryTotal = PerfDataGetPhysicalMemoryTotalK();
469 PhysicalMemoryAvailable = PerfDataGetPhysicalMemoryAvailableK();
470 nBarsUsed2 = ((PhysicalMemoryAvailable * 100) / PhysicalMemoryTotal);
471
472
473 PerformancePageCpuUsageHistoryGraph.AppendPoint(CpuUsage, CpuKernelUsage);
474 PerformancePageMemUsageHistoryGraph.AppendPoint(nBarsUsed1, nBarsUsed2);
475 //PerformancePageMemUsageHistoryGraph.SetRange(0.0, 100.0, 10) ;
476 InvalidateRect(hPerformancePageMemUsageHistoryGraph, NULL, FALSE);
477 InvalidateRect(hPerformancePageCpuUsageHistoryGraph, NULL, FALSE);
478 }
479 }
480 }
481
482 void PerformancePage_OnViewShowKernelTimes(void)
483 {
484 HMENU hMenu;
485 HMENU hViewMenu;
486
487 hMenu = GetMenu(hMainWnd);
488 hViewMenu = GetSubMenu(hMenu, 2);
489
490 // Check or uncheck the show 16-bit tasks menu item
491 if (GetMenuState(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND) & MF_CHECKED)
492 {
493 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_UNCHECKED);
494 TaskManagerSettings.ShowKernelTimes = FALSE;
495 }
496 else
497 {
498 CheckMenuItem(hViewMenu, ID_VIEW_SHOWKERNELTIMES, MF_BYCOMMAND|MF_CHECKED);
499 TaskManagerSettings.ShowKernelTimes = TRUE;
500 }
501
502 RefreshPerformancePage();
503 }
504
505 void PerformancePage_OnViewCPUHistoryOneGraphAll(void)
506 {
507 HMENU hMenu;
508 HMENU hViewMenu;
509 HMENU hCPUHistoryMenu;
510
511 hMenu = GetMenu(hMainWnd);
512 hViewMenu = GetSubMenu(hMenu, 2);
513 hCPUHistoryMenu = GetSubMenu(hViewMenu, 3);
514
515 TaskManagerSettings.CPUHistory_OneGraphPerCPU = FALSE;
516 CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHALL, MF_BYCOMMAND);
517 }
518
519 void PerformancePage_OnViewCPUHistoryOneGraphPerCPU(void)
520 {
521 HMENU hMenu;
522 HMENU hViewMenu;
523 HMENU hCPUHistoryMenu;
524
525 hMenu = GetMenu(hMainWnd);
526 hViewMenu = GetSubMenu(hMenu, 2);
527 hCPUHistoryMenu = GetSubMenu(hViewMenu, 3);
528
529 TaskManagerSettings.CPUHistory_OneGraphPerCPU = TRUE;
530 CheckMenuRadioItem(hCPUHistoryMenu, ID_VIEW_CPUHISTORY_ONEGRAPHALL, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU, MF_BYCOMMAND);
531 }
532