6 * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
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.
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.
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.
25 #include "PerformancePage.h"
29 HWND hPerformancePage
; // Performance Property Page
31 HWND hPerformancePageCpuUsageGraph
; // CPU Usage Graph
32 HWND hPerformancePageMemUsageGraph
; // MEM Usage Graph
33 HWND hPerformancePageMemUsageHistoryGraph
; // Memory Usage History Graph
35 HWND hPerformancePageTotalsFrame
; // Totals Frame
36 HWND hPerformancePageCommitChargeFrame
; // Commit Charge Frame
37 HWND hPerformancePageKernelMemoryFrame
; // Kernel Memory Frame
38 HWND hPerformancePagePhysicalMemoryFrame
; // Physical Memory Frame
40 HWND hPerformancePageCommitChargeTotalEdit
; // Commit Charge Total Edit Control
41 HWND hPerformancePageCommitChargeLimitEdit
; // Commit Charge Limit Edit Control
42 HWND hPerformancePageCommitChargePeakEdit
; // Commit Charge Peak Edit Control
44 HWND hPerformancePageKernelMemoryTotalEdit
; // Kernel Memory Total Edit Control
45 HWND hPerformancePageKernelMemoryPagedEdit
; // Kernel Memory Paged Edit Control
46 HWND hPerformancePageKernelMemoryNonPagedEdit
; // Kernel Memory NonPaged Edit Control
48 HWND hPerformancePagePhysicalMemoryTotalEdit
; // Physical Memory Total Edit Control
49 HWND hPerformancePagePhysicalMemoryAvailableEdit
; // Physical Memory Available Edit Control
50 HWND hPerformancePagePhysicalMemorySystemCacheEdit
; // Physical Memory System Cache Edit Control
52 HWND hPerformancePageTotalsHandleCountEdit
; // Total Handles Edit Control
53 HWND hPerformancePageTotalsProcessCountEdit
; // Total Processes Edit Control
54 HWND hPerformancePageTotalsThreadCountEdit
; // Total Threads Edit Control
56 static int nPerformancePageWidth
;
57 static int nPerformancePageHeight
;
59 static HANDLE hPerformancePageEvent
= NULL
; // When this event becomes signaled then we refresh the performance page
61 void PerformancePageRefreshThread(void *lpParameter
);
63 LRESULT CALLBACK
PerformancePageWndProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
73 // Save the width and height
74 GetClientRect(hDlg
, &rc
);
75 nPerformancePageWidth
= rc
.right
;
76 nPerformancePageHeight
= rc
.bottom
;
78 // Update window position
79 SetWindowPos(hDlg
, NULL
, 15, 30, 0, 0, SWP_NOACTIVATE
|SWP_NOOWNERZORDER
|SWP_NOSIZE
|SWP_NOZORDER
);
82 // Get handles to all the controls
84 hPerformancePageTotalsFrame
= GetDlgItem(hDlg
, IDC_TOTALS_FRAME
);
85 hPerformancePageCommitChargeFrame
= GetDlgItem(hDlg
, IDC_COMMIT_CHARGE_FRAME
);
86 hPerformancePageKernelMemoryFrame
= GetDlgItem(hDlg
, IDC_KERNEL_MEMORY_FRAME
);
87 hPerformancePagePhysicalMemoryFrame
= GetDlgItem(hDlg
, IDC_PHYSICAL_MEMORY_FRAME
);
88 hPerformancePageCommitChargeTotalEdit
= GetDlgItem(hDlg
, IDC_COMMIT_CHARGE_TOTAL
);
89 hPerformancePageCommitChargeLimitEdit
= GetDlgItem(hDlg
, IDC_COMMIT_CHARGE_LIMIT
);
90 hPerformancePageCommitChargePeakEdit
= GetDlgItem(hDlg
, IDC_COMMIT_CHARGE_PEAK
);
91 hPerformancePageKernelMemoryTotalEdit
= GetDlgItem(hDlg
, IDC_KERNEL_MEMORY_TOTAL
);
92 hPerformancePageKernelMemoryPagedEdit
= GetDlgItem(hDlg
, IDC_KERNEL_MEMORY_PAGED
);
93 hPerformancePageKernelMemoryNonPagedEdit
= GetDlgItem(hDlg
, IDC_KERNEL_MEMORY_NONPAGED
);
94 hPerformancePagePhysicalMemoryTotalEdit
= GetDlgItem(hDlg
, IDC_PHYSICAL_MEMORY_TOTAL
);
95 hPerformancePagePhysicalMemoryAvailableEdit
= GetDlgItem(hDlg
, IDC_PHYSICAL_MEMORY_AVAILABLE
);
96 hPerformancePagePhysicalMemorySystemCacheEdit
= GetDlgItem(hDlg
, IDC_PHYSICAL_MEMORY_SYSTEM_CACHE
);
97 hPerformancePageTotalsHandleCountEdit
= GetDlgItem(hDlg
, IDC_TOTALS_HANDLE_COUNT
);
98 hPerformancePageTotalsProcessCountEdit
= GetDlgItem(hDlg
, IDC_TOTALS_PROCESS_COUNT
);
99 hPerformancePageTotalsThreadCountEdit
= GetDlgItem(hDlg
, IDC_TOTALS_THREAD_COUNT
);
100 hPerformancePageCpuUsageGraph
= GetDlgItem(hDlg
, IDC_CPU_USAGE_GRAPH
);
101 hPerformancePageMemUsageGraph
= GetDlgItem(hDlg
, IDC_MEM_USAGE_GRAPH
);
102 hPerformancePageMemUsageHistoryGraph
= GetDlgItem(hDlg
, IDC_MEM_USAGE_HISTORY_GRAPH
);
104 // Start our refresh thread
105 _beginthread(PerformancePageRefreshThread
, 0, NULL
);
108 // Subclass graph buttons
110 OldGraphWndProc
= SetWindowLong(hPerformancePageCpuUsageGraph
, GWL_WNDPROC
, (LONG
)Graph_WndProc
);
111 SetWindowLong(hPerformancePageMemUsageGraph
, GWL_WNDPROC
, (LONG
)Graph_WndProc
);
112 SetWindowLong(hPerformancePageMemUsageHistoryGraph
, GWL_WNDPROC
, (LONG
)Graph_WndProc
);
122 if (wParam
== SIZE_MINIMIZED
)
127 nXDifference
= cx
- nPerformancePageWidth
;
128 nYDifference
= cy
- nPerformancePageHeight
;
129 nPerformancePageWidth
= cx
;
130 nPerformancePageHeight
= cy
;
132 // Reposition the performance page's controls
133 /*GetWindowRect(hApplicationPageListCtrl, &rc);
134 cx = (rc.right - rc.left) + nXDifference;
135 cy = (rc.bottom - rc.top) + nYDifference;
136 SetWindowPos(hApplicationPageListCtrl, NULL, 0, 0, cx, cy, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOMOVE|SWP_NOZORDER);
137 InvalidateRect(hApplicationPageListCtrl, NULL, TRUE);
139 GetClientRect(hApplicationPageEndTaskButton, &rc);
140 MapWindowPoints(hApplicationPageEndTaskButton, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT)) );
141 cx = rc.left + nXDifference;
142 cy = rc.top + nYDifference;
143 SetWindowPos(hApplicationPageEndTaskButton, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
144 InvalidateRect(hApplicationPageEndTaskButton, NULL, TRUE);
146 GetClientRect(hApplicationPageSwitchToButton, &rc);
147 MapWindowPoints(hApplicationPageSwitchToButton, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT)) );
148 cx = rc.left + nXDifference;
149 cy = rc.top + nYDifference;
150 SetWindowPos(hApplicationPageSwitchToButton, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
151 InvalidateRect(hApplicationPageSwitchToButton, NULL, TRUE);
153 GetClientRect(hApplicationPageNewTaskButton, &rc);
154 MapWindowPoints(hApplicationPageNewTaskButton, hDlg, (LPPOINT)(&rc), (sizeof(RECT)/sizeof(POINT)) );
155 cx = rc.left + nXDifference;
156 cy = rc.top + nYDifference;
157 SetWindowPos(hApplicationPageNewTaskButton, NULL, cx, cy, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSIZE|SWP_NOZORDER);
158 InvalidateRect(hApplicationPageNewTaskButton, NULL, TRUE);*/
166 void RefreshPerformancePage(void)
168 // Signal the event so that our refresh thread
169 // will wake up and refresh the performance page
170 SetEvent(hPerformancePageEvent
);
173 void PerformancePageRefreshThread(void *lpParameter
)
175 ULONG CommitChargeTotal
;
176 ULONG CommitChargeLimit
;
177 ULONG CommitChargePeak
;
179 ULONG KernelMemoryTotal
;
180 ULONG KernelMemoryPaged
;
181 ULONG KernelMemoryNonPaged
;
183 ULONG PhysicalMemoryTotal
;
184 ULONG PhysicalMemoryAvailable
;
185 ULONG PhysicalMemorySystemCache
;
189 ULONG TotalProcesses
;
194 hPerformancePageEvent
= CreateEvent(NULL
, TRUE
, TRUE
, "Performance Page Event");
196 // If we couldn't create the event then exit the thread
197 if (!hPerformancePageEvent
)
205 dwWaitVal
= WaitForSingleObject(hPerformancePageEvent
, INFINITE
);
207 // If the wait failed then the event object must have been
208 // closed and the task manager is exiting so exit this thread
209 if (dwWaitVal
== WAIT_FAILED
)
212 if (dwWaitVal
== WAIT_OBJECT_0
)
215 ResetEvent(hPerformancePageEvent
);
218 // Update the commit charge info
220 CommitChargeTotal
= PerfDataGetCommitChargeTotalK();
221 CommitChargeLimit
= PerfDataGetCommitChargeLimitK();
222 CommitChargePeak
= PerfDataGetCommitChargePeakK();
223 _ultot(CommitChargeTotal
, Text
, 10);
224 SetWindowText(hPerformancePageCommitChargeTotalEdit
, Text
);
225 _ultot(CommitChargeLimit
, Text
, 10);
226 SetWindowText(hPerformancePageCommitChargeLimitEdit
, Text
);
227 _ultot(CommitChargePeak
, Text
, 10);
228 SetWindowText(hPerformancePageCommitChargePeakEdit
, Text
);
229 wsprintf(Text
, _T("Mem Usage: %dK / %dK"), CommitChargeTotal
, CommitChargeLimit
);
230 SendMessage(hStatusWnd
, SB_SETTEXT
, 2, (LPARAM
)Text
);
233 // Update the kernel memory info
235 KernelMemoryTotal
= PerfDataGetKernelMemoryTotalK();
236 KernelMemoryPaged
= PerfDataGetKernelMemoryPagedK();
237 KernelMemoryNonPaged
= PerfDataGetKernelMemoryNonPagedK();
238 _ultot(KernelMemoryTotal
, Text
, 10);
239 SetWindowText(hPerformancePageKernelMemoryTotalEdit
, Text
);
240 _ultot(KernelMemoryPaged
, Text
, 10);
241 SetWindowText(hPerformancePageKernelMemoryPagedEdit
, Text
);
242 _ultot(KernelMemoryNonPaged
, Text
, 10);
243 SetWindowText(hPerformancePageKernelMemoryNonPagedEdit
, Text
);
246 // Update the physical memory info
248 PhysicalMemoryTotal
= PerfDataGetPhysicalMemoryTotalK();
249 PhysicalMemoryAvailable
= PerfDataGetPhysicalMemoryAvailableK();
250 PhysicalMemorySystemCache
= PerfDataGetPhysicalMemorySystemCacheK();
251 _ultot(PhysicalMemoryTotal
, Text
, 10);
252 SetWindowText(hPerformancePagePhysicalMemoryTotalEdit
, Text
);
253 _ultot(PhysicalMemoryAvailable
, Text
, 10);
254 SetWindowText(hPerformancePagePhysicalMemoryAvailableEdit
, Text
);
255 _ultot(PhysicalMemorySystemCache
, Text
, 10);
256 SetWindowText(hPerformancePagePhysicalMemorySystemCacheEdit
, Text
);
259 // Update the totals info
261 TotalHandles
= PerfDataGetSystemHandleCount();
262 TotalThreads
= PerfDataGetTotalThreadCount();
263 TotalProcesses
= PerfDataGetProcessCount();
264 _ultot(TotalHandles
, Text
, 10);
265 SetWindowText(hPerformancePageTotalsHandleCountEdit
, Text
);
266 _ultot(TotalThreads
, Text
, 10);
267 SetWindowText(hPerformancePageTotalsThreadCountEdit
, Text
);
268 _ultot(TotalProcesses
, Text
, 10);
269 SetWindowText(hPerformancePageTotalsProcessCountEdit
, Text
);
274 InvalidateRect(hPerformancePageCpuUsageGraph
, NULL
, FALSE
);
275 InvalidateRect(hPerformancePageMemUsageGraph
, NULL
, FALSE
);
276 InvalidateRect(hPerformancePageMemUsageHistoryGraph
, NULL
, FALSE
);
281 void PerformancePage_OnViewShowKernelTimes(void)
286 hMenu
= GetMenu(hMainWnd
);
287 hViewMenu
= GetSubMenu(hMenu
, 2);
289 // Check or uncheck the show 16-bit tasks menu item
290 if (GetMenuState(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
) & MF_CHECKED
)
292 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_UNCHECKED
);
293 TaskManagerSettings
.ShowKernelTimes
= FALSE
;
297 CheckMenuItem(hViewMenu
, ID_VIEW_SHOWKERNELTIMES
, MF_BYCOMMAND
|MF_CHECKED
);
298 TaskManagerSettings
.ShowKernelTimes
= TRUE
;
301 RefreshPerformancePage();
304 void PerformancePage_OnViewCPUHistoryOneGraphAll(void)
308 HMENU hCPUHistoryMenu
;
310 hMenu
= GetMenu(hMainWnd
);
311 hViewMenu
= GetSubMenu(hMenu
, 2);
312 hCPUHistoryMenu
= GetSubMenu(hViewMenu
, 3);
314 TaskManagerSettings
.CPUHistory_OneGraphPerCPU
= FALSE
;
315 CheckMenuRadioItem(hCPUHistoryMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, MF_BYCOMMAND
);
318 void PerformancePage_OnViewCPUHistoryOneGraphPerCPU(void)
322 HMENU hCPUHistoryMenu
;
324 hMenu
= GetMenu(hMainWnd
);
325 hViewMenu
= GetSubMenu(hMenu
, 2);
326 hCPUHistoryMenu
= GetSubMenu(hViewMenu
, 3);
328 TaskManagerSettings
.CPUHistory_OneGraphPerCPU
= TRUE
;
329 CheckMenuRadioItem(hCPUHistoryMenu
, ID_VIEW_CPUHISTORY_ONEGRAPHALL
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, ID_VIEW_CPUHISTORY_ONEGRAPHPERCPU
, MF_BYCOMMAND
);