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(SystemCacheInformation
, &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
.NumberProcessors
);
100 status
= NtQuerySystemInformation(SystemProcessorPerformanceInformation
, SysProcessorTimeInfo
, sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) * SystemBasicInfo
.NumberProcessors
, &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
== 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/) {
117 HeapFree(GetProcessHeap(), 0, SysHandleInfoData
);
120 } while (status
== 0xC0000004 /*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
== 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/) {
135 HeapFree(GetProcessHeap(), 0, pBuffer
);
138 } while (status
== 0xC0000004 /*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
<SystemBasicInfo
.NumberProcessors
; 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
.IdleTime
) - 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
.NumberProcessors
; /* + 0.5; */
185 dbKernelTime
= 100.0 - dbKernelTime
* 100.0 / (double)SystemBasicInfo
.NumberProcessors
; /* + 0.5; */
188 /* Store new CPU's idle and system time */
189 liOldIdleTime
= SysPerfInfo
.IdleTime
;
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
.NumberProcessors
; /* + 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
->QuotaPagedPoolUsage
;
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 ULONG
PerfDataGetProcessId(ULONG Index
)
352 EnterCriticalSection(&PerfDataCriticalSection
);
354 if (Index
< ProcessCount
)
355 ProcessId
= (ULONG
)pPerfData
[Index
].ProcessId
;
359 LeaveCriticalSection(&PerfDataCriticalSection
);
364 BOOL
PerfDataGetUserName(ULONG Index
, LPTSTR lpUserName
, int nMaxCount
)
368 EnterCriticalSection(&PerfDataCriticalSection
);
370 if (Index
< ProcessCount
) {
372 wcsncpy(lpUserName
, pPerfData
[Index
].UserName
, nMaxCount
);
374 WideCharToMultiByte(CP_ACP
, 0, pPerfData
[Index
].UserName
, -1, lpUserName
, nMaxCount
, NULL
, NULL
);
382 LeaveCriticalSection(&PerfDataCriticalSection
);
387 ULONG
PerfDataGetSessionId(ULONG Index
)
391 EnterCriticalSection(&PerfDataCriticalSection
);
393 if (Index
< ProcessCount
)
394 SessionId
= pPerfData
[Index
].SessionId
;
398 LeaveCriticalSection(&PerfDataCriticalSection
);
403 ULONG
PerfDataGetCPUUsage(ULONG Index
)
407 EnterCriticalSection(&PerfDataCriticalSection
);
409 if (Index
< ProcessCount
)
410 CpuUsage
= pPerfData
[Index
].CPUUsage
;
414 LeaveCriticalSection(&PerfDataCriticalSection
);
419 TIME
PerfDataGetCPUTime(ULONG Index
)
421 TIME CpuTime
= {{0,0}};
423 EnterCriticalSection(&PerfDataCriticalSection
);
425 if (Index
< ProcessCount
)
426 CpuTime
= pPerfData
[Index
].CPUTime
;
428 LeaveCriticalSection(&PerfDataCriticalSection
);
433 ULONG
PerfDataGetWorkingSetSizeBytes(ULONG Index
)
435 ULONG WorkingSetSizeBytes
;
437 EnterCriticalSection(&PerfDataCriticalSection
);
439 if (Index
< ProcessCount
)
440 WorkingSetSizeBytes
= pPerfData
[Index
].WorkingSetSizeBytes
;
442 WorkingSetSizeBytes
= 0;
444 LeaveCriticalSection(&PerfDataCriticalSection
);
446 return WorkingSetSizeBytes
;
449 ULONG
PerfDataGetPeakWorkingSetSizeBytes(ULONG Index
)
451 ULONG PeakWorkingSetSizeBytes
;
453 EnterCriticalSection(&PerfDataCriticalSection
);
455 if (Index
< ProcessCount
)
456 PeakWorkingSetSizeBytes
= pPerfData
[Index
].PeakWorkingSetSizeBytes
;
458 PeakWorkingSetSizeBytes
= 0;
460 LeaveCriticalSection(&PerfDataCriticalSection
);
462 return PeakWorkingSetSizeBytes
;
465 ULONG
PerfDataGetWorkingSetSizeDelta(ULONG Index
)
467 ULONG WorkingSetSizeDelta
;
469 EnterCriticalSection(&PerfDataCriticalSection
);
471 if (Index
< ProcessCount
)
472 WorkingSetSizeDelta
= pPerfData
[Index
].WorkingSetSizeDelta
;
474 WorkingSetSizeDelta
= 0;
476 LeaveCriticalSection(&PerfDataCriticalSection
);
478 return WorkingSetSizeDelta
;
481 ULONG
PerfDataGetPageFaultCount(ULONG Index
)
483 ULONG PageFaultCount
;
485 EnterCriticalSection(&PerfDataCriticalSection
);
487 if (Index
< ProcessCount
)
488 PageFaultCount
= pPerfData
[Index
].PageFaultCount
;
492 LeaveCriticalSection(&PerfDataCriticalSection
);
494 return PageFaultCount
;
497 ULONG
PerfDataGetPageFaultCountDelta(ULONG Index
)
499 ULONG PageFaultCountDelta
;
501 EnterCriticalSection(&PerfDataCriticalSection
);
503 if (Index
< ProcessCount
)
504 PageFaultCountDelta
= pPerfData
[Index
].PageFaultCountDelta
;
506 PageFaultCountDelta
= 0;
508 LeaveCriticalSection(&PerfDataCriticalSection
);
510 return PageFaultCountDelta
;
513 ULONG
PerfDataGetVirtualMemorySizeBytes(ULONG Index
)
515 ULONG VirtualMemorySizeBytes
;
517 EnterCriticalSection(&PerfDataCriticalSection
);
519 if (Index
< ProcessCount
)
520 VirtualMemorySizeBytes
= pPerfData
[Index
].VirtualMemorySizeBytes
;
522 VirtualMemorySizeBytes
= 0;
524 LeaveCriticalSection(&PerfDataCriticalSection
);
526 return VirtualMemorySizeBytes
;
529 ULONG
PerfDataGetPagedPoolUsagePages(ULONG Index
)
531 ULONG PagedPoolUsagePages
;
533 EnterCriticalSection(&PerfDataCriticalSection
);
535 if (Index
< ProcessCount
)
536 PagedPoolUsagePages
= pPerfData
[Index
].PagedPoolUsagePages
;
538 PagedPoolUsagePages
= 0;
540 LeaveCriticalSection(&PerfDataCriticalSection
);
542 return PagedPoolUsagePages
;
545 ULONG
PerfDataGetNonPagedPoolUsagePages(ULONG Index
)
547 ULONG NonPagedPoolUsagePages
;
549 EnterCriticalSection(&PerfDataCriticalSection
);
551 if (Index
< ProcessCount
)
552 NonPagedPoolUsagePages
= pPerfData
[Index
].NonPagedPoolUsagePages
;
554 NonPagedPoolUsagePages
= 0;
556 LeaveCriticalSection(&PerfDataCriticalSection
);
558 return NonPagedPoolUsagePages
;
561 ULONG
PerfDataGetBasePriority(ULONG Index
)
565 EnterCriticalSection(&PerfDataCriticalSection
);
567 if (Index
< ProcessCount
)
568 BasePriority
= pPerfData
[Index
].BasePriority
;
572 LeaveCriticalSection(&PerfDataCriticalSection
);
577 ULONG
PerfDataGetHandleCount(ULONG Index
)
581 EnterCriticalSection(&PerfDataCriticalSection
);
583 if (Index
< ProcessCount
)
584 HandleCount
= pPerfData
[Index
].HandleCount
;
588 LeaveCriticalSection(&PerfDataCriticalSection
);
593 ULONG
PerfDataGetThreadCount(ULONG Index
)
597 EnterCriticalSection(&PerfDataCriticalSection
);
599 if (Index
< ProcessCount
)
600 ThreadCount
= pPerfData
[Index
].ThreadCount
;
604 LeaveCriticalSection(&PerfDataCriticalSection
);
609 ULONG
PerfDataGetUSERObjectCount(ULONG Index
)
611 ULONG USERObjectCount
;
613 EnterCriticalSection(&PerfDataCriticalSection
);
615 if (Index
< ProcessCount
)
616 USERObjectCount
= pPerfData
[Index
].USERObjectCount
;
620 LeaveCriticalSection(&PerfDataCriticalSection
);
622 return USERObjectCount
;
625 ULONG
PerfDataGetGDIObjectCount(ULONG Index
)
627 ULONG GDIObjectCount
;
629 EnterCriticalSection(&PerfDataCriticalSection
);
631 if (Index
< ProcessCount
)
632 GDIObjectCount
= pPerfData
[Index
].GDIObjectCount
;
636 LeaveCriticalSection(&PerfDataCriticalSection
);
638 return GDIObjectCount
;
641 BOOL
PerfDataGetIOCounters(ULONG Index
, PIO_COUNTERS pIoCounters
)
645 EnterCriticalSection(&PerfDataCriticalSection
);
647 if (Index
< ProcessCount
)
649 memcpy(pIoCounters
, &pPerfData
[Index
].IOCounters
, sizeof(IO_COUNTERS
));
655 LeaveCriticalSection(&PerfDataCriticalSection
);
660 ULONG
PerfDataGetCommitChargeTotalK(void)
665 EnterCriticalSection(&PerfDataCriticalSection
);
667 Total
= SystemPerfInfo
.TotalCommittedPages
;
668 PageSize
= SystemBasicInfo
.PhysicalPageSize
;
670 LeaveCriticalSection(&PerfDataCriticalSection
);
672 Total
= Total
* (PageSize
/ 1024);
677 ULONG
PerfDataGetCommitChargeLimitK(void)
682 EnterCriticalSection(&PerfDataCriticalSection
);
684 Limit
= SystemPerfInfo
.TotalCommitLimit
;
685 PageSize
= SystemBasicInfo
.PhysicalPageSize
;
687 LeaveCriticalSection(&PerfDataCriticalSection
);
689 Limit
= Limit
* (PageSize
/ 1024);
694 ULONG
PerfDataGetCommitChargePeakK(void)
699 EnterCriticalSection(&PerfDataCriticalSection
);
701 Peak
= SystemPerfInfo
.PeakCommitment
;
702 PageSize
= SystemBasicInfo
.PhysicalPageSize
;
704 LeaveCriticalSection(&PerfDataCriticalSection
);
706 Peak
= Peak
* (PageSize
/ 1024);
711 ULONG
PerfDataGetKernelMemoryTotalK(void)
718 EnterCriticalSection(&PerfDataCriticalSection
);
720 Paged
= SystemPerfInfo
.PagedPoolUsage
;
721 NonPaged
= SystemPerfInfo
.NonPagedPoolUsage
;
722 PageSize
= SystemBasicInfo
.PhysicalPageSize
;
724 LeaveCriticalSection(&PerfDataCriticalSection
);
726 Paged
= Paged
* (PageSize
/ 1024);
727 NonPaged
= NonPaged
* (PageSize
/ 1024);
729 Total
= Paged
+ NonPaged
;
734 ULONG
PerfDataGetKernelMemoryPagedK(void)
739 EnterCriticalSection(&PerfDataCriticalSection
);
741 Paged
= SystemPerfInfo
.PagedPoolUsage
;
742 PageSize
= SystemBasicInfo
.PhysicalPageSize
;
744 LeaveCriticalSection(&PerfDataCriticalSection
);
746 Paged
= Paged
* (PageSize
/ 1024);
751 ULONG
PerfDataGetKernelMemoryNonPagedK(void)
756 EnterCriticalSection(&PerfDataCriticalSection
);
758 NonPaged
= SystemPerfInfo
.NonPagedPoolUsage
;
759 PageSize
= SystemBasicInfo
.PhysicalPageSize
;
761 LeaveCriticalSection(&PerfDataCriticalSection
);
763 NonPaged
= NonPaged
* (PageSize
/ 1024);
768 ULONG
PerfDataGetPhysicalMemoryTotalK(void)
773 EnterCriticalSection(&PerfDataCriticalSection
);
775 Total
= SystemBasicInfo
.NumberOfPhysicalPages
;
776 PageSize
= SystemBasicInfo
.PhysicalPageSize
;
778 LeaveCriticalSection(&PerfDataCriticalSection
);
780 Total
= Total
* (PageSize
/ 1024);
785 ULONG
PerfDataGetPhysicalMemoryAvailableK(void)
790 EnterCriticalSection(&PerfDataCriticalSection
);
792 Available
= SystemPerfInfo
.AvailablePages
;
793 PageSize
= SystemBasicInfo
.PhysicalPageSize
;
795 LeaveCriticalSection(&PerfDataCriticalSection
);
797 Available
= Available
* (PageSize
/ 1024);
802 ULONG
PerfDataGetPhysicalMemorySystemCacheK(void)
807 EnterCriticalSection(&PerfDataCriticalSection
);
809 SystemCache
= SystemCacheInfo
.CurrentSize
;
810 PageSize
= SystemBasicInfo
.PhysicalPageSize
;
812 LeaveCriticalSection(&PerfDataCriticalSection
);
814 /* SystemCache = SystemCache * (PageSize / 1024); */
815 SystemCache
= SystemCache
/ 1024;
820 ULONG
PerfDataGetSystemHandleCount(void)
824 EnterCriticalSection(&PerfDataCriticalSection
);
826 HandleCount
= SystemHandleInfo
.NumberOfHandles
;
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
);