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