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