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