6 * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library 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 GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 static PROCNTQSI pNtQuerySystemInformation
= NULL
;
34 static PROCGGR pGetGuiResources
= NULL
;
35 static PROCGPIC pGetProcessIoCounters
= NULL
;
36 static PROCISW64 pIsWow64Process
= NULL
;
37 static CRITICAL_SECTION PerfDataCriticalSection
;
38 static PPERFDATA pPerfDataOld
= NULL
; /* Older perf data (saved to establish delta values) */
39 static PPERFDATA pPerfData
= NULL
; /* Most recent copy of perf data */
40 static ULONG ProcessCountOld
= 0;
41 static ULONG ProcessCount
= 0;
42 static double dbIdleTime
;
43 static double dbKernelTime
;
44 static double dbSystemTime
;
45 static LARGE_INTEGER liOldIdleTime
= {{0,0}};
46 static double OldKernelTime
= 0;
47 static LARGE_INTEGER liOldSystemTime
= {{0,0}};
48 static SYSTEM_PERFORMANCE_INFORMATION SystemPerfInfo
;
49 static SYSTEM_BASIC_INFORMATION SystemBasicInfo
;
50 static SYSTEM_CACHE_INFORMATION SystemCacheInfo
;
51 static SYSTEM_HANDLE_INFORMATION SystemHandleInfo
;
52 static PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION SystemProcessorTimeInfo
= NULL
;
54 BOOL
PerfDataInitialize(void)
57 static const WCHAR wszNtdll
[] = {'n','t','d','l','l','.','d','l','l',0};
58 static const WCHAR wszUser32
[] = {'u','s','e','r','3','2','.','d','l','l',0};
59 static const WCHAR wszKernel32
[] = {'k','e','r','n','e','l','3','2','.','d','l','l',0};
61 pNtQuerySystemInformation
= (PROCNTQSI
)GetProcAddress(GetModuleHandleW(wszNtdll
), "NtQuerySystemInformation");
62 pGetGuiResources
= (PROCGGR
)GetProcAddress(GetModuleHandleW(wszUser32
), "GetGuiResources");
63 pGetProcessIoCounters
= (PROCGPIC
)GetProcAddress(GetModuleHandleW(wszKernel32
), "GetProcessIoCounters");
64 pIsWow64Process
= (PROCISW64
)GetProcAddress(GetModuleHandleW(wszKernel32
), "IsWow64Process");
66 InitializeCriticalSection(&PerfDataCriticalSection
);
68 if (!pNtQuerySystemInformation
)
72 * Get number of processors in the system
74 status
= pNtQuerySystemInformation(SystemBasicInformation
, &SystemBasicInfo
, sizeof(SystemBasicInfo
), NULL
);
75 if (status
!= NO_ERROR
)
81 void PerfDataRefresh(void)
87 PSYSTEM_PROCESS_INFORMATION pSPI
;
92 WCHAR wszTemp
[MAX_PATH
];
94 SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo
;
95 SYSTEM_TIMEOFDAY_INFORMATION SysTimeInfo
;
96 SYSTEM_CACHE_INFORMATION SysCacheInfo
;
97 LPBYTE SysHandleInfoData
;
98 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
*SysProcessorTimeInfo
;
99 double CurrentKernelTime
;
102 /* Get new system time */
103 status
= pNtQuerySystemInformation(SystemTimeOfDayInformation
, &SysTimeInfo
, sizeof(SysTimeInfo
), 0);
104 if (status
!= NO_ERROR
)
107 /* Get new CPU's idle time */
108 status
= pNtQuerySystemInformation(SystemPerformanceInformation
, &SysPerfInfo
, sizeof(SysPerfInfo
), NULL
);
109 if (status
!= NO_ERROR
)
112 /* Get system cache information */
113 status
= pNtQuerySystemInformation(SystemCacheInformation
, &SysCacheInfo
, sizeof(SysCacheInfo
), NULL
);
114 if (status
!= NO_ERROR
)
117 /* Get processor time information */
118 SysProcessorTimeInfo
= HeapAlloc(GetProcessHeap(), 0,
119 sizeof(*SysProcessorTimeInfo
) * SystemBasicInfo
.NumberOfProcessors
);
120 status
= pNtQuerySystemInformation(SystemProcessorPerformanceInformation
, SysProcessorTimeInfo
, sizeof(*SysProcessorTimeInfo
) * SystemBasicInfo
.NumberOfProcessors
, &ulSize
);
121 if (status
!= NO_ERROR
) {
122 HeapFree(GetProcessHeap(), 0, SysProcessorTimeInfo
);
126 /* Get handle information
127 * We don't know how much data there is so just keep
128 * increasing the buffer size until the call succeeds
133 BufferSize
+= 0x10000;
134 SysHandleInfoData
= HeapAlloc(GetProcessHeap(), 0, BufferSize
);
136 status
= pNtQuerySystemInformation(SystemHandleInformation
, SysHandleInfoData
, BufferSize
, &ulSize
);
138 if (status
== 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/) {
139 HeapFree(GetProcessHeap(), 0, SysHandleInfoData
);
142 } while (status
== 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/);
144 /* Get process information
145 * We don't know how much data there is so just keep
146 * increasing the buffer size until the call succeeds
151 BufferSize
+= 0x10000;
152 pBuffer
= HeapAlloc(GetProcessHeap(), 0, BufferSize
);
154 status
= pNtQuerySystemInformation(SystemProcessInformation
, pBuffer
, BufferSize
, &ulSize
);
156 if (status
== 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/) {
157 HeapFree(GetProcessHeap(), 0, pBuffer
);
160 } while (status
== 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/);
162 EnterCriticalSection(&PerfDataCriticalSection
);
165 * Save system performance info
167 memcpy(&SystemPerfInfo
, &SysPerfInfo
, sizeof(SYSTEM_PERFORMANCE_INFORMATION
));
170 * Save system cache info
172 memcpy(&SystemCacheInfo
, &SysCacheInfo
, sizeof(SYSTEM_CACHE_INFORMATION
));
175 * Save system processor time info
177 HeapFree(GetProcessHeap(), 0, SystemProcessorTimeInfo
);
178 SystemProcessorTimeInfo
= SysProcessorTimeInfo
;
181 * Save system handle info
183 memcpy(&SystemHandleInfo
, SysHandleInfoData
, sizeof(SYSTEM_HANDLE_INFORMATION
));
184 HeapFree(GetProcessHeap(), 0, SysHandleInfoData
);
186 for (CurrentKernelTime
=0, Idx
=0; Idx
<SystemBasicInfo
.NumberOfProcessors
; Idx
++) {
187 CurrentKernelTime
+= Li2Double(SystemProcessorTimeInfo
[Idx
].KernelTime
);
188 CurrentKernelTime
+= Li2Double(SystemProcessorTimeInfo
[Idx
].Reserved1
[0]);
189 CurrentKernelTime
+= Li2Double(SystemProcessorTimeInfo
[Idx
].Reserved1
[1]);
192 /* If it's a first call - skip idle time calcs */
193 if (liOldIdleTime
.QuadPart
!= 0) {
194 /* CurrentValue = NewValue - OldValue */
195 dbIdleTime
= Li2Double(SysPerfInfo
.IdleTime
) - Li2Double(liOldIdleTime
);
196 dbKernelTime
= CurrentKernelTime
- OldKernelTime
;
197 dbSystemTime
= Li2Double(SysTimeInfo
.liKeSystemTime
) - Li2Double(liOldSystemTime
);
199 /* CurrentCpuIdle = IdleTime / SystemTime */
200 dbIdleTime
= dbIdleTime
/ dbSystemTime
;
201 dbKernelTime
= dbKernelTime
/ dbSystemTime
;
203 /* CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) / NumberOfProcessors */
204 dbIdleTime
= 100.0 - dbIdleTime
* 100.0 / (double)SystemBasicInfo
.NumberOfProcessors
; /* + 0.5; */
205 dbKernelTime
= 100.0 - dbKernelTime
* 100.0 / (double)SystemBasicInfo
.NumberOfProcessors
; /* + 0.5; */
208 /* Store new CPU's idle and system time */
209 liOldIdleTime
= SysPerfInfo
.IdleTime
;
210 liOldSystemTime
= SysTimeInfo
.liKeSystemTime
;
211 OldKernelTime
= CurrentKernelTime
;
213 /* Determine the process count
214 * We loop through the data we got from NtQuerySystemInformation
215 * and count how many structures there are (until RelativeOffset is 0)
217 ProcessCountOld
= ProcessCount
;
219 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)pBuffer
;
222 if (pSPI
->NextEntryOffset
== 0)
224 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)((LPBYTE
)pSPI
+ pSPI
->NextEntryOffset
);
227 /* Now alloc a new PERFDATA array and fill in the data */
228 HeapFree(GetProcessHeap(), 0, pPerfDataOld
);
229 pPerfDataOld
= pPerfData
;
230 pPerfData
= HeapAlloc(GetProcessHeap(), 0, sizeof(PERFDATA
) * ProcessCount
);
231 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)pBuffer
;
232 for (Idx
=0; Idx
<ProcessCount
; Idx
++) {
233 /* Get the old perf data for this process (if any) */
234 /* so that we can establish delta values */
236 for (Idx2
=0; Idx2
<ProcessCountOld
; Idx2
++) {
237 if (pPerfDataOld
[Idx2
].ProcessId
== (DWORD_PTR
)pSPI
->UniqueProcessId
) {
238 pPDOld
= &pPerfDataOld
[Idx2
];
243 /* Clear out process perf data structure */
244 memset(&pPerfData
[Idx
], 0, sizeof(PERFDATA
));
246 if (pSPI
->ProcessName
.Buffer
)
247 lstrcpyW(pPerfData
[Idx
].ImageName
, pSPI
->ProcessName
.Buffer
);
251 LoadStringW(hInst
, IDS_SYSTEM_IDLE_PROCESS
, idleW
, sizeof(idleW
)/sizeof(WCHAR
));
252 lstrcpyW(pPerfData
[Idx
].ImageName
, idleW
);
255 pPerfData
[Idx
].ProcessId
= (DWORD_PTR
)pSPI
->UniqueProcessId
;
258 double CurTime
= Li2Double(pSPI
->KernelTime
) + Li2Double(pSPI
->UserTime
);
259 double OldTime
= Li2Double(pPDOld
->KernelTime
) + Li2Double(pPDOld
->UserTime
);
260 double CpuTime
= (CurTime
- OldTime
) / dbSystemTime
;
261 CpuTime
= CpuTime
* 100.0 / (double)SystemBasicInfo
.NumberOfProcessors
; /* + 0.5; */
262 pPerfData
[Idx
].CPUUsage
= (ULONG
)CpuTime
;
265 pPerfData
[Idx
].CPUTime
.QuadPart
= pSPI
->UserTime
.QuadPart
+ pSPI
->KernelTime
.QuadPart
;
266 pPerfData
[Idx
].vmCounters
.WorkingSetSize
= pSPI
->vmCounters
.WorkingSetSize
;
267 pPerfData
[Idx
].vmCounters
.PeakWorkingSetSize
= pSPI
->vmCounters
.PeakWorkingSetSize
;
269 pPerfData
[Idx
].WorkingSetSizeDelta
= labs(pSPI
->vmCounters
.WorkingSetSize
- pPDOld
->vmCounters
.WorkingSetSize
);
271 pPerfData
[Idx
].WorkingSetSizeDelta
= 0;
272 pPerfData
[Idx
].vmCounters
.PageFaultCount
= pSPI
->vmCounters
.PageFaultCount
;
274 pPerfData
[Idx
].PageFaultCountDelta
= labs(pSPI
->vmCounters
.PageFaultCount
- pPDOld
->vmCounters
.PageFaultCount
);
276 pPerfData
[Idx
].PageFaultCountDelta
= 0;
277 pPerfData
[Idx
].vmCounters
.VirtualSize
= pSPI
->vmCounters
.VirtualSize
;
278 pPerfData
[Idx
].vmCounters
.QuotaPagedPoolUsage
= pSPI
->vmCounters
.QuotaPagedPoolUsage
;
279 pPerfData
[Idx
].vmCounters
.QuotaNonPagedPoolUsage
= pSPI
->vmCounters
.QuotaNonPagedPoolUsage
;
280 pPerfData
[Idx
].BasePriority
= pSPI
->dwBasePriority
;
281 pPerfData
[Idx
].HandleCount
= pSPI
->HandleCount
;
282 pPerfData
[Idx
].ThreadCount
= pSPI
->dwThreadCount
;
283 pPerfData
[Idx
].SessionId
= pSPI
->SessionId
;
285 hProcess
= OpenProcess(PROCESS_QUERY_INFORMATION
, FALSE
, (DWORD_PTR
)pSPI
->UniqueProcessId
);
287 if (OpenProcessToken(hProcess
, TOKEN_QUERY
|TOKEN_DUPLICATE
|TOKEN_IMPERSONATE
, &hProcessToken
)) {
288 ImpersonateLoggedOnUser(hProcessToken
);
289 memset(wszTemp
, 0, sizeof(wszTemp
));
291 GetUserNameW(wszTemp
, &dwSize
);
293 CloseHandle(hProcessToken
);
295 if (pGetGuiResources
) {
296 pPerfData
[Idx
].USERObjectCount
= pGetGuiResources(hProcess
, GR_USEROBJECTS
);
297 pPerfData
[Idx
].GDIObjectCount
= pGetGuiResources(hProcess
, GR_GDIOBJECTS
);
299 if (pGetProcessIoCounters
)
300 pGetProcessIoCounters(hProcess
, &pPerfData
[Idx
].IOCounters
);
302 pIsWow64Process(hProcess
, &pPerfData
[Idx
].Wow64Process
);
303 CloseHandle(hProcess
);
305 pPerfData
[Idx
].UserTime
.QuadPart
= pSPI
->UserTime
.QuadPart
;
306 pPerfData
[Idx
].KernelTime
.QuadPart
= pSPI
->KernelTime
.QuadPart
;
307 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)((LPBYTE
)pSPI
+ pSPI
->NextEntryOffset
);
309 HeapFree(GetProcessHeap(), 0, pBuffer
);
310 LeaveCriticalSection(&PerfDataCriticalSection
);
313 ULONG
PerfDataGetProcessCount(void)
318 ULONG
PerfDataGetProcessorUsage(void)
320 if( dbIdleTime
< 0.0 )
322 if( dbIdleTime
> 100.0 )
324 return (ULONG
)dbIdleTime
;
327 ULONG
PerfDataGetProcessorSystemUsage(void)
329 if( dbKernelTime
< 0.0 )
331 if( dbKernelTime
> 100.0 )
333 return (ULONG
)dbKernelTime
;
336 BOOL
PerfDataGetImageName(ULONG Index
, LPWSTR lpImageName
, int nMaxCount
)
338 static const WCHAR proc32W
[] = {' ','*','3','2',0};
341 EnterCriticalSection(&PerfDataCriticalSection
);
343 if (Index
< ProcessCount
) {
344 wcsncpy(lpImageName
, pPerfData
[Index
].ImageName
, nMaxCount
);
345 if (pPerfData
[Index
].Wow64Process
&&
346 nMaxCount
- lstrlenW(lpImageName
) > 4 /* =lstrlenW(proc32W) */)
347 lstrcatW(lpImageName
, proc32W
);
352 LeaveCriticalSection(&PerfDataCriticalSection
);
356 ULONG
PerfDataGetProcessId(ULONG Index
)
360 EnterCriticalSection(&PerfDataCriticalSection
);
362 if (Index
< ProcessCount
)
363 ProcessId
= pPerfData
[Index
].ProcessId
;
367 LeaveCriticalSection(&PerfDataCriticalSection
);
372 BOOL
PerfDataGetUserName(ULONG Index
, LPWSTR lpUserName
, int nMaxCount
)
376 EnterCriticalSection(&PerfDataCriticalSection
);
378 if (Index
< ProcessCount
) {
379 wcsncpy(lpUserName
, pPerfData
[Index
].UserName
, nMaxCount
);
385 LeaveCriticalSection(&PerfDataCriticalSection
);
390 ULONG
PerfDataGetSessionId(ULONG Index
)
394 EnterCriticalSection(&PerfDataCriticalSection
);
396 if (Index
< ProcessCount
)
397 SessionId
= pPerfData
[Index
].SessionId
;
401 LeaveCriticalSection(&PerfDataCriticalSection
);
406 ULONG
PerfDataGetCPUUsage(ULONG Index
)
410 EnterCriticalSection(&PerfDataCriticalSection
);
412 if (Index
< ProcessCount
)
413 CpuUsage
= pPerfData
[Index
].CPUUsage
;
417 LeaveCriticalSection(&PerfDataCriticalSection
);
422 TIME
PerfDataGetCPUTime(ULONG Index
)
424 TIME CpuTime
= {{0,0}};
426 EnterCriticalSection(&PerfDataCriticalSection
);
428 if (Index
< ProcessCount
)
429 CpuTime
= pPerfData
[Index
].CPUTime
;
431 LeaveCriticalSection(&PerfDataCriticalSection
);
436 ULONG
PerfDataGetWorkingSetSizeBytes(ULONG Index
)
438 ULONG WorkingSetSizeBytes
;
440 EnterCriticalSection(&PerfDataCriticalSection
);
442 if (Index
< ProcessCount
)
443 WorkingSetSizeBytes
= pPerfData
[Index
].vmCounters
.WorkingSetSize
;
445 WorkingSetSizeBytes
= 0;
447 LeaveCriticalSection(&PerfDataCriticalSection
);
449 return WorkingSetSizeBytes
;
452 ULONG
PerfDataGetPeakWorkingSetSizeBytes(ULONG Index
)
454 ULONG PeakWorkingSetSizeBytes
;
456 EnterCriticalSection(&PerfDataCriticalSection
);
458 if (Index
< ProcessCount
)
459 PeakWorkingSetSizeBytes
= pPerfData
[Index
].vmCounters
.PeakWorkingSetSize
;
461 PeakWorkingSetSizeBytes
= 0;
463 LeaveCriticalSection(&PerfDataCriticalSection
);
465 return PeakWorkingSetSizeBytes
;
468 ULONG
PerfDataGetWorkingSetSizeDelta(ULONG Index
)
470 ULONG WorkingSetSizeDelta
;
472 EnterCriticalSection(&PerfDataCriticalSection
);
474 if (Index
< ProcessCount
)
475 WorkingSetSizeDelta
= pPerfData
[Index
].WorkingSetSizeDelta
;
477 WorkingSetSizeDelta
= 0;
479 LeaveCriticalSection(&PerfDataCriticalSection
);
481 return WorkingSetSizeDelta
;
484 ULONG
PerfDataGetPageFaultCount(ULONG Index
)
486 ULONG PageFaultCount
;
488 EnterCriticalSection(&PerfDataCriticalSection
);
490 if (Index
< ProcessCount
)
491 PageFaultCount
= pPerfData
[Index
].vmCounters
.PageFaultCount
;
495 LeaveCriticalSection(&PerfDataCriticalSection
);
497 return PageFaultCount
;
500 ULONG
PerfDataGetPageFaultCountDelta(ULONG Index
)
502 ULONG PageFaultCountDelta
;
504 EnterCriticalSection(&PerfDataCriticalSection
);
506 if (Index
< ProcessCount
)
507 PageFaultCountDelta
= pPerfData
[Index
].PageFaultCountDelta
;
509 PageFaultCountDelta
= 0;
511 LeaveCriticalSection(&PerfDataCriticalSection
);
513 return PageFaultCountDelta
;
516 ULONG
PerfDataGetVirtualMemorySizeBytes(ULONG Index
)
518 ULONG VirtualMemorySizeBytes
;
520 EnterCriticalSection(&PerfDataCriticalSection
);
522 if (Index
< ProcessCount
)
523 VirtualMemorySizeBytes
= pPerfData
[Index
].vmCounters
.VirtualSize
;
525 VirtualMemorySizeBytes
= 0;
527 LeaveCriticalSection(&PerfDataCriticalSection
);
529 return VirtualMemorySizeBytes
;
532 ULONG
PerfDataGetPagedPoolUsagePages(ULONG Index
)
534 ULONG PagedPoolUsagePages
;
536 EnterCriticalSection(&PerfDataCriticalSection
);
538 if (Index
< ProcessCount
)
539 PagedPoolUsagePages
= pPerfData
[Index
].vmCounters
.QuotaPagedPoolUsage
;
541 PagedPoolUsagePages
= 0;
543 LeaveCriticalSection(&PerfDataCriticalSection
);
545 return PagedPoolUsagePages
;
548 ULONG
PerfDataGetNonPagedPoolUsagePages(ULONG Index
)
550 ULONG NonPagedPoolUsagePages
;
552 EnterCriticalSection(&PerfDataCriticalSection
);
554 if (Index
< ProcessCount
)
555 NonPagedPoolUsagePages
= pPerfData
[Index
].vmCounters
.QuotaNonPagedPoolUsage
;
557 NonPagedPoolUsagePages
= 0;
559 LeaveCriticalSection(&PerfDataCriticalSection
);
561 return NonPagedPoolUsagePages
;
564 ULONG
PerfDataGetBasePriority(ULONG Index
)
568 EnterCriticalSection(&PerfDataCriticalSection
);
570 if (Index
< ProcessCount
)
571 BasePriority
= pPerfData
[Index
].BasePriority
;
575 LeaveCriticalSection(&PerfDataCriticalSection
);
580 ULONG
PerfDataGetHandleCount(ULONG Index
)
584 EnterCriticalSection(&PerfDataCriticalSection
);
586 if (Index
< ProcessCount
)
587 HandleCount
= pPerfData
[Index
].HandleCount
;
591 LeaveCriticalSection(&PerfDataCriticalSection
);
596 ULONG
PerfDataGetThreadCount(ULONG Index
)
600 EnterCriticalSection(&PerfDataCriticalSection
);
602 if (Index
< ProcessCount
)
603 ThreadCount
= pPerfData
[Index
].ThreadCount
;
607 LeaveCriticalSection(&PerfDataCriticalSection
);
612 ULONG
PerfDataGetUSERObjectCount(ULONG Index
)
614 ULONG USERObjectCount
;
616 EnterCriticalSection(&PerfDataCriticalSection
);
618 if (Index
< ProcessCount
)
619 USERObjectCount
= pPerfData
[Index
].USERObjectCount
;
623 LeaveCriticalSection(&PerfDataCriticalSection
);
625 return USERObjectCount
;
628 ULONG
PerfDataGetGDIObjectCount(ULONG Index
)
630 ULONG GDIObjectCount
;
632 EnterCriticalSection(&PerfDataCriticalSection
);
634 if (Index
< ProcessCount
)
635 GDIObjectCount
= pPerfData
[Index
].GDIObjectCount
;
639 LeaveCriticalSection(&PerfDataCriticalSection
);
641 return GDIObjectCount
;
644 BOOL
PerfDataGetIOCounters(ULONG Index
, PIO_COUNTERS pIoCounters
)
648 EnterCriticalSection(&PerfDataCriticalSection
);
650 if (Index
< ProcessCount
)
652 memcpy(pIoCounters
, &pPerfData
[Index
].IOCounters
, sizeof(IO_COUNTERS
));
658 LeaveCriticalSection(&PerfDataCriticalSection
);
663 ULONG
PerfDataGetCommitChargeTotalK(void)
668 EnterCriticalSection(&PerfDataCriticalSection
);
670 Total
= SystemPerfInfo
.TotalCommittedPages
;
671 PageSize
= SystemBasicInfo
.PageSize
;
673 LeaveCriticalSection(&PerfDataCriticalSection
);
675 Total
= Total
* (PageSize
/ 1024);
680 ULONG
PerfDataGetCommitChargeLimitK(void)
685 EnterCriticalSection(&PerfDataCriticalSection
);
687 Limit
= SystemPerfInfo
.TotalCommitLimit
;
688 PageSize
= SystemBasicInfo
.PageSize
;
690 LeaveCriticalSection(&PerfDataCriticalSection
);
692 Limit
= Limit
* (PageSize
/ 1024);
697 ULONG
PerfDataGetCommitChargePeakK(void)
702 EnterCriticalSection(&PerfDataCriticalSection
);
704 Peak
= SystemPerfInfo
.PeakCommitment
;
705 PageSize
= SystemBasicInfo
.PageSize
;
707 LeaveCriticalSection(&PerfDataCriticalSection
);
709 Peak
= Peak
* (PageSize
/ 1024);
714 ULONG
PerfDataGetKernelMemoryTotalK(void)
721 EnterCriticalSection(&PerfDataCriticalSection
);
723 Paged
= SystemPerfInfo
.PagedPoolUsage
;
724 NonPaged
= SystemPerfInfo
.NonPagedPoolUsage
;
725 PageSize
= SystemBasicInfo
.PageSize
;
727 LeaveCriticalSection(&PerfDataCriticalSection
);
729 Paged
= Paged
* (PageSize
/ 1024);
730 NonPaged
= NonPaged
* (PageSize
/ 1024);
732 Total
= Paged
+ NonPaged
;
737 ULONG
PerfDataGetKernelMemoryPagedK(void)
742 EnterCriticalSection(&PerfDataCriticalSection
);
744 Paged
= SystemPerfInfo
.PagedPoolUsage
;
745 PageSize
= SystemBasicInfo
.PageSize
;
747 LeaveCriticalSection(&PerfDataCriticalSection
);
749 Paged
= Paged
* (PageSize
/ 1024);
754 ULONG
PerfDataGetKernelMemoryNonPagedK(void)
759 EnterCriticalSection(&PerfDataCriticalSection
);
761 NonPaged
= SystemPerfInfo
.NonPagedPoolUsage
;
762 PageSize
= SystemBasicInfo
.PageSize
;
764 LeaveCriticalSection(&PerfDataCriticalSection
);
766 NonPaged
= NonPaged
* (PageSize
/ 1024);
771 ULONG
PerfDataGetPhysicalMemoryTotalK(void)
776 EnterCriticalSection(&PerfDataCriticalSection
);
778 Total
= SystemBasicInfo
.MmNumberOfPhysicalPages
;
779 PageSize
= SystemBasicInfo
.PageSize
;
781 LeaveCriticalSection(&PerfDataCriticalSection
);
783 Total
= Total
* (PageSize
/ 1024);
788 ULONG
PerfDataGetPhysicalMemoryAvailableK(void)
793 EnterCriticalSection(&PerfDataCriticalSection
);
795 Available
= SystemPerfInfo
.AvailablePages
;
796 PageSize
= SystemBasicInfo
.PageSize
;
798 LeaveCriticalSection(&PerfDataCriticalSection
);
800 Available
= Available
* (PageSize
/ 1024);
805 ULONG
PerfDataGetPhysicalMemorySystemCacheK(void)
809 EnterCriticalSection(&PerfDataCriticalSection
);
811 SystemCache
= SystemCacheInfo
.CurrentSize
;
813 LeaveCriticalSection(&PerfDataCriticalSection
);
815 SystemCache
= SystemCache
/ 1024;
820 ULONG
PerfDataGetSystemHandleCount(void)
824 EnterCriticalSection(&PerfDataCriticalSection
);
826 HandleCount
= SystemHandleInfo
.Count
;
828 LeaveCriticalSection(&PerfDataCriticalSection
);
833 ULONG
PerfDataGetTotalThreadCount(void)
835 ULONG ThreadCount
= 0;
838 EnterCriticalSection(&PerfDataCriticalSection
);
840 for (i
=0; i
<ProcessCount
; i
++)
842 ThreadCount
+= pPerfData
[i
].ThreadCount
;
845 LeaveCriticalSection(&PerfDataCriticalSection
);