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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 CRITICAL_SECTION PerfDataCriticalSection
;
26 PPERFDATA pPerfDataOld
= NULL
; /* Older perf data (saved to establish delta values) */
27 PPERFDATA pPerfData
= NULL
; /* Most recent copy of perf data */
28 ULONG ProcessCountOld
= 0;
29 ULONG ProcessCount
= 0;
33 LARGE_INTEGER liOldIdleTime
= {{0,0}};
34 double OldKernelTime
= 0;
35 LARGE_INTEGER liOldSystemTime
= {{0,0}};
36 SYSTEM_PERFORMANCE_INFORMATION SystemPerfInfo
;
37 SYSTEM_BASIC_INFORMATION SystemBasicInfo
;
38 SYSTEM_CACHE_INFORMATION SystemCacheInfo
;
39 SYSTEM_HANDLE_INFORMATION SystemHandleInfo
;
40 PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION SystemProcessorTimeInfo
= NULL
;
42 BOOL
PerfDataInitialize(void)
46 InitializeCriticalSection(&PerfDataCriticalSection
);
49 * Get number of processors in the system
51 status
= NtQuerySystemInformation(SystemBasicInformation
, &SystemBasicInfo
, sizeof(SystemBasicInfo
), NULL
);
52 if (status
!= NO_ERROR
)
58 void PerfDataUninitialize(void)
60 DeleteCriticalSection(&PerfDataCriticalSection
);
63 void PerfDataRefresh(void)
69 PSYSTEM_PROCESS_INFORMATION pSPI
;
74 TCHAR szTemp
[MAX_PATH
];
76 SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo
;
77 SYSTEM_TIMEOFDAY_INFORMATION SysTimeInfo
;
78 SYSTEM_CACHE_INFORMATION SysCacheInfo
;
79 LPBYTE SysHandleInfoData
;
80 PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION SysProcessorTimeInfo
;
81 double CurrentKernelTime
;
83 /* Get new system time */
84 status
= NtQuerySystemInformation(SystemTimeOfDayInformation
, &SysTimeInfo
, sizeof(SysTimeInfo
), 0);
85 if (status
!= NO_ERROR
)
88 /* Get new CPU's idle time */
89 status
= NtQuerySystemInformation(SystemPerformanceInformation
, &SysPerfInfo
, sizeof(SysPerfInfo
), NULL
);
90 if (status
!= NO_ERROR
)
93 /* Get system cache information */
94 status
= NtQuerySystemInformation(SystemFileCacheInformation
, &SysCacheInfo
, sizeof(SysCacheInfo
), NULL
);
95 if (status
!= NO_ERROR
)
98 /* Get processor time information */
99 SysProcessorTimeInfo
= (PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
)HeapAlloc(GetProcessHeap(), 0, sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) * SystemBasicInfo
.NumberOfProcessors
);
100 status
= NtQuerySystemInformation(SystemProcessorPerformanceInformation
, SysProcessorTimeInfo
, sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) * SystemBasicInfo
.NumberOfProcessors
, &ulSize
);
101 if (status
!= NO_ERROR
)
104 /* Get handle information
105 * We don't know how much data there is so just keep
106 * increasing the buffer size until the call succeeds
111 BufferSize
+= 0x10000;
112 SysHandleInfoData
= (LPBYTE
)HeapAlloc(GetProcessHeap(), 0, BufferSize
);
114 status
= NtQuerySystemInformation(SystemHandleInformation
, SysHandleInfoData
, BufferSize
, &ulSize
);
116 if (status
== STATUS_INFO_LENGTH_MISMATCH
) {
117 HeapFree(GetProcessHeap(), 0, SysHandleInfoData
);
120 } while (status
== STATUS_INFO_LENGTH_MISMATCH
);
122 /* Get process information
123 * We don't know how much data there is so just keep
124 * increasing the buffer size until the call succeeds
129 BufferSize
+= 0x10000;
130 pBuffer
= (LPBYTE
)HeapAlloc(GetProcessHeap(), 0, BufferSize
);
132 status
= NtQuerySystemInformation(SystemProcessInformation
, pBuffer
, BufferSize
, &ulSize
);
134 if (status
== STATUS_INFO_LENGTH_MISMATCH
) {
135 HeapFree(GetProcessHeap(), 0, pBuffer
);
138 } while (status
== STATUS_INFO_LENGTH_MISMATCH
);
140 EnterCriticalSection(&PerfDataCriticalSection
);
143 * Save system performance info
145 memcpy(&SystemPerfInfo
, &SysPerfInfo
, sizeof(SYSTEM_PERFORMANCE_INFORMATION
));
148 * Save system cache info
150 memcpy(&SystemCacheInfo
, &SysCacheInfo
, sizeof(SYSTEM_CACHE_INFORMATION
));
153 * Save system processor time info
155 if (SystemProcessorTimeInfo
) {
156 HeapFree(GetProcessHeap(), 0, SystemProcessorTimeInfo
);
158 SystemProcessorTimeInfo
= SysProcessorTimeInfo
;
161 * Save system handle info
163 memcpy(&SystemHandleInfo
, SysHandleInfoData
, sizeof(SYSTEM_HANDLE_INFORMATION
));
164 HeapFree(GetProcessHeap(), 0, SysHandleInfoData
);
166 for (CurrentKernelTime
=0, Idx
=0; Idx
<(ULONG
)SystemBasicInfo
.NumberOfProcessors
; Idx
++) {
167 CurrentKernelTime
+= Li2Double(SystemProcessorTimeInfo
[Idx
].KernelTime
);
168 CurrentKernelTime
+= Li2Double(SystemProcessorTimeInfo
[Idx
].DpcTime
);
169 CurrentKernelTime
+= Li2Double(SystemProcessorTimeInfo
[Idx
].InterruptTime
);
172 /* If it's a first call - skip idle time calcs */
173 if (liOldIdleTime
.QuadPart
!= 0) {
174 /* CurrentValue = NewValue - OldValue */
175 dbIdleTime
= Li2Double(SysPerfInfo
.IdleProcessTime
) - Li2Double(liOldIdleTime
);
176 dbKernelTime
= CurrentKernelTime
- OldKernelTime
;
177 dbSystemTime
= Li2Double(SysTimeInfo
.CurrentTime
) - Li2Double(liOldSystemTime
);
179 /* CurrentCpuIdle = IdleTime / SystemTime */
180 dbIdleTime
= dbIdleTime
/ dbSystemTime
;
181 dbKernelTime
= dbKernelTime
/ dbSystemTime
;
183 /* CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) / NumberOfProcessors */
184 dbIdleTime
= 100.0 - dbIdleTime
* 100.0 / (double)SystemBasicInfo
.NumberOfProcessors
; /* + 0.5; */
185 dbKernelTime
= 100.0 - dbKernelTime
* 100.0 / (double)SystemBasicInfo
.NumberOfProcessors
; /* + 0.5; */
188 /* Store new CPU's idle and system time */
189 liOldIdleTime
= SysPerfInfo
.IdleProcessTime
;
190 liOldSystemTime
= SysTimeInfo
.CurrentTime
;
191 OldKernelTime
= CurrentKernelTime
;
193 /* Determine the process count
194 * We loop through the data we got from NtQuerySystemInformation
195 * and count how many structures there are (until RelativeOffset is 0)
197 ProcessCountOld
= ProcessCount
;
199 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)pBuffer
;
202 if (pSPI
->NextEntryOffset
== 0)
204 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)((LPBYTE
)pSPI
+ pSPI
->NextEntryOffset
);
207 /* Now alloc a new PERFDATA array and fill in the data */
209 HeapFree(GetProcessHeap(), 0, pPerfDataOld
);
211 pPerfDataOld
= pPerfData
;
212 pPerfData
= (PPERFDATA
)HeapAlloc(GetProcessHeap(), 0, sizeof(PERFDATA
) * ProcessCount
);
213 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)pBuffer
;
214 for (Idx
=0; Idx
<ProcessCount
; Idx
++) {
215 /* Get the old perf data for this process (if any) */
216 /* so that we can establish delta values */
218 for (Idx2
=0; Idx2
<ProcessCountOld
; Idx2
++) {
219 if (pPerfDataOld
[Idx2
].ProcessId
== pSPI
->UniqueProcessId
) {
220 pPDOld
= &pPerfDataOld
[Idx2
];
225 /* Clear out process perf data structure */
226 memset(&pPerfData
[Idx
], 0, sizeof(PERFDATA
));
228 if (pSPI
->ImageName
.Buffer
)
229 wcscpy(pPerfData
[Idx
].ImageName
, pSPI
->ImageName
.Buffer
);
231 LoadStringW(hInst
, IDS_IDLE_PROCESS
, pPerfData
[Idx
].ImageName
,
232 sizeof(pPerfData
[Idx
].ImageName
) / sizeof(pPerfData
[Idx
].ImageName
[0]));
234 pPerfData
[Idx
].ProcessId
= pSPI
->UniqueProcessId
;
237 double CurTime
= Li2Double(pSPI
->KernelTime
) + Li2Double(pSPI
->UserTime
);
238 double OldTime
= Li2Double(pPDOld
->KernelTime
) + Li2Double(pPDOld
->UserTime
);
239 double CpuTime
= (CurTime
- OldTime
) / dbSystemTime
;
240 CpuTime
= CpuTime
* 100.0 / (double)SystemBasicInfo
.NumberOfProcessors
; /* + 0.5; */
241 pPerfData
[Idx
].CPUUsage
= (ULONG
)CpuTime
;
243 pPerfData
[Idx
].CPUTime
.QuadPart
= pSPI
->UserTime
.QuadPart
+ pSPI
->KernelTime
.QuadPart
;
244 pPerfData
[Idx
].WorkingSetSizeBytes
= pSPI
->WorkingSetSize
;
245 pPerfData
[Idx
].PeakWorkingSetSizeBytes
= pSPI
->PeakWorkingSetSize
;
247 pPerfData
[Idx
].WorkingSetSizeDelta
= labs((LONG
)pSPI
->WorkingSetSize
- (LONG
)pPDOld
->WorkingSetSizeBytes
);
249 pPerfData
[Idx
].WorkingSetSizeDelta
= 0;
250 pPerfData
[Idx
].PageFaultCount
= pSPI
->PageFaultCount
;
252 pPerfData
[Idx
].PageFaultCountDelta
= labs((LONG
)pSPI
->PageFaultCount
- (LONG
)pPDOld
->PageFaultCount
);
254 pPerfData
[Idx
].PageFaultCountDelta
= 0;
255 pPerfData
[Idx
].VirtualMemorySizeBytes
= pSPI
->VirtualSize
;
256 pPerfData
[Idx
].PagedPoolUsagePages
= pSPI
->QuotaPeakPagedPoolUsage
;
257 pPerfData
[Idx
].NonPagedPoolUsagePages
= pSPI
->QuotaPeakNonPagedPoolUsage
;
258 pPerfData
[Idx
].BasePriority
= pSPI
->BasePriority
;
259 pPerfData
[Idx
].HandleCount
= pSPI
->HandleCount
;
260 pPerfData
[Idx
].ThreadCount
= pSPI
->NumberOfThreads
;
261 pPerfData
[Idx
].SessionId
= pSPI
->SessionId
;
263 if (pSPI
->UniqueProcessId
!= NULL
) {
264 hProcess
= OpenProcess(PROCESS_QUERY_INFORMATION
, FALSE
, (DWORD
)pSPI
->UniqueProcessId
);
266 if (OpenProcessToken(hProcess
, TOKEN_QUERY
|TOKEN_DUPLICATE
|TOKEN_IMPERSONATE
, &hProcessToken
)) {
267 ImpersonateLoggedOnUser(hProcessToken
);
268 memset(szTemp
, 0, sizeof(TCHAR
[MAX_PATH
]));
270 GetUserName(szTemp
, &dwSize
);
272 MultiByteToWideChar(CP_ACP
, MB_PRECOMPOSED
, szTemp
, -1, pPerfData
[Idx
].UserName
, MAX_PATH
);
274 int MultiByteToWideChar(
275 UINT CodePage, // code page
276 DWORD dwFlags, // character-type options
277 LPCSTR lpMultiByteStr, // string to map
278 int cbMultiByte, // number of bytes in string
279 LPWSTR lpWideCharStr, // wide-character buffer
280 int cchWideChar // size of buffer
285 CloseHandle(hProcessToken
);
287 pPerfData
[Idx
].UserName
[0] = _T('\0');
289 pPerfData
[Idx
].USERObjectCount
= GetGuiResources(hProcess
, GR_USEROBJECTS
);
290 pPerfData
[Idx
].GDIObjectCount
= GetGuiResources(hProcess
, GR_GDIOBJECTS
);
291 GetProcessIoCounters(hProcess
, &pPerfData
[Idx
].IOCounters
);
292 CloseHandle(hProcess
);
298 /* clear information we were unable to fetch */
299 pPerfData
[Idx
].UserName
[0] = _T('\0');
300 pPerfData
[Idx
].USERObjectCount
= 0;
301 pPerfData
[Idx
].GDIObjectCount
= 0;
302 ZeroMemory(&pPerfData
[Idx
].IOCounters
, sizeof(IO_COUNTERS
));
304 pPerfData
[Idx
].UserTime
.QuadPart
= pSPI
->UserTime
.QuadPart
;
305 pPerfData
[Idx
].KernelTime
.QuadPart
= pSPI
->KernelTime
.QuadPart
;
306 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)((LPBYTE
)pSPI
+ pSPI
->NextEntryOffset
);
308 HeapFree(GetProcessHeap(), 0, pBuffer
);
309 LeaveCriticalSection(&PerfDataCriticalSection
);
312 ULONG
PerfDataGetProcessCount(void)
317 ULONG
PerfDataGetProcessorUsage(void)
319 return (ULONG
)dbIdleTime
;
322 ULONG
PerfDataGetProcessorSystemUsage(void)
324 return (ULONG
)dbKernelTime
;
327 BOOL
PerfDataGetImageName(ULONG Index
, LPTSTR lpImageName
, int nMaxCount
)
331 EnterCriticalSection(&PerfDataCriticalSection
);
333 if (Index
< ProcessCount
) {
335 wcsncpy(lpImageName
, pPerfData
[Index
].ImageName
, nMaxCount
);
337 WideCharToMultiByte(CP_ACP
, 0, pPerfData
[Index
].ImageName
, -1, lpImageName
, nMaxCount
, NULL
, NULL
);
344 LeaveCriticalSection(&PerfDataCriticalSection
);
348 int PerfGetIndexByProcessId(DWORD dwProcessId
)
350 int Index
, FoundIndex
= -1;
352 EnterCriticalSection(&PerfDataCriticalSection
);
354 for (Index
= 0; Index
< ProcessCount
; Index
++)
356 if ((DWORD
)pPerfData
[Index
].ProcessId
== dwProcessId
)
363 LeaveCriticalSection(&PerfDataCriticalSection
);
368 ULONG
PerfDataGetProcessId(ULONG Index
)
372 EnterCriticalSection(&PerfDataCriticalSection
);
374 if (Index
< ProcessCount
)
375 ProcessId
= (ULONG
)pPerfData
[Index
].ProcessId
;
379 LeaveCriticalSection(&PerfDataCriticalSection
);
384 BOOL
PerfDataGetUserName(ULONG Index
, LPTSTR lpUserName
, int nMaxCount
)
388 EnterCriticalSection(&PerfDataCriticalSection
);
390 if (Index
< ProcessCount
) {
392 wcsncpy(lpUserName
, pPerfData
[Index
].UserName
, nMaxCount
);
394 WideCharToMultiByte(CP_ACP
, 0, pPerfData
[Index
].UserName
, -1, lpUserName
, nMaxCount
, NULL
, NULL
);
402 LeaveCriticalSection(&PerfDataCriticalSection
);
407 ULONG
PerfDataGetSessionId(ULONG Index
)
411 EnterCriticalSection(&PerfDataCriticalSection
);
413 if (Index
< ProcessCount
)
414 SessionId
= pPerfData
[Index
].SessionId
;
418 LeaveCriticalSection(&PerfDataCriticalSection
);
423 ULONG
PerfDataGetCPUUsage(ULONG Index
)
427 EnterCriticalSection(&PerfDataCriticalSection
);
429 if (Index
< ProcessCount
)
430 CpuUsage
= pPerfData
[Index
].CPUUsage
;
434 LeaveCriticalSection(&PerfDataCriticalSection
);
439 LARGE_INTEGER
PerfDataGetCPUTime(ULONG Index
)
441 LARGE_INTEGER CpuTime
= {{0,0}};
443 EnterCriticalSection(&PerfDataCriticalSection
);
445 if (Index
< ProcessCount
)
446 CpuTime
= pPerfData
[Index
].CPUTime
;
448 LeaveCriticalSection(&PerfDataCriticalSection
);
453 ULONG
PerfDataGetWorkingSetSizeBytes(ULONG Index
)
455 ULONG WorkingSetSizeBytes
;
457 EnterCriticalSection(&PerfDataCriticalSection
);
459 if (Index
< ProcessCount
)
460 WorkingSetSizeBytes
= pPerfData
[Index
].WorkingSetSizeBytes
;
462 WorkingSetSizeBytes
= 0;
464 LeaveCriticalSection(&PerfDataCriticalSection
);
466 return WorkingSetSizeBytes
;
469 ULONG
PerfDataGetPeakWorkingSetSizeBytes(ULONG Index
)
471 ULONG PeakWorkingSetSizeBytes
;
473 EnterCriticalSection(&PerfDataCriticalSection
);
475 if (Index
< ProcessCount
)
476 PeakWorkingSetSizeBytes
= pPerfData
[Index
].PeakWorkingSetSizeBytes
;
478 PeakWorkingSetSizeBytes
= 0;
480 LeaveCriticalSection(&PerfDataCriticalSection
);
482 return PeakWorkingSetSizeBytes
;
485 ULONG
PerfDataGetWorkingSetSizeDelta(ULONG Index
)
487 ULONG WorkingSetSizeDelta
;
489 EnterCriticalSection(&PerfDataCriticalSection
);
491 if (Index
< ProcessCount
)
492 WorkingSetSizeDelta
= pPerfData
[Index
].WorkingSetSizeDelta
;
494 WorkingSetSizeDelta
= 0;
496 LeaveCriticalSection(&PerfDataCriticalSection
);
498 return WorkingSetSizeDelta
;
501 ULONG
PerfDataGetPageFaultCount(ULONG Index
)
503 ULONG PageFaultCount
;
505 EnterCriticalSection(&PerfDataCriticalSection
);
507 if (Index
< ProcessCount
)
508 PageFaultCount
= pPerfData
[Index
].PageFaultCount
;
512 LeaveCriticalSection(&PerfDataCriticalSection
);
514 return PageFaultCount
;
517 ULONG
PerfDataGetPageFaultCountDelta(ULONG Index
)
519 ULONG PageFaultCountDelta
;
521 EnterCriticalSection(&PerfDataCriticalSection
);
523 if (Index
< ProcessCount
)
524 PageFaultCountDelta
= pPerfData
[Index
].PageFaultCountDelta
;
526 PageFaultCountDelta
= 0;
528 LeaveCriticalSection(&PerfDataCriticalSection
);
530 return PageFaultCountDelta
;
533 ULONG
PerfDataGetVirtualMemorySizeBytes(ULONG Index
)
535 ULONG VirtualMemorySizeBytes
;
537 EnterCriticalSection(&PerfDataCriticalSection
);
539 if (Index
< ProcessCount
)
540 VirtualMemorySizeBytes
= pPerfData
[Index
].VirtualMemorySizeBytes
;
542 VirtualMemorySizeBytes
= 0;
544 LeaveCriticalSection(&PerfDataCriticalSection
);
546 return VirtualMemorySizeBytes
;
549 ULONG
PerfDataGetPagedPoolUsagePages(ULONG Index
)
551 ULONG PagedPoolUsage
;
553 EnterCriticalSection(&PerfDataCriticalSection
);
555 if (Index
< ProcessCount
)
556 PagedPoolUsage
= pPerfData
[Index
].PagedPoolUsagePages
;
560 LeaveCriticalSection(&PerfDataCriticalSection
);
562 return PagedPoolUsage
;
565 ULONG
PerfDataGetNonPagedPoolUsagePages(ULONG Index
)
567 ULONG NonPagedPoolUsage
;
569 EnterCriticalSection(&PerfDataCriticalSection
);
571 if (Index
< ProcessCount
)
572 NonPagedPoolUsage
= pPerfData
[Index
].NonPagedPoolUsagePages
;
574 NonPagedPoolUsage
= 0;
576 LeaveCriticalSection(&PerfDataCriticalSection
);
578 return NonPagedPoolUsage
;
581 ULONG
PerfDataGetBasePriority(ULONG Index
)
585 EnterCriticalSection(&PerfDataCriticalSection
);
587 if (Index
< ProcessCount
)
588 BasePriority
= pPerfData
[Index
].BasePriority
;
592 LeaveCriticalSection(&PerfDataCriticalSection
);
597 ULONG
PerfDataGetHandleCount(ULONG Index
)
601 EnterCriticalSection(&PerfDataCriticalSection
);
603 if (Index
< ProcessCount
)
604 HandleCount
= pPerfData
[Index
].HandleCount
;
608 LeaveCriticalSection(&PerfDataCriticalSection
);
613 ULONG
PerfDataGetThreadCount(ULONG Index
)
617 EnterCriticalSection(&PerfDataCriticalSection
);
619 if (Index
< ProcessCount
)
620 ThreadCount
= pPerfData
[Index
].ThreadCount
;
624 LeaveCriticalSection(&PerfDataCriticalSection
);
629 ULONG
PerfDataGetUSERObjectCount(ULONG Index
)
631 ULONG USERObjectCount
;
633 EnterCriticalSection(&PerfDataCriticalSection
);
635 if (Index
< ProcessCount
)
636 USERObjectCount
= pPerfData
[Index
].USERObjectCount
;
640 LeaveCriticalSection(&PerfDataCriticalSection
);
642 return USERObjectCount
;
645 ULONG
PerfDataGetGDIObjectCount(ULONG Index
)
647 ULONG GDIObjectCount
;
649 EnterCriticalSection(&PerfDataCriticalSection
);
651 if (Index
< ProcessCount
)
652 GDIObjectCount
= pPerfData
[Index
].GDIObjectCount
;
656 LeaveCriticalSection(&PerfDataCriticalSection
);
658 return GDIObjectCount
;
661 BOOL
PerfDataGetIOCounters(ULONG Index
, PIO_COUNTERS pIoCounters
)
665 EnterCriticalSection(&PerfDataCriticalSection
);
667 if (Index
< ProcessCount
)
669 memcpy(pIoCounters
, &pPerfData
[Index
].IOCounters
, sizeof(IO_COUNTERS
));
675 LeaveCriticalSection(&PerfDataCriticalSection
);
680 ULONG
PerfDataGetCommitChargeTotalK(void)
685 EnterCriticalSection(&PerfDataCriticalSection
);
687 Total
= SystemPerfInfo
.CommittedPages
;
688 PageSize
= SystemBasicInfo
.PageSize
;
690 LeaveCriticalSection(&PerfDataCriticalSection
);
692 Total
= Total
* (PageSize
/ 1024);
697 ULONG
PerfDataGetCommitChargeLimitK(void)
702 EnterCriticalSection(&PerfDataCriticalSection
);
704 Limit
= SystemPerfInfo
.CommitLimit
;
705 PageSize
= SystemBasicInfo
.PageSize
;
707 LeaveCriticalSection(&PerfDataCriticalSection
);
709 Limit
= Limit
* (PageSize
/ 1024);
714 ULONG
PerfDataGetCommitChargePeakK(void)
719 EnterCriticalSection(&PerfDataCriticalSection
);
721 Peak
= SystemPerfInfo
.PeakCommitment
;
722 PageSize
= SystemBasicInfo
.PageSize
;
724 LeaveCriticalSection(&PerfDataCriticalSection
);
726 Peak
= Peak
* (PageSize
/ 1024);
731 ULONG
PerfDataGetKernelMemoryTotalK(void)
738 EnterCriticalSection(&PerfDataCriticalSection
);
740 Paged
= SystemPerfInfo
.PagedPoolPages
;
741 NonPaged
= SystemPerfInfo
.NonPagedPoolPages
;
742 PageSize
= SystemBasicInfo
.PageSize
;
744 LeaveCriticalSection(&PerfDataCriticalSection
);
746 Paged
= Paged
* (PageSize
/ 1024);
747 NonPaged
= NonPaged
* (PageSize
/ 1024);
749 Total
= Paged
+ NonPaged
;
754 ULONG
PerfDataGetKernelMemoryPagedK(void)
759 EnterCriticalSection(&PerfDataCriticalSection
);
761 Paged
= SystemPerfInfo
.PagedPoolPages
;
762 PageSize
= SystemBasicInfo
.PageSize
;
764 LeaveCriticalSection(&PerfDataCriticalSection
);
766 Paged
= Paged
* (PageSize
/ 1024);
771 ULONG
PerfDataGetKernelMemoryNonPagedK(void)
776 EnterCriticalSection(&PerfDataCriticalSection
);
778 NonPaged
= SystemPerfInfo
.NonPagedPoolPages
;
779 PageSize
= SystemBasicInfo
.PageSize
;
781 LeaveCriticalSection(&PerfDataCriticalSection
);
783 NonPaged
= NonPaged
* (PageSize
/ 1024);
788 ULONG
PerfDataGetPhysicalMemoryTotalK(void)
793 EnterCriticalSection(&PerfDataCriticalSection
);
795 Total
= SystemBasicInfo
.NumberOfPhysicalPages
;
796 PageSize
= SystemBasicInfo
.PageSize
;
798 LeaveCriticalSection(&PerfDataCriticalSection
);
800 Total
= Total
* (PageSize
/ 1024);
805 ULONG
PerfDataGetPhysicalMemoryAvailableK(void)
810 EnterCriticalSection(&PerfDataCriticalSection
);
812 Available
= SystemPerfInfo
.AvailablePages
;
813 PageSize
= SystemBasicInfo
.PageSize
;
815 LeaveCriticalSection(&PerfDataCriticalSection
);
817 Available
= Available
* (PageSize
/ 1024);
822 ULONG
PerfDataGetPhysicalMemorySystemCacheK(void)
827 EnterCriticalSection(&PerfDataCriticalSection
);
829 PageSize
= SystemBasicInfo
.PageSize
;
830 SystemCache
= SystemCacheInfo
.CurrentSizeIncludingTransitionInPages
* PageSize
;
832 LeaveCriticalSection(&PerfDataCriticalSection
);
834 return SystemCache
/ 1024;
837 ULONG
PerfDataGetSystemHandleCount(void)
841 EnterCriticalSection(&PerfDataCriticalSection
);
843 HandleCount
= SystemHandleInfo
.NumberOfHandles
;
845 LeaveCriticalSection(&PerfDataCriticalSection
);
850 ULONG
PerfDataGetTotalThreadCount(void)
852 ULONG ThreadCount
= 0;
855 EnterCriticalSection(&PerfDataCriticalSection
);
857 for (i
=0; i
<ProcessCount
; i
++)
859 ThreadCount
+= pPerfData
[i
].ThreadCount
;
862 LeaveCriticalSection(&PerfDataCriticalSection
);