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.
23 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
36 PROCNTQSI NtQuerySystemInformation
= NULL
;
37 PROCGGR pGetGuiResources
= NULL
;
38 PROCGPIC pGetProcessIoCounters
= NULL
;
39 CRITICAL_SECTION PerfDataCriticalSection
;
40 PPERFDATA pPerfDataOld
= NULL
; // Older perf data (saved to establish delta values)
41 PPERFDATA pPerfData
= NULL
; // Most recent copy of perf data
42 ULONG ProcessCountOld
= 0;
43 ULONG ProcessCount
= 0;
47 LARGE_INTEGER liOldIdleTime
= {{0,0}};
48 double OldKernelTime
= 0;
49 LARGE_INTEGER liOldSystemTime
= {{0,0}};
50 SYSTEM_PERFORMANCE_INFORMATION SystemPerfInfo
;
51 SYSTEM_BASIC_INFORMATION SystemBasicInfo
;
52 SYSTEM_CACHE_INFORMATION SystemCacheInfo
;
53 SYSTEM_HANDLE_INFORMATION SystemHandleInfo
;
54 PSYSTEM_PROCESSORTIME_INFO SystemProcessorTimeInfo
= NULL
;
56 BOOL
PerfDataInitialize(void)
60 NtQuerySystemInformation
= (PROCNTQSI
)GetProcAddress(GetModuleHandle(_T("ntdll.dll")), "NtQuerySystemInformation");
61 pGetGuiResources
= (PROCGGR
)GetProcAddress(GetModuleHandle(_T("user32.dll")), "GetGuiResources");
62 pGetProcessIoCounters
= (PROCGPIC
)GetProcAddress(GetModuleHandle(_T("kernel32.dll")), "GetProcessIoCounters");
64 InitializeCriticalSection(&PerfDataCriticalSection
);
66 if (!NtQuerySystemInformation
)
70 // Get number of processors in the system
72 status
= NtQuerySystemInformation(SystemBasicInformation
, &SystemBasicInfo
, sizeof(SystemBasicInfo
), NULL
);
73 if (status
!= NO_ERROR
)
79 void PerfDataUninitialize(void)
81 NtQuerySystemInformation
= NULL
;
83 DeleteCriticalSection(&PerfDataCriticalSection
);
86 void PerfDataRefresh(void)
92 PSYSTEM_PROCESS_INFORMATION pSPI
;
97 TCHAR szTemp
[MAX_PATH
];
99 SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo
;
100 SYSTEM_TIME_INFORMATION SysTimeInfo
;
101 SYSTEM_CACHE_INFORMATION SysCacheInfo
;
102 LPBYTE SysHandleInfoData
;
103 PSYSTEM_PROCESSORTIME_INFO SysProcessorTimeInfo
;
104 double CurrentKernelTime
;
107 if (!NtQuerySystemInformation
)
110 // Get new system time
111 status
= NtQuerySystemInformation(SystemTimeInformation
, &SysTimeInfo
, sizeof(SysTimeInfo
), 0);
112 if (status
!= NO_ERROR
)
115 // Get new CPU's idle time
116 status
= NtQuerySystemInformation(SystemPerformanceInformation
, &SysPerfInfo
, sizeof(SysPerfInfo
), NULL
);
117 if (status
!= NO_ERROR
)
120 // Get system cache information
121 status
= NtQuerySystemInformation(SystemCacheInformation
, &SysCacheInfo
, sizeof(SysCacheInfo
), NULL
);
122 if (status
!= NO_ERROR
)
125 // Get processor time information
126 //SysProcessorTimeInfo = new SYSTEM_PROCESSORTIME_INFO[SystemBasicInfo.bKeNumberProcessors];
127 SysProcessorTimeInfo
= (PSYSTEM_PROCESSORTIME_INFO
)malloc(sizeof(SYSTEM_PROCESSORTIME_INFO
) * SystemBasicInfo
.bKeNumberProcessors
);
128 status
= NtQuerySystemInformation(SystemProcessorTimeInformation
, SysProcessorTimeInfo
, sizeof(SYSTEM_PROCESSORTIME_INFO
) * SystemBasicInfo
.bKeNumberProcessors
, &ulSize
);
129 if (status
!= NO_ERROR
)
132 // Get handle information
133 // We don't know how much data there is so just keep
134 // increasing the buffer size until the call succeeds
138 BufferSize
+= 0x10000;
139 //SysHandleInfoData = new BYTE[BufferSize];
140 SysHandleInfoData
= (LPBYTE
)malloc(BufferSize
);
142 status
= NtQuerySystemInformation(SystemHandleInformation
, SysHandleInfoData
, BufferSize
, &ulSize
);
144 if (status
== 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/) {
145 //delete[] SysHandleInfoData;
146 free(SysHandleInfoData
);
149 } while (status
== 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/);
151 // Get process information
152 // We don't know how much data there is so just keep
153 // increasing the buffer size until the call succeeds
157 BufferSize
+= 0x10000;
158 //pBuffer = new BYTE[BufferSize];
159 pBuffer
= (LPBYTE
)malloc(BufferSize
);
161 status
= NtQuerySystemInformation(SystemProcessInformation
, pBuffer
, BufferSize
, &ulSize
);
163 if (status
== 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/) {
168 } while (status
== 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/);
170 EnterCriticalSection(&PerfDataCriticalSection
);
173 // Save system performance info
175 memcpy(&SystemPerfInfo
, &SysPerfInfo
, sizeof(SYSTEM_PERFORMANCE_INFORMATION
));
178 // Save system cache info
180 memcpy(&SystemCacheInfo
, &SysCacheInfo
, sizeof(SYSTEM_CACHE_INFORMATION
));
183 // Save system processor time info
185 if (SystemProcessorTimeInfo
) {
186 //delete[] SystemProcessorTimeInfo;
187 free(SystemProcessorTimeInfo
);
189 SystemProcessorTimeInfo
= SysProcessorTimeInfo
;
192 // Save system handle info
194 memcpy(&SystemHandleInfo
, SysHandleInfoData
, sizeof(SYSTEM_HANDLE_INFORMATION
));
195 //delete[] SysHandleInfoData;
196 free(SysHandleInfoData
);
198 for (CurrentKernelTime
=0, Idx
=0; Idx
<SystemBasicInfo
.bKeNumberProcessors
; Idx
++) {
199 CurrentKernelTime
+= Li2Double(SystemProcessorTimeInfo
[Idx
].KernelTime
);
200 CurrentKernelTime
+= Li2Double(SystemProcessorTimeInfo
[Idx
].DpcTime
);
201 CurrentKernelTime
+= Li2Double(SystemProcessorTimeInfo
[Idx
].InterruptTime
);
204 // If it's a first call - skip idle time calcs
205 if (liOldIdleTime
.QuadPart
!= 0) {
206 // CurrentValue = NewValue - OldValue
207 dbIdleTime
= Li2Double(SysPerfInfo
.liIdleTime
) - Li2Double(liOldIdleTime
);
208 dbKernelTime
= CurrentKernelTime
- OldKernelTime
;
209 dbSystemTime
= Li2Double(SysTimeInfo
.liKeSystemTime
) - Li2Double(liOldSystemTime
);
211 // CurrentCpuIdle = IdleTime / SystemTime
212 dbIdleTime
= dbIdleTime
/ dbSystemTime
;
213 dbKernelTime
= dbKernelTime
/ dbSystemTime
;
215 // CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) / NumberOfProcessors
216 dbIdleTime
= 100.0 - dbIdleTime
* 100.0 / (double)SystemBasicInfo
.bKeNumberProcessors
;// + 0.5;
217 dbKernelTime
= 100.0 - dbKernelTime
* 100.0 / (double)SystemBasicInfo
.bKeNumberProcessors
;// + 0.5;
220 // Store new CPU's idle and system time
221 liOldIdleTime
= SysPerfInfo
.liIdleTime
;
222 liOldSystemTime
= SysTimeInfo
.liKeSystemTime
;
223 OldKernelTime
= CurrentKernelTime
;
225 // Determine the process count
226 // We loop through the data we got from NtQuerySystemInformation
227 // and count how many structures there are (until RelativeOffset is 0)
228 ProcessCountOld
= ProcessCount
;
230 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)pBuffer
;
233 if (pSPI
->RelativeOffset
== 0)
235 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)((LPBYTE
)pSPI
+ pSPI
->RelativeOffset
);
238 // Now alloc a new PERFDATA array and fill in the data
240 //delete[] pPerfDataOld;
243 pPerfDataOld
= pPerfData
;
244 //pPerfData = new PERFDATA[ProcessCount];
245 pPerfData
= (PPERFDATA
)malloc(sizeof(PERFDATA
) * ProcessCount
);
246 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)pBuffer
;
247 for (Idx
=0; Idx
<ProcessCount
; Idx
++) {
248 // Get the old perf data for this process (if any)
249 // so that we can establish delta values
251 for (Idx2
=0; Idx2
<ProcessCountOld
; Idx2
++) {
252 if (pPerfDataOld
[Idx2
].ProcessId
== pSPI
->ProcessId
) {
253 pPDOld
= &pPerfDataOld
[Idx2
];
258 // Clear out process perf data structure
259 memset(&pPerfData
[Idx
], 0, sizeof(PERFDATA
));
261 if (pSPI
->Name
.Buffer
)
262 wcscpy(pPerfData
[Idx
].ImageName
, pSPI
->Name
.Buffer
);
264 wcscpy(pPerfData
[Idx
].ImageName
, L
"System Idle Process");
266 pPerfData
[Idx
].ProcessId
= pSPI
->ProcessId
;
269 double CurTime
= Li2Double(pSPI
->KernelTime
) + Li2Double(pSPI
->UserTime
);
270 double OldTime
= Li2Double(pPDOld
->KernelTime
) + Li2Double(pPDOld
->UserTime
);
271 double CpuTime
= (CurTime
- OldTime
) / dbSystemTime
;
272 CpuTime
= CpuTime
* 100.0 / (double)SystemBasicInfo
.bKeNumberProcessors
;// + 0.5;
273 pPerfData
[Idx
].CPUUsage
= (ULONG
)CpuTime
;
275 pPerfData
[Idx
].CPUTime
.QuadPart
= pSPI
->UserTime
.QuadPart
+ pSPI
->KernelTime
.QuadPart
;
276 pPerfData
[Idx
].WorkingSetSizeBytes
= pSPI
->TotalWorkingSetSizeBytes
;
277 pPerfData
[Idx
].PeakWorkingSetSizeBytes
= pSPI
->PeakWorkingSetSizeBytes
;
279 pPerfData
[Idx
].WorkingSetSizeDelta
= labs((LONG
)pSPI
->TotalWorkingSetSizeBytes
- (LONG
)pPDOld
->WorkingSetSizeBytes
);
281 pPerfData
[Idx
].WorkingSetSizeDelta
= 0;
282 pPerfData
[Idx
].PageFaultCount
= pSPI
->PageFaultCount
;
284 pPerfData
[Idx
].PageFaultCountDelta
= labs((LONG
)pSPI
->PageFaultCount
- (LONG
)pPDOld
->PageFaultCount
);
286 pPerfData
[Idx
].PageFaultCountDelta
= 0;
287 pPerfData
[Idx
].VirtualMemorySizeBytes
= pSPI
->TotalVirtualSizeBytes
;
288 pPerfData
[Idx
].PagedPoolUsagePages
= pSPI
->TotalPagedPoolUsagePages
;
289 pPerfData
[Idx
].NonPagedPoolUsagePages
= pSPI
->TotalNonPagedPoolUsagePages
;
290 pPerfData
[Idx
].BasePriority
= pSPI
->BasePriority
;
291 pPerfData
[Idx
].HandleCount
= pSPI
->HandleCount
;
292 pPerfData
[Idx
].ThreadCount
= pSPI
->ThreadCount
;
293 pPerfData
[Idx
].SessionId
= pSPI
->SessionId
;
295 hProcess
= OpenProcess(PROCESS_QUERY_INFORMATION
, FALSE
, pSPI
->ProcessId
);
297 if (OpenProcessToken(hProcess
, TOKEN_QUERY
|TOKEN_DUPLICATE
|TOKEN_IMPERSONATE
, &hProcessToken
)) {
298 ImpersonateLoggedOnUser(hProcessToken
);
299 memset(szTemp
, 0, sizeof(TCHAR
[MAX_PATH
]));
301 GetUserName(szTemp
, &dwSize
);
303 MultiByteToWideChar(CP_ACP
, MB_PRECOMPOSED
, szTemp
, -1, pPerfData
[Idx
].UserName
, MAX_PATH
);
305 int MultiByteToWideChar(
306 UINT CodePage, // code page
307 DWORD dwFlags, // character-type options
308 LPCSTR lpMultiByteStr, // string to map
309 int cbMultiByte, // number of bytes in string
310 LPWSTR lpWideCharStr, // wide-character buffer
311 int cchWideChar // size of buffer
316 CloseHandle(hProcessToken
);
318 if (pGetGuiResources
) {
319 pPerfData
[Idx
].USERObjectCount
= pGetGuiResources(hProcess
, GR_USEROBJECTS
);
320 pPerfData
[Idx
].GDIObjectCount
= pGetGuiResources(hProcess
, GR_GDIOBJECTS
);
322 if (pGetProcessIoCounters
)
323 pGetProcessIoCounters(hProcess
, &pPerfData
[Idx
].IOCounters
);
324 CloseHandle(hProcess
);
326 pPerfData
[Idx
].UserTime
.QuadPart
= pSPI
->UserTime
.QuadPart
;
327 pPerfData
[Idx
].KernelTime
.QuadPart
= pSPI
->KernelTime
.QuadPart
;
328 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)((LPBYTE
)pSPI
+ pSPI
->RelativeOffset
);
332 LeaveCriticalSection(&PerfDataCriticalSection
);
335 ULONG
PerfDataGetProcessCount(void)
340 ULONG
PerfDataGetProcessorUsage(void)
342 return (ULONG
)dbIdleTime
;
345 ULONG
PerfDataGetProcessorSystemUsage(void)
347 return (ULONG
)dbKernelTime
;
350 BOOL
PerfDataGetImageName(ULONG Index
, LPTSTR lpImageName
, int nMaxCount
)
354 EnterCriticalSection(&PerfDataCriticalSection
);
356 if (Index
< ProcessCount
) {
358 wcsncpy(lpImageName
, pPerfData
[Index
].ImageName
, nMaxCount
);
360 WideCharToMultiByte(CP_ACP
, 0, pPerfData
[Index
].ImageName
, -1, lpImageName
, nMaxCount
, NULL
, NULL
);
367 LeaveCriticalSection(&PerfDataCriticalSection
);
371 ULONG
PerfDataGetProcessId(ULONG Index
)
375 EnterCriticalSection(&PerfDataCriticalSection
);
377 if (Index
< ProcessCount
)
378 ProcessId
= pPerfData
[Index
].ProcessId
;
382 LeaveCriticalSection(&PerfDataCriticalSection
);
387 BOOL
PerfDataGetUserName(ULONG Index
, LPTSTR lpUserName
, int nMaxCount
)
391 EnterCriticalSection(&PerfDataCriticalSection
);
393 if (Index
< ProcessCount
) {
395 wcsncpy(lpUserName
, pPerfData
[Index
].UserName
, nMaxCount
);
397 WideCharToMultiByte(CP_ACP
, 0, pPerfData
[Index
].UserName
, -1, lpUserName
, nMaxCount
, NULL
, NULL
);
405 LeaveCriticalSection(&PerfDataCriticalSection
);
410 ULONG
PerfDataGetSessionId(ULONG Index
)
414 EnterCriticalSection(&PerfDataCriticalSection
);
416 if (Index
< ProcessCount
)
417 SessionId
= pPerfData
[Index
].SessionId
;
421 LeaveCriticalSection(&PerfDataCriticalSection
);
426 ULONG
PerfDataGetCPUUsage(ULONG Index
)
430 EnterCriticalSection(&PerfDataCriticalSection
);
432 if (Index
< ProcessCount
)
433 CpuUsage
= pPerfData
[Index
].CPUUsage
;
437 LeaveCriticalSection(&PerfDataCriticalSection
);
442 TIME
PerfDataGetCPUTime(ULONG Index
)
444 TIME CpuTime
= {{0,0}};
446 EnterCriticalSection(&PerfDataCriticalSection
);
448 if (Index
< ProcessCount
)
449 CpuTime
= pPerfData
[Index
].CPUTime
;
451 LeaveCriticalSection(&PerfDataCriticalSection
);
456 ULONG
PerfDataGetWorkingSetSizeBytes(ULONG Index
)
458 ULONG WorkingSetSizeBytes
;
460 EnterCriticalSection(&PerfDataCriticalSection
);
462 if (Index
< ProcessCount
)
463 WorkingSetSizeBytes
= pPerfData
[Index
].WorkingSetSizeBytes
;
465 WorkingSetSizeBytes
= 0;
467 LeaveCriticalSection(&PerfDataCriticalSection
);
469 return WorkingSetSizeBytes
;
472 ULONG
PerfDataGetPeakWorkingSetSizeBytes(ULONG Index
)
474 ULONG PeakWorkingSetSizeBytes
;
476 EnterCriticalSection(&PerfDataCriticalSection
);
478 if (Index
< ProcessCount
)
479 PeakWorkingSetSizeBytes
= pPerfData
[Index
].PeakWorkingSetSizeBytes
;
481 PeakWorkingSetSizeBytes
= 0;
483 LeaveCriticalSection(&PerfDataCriticalSection
);
485 return PeakWorkingSetSizeBytes
;
488 ULONG
PerfDataGetWorkingSetSizeDelta(ULONG Index
)
490 ULONG WorkingSetSizeDelta
;
492 EnterCriticalSection(&PerfDataCriticalSection
);
494 if (Index
< ProcessCount
)
495 WorkingSetSizeDelta
= pPerfData
[Index
].WorkingSetSizeDelta
;
497 WorkingSetSizeDelta
= 0;
499 LeaveCriticalSection(&PerfDataCriticalSection
);
501 return WorkingSetSizeDelta
;
504 ULONG
PerfDataGetPageFaultCount(ULONG Index
)
506 ULONG PageFaultCount
;
508 EnterCriticalSection(&PerfDataCriticalSection
);
510 if (Index
< ProcessCount
)
511 PageFaultCount
= pPerfData
[Index
].PageFaultCount
;
515 LeaveCriticalSection(&PerfDataCriticalSection
);
517 return PageFaultCount
;
520 ULONG
PerfDataGetPageFaultCountDelta(ULONG Index
)
522 ULONG PageFaultCountDelta
;
524 EnterCriticalSection(&PerfDataCriticalSection
);
526 if (Index
< ProcessCount
)
527 PageFaultCountDelta
= pPerfData
[Index
].PageFaultCountDelta
;
529 PageFaultCountDelta
= 0;
531 LeaveCriticalSection(&PerfDataCriticalSection
);
533 return PageFaultCountDelta
;
536 ULONG
PerfDataGetVirtualMemorySizeBytes(ULONG Index
)
538 ULONG VirtualMemorySizeBytes
;
540 EnterCriticalSection(&PerfDataCriticalSection
);
542 if (Index
< ProcessCount
)
543 VirtualMemorySizeBytes
= pPerfData
[Index
].VirtualMemorySizeBytes
;
545 VirtualMemorySizeBytes
= 0;
547 LeaveCriticalSection(&PerfDataCriticalSection
);
549 return VirtualMemorySizeBytes
;
552 ULONG
PerfDataGetPagedPoolUsagePages(ULONG Index
)
554 ULONG PagedPoolUsagePages
;
556 EnterCriticalSection(&PerfDataCriticalSection
);
558 if (Index
< ProcessCount
)
559 PagedPoolUsagePages
= pPerfData
[Index
].PagedPoolUsagePages
;
561 PagedPoolUsagePages
= 0;
563 LeaveCriticalSection(&PerfDataCriticalSection
);
565 return PagedPoolUsagePages
;
568 ULONG
PerfDataGetNonPagedPoolUsagePages(ULONG Index
)
570 ULONG NonPagedPoolUsagePages
;
572 EnterCriticalSection(&PerfDataCriticalSection
);
574 if (Index
< ProcessCount
)
575 NonPagedPoolUsagePages
= pPerfData
[Index
].NonPagedPoolUsagePages
;
577 NonPagedPoolUsagePages
= 0;
579 LeaveCriticalSection(&PerfDataCriticalSection
);
581 return NonPagedPoolUsagePages
;
584 ULONG
PerfDataGetBasePriority(ULONG Index
)
588 EnterCriticalSection(&PerfDataCriticalSection
);
590 if (Index
< ProcessCount
)
591 BasePriority
= pPerfData
[Index
].BasePriority
;
595 LeaveCriticalSection(&PerfDataCriticalSection
);
600 ULONG
PerfDataGetHandleCount(ULONG Index
)
604 EnterCriticalSection(&PerfDataCriticalSection
);
606 if (Index
< ProcessCount
)
607 HandleCount
= pPerfData
[Index
].HandleCount
;
611 LeaveCriticalSection(&PerfDataCriticalSection
);
616 ULONG
PerfDataGetThreadCount(ULONG Index
)
620 EnterCriticalSection(&PerfDataCriticalSection
);
622 if (Index
< ProcessCount
)
623 ThreadCount
= pPerfData
[Index
].ThreadCount
;
627 LeaveCriticalSection(&PerfDataCriticalSection
);
632 ULONG
PerfDataGetUSERObjectCount(ULONG Index
)
634 ULONG USERObjectCount
;
636 EnterCriticalSection(&PerfDataCriticalSection
);
638 if (Index
< ProcessCount
)
639 USERObjectCount
= pPerfData
[Index
].USERObjectCount
;
643 LeaveCriticalSection(&PerfDataCriticalSection
);
645 return USERObjectCount
;
648 ULONG
PerfDataGetGDIObjectCount(ULONG Index
)
650 ULONG GDIObjectCount
;
652 EnterCriticalSection(&PerfDataCriticalSection
);
654 if (Index
< ProcessCount
)
655 GDIObjectCount
= pPerfData
[Index
].GDIObjectCount
;
659 LeaveCriticalSection(&PerfDataCriticalSection
);
661 return GDIObjectCount
;
664 BOOL
PerfDataGetIOCounters(ULONG Index
, PIO_COUNTERS pIoCounters
)
668 EnterCriticalSection(&PerfDataCriticalSection
);
670 if (Index
< ProcessCount
)
672 memcpy(pIoCounters
, &pPerfData
[Index
].IOCounters
, sizeof(IO_COUNTERS
));
678 LeaveCriticalSection(&PerfDataCriticalSection
);
683 ULONG
PerfDataGetCommitChargeTotalK(void)
688 EnterCriticalSection(&PerfDataCriticalSection
);
690 Total
= SystemPerfInfo
.MmTotalCommitedPages
;
691 PageSize
= SystemBasicInfo
.uPageSize
;
693 LeaveCriticalSection(&PerfDataCriticalSection
);
695 Total
= Total
* (PageSize
/ 1024);
700 ULONG
PerfDataGetCommitChargeLimitK(void)
705 EnterCriticalSection(&PerfDataCriticalSection
);
707 Limit
= SystemPerfInfo
.MmTotalCommitLimit
;
708 PageSize
= SystemBasicInfo
.uPageSize
;
710 LeaveCriticalSection(&PerfDataCriticalSection
);
712 Limit
= Limit
* (PageSize
/ 1024);
717 ULONG
PerfDataGetCommitChargePeakK(void)
722 EnterCriticalSection(&PerfDataCriticalSection
);
724 Peak
= SystemPerfInfo
.MmPeakLimit
;
725 PageSize
= SystemBasicInfo
.uPageSize
;
727 LeaveCriticalSection(&PerfDataCriticalSection
);
729 Peak
= Peak
* (PageSize
/ 1024);
734 ULONG
PerfDataGetKernelMemoryTotalK(void)
741 EnterCriticalSection(&PerfDataCriticalSection
);
743 Paged
= SystemPerfInfo
.PoolPagedBytes
;
744 NonPaged
= SystemPerfInfo
.PoolNonPagedBytes
;
745 PageSize
= SystemBasicInfo
.uPageSize
;
747 LeaveCriticalSection(&PerfDataCriticalSection
);
749 Paged
= Paged
* (PageSize
/ 1024);
750 NonPaged
= NonPaged
* (PageSize
/ 1024);
752 Total
= Paged
+ NonPaged
;
757 ULONG
PerfDataGetKernelMemoryPagedK(void)
762 EnterCriticalSection(&PerfDataCriticalSection
);
764 Paged
= SystemPerfInfo
.PoolPagedBytes
;
765 PageSize
= SystemBasicInfo
.uPageSize
;
767 LeaveCriticalSection(&PerfDataCriticalSection
);
769 Paged
= Paged
* (PageSize
/ 1024);
774 ULONG
PerfDataGetKernelMemoryNonPagedK(void)
779 EnterCriticalSection(&PerfDataCriticalSection
);
781 NonPaged
= SystemPerfInfo
.PoolNonPagedBytes
;
782 PageSize
= SystemBasicInfo
.uPageSize
;
784 LeaveCriticalSection(&PerfDataCriticalSection
);
786 NonPaged
= NonPaged
* (PageSize
/ 1024);
791 ULONG
PerfDataGetPhysicalMemoryTotalK(void)
796 EnterCriticalSection(&PerfDataCriticalSection
);
798 Total
= SystemBasicInfo
.uMmNumberOfPhysicalPages
;
799 PageSize
= SystemBasicInfo
.uPageSize
;
801 LeaveCriticalSection(&PerfDataCriticalSection
);
803 Total
= Total
* (PageSize
/ 1024);
808 ULONG
PerfDataGetPhysicalMemoryAvailableK(void)
813 EnterCriticalSection(&PerfDataCriticalSection
);
815 Available
= SystemPerfInfo
.MmAvailablePages
;
816 PageSize
= SystemBasicInfo
.uPageSize
;
818 LeaveCriticalSection(&PerfDataCriticalSection
);
820 Available
= Available
* (PageSize
/ 1024);
825 ULONG
PerfDataGetPhysicalMemorySystemCacheK(void)
830 EnterCriticalSection(&PerfDataCriticalSection
);
832 SystemCache
= SystemCacheInfo
.CurrentSize
;
833 PageSize
= SystemBasicInfo
.uPageSize
;
835 LeaveCriticalSection(&PerfDataCriticalSection
);
837 //SystemCache = SystemCache * (PageSize / 1024);
838 SystemCache
= SystemCache
/ 1024;
843 ULONG
PerfDataGetSystemHandleCount(void)
847 EnterCriticalSection(&PerfDataCriticalSection
);
849 HandleCount
= SystemHandleInfo
.Count
;
851 LeaveCriticalSection(&PerfDataCriticalSection
);
856 ULONG
PerfDataGetTotalThreadCount(void)
858 ULONG ThreadCount
= 0;
861 EnterCriticalSection(&PerfDataCriticalSection
);
863 for (i
=0; i
<ProcessCount
; i
++)
865 ThreadCount
+= pPerfData
[i
].ThreadCount
;
868 LeaveCriticalSection(&PerfDataCriticalSection
);