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 CRITICAL_SECTION PerfDataCriticalSection
;
37 static PPERFDATA pPerfDataOld
= NULL
; /* Older perf data (saved to establish delta values) */
38 static PPERFDATA pPerfData
= NULL
; /* Most recent copy of perf data */
39 static ULONG ProcessCountOld
= 0;
40 static ULONG ProcessCount
= 0;
41 static double dbIdleTime
;
42 static double dbKernelTime
;
43 static double dbSystemTime
;
44 static LARGE_INTEGER liOldIdleTime
= {{0,0}};
45 static double OldKernelTime
= 0;
46 static LARGE_INTEGER liOldSystemTime
= {{0,0}};
47 static SYSTEM_PERFORMANCE_INFORMATION SystemPerfInfo
;
48 static SYSTEM_BASIC_INFORMATION SystemBasicInfo
;
49 static SYSTEM_CACHE_INFORMATION SystemCacheInfo
;
50 static SYSTEM_HANDLE_INFORMATION SystemHandleInfo
;
51 static PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION SystemProcessorTimeInfo
= NULL
;
53 BOOL
PerfDataInitialize(void)
56 static const WCHAR wszNtdll
[] = {'n','t','d','l','l','.','d','l','l',0};
57 static const WCHAR wszUser32
[] = {'u','s','e','r','3','2','.','d','l','l',0};
58 static const WCHAR wszKernel32
[] = {'k','e','r','n','e','l','3','2','.','d','l','l',0};
60 pNtQuerySystemInformation
= (PROCNTQSI
)GetProcAddress(GetModuleHandleW(wszNtdll
), "NtQuerySystemInformation");
61 pGetGuiResources
= (PROCGGR
)GetProcAddress(GetModuleHandleW(wszUser32
), "GetGuiResources");
62 pGetProcessIoCounters
= (PROCGPIC
)GetProcAddress(GetModuleHandleW(wszKernel32
), "GetProcessIoCounters");
64 InitializeCriticalSection(&PerfDataCriticalSection
);
66 if (!pNtQuerySystemInformation
)
70 * Get number of processors in the system
72 status
= pNtQuerySystemInformation(SystemBasicInformation
, &SystemBasicInfo
, sizeof(SystemBasicInfo
), NULL
);
73 if (status
!= NO_ERROR
)
79 void PerfDataRefresh(void)
85 PSYSTEM_PROCESS_INFORMATION pSPI
;
90 WCHAR wszTemp
[MAX_PATH
];
92 SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo
;
93 SYSTEM_TIMEOFDAY_INFORMATION SysTimeInfo
;
94 SYSTEM_CACHE_INFORMATION SysCacheInfo
;
95 LPBYTE SysHandleInfoData
;
96 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
*SysProcessorTimeInfo
;
97 double CurrentKernelTime
;
100 /* Get new system time */
101 status
= pNtQuerySystemInformation(SystemTimeOfDayInformation
, &SysTimeInfo
, sizeof(SysTimeInfo
), 0);
102 if (status
!= NO_ERROR
)
105 /* Get new CPU's idle time */
106 status
= pNtQuerySystemInformation(SystemPerformanceInformation
, &SysPerfInfo
, sizeof(SysPerfInfo
), NULL
);
107 if (status
!= NO_ERROR
)
110 /* Get system cache information */
111 status
= pNtQuerySystemInformation(SystemCacheInformation
, &SysCacheInfo
, sizeof(SysCacheInfo
), NULL
);
112 if (status
!= NO_ERROR
)
115 /* Get processor time information */
116 SysProcessorTimeInfo
= HeapAlloc(GetProcessHeap(), 0,
117 sizeof(*SysProcessorTimeInfo
) * SystemBasicInfo
.NumberOfProcessors
);
118 status
= pNtQuerySystemInformation(SystemProcessorPerformanceInformation
, SysProcessorTimeInfo
, sizeof(*SysProcessorTimeInfo
) * SystemBasicInfo
.NumberOfProcessors
, &ulSize
);
119 if (status
!= NO_ERROR
) {
120 HeapFree(GetProcessHeap(), 0, SysProcessorTimeInfo
);
124 /* Get handle information
125 * We don't know how much data there is so just keep
126 * increasing the buffer size until the call succeeds
131 BufferSize
+= 0x10000;
132 SysHandleInfoData
= HeapAlloc(GetProcessHeap(), 0, BufferSize
);
134 status
= pNtQuerySystemInformation(SystemHandleInformation
, SysHandleInfoData
, BufferSize
, &ulSize
);
136 if (status
== 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/) {
137 HeapFree(GetProcessHeap(), 0, SysHandleInfoData
);
140 } while (status
== 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/);
142 /* Get process information
143 * We don't know how much data there is so just keep
144 * increasing the buffer size until the call succeeds
149 BufferSize
+= 0x10000;
150 pBuffer
= HeapAlloc(GetProcessHeap(), 0, BufferSize
);
152 status
= pNtQuerySystemInformation(SystemProcessInformation
, pBuffer
, BufferSize
, &ulSize
);
154 if (status
== 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/) {
155 HeapFree(GetProcessHeap(), 0, pBuffer
);
158 } while (status
== 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/);
160 EnterCriticalSection(&PerfDataCriticalSection
);
163 * Save system performance info
165 memcpy(&SystemPerfInfo
, &SysPerfInfo
, sizeof(SYSTEM_PERFORMANCE_INFORMATION
));
168 * Save system cache info
170 memcpy(&SystemCacheInfo
, &SysCacheInfo
, sizeof(SYSTEM_CACHE_INFORMATION
));
173 * Save system processor time info
175 HeapFree(GetProcessHeap(), 0, SystemProcessorTimeInfo
);
176 SystemProcessorTimeInfo
= SysProcessorTimeInfo
;
179 * Save system handle info
181 memcpy(&SystemHandleInfo
, SysHandleInfoData
, sizeof(SYSTEM_HANDLE_INFORMATION
));
182 HeapFree(GetProcessHeap(), 0, SysHandleInfoData
);
184 for (CurrentKernelTime
=0, Idx
=0; Idx
<SystemBasicInfo
.NumberOfProcessors
; Idx
++) {
185 CurrentKernelTime
+= Li2Double(SystemProcessorTimeInfo
[Idx
].KernelTime
);
186 CurrentKernelTime
+= Li2Double(SystemProcessorTimeInfo
[Idx
].Reserved1
[0]);
187 CurrentKernelTime
+= Li2Double(SystemProcessorTimeInfo
[Idx
].Reserved1
[1]);
190 /* If it's a first call - skip idle time calcs */
191 if (liOldIdleTime
.QuadPart
!= 0) {
192 /* CurrentValue = NewValue - OldValue */
193 dbIdleTime
= Li2Double(SysPerfInfo
.IdleTime
) - Li2Double(liOldIdleTime
);
194 dbKernelTime
= CurrentKernelTime
- OldKernelTime
;
195 dbSystemTime
= Li2Double(SysTimeInfo
.liKeSystemTime
) - Li2Double(liOldSystemTime
);
197 /* CurrentCpuIdle = IdleTime / SystemTime */
198 dbIdleTime
= dbIdleTime
/ dbSystemTime
;
199 dbKernelTime
= dbKernelTime
/ dbSystemTime
;
201 /* CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) / NumberOfProcessors */
202 dbIdleTime
= 100.0 - dbIdleTime
* 100.0 / (double)SystemBasicInfo
.NumberOfProcessors
; /* + 0.5; */
203 dbKernelTime
= 100.0 - dbKernelTime
* 100.0 / (double)SystemBasicInfo
.NumberOfProcessors
; /* + 0.5; */
206 /* Store new CPU's idle and system time */
207 liOldIdleTime
= SysPerfInfo
.IdleTime
;
208 liOldSystemTime
= SysTimeInfo
.liKeSystemTime
;
209 OldKernelTime
= CurrentKernelTime
;
211 /* Determine the process count
212 * We loop through the data we got from NtQuerySystemInformation
213 * and count how many structures there are (until RelativeOffset is 0)
215 ProcessCountOld
= ProcessCount
;
217 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)pBuffer
;
220 if (pSPI
->NextEntryOffset
== 0)
222 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)((LPBYTE
)pSPI
+ pSPI
->NextEntryOffset
);
225 /* Now alloc a new PERFDATA array and fill in the data */
226 HeapFree(GetProcessHeap(), 0, pPerfDataOld
);
227 pPerfDataOld
= pPerfData
;
228 pPerfData
= HeapAlloc(GetProcessHeap(), 0, sizeof(PERFDATA
) * ProcessCount
);
229 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)pBuffer
;
230 for (Idx
=0; Idx
<ProcessCount
; Idx
++) {
231 /* Get the old perf data for this process (if any) */
232 /* so that we can establish delta values */
234 for (Idx2
=0; Idx2
<ProcessCountOld
; Idx2
++) {
235 if (pPerfDataOld
[Idx2
].ProcessId
== (DWORD_PTR
)pSPI
->UniqueProcessId
) {
236 pPDOld
= &pPerfDataOld
[Idx2
];
241 /* Clear out process perf data structure */
242 memset(&pPerfData
[Idx
], 0, sizeof(PERFDATA
));
244 if (pSPI
->ProcessName
.Buffer
)
245 lstrcpyW(pPerfData
[Idx
].ImageName
, pSPI
->ProcessName
.Buffer
);
249 LoadStringW(hInst
, IDS_SYSTEM_IDLE_PROCESS
, idleW
, sizeof(idleW
)/sizeof(WCHAR
));
250 lstrcpyW(pPerfData
[Idx
].ImageName
, idleW
);
253 pPerfData
[Idx
].ProcessId
= (DWORD_PTR
)pSPI
->UniqueProcessId
;
256 double CurTime
= Li2Double(pSPI
->KernelTime
) + Li2Double(pSPI
->UserTime
);
257 double OldTime
= Li2Double(pPDOld
->KernelTime
) + Li2Double(pPDOld
->UserTime
);
258 double CpuTime
= (CurTime
- OldTime
) / dbSystemTime
;
259 CpuTime
= CpuTime
* 100.0 / (double)SystemBasicInfo
.NumberOfProcessors
; /* + 0.5; */
260 pPerfData
[Idx
].CPUUsage
= (ULONG
)CpuTime
;
263 pPerfData
[Idx
].CPUTime
.QuadPart
= pSPI
->UserTime
.QuadPart
+ pSPI
->KernelTime
.QuadPart
;
264 pPerfData
[Idx
].vmCounters
.WorkingSetSize
= pSPI
->vmCounters
.WorkingSetSize
;
265 pPerfData
[Idx
].vmCounters
.PeakWorkingSetSize
= pSPI
->vmCounters
.PeakWorkingSetSize
;
267 pPerfData
[Idx
].WorkingSetSizeDelta
= labs(pSPI
->vmCounters
.WorkingSetSize
- pPDOld
->vmCounters
.WorkingSetSize
);
269 pPerfData
[Idx
].WorkingSetSizeDelta
= 0;
270 pPerfData
[Idx
].vmCounters
.PageFaultCount
= pSPI
->vmCounters
.PageFaultCount
;
272 pPerfData
[Idx
].PageFaultCountDelta
= labs(pSPI
->vmCounters
.PageFaultCount
- pPDOld
->vmCounters
.PageFaultCount
);
274 pPerfData
[Idx
].PageFaultCountDelta
= 0;
275 pPerfData
[Idx
].vmCounters
.VirtualSize
= pSPI
->vmCounters
.VirtualSize
;
276 pPerfData
[Idx
].vmCounters
.QuotaPagedPoolUsage
= pSPI
->vmCounters
.QuotaPagedPoolUsage
;
277 pPerfData
[Idx
].vmCounters
.QuotaNonPagedPoolUsage
= pSPI
->vmCounters
.QuotaNonPagedPoolUsage
;
278 pPerfData
[Idx
].BasePriority
= pSPI
->dwBasePriority
;
279 pPerfData
[Idx
].HandleCount
= pSPI
->HandleCount
;
280 pPerfData
[Idx
].ThreadCount
= pSPI
->dwThreadCount
;
281 pPerfData
[Idx
].SessionId
= pSPI
->SessionId
;
283 hProcess
= OpenProcess(PROCESS_QUERY_INFORMATION
, FALSE
, (DWORD_PTR
)pSPI
->UniqueProcessId
);
285 if (OpenProcessToken(hProcess
, TOKEN_QUERY
|TOKEN_DUPLICATE
|TOKEN_IMPERSONATE
, &hProcessToken
)) {
286 ImpersonateLoggedOnUser(hProcessToken
);
287 memset(wszTemp
, 0, sizeof(wszTemp
));
289 GetUserNameW(wszTemp
, &dwSize
);
291 CloseHandle(hProcessToken
);
293 if (pGetGuiResources
) {
294 pPerfData
[Idx
].USERObjectCount
= pGetGuiResources(hProcess
, GR_USEROBJECTS
);
295 pPerfData
[Idx
].GDIObjectCount
= pGetGuiResources(hProcess
, GR_GDIOBJECTS
);
297 if (pGetProcessIoCounters
)
298 pGetProcessIoCounters(hProcess
, &pPerfData
[Idx
].IOCounters
);
299 CloseHandle(hProcess
);
301 pPerfData
[Idx
].UserTime
.QuadPart
= pSPI
->UserTime
.QuadPart
;
302 pPerfData
[Idx
].KernelTime
.QuadPart
= pSPI
->KernelTime
.QuadPart
;
303 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)((LPBYTE
)pSPI
+ pSPI
->NextEntryOffset
);
305 HeapFree(GetProcessHeap(), 0, pBuffer
);
306 LeaveCriticalSection(&PerfDataCriticalSection
);
309 ULONG
PerfDataGetProcessCount(void)
314 ULONG
PerfDataGetProcessorUsage(void)
316 if( dbIdleTime
< 0.0 )
318 if( dbIdleTime
> 100.0 )
320 return (ULONG
)dbIdleTime
;
323 ULONG
PerfDataGetProcessorSystemUsage(void)
325 if( dbKernelTime
< 0.0 )
327 if( dbKernelTime
> 100.0 )
329 return (ULONG
)dbKernelTime
;
332 BOOL
PerfDataGetImageName(ULONG Index
, LPWSTR lpImageName
, int nMaxCount
)
336 EnterCriticalSection(&PerfDataCriticalSection
);
338 if (Index
< ProcessCount
) {
339 wcsncpy(lpImageName
, pPerfData
[Index
].ImageName
, nMaxCount
);
344 LeaveCriticalSection(&PerfDataCriticalSection
);
348 ULONG
PerfDataGetProcessId(ULONG Index
)
352 EnterCriticalSection(&PerfDataCriticalSection
);
354 if (Index
< ProcessCount
)
355 ProcessId
= pPerfData
[Index
].ProcessId
;
359 LeaveCriticalSection(&PerfDataCriticalSection
);
364 BOOL
PerfDataGetUserName(ULONG Index
, LPWSTR lpUserName
, int nMaxCount
)
368 EnterCriticalSection(&PerfDataCriticalSection
);
370 if (Index
< ProcessCount
) {
371 wcsncpy(lpUserName
, pPerfData
[Index
].UserName
, nMaxCount
);
377 LeaveCriticalSection(&PerfDataCriticalSection
);
382 ULONG
PerfDataGetSessionId(ULONG Index
)
386 EnterCriticalSection(&PerfDataCriticalSection
);
388 if (Index
< ProcessCount
)
389 SessionId
= pPerfData
[Index
].SessionId
;
393 LeaveCriticalSection(&PerfDataCriticalSection
);
398 ULONG
PerfDataGetCPUUsage(ULONG Index
)
402 EnterCriticalSection(&PerfDataCriticalSection
);
404 if (Index
< ProcessCount
)
405 CpuUsage
= pPerfData
[Index
].CPUUsage
;
409 LeaveCriticalSection(&PerfDataCriticalSection
);
414 TIME
PerfDataGetCPUTime(ULONG Index
)
416 TIME CpuTime
= {{0,0}};
418 EnterCriticalSection(&PerfDataCriticalSection
);
420 if (Index
< ProcessCount
)
421 CpuTime
= pPerfData
[Index
].CPUTime
;
423 LeaveCriticalSection(&PerfDataCriticalSection
);
428 ULONG
PerfDataGetWorkingSetSizeBytes(ULONG Index
)
430 ULONG WorkingSetSizeBytes
;
432 EnterCriticalSection(&PerfDataCriticalSection
);
434 if (Index
< ProcessCount
)
435 WorkingSetSizeBytes
= pPerfData
[Index
].vmCounters
.WorkingSetSize
;
437 WorkingSetSizeBytes
= 0;
439 LeaveCriticalSection(&PerfDataCriticalSection
);
441 return WorkingSetSizeBytes
;
444 ULONG
PerfDataGetPeakWorkingSetSizeBytes(ULONG Index
)
446 ULONG PeakWorkingSetSizeBytes
;
448 EnterCriticalSection(&PerfDataCriticalSection
);
450 if (Index
< ProcessCount
)
451 PeakWorkingSetSizeBytes
= pPerfData
[Index
].vmCounters
.PeakWorkingSetSize
;
453 PeakWorkingSetSizeBytes
= 0;
455 LeaveCriticalSection(&PerfDataCriticalSection
);
457 return PeakWorkingSetSizeBytes
;
460 ULONG
PerfDataGetWorkingSetSizeDelta(ULONG Index
)
462 ULONG WorkingSetSizeDelta
;
464 EnterCriticalSection(&PerfDataCriticalSection
);
466 if (Index
< ProcessCount
)
467 WorkingSetSizeDelta
= pPerfData
[Index
].WorkingSetSizeDelta
;
469 WorkingSetSizeDelta
= 0;
471 LeaveCriticalSection(&PerfDataCriticalSection
);
473 return WorkingSetSizeDelta
;
476 ULONG
PerfDataGetPageFaultCount(ULONG Index
)
478 ULONG PageFaultCount
;
480 EnterCriticalSection(&PerfDataCriticalSection
);
482 if (Index
< ProcessCount
)
483 PageFaultCount
= pPerfData
[Index
].vmCounters
.PageFaultCount
;
487 LeaveCriticalSection(&PerfDataCriticalSection
);
489 return PageFaultCount
;
492 ULONG
PerfDataGetPageFaultCountDelta(ULONG Index
)
494 ULONG PageFaultCountDelta
;
496 EnterCriticalSection(&PerfDataCriticalSection
);
498 if (Index
< ProcessCount
)
499 PageFaultCountDelta
= pPerfData
[Index
].PageFaultCountDelta
;
501 PageFaultCountDelta
= 0;
503 LeaveCriticalSection(&PerfDataCriticalSection
);
505 return PageFaultCountDelta
;
508 ULONG
PerfDataGetVirtualMemorySizeBytes(ULONG Index
)
510 ULONG VirtualMemorySizeBytes
;
512 EnterCriticalSection(&PerfDataCriticalSection
);
514 if (Index
< ProcessCount
)
515 VirtualMemorySizeBytes
= pPerfData
[Index
].vmCounters
.VirtualSize
;
517 VirtualMemorySizeBytes
= 0;
519 LeaveCriticalSection(&PerfDataCriticalSection
);
521 return VirtualMemorySizeBytes
;
524 ULONG
PerfDataGetPagedPoolUsagePages(ULONG Index
)
526 ULONG PagedPoolUsagePages
;
528 EnterCriticalSection(&PerfDataCriticalSection
);
530 if (Index
< ProcessCount
)
531 PagedPoolUsagePages
= pPerfData
[Index
].vmCounters
.QuotaPagedPoolUsage
;
533 PagedPoolUsagePages
= 0;
535 LeaveCriticalSection(&PerfDataCriticalSection
);
537 return PagedPoolUsagePages
;
540 ULONG
PerfDataGetNonPagedPoolUsagePages(ULONG Index
)
542 ULONG NonPagedPoolUsagePages
;
544 EnterCriticalSection(&PerfDataCriticalSection
);
546 if (Index
< ProcessCount
)
547 NonPagedPoolUsagePages
= pPerfData
[Index
].vmCounters
.QuotaNonPagedPoolUsage
;
549 NonPagedPoolUsagePages
= 0;
551 LeaveCriticalSection(&PerfDataCriticalSection
);
553 return NonPagedPoolUsagePages
;
556 ULONG
PerfDataGetBasePriority(ULONG Index
)
560 EnterCriticalSection(&PerfDataCriticalSection
);
562 if (Index
< ProcessCount
)
563 BasePriority
= pPerfData
[Index
].BasePriority
;
567 LeaveCriticalSection(&PerfDataCriticalSection
);
572 ULONG
PerfDataGetHandleCount(ULONG Index
)
576 EnterCriticalSection(&PerfDataCriticalSection
);
578 if (Index
< ProcessCount
)
579 HandleCount
= pPerfData
[Index
].HandleCount
;
583 LeaveCriticalSection(&PerfDataCriticalSection
);
588 ULONG
PerfDataGetThreadCount(ULONG Index
)
592 EnterCriticalSection(&PerfDataCriticalSection
);
594 if (Index
< ProcessCount
)
595 ThreadCount
= pPerfData
[Index
].ThreadCount
;
599 LeaveCriticalSection(&PerfDataCriticalSection
);
604 ULONG
PerfDataGetUSERObjectCount(ULONG Index
)
606 ULONG USERObjectCount
;
608 EnterCriticalSection(&PerfDataCriticalSection
);
610 if (Index
< ProcessCount
)
611 USERObjectCount
= pPerfData
[Index
].USERObjectCount
;
615 LeaveCriticalSection(&PerfDataCriticalSection
);
617 return USERObjectCount
;
620 ULONG
PerfDataGetGDIObjectCount(ULONG Index
)
622 ULONG GDIObjectCount
;
624 EnterCriticalSection(&PerfDataCriticalSection
);
626 if (Index
< ProcessCount
)
627 GDIObjectCount
= pPerfData
[Index
].GDIObjectCount
;
631 LeaveCriticalSection(&PerfDataCriticalSection
);
633 return GDIObjectCount
;
636 BOOL
PerfDataGetIOCounters(ULONG Index
, PIO_COUNTERS pIoCounters
)
640 EnterCriticalSection(&PerfDataCriticalSection
);
642 if (Index
< ProcessCount
)
644 memcpy(pIoCounters
, &pPerfData
[Index
].IOCounters
, sizeof(IO_COUNTERS
));
650 LeaveCriticalSection(&PerfDataCriticalSection
);
655 ULONG
PerfDataGetCommitChargeTotalK(void)
660 EnterCriticalSection(&PerfDataCriticalSection
);
662 Total
= SystemPerfInfo
.TotalCommittedPages
;
663 PageSize
= SystemBasicInfo
.PageSize
;
665 LeaveCriticalSection(&PerfDataCriticalSection
);
667 Total
= Total
* (PageSize
/ 1024);
672 ULONG
PerfDataGetCommitChargeLimitK(void)
677 EnterCriticalSection(&PerfDataCriticalSection
);
679 Limit
= SystemPerfInfo
.TotalCommitLimit
;
680 PageSize
= SystemBasicInfo
.PageSize
;
682 LeaveCriticalSection(&PerfDataCriticalSection
);
684 Limit
= Limit
* (PageSize
/ 1024);
689 ULONG
PerfDataGetCommitChargePeakK(void)
694 EnterCriticalSection(&PerfDataCriticalSection
);
696 Peak
= SystemPerfInfo
.PeakCommitment
;
697 PageSize
= SystemBasicInfo
.PageSize
;
699 LeaveCriticalSection(&PerfDataCriticalSection
);
701 Peak
= Peak
* (PageSize
/ 1024);
706 ULONG
PerfDataGetKernelMemoryTotalK(void)
713 EnterCriticalSection(&PerfDataCriticalSection
);
715 Paged
= SystemPerfInfo
.PagedPoolUsage
;
716 NonPaged
= SystemPerfInfo
.NonPagedPoolUsage
;
717 PageSize
= SystemBasicInfo
.PageSize
;
719 LeaveCriticalSection(&PerfDataCriticalSection
);
721 Paged
= Paged
* (PageSize
/ 1024);
722 NonPaged
= NonPaged
* (PageSize
/ 1024);
724 Total
= Paged
+ NonPaged
;
729 ULONG
PerfDataGetKernelMemoryPagedK(void)
734 EnterCriticalSection(&PerfDataCriticalSection
);
736 Paged
= SystemPerfInfo
.PagedPoolUsage
;
737 PageSize
= SystemBasicInfo
.PageSize
;
739 LeaveCriticalSection(&PerfDataCriticalSection
);
741 Paged
= Paged
* (PageSize
/ 1024);
746 ULONG
PerfDataGetKernelMemoryNonPagedK(void)
751 EnterCriticalSection(&PerfDataCriticalSection
);
753 NonPaged
= SystemPerfInfo
.NonPagedPoolUsage
;
754 PageSize
= SystemBasicInfo
.PageSize
;
756 LeaveCriticalSection(&PerfDataCriticalSection
);
758 NonPaged
= NonPaged
* (PageSize
/ 1024);
763 ULONG
PerfDataGetPhysicalMemoryTotalK(void)
768 EnterCriticalSection(&PerfDataCriticalSection
);
770 Total
= SystemBasicInfo
.MmNumberOfPhysicalPages
;
771 PageSize
= SystemBasicInfo
.PageSize
;
773 LeaveCriticalSection(&PerfDataCriticalSection
);
775 Total
= Total
* (PageSize
/ 1024);
780 ULONG
PerfDataGetPhysicalMemoryAvailableK(void)
785 EnterCriticalSection(&PerfDataCriticalSection
);
787 Available
= SystemPerfInfo
.AvailablePages
;
788 PageSize
= SystemBasicInfo
.PageSize
;
790 LeaveCriticalSection(&PerfDataCriticalSection
);
792 Available
= Available
* (PageSize
/ 1024);
797 ULONG
PerfDataGetPhysicalMemorySystemCacheK(void)
801 EnterCriticalSection(&PerfDataCriticalSection
);
803 SystemCache
= SystemCacheInfo
.CurrentSize
;
805 LeaveCriticalSection(&PerfDataCriticalSection
);
807 SystemCache
= SystemCache
/ 1024;
812 ULONG
PerfDataGetSystemHandleCount(void)
816 EnterCriticalSection(&PerfDataCriticalSection
);
818 HandleCount
= SystemHandleInfo
.Count
;
820 LeaveCriticalSection(&PerfDataCriticalSection
);
825 ULONG
PerfDataGetTotalThreadCount(void)
827 ULONG ThreadCount
= 0;
830 EnterCriticalSection(&PerfDataCriticalSection
);
832 for (i
=0; i
<ProcessCount
; i
++)
834 ThreadCount
+= pPerfData
[i
].ThreadCount
;
837 LeaveCriticalSection(&PerfDataCriticalSection
);