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