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 NtQuerySystemInformation
= 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_PROCESSORTIME_INFO 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 NtQuerySystemInformation
= (PROCNTQSI
)GetProcAddress(GetModuleHandleW(wszNtdll
), "NtQuerySystemInformation");
61 pGetGuiResources
= (PROCGGR
)GetProcAddress(GetModuleHandleW(wszUser32
), "GetGuiResources");
62 pGetProcessIoCounters
= (PROCGPIC
)GetProcAddress(GetModuleHandleW(wszKernel32
), "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 WCHAR wszTemp
[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
= HeapAlloc(GetProcessHeap(), 0,
127 sizeof(SYSTEM_PROCESSORTIME_INFO
) * SystemBasicInfo
.bKeNumberProcessors
);
128 status
= NtQuerySystemInformation(SystemProcessorTimeInformation
, SysProcessorTimeInfo
, sizeof(SYSTEM_PROCESSORTIME_INFO
) * SystemBasicInfo
.bKeNumberProcessors
, &ulSize
);
129 if (status
!= NO_ERROR
) {
130 HeapFree(GetProcessHeap(), 0, SysProcessorTimeInfo
);
134 /* Get handle information
135 * We don't know how much data there is so just keep
136 * increasing the buffer size until the call succeeds
141 BufferSize
+= 0x10000;
142 SysHandleInfoData
= HeapAlloc(GetProcessHeap(), 0, BufferSize
);
144 status
= NtQuerySystemInformation(SystemHandleInformation
, SysHandleInfoData
, BufferSize
, &ulSize
);
146 if (status
== 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/) {
147 HeapFree(GetProcessHeap(), 0, SysHandleInfoData
);
150 } while (status
== 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/);
152 /* Get process information
153 * We don't know how much data there is so just keep
154 * increasing the buffer size until the call succeeds
159 BufferSize
+= 0x10000;
160 pBuffer
= HeapAlloc(GetProcessHeap(), 0, BufferSize
);
162 status
= NtQuerySystemInformation(SystemProcessInformation
, pBuffer
, BufferSize
, &ulSize
);
164 if (status
== 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/) {
165 HeapFree(GetProcessHeap(), 0, pBuffer
);
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 HeapFree(GetProcessHeap(), 0, SystemProcessorTimeInfo
);
186 SystemProcessorTimeInfo
= SysProcessorTimeInfo
;
189 * Save system handle info
191 memcpy(&SystemHandleInfo
, SysHandleInfoData
, sizeof(SYSTEM_HANDLE_INFORMATION
));
192 HeapFree(GetProcessHeap(), 0, SysHandleInfoData
);
194 for (CurrentKernelTime
=0, Idx
=0; Idx
<SystemBasicInfo
.bKeNumberProcessors
; Idx
++) {
195 CurrentKernelTime
+= Li2Double(SystemProcessorTimeInfo
[Idx
].KernelTime
);
196 CurrentKernelTime
+= Li2Double(SystemProcessorTimeInfo
[Idx
].DpcTime
);
197 CurrentKernelTime
+= Li2Double(SystemProcessorTimeInfo
[Idx
].InterruptTime
);
200 /* If it's a first call - skip idle time calcs */
201 if (liOldIdleTime
.QuadPart
!= 0) {
202 /* CurrentValue = NewValue - OldValue */
203 dbIdleTime
= Li2Double(SysPerfInfo
.liIdleTime
) - Li2Double(liOldIdleTime
);
204 dbKernelTime
= CurrentKernelTime
- OldKernelTime
;
205 dbSystemTime
= Li2Double(SysTimeInfo
.liKeSystemTime
) - Li2Double(liOldSystemTime
);
207 /* CurrentCpuIdle = IdleTime / SystemTime */
208 dbIdleTime
= dbIdleTime
/ dbSystemTime
;
209 dbKernelTime
= dbKernelTime
/ dbSystemTime
;
211 /* CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) / NumberOfProcessors */
212 dbIdleTime
= 100.0 - dbIdleTime
* 100.0 / (double)SystemBasicInfo
.bKeNumberProcessors
; /* + 0.5; */
213 dbKernelTime
= 100.0 - dbKernelTime
* 100.0 / (double)SystemBasicInfo
.bKeNumberProcessors
; /* + 0.5; */
216 /* Store new CPU's idle and system time */
217 liOldIdleTime
= SysPerfInfo
.liIdleTime
;
218 liOldSystemTime
= SysTimeInfo
.liKeSystemTime
;
219 OldKernelTime
= CurrentKernelTime
;
221 /* Determine the process count
222 * We loop through the data we got from NtQuerySystemInformation
223 * and count how many structures there are (until RelativeOffset is 0)
225 ProcessCountOld
= ProcessCount
;
227 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)pBuffer
;
230 if (pSPI
->RelativeOffset
== 0)
232 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)((LPBYTE
)pSPI
+ pSPI
->RelativeOffset
);
235 /* Now alloc a new PERFDATA array and fill in the data */
236 HeapFree(GetProcessHeap(), 0, pPerfDataOld
);
237 pPerfDataOld
= pPerfData
;
238 pPerfData
= HeapAlloc(GetProcessHeap(), 0, sizeof(PERFDATA
) * ProcessCount
);
239 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)pBuffer
;
240 for (Idx
=0; Idx
<ProcessCount
; Idx
++) {
241 /* Get the old perf data for this process (if any) */
242 /* so that we can establish delta values */
244 for (Idx2
=0; Idx2
<ProcessCountOld
; Idx2
++) {
245 if (pPerfDataOld
[Idx2
].ProcessId
== pSPI
->ProcessId
) {
246 pPDOld
= &pPerfDataOld
[Idx2
];
251 /* Clear out process perf data structure */
252 memset(&pPerfData
[Idx
], 0, sizeof(PERFDATA
));
254 if (pSPI
->Name
.Buffer
)
255 lstrcpyW(pPerfData
[Idx
].ImageName
, pSPI
->Name
.Buffer
);
259 LoadStringW(hInst
, IDS_SYSTEM_IDLE_PROCESS
, idleW
, sizeof(idleW
)/sizeof(WCHAR
));
260 lstrcpyW(pPerfData
[Idx
].ImageName
, idleW
);
263 pPerfData
[Idx
].ProcessId
= pSPI
->ProcessId
;
266 double CurTime
= Li2Double(pSPI
->KernelTime
) + Li2Double(pSPI
->UserTime
);
267 double OldTime
= Li2Double(pPDOld
->KernelTime
) + Li2Double(pPDOld
->UserTime
);
268 double CpuTime
= (CurTime
- OldTime
) / dbSystemTime
;
269 CpuTime
= CpuTime
* 100.0 / (double)SystemBasicInfo
.bKeNumberProcessors
; /* + 0.5; */
270 pPerfData
[Idx
].CPUUsage
= (ULONG
)CpuTime
;
272 pPerfData
[Idx
].CPUTime
.QuadPart
= pSPI
->UserTime
.QuadPart
+ pSPI
->KernelTime
.QuadPart
;
273 pPerfData
[Idx
].WorkingSetSizeBytes
= pSPI
->TotalWorkingSetSizeBytes
;
274 pPerfData
[Idx
].PeakWorkingSetSizeBytes
= pSPI
->PeakWorkingSetSizeBytes
;
276 pPerfData
[Idx
].WorkingSetSizeDelta
= labs((LONG
)pSPI
->TotalWorkingSetSizeBytes
- (LONG
)pPDOld
->WorkingSetSizeBytes
);
278 pPerfData
[Idx
].WorkingSetSizeDelta
= 0;
279 pPerfData
[Idx
].PageFaultCount
= pSPI
->PageFaultCount
;
281 pPerfData
[Idx
].PageFaultCountDelta
= labs((LONG
)pSPI
->PageFaultCount
- (LONG
)pPDOld
->PageFaultCount
);
283 pPerfData
[Idx
].PageFaultCountDelta
= 0;
284 pPerfData
[Idx
].VirtualMemorySizeBytes
= pSPI
->TotalVirtualSizeBytes
;
285 pPerfData
[Idx
].PagedPoolUsagePages
= pSPI
->TotalPagedPoolUsagePages
;
286 pPerfData
[Idx
].NonPagedPoolUsagePages
= pSPI
->TotalNonPagedPoolUsagePages
;
287 pPerfData
[Idx
].BasePriority
= pSPI
->BasePriority
;
288 pPerfData
[Idx
].HandleCount
= pSPI
->HandleCount
;
289 pPerfData
[Idx
].ThreadCount
= pSPI
->ThreadCount
;
290 pPerfData
[Idx
].SessionId
= pSPI
->SessionId
;
292 hProcess
= OpenProcess(PROCESS_QUERY_INFORMATION
, FALSE
, pSPI
->ProcessId
);
294 if (OpenProcessToken(hProcess
, TOKEN_QUERY
|TOKEN_DUPLICATE
|TOKEN_IMPERSONATE
, &hProcessToken
)) {
295 ImpersonateLoggedOnUser(hProcessToken
);
296 memset(wszTemp
, 0, sizeof(wszTemp
));
298 GetUserNameW(wszTemp
, &dwSize
);
300 CloseHandle(hProcessToken
);
302 if (pGetGuiResources
) {
303 pPerfData
[Idx
].USERObjectCount
= pGetGuiResources(hProcess
, GR_USEROBJECTS
);
304 pPerfData
[Idx
].GDIObjectCount
= pGetGuiResources(hProcess
, GR_GDIOBJECTS
);
306 if (pGetProcessIoCounters
)
307 pGetProcessIoCounters(hProcess
, &pPerfData
[Idx
].IOCounters
);
308 CloseHandle(hProcess
);
310 pPerfData
[Idx
].UserTime
.QuadPart
= pSPI
->UserTime
.QuadPart
;
311 pPerfData
[Idx
].KernelTime
.QuadPart
= pSPI
->KernelTime
.QuadPart
;
312 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)((LPBYTE
)pSPI
+ pSPI
->RelativeOffset
);
314 HeapFree(GetProcessHeap(), 0, pBuffer
);
315 LeaveCriticalSection(&PerfDataCriticalSection
);
318 ULONG
PerfDataGetProcessCount(void)
323 ULONG
PerfDataGetProcessorUsage(void)
325 if( dbIdleTime
< 0.0 )
327 if( dbIdleTime
> 100.0 )
329 return (ULONG
)dbIdleTime
;
332 ULONG
PerfDataGetProcessorSystemUsage(void)
334 if( dbKernelTime
< 0.0 )
336 if( dbKernelTime
> 100.0 )
338 return (ULONG
)dbKernelTime
;
341 BOOL
PerfDataGetImageName(ULONG Index
, LPWSTR lpImageName
, int nMaxCount
)
345 EnterCriticalSection(&PerfDataCriticalSection
);
347 if (Index
< ProcessCount
) {
348 wcsncpy(lpImageName
, pPerfData
[Index
].ImageName
, nMaxCount
);
353 LeaveCriticalSection(&PerfDataCriticalSection
);
357 ULONG
PerfDataGetProcessId(ULONG Index
)
361 EnterCriticalSection(&PerfDataCriticalSection
);
363 if (Index
< ProcessCount
)
364 ProcessId
= pPerfData
[Index
].ProcessId
;
368 LeaveCriticalSection(&PerfDataCriticalSection
);
373 BOOL
PerfDataGetUserName(ULONG Index
, LPWSTR lpUserName
, int nMaxCount
)
377 EnterCriticalSection(&PerfDataCriticalSection
);
379 if (Index
< ProcessCount
) {
380 wcsncpy(lpUserName
, pPerfData
[Index
].UserName
, nMaxCount
);
386 LeaveCriticalSection(&PerfDataCriticalSection
);
391 ULONG
PerfDataGetSessionId(ULONG Index
)
395 EnterCriticalSection(&PerfDataCriticalSection
);
397 if (Index
< ProcessCount
)
398 SessionId
= pPerfData
[Index
].SessionId
;
402 LeaveCriticalSection(&PerfDataCriticalSection
);
407 ULONG
PerfDataGetCPUUsage(ULONG Index
)
411 EnterCriticalSection(&PerfDataCriticalSection
);
413 if (Index
< ProcessCount
)
414 CpuUsage
= pPerfData
[Index
].CPUUsage
;
418 LeaveCriticalSection(&PerfDataCriticalSection
);
423 TIME
PerfDataGetCPUTime(ULONG Index
)
425 TIME CpuTime
= {{0,0}};
427 EnterCriticalSection(&PerfDataCriticalSection
);
429 if (Index
< ProcessCount
)
430 CpuTime
= pPerfData
[Index
].CPUTime
;
432 LeaveCriticalSection(&PerfDataCriticalSection
);
437 ULONG
PerfDataGetWorkingSetSizeBytes(ULONG Index
)
439 ULONG WorkingSetSizeBytes
;
441 EnterCriticalSection(&PerfDataCriticalSection
);
443 if (Index
< ProcessCount
)
444 WorkingSetSizeBytes
= pPerfData
[Index
].WorkingSetSizeBytes
;
446 WorkingSetSizeBytes
= 0;
448 LeaveCriticalSection(&PerfDataCriticalSection
);
450 return WorkingSetSizeBytes
;
453 ULONG
PerfDataGetPeakWorkingSetSizeBytes(ULONG Index
)
455 ULONG PeakWorkingSetSizeBytes
;
457 EnterCriticalSection(&PerfDataCriticalSection
);
459 if (Index
< ProcessCount
)
460 PeakWorkingSetSizeBytes
= pPerfData
[Index
].PeakWorkingSetSizeBytes
;
462 PeakWorkingSetSizeBytes
= 0;
464 LeaveCriticalSection(&PerfDataCriticalSection
);
466 return PeakWorkingSetSizeBytes
;
469 ULONG
PerfDataGetWorkingSetSizeDelta(ULONG Index
)
471 ULONG WorkingSetSizeDelta
;
473 EnterCriticalSection(&PerfDataCriticalSection
);
475 if (Index
< ProcessCount
)
476 WorkingSetSizeDelta
= pPerfData
[Index
].WorkingSetSizeDelta
;
478 WorkingSetSizeDelta
= 0;
480 LeaveCriticalSection(&PerfDataCriticalSection
);
482 return WorkingSetSizeDelta
;
485 ULONG
PerfDataGetPageFaultCount(ULONG Index
)
487 ULONG PageFaultCount
;
489 EnterCriticalSection(&PerfDataCriticalSection
);
491 if (Index
< ProcessCount
)
492 PageFaultCount
= pPerfData
[Index
].PageFaultCount
;
496 LeaveCriticalSection(&PerfDataCriticalSection
);
498 return PageFaultCount
;
501 ULONG
PerfDataGetPageFaultCountDelta(ULONG Index
)
503 ULONG PageFaultCountDelta
;
505 EnterCriticalSection(&PerfDataCriticalSection
);
507 if (Index
< ProcessCount
)
508 PageFaultCountDelta
= pPerfData
[Index
].PageFaultCountDelta
;
510 PageFaultCountDelta
= 0;
512 LeaveCriticalSection(&PerfDataCriticalSection
);
514 return PageFaultCountDelta
;
517 ULONG
PerfDataGetVirtualMemorySizeBytes(ULONG Index
)
519 ULONG VirtualMemorySizeBytes
;
521 EnterCriticalSection(&PerfDataCriticalSection
);
523 if (Index
< ProcessCount
)
524 VirtualMemorySizeBytes
= pPerfData
[Index
].VirtualMemorySizeBytes
;
526 VirtualMemorySizeBytes
= 0;
528 LeaveCriticalSection(&PerfDataCriticalSection
);
530 return VirtualMemorySizeBytes
;
533 ULONG
PerfDataGetPagedPoolUsagePages(ULONG Index
)
535 ULONG PagedPoolUsagePages
;
537 EnterCriticalSection(&PerfDataCriticalSection
);
539 if (Index
< ProcessCount
)
540 PagedPoolUsagePages
= pPerfData
[Index
].PagedPoolUsagePages
;
542 PagedPoolUsagePages
= 0;
544 LeaveCriticalSection(&PerfDataCriticalSection
);
546 return PagedPoolUsagePages
;
549 ULONG
PerfDataGetNonPagedPoolUsagePages(ULONG Index
)
551 ULONG NonPagedPoolUsagePages
;
553 EnterCriticalSection(&PerfDataCriticalSection
);
555 if (Index
< ProcessCount
)
556 NonPagedPoolUsagePages
= pPerfData
[Index
].NonPagedPoolUsagePages
;
558 NonPagedPoolUsagePages
= 0;
560 LeaveCriticalSection(&PerfDataCriticalSection
);
562 return NonPagedPoolUsagePages
;
565 ULONG
PerfDataGetBasePriority(ULONG Index
)
569 EnterCriticalSection(&PerfDataCriticalSection
);
571 if (Index
< ProcessCount
)
572 BasePriority
= pPerfData
[Index
].BasePriority
;
576 LeaveCriticalSection(&PerfDataCriticalSection
);
581 ULONG
PerfDataGetHandleCount(ULONG Index
)
585 EnterCriticalSection(&PerfDataCriticalSection
);
587 if (Index
< ProcessCount
)
588 HandleCount
= pPerfData
[Index
].HandleCount
;
592 LeaveCriticalSection(&PerfDataCriticalSection
);
597 ULONG
PerfDataGetThreadCount(ULONG Index
)
601 EnterCriticalSection(&PerfDataCriticalSection
);
603 if (Index
< ProcessCount
)
604 ThreadCount
= pPerfData
[Index
].ThreadCount
;
608 LeaveCriticalSection(&PerfDataCriticalSection
);
613 ULONG
PerfDataGetUSERObjectCount(ULONG Index
)
615 ULONG USERObjectCount
;
617 EnterCriticalSection(&PerfDataCriticalSection
);
619 if (Index
< ProcessCount
)
620 USERObjectCount
= pPerfData
[Index
].USERObjectCount
;
624 LeaveCriticalSection(&PerfDataCriticalSection
);
626 return USERObjectCount
;
629 ULONG
PerfDataGetGDIObjectCount(ULONG Index
)
631 ULONG GDIObjectCount
;
633 EnterCriticalSection(&PerfDataCriticalSection
);
635 if (Index
< ProcessCount
)
636 GDIObjectCount
= pPerfData
[Index
].GDIObjectCount
;
640 LeaveCriticalSection(&PerfDataCriticalSection
);
642 return GDIObjectCount
;
645 BOOL
PerfDataGetIOCounters(ULONG Index
, PIO_COUNTERS pIoCounters
)
649 EnterCriticalSection(&PerfDataCriticalSection
);
651 if (Index
< ProcessCount
)
653 memcpy(pIoCounters
, &pPerfData
[Index
].IOCounters
, sizeof(IO_COUNTERS
));
659 LeaveCriticalSection(&PerfDataCriticalSection
);
664 ULONG
PerfDataGetCommitChargeTotalK(void)
669 EnterCriticalSection(&PerfDataCriticalSection
);
671 Total
= SystemPerfInfo
.MmTotalCommittedPages
;
672 PageSize
= SystemBasicInfo
.uPageSize
;
674 LeaveCriticalSection(&PerfDataCriticalSection
);
676 Total
= Total
* (PageSize
/ 1024);
681 ULONG
PerfDataGetCommitChargeLimitK(void)
686 EnterCriticalSection(&PerfDataCriticalSection
);
688 Limit
= SystemPerfInfo
.MmTotalCommitLimit
;
689 PageSize
= SystemBasicInfo
.uPageSize
;
691 LeaveCriticalSection(&PerfDataCriticalSection
);
693 Limit
= Limit
* (PageSize
/ 1024);
698 ULONG
PerfDataGetCommitChargePeakK(void)
703 EnterCriticalSection(&PerfDataCriticalSection
);
705 Peak
= SystemPerfInfo
.MmPeakLimit
;
706 PageSize
= SystemBasicInfo
.uPageSize
;
708 LeaveCriticalSection(&PerfDataCriticalSection
);
710 Peak
= Peak
* (PageSize
/ 1024);
715 ULONG
PerfDataGetKernelMemoryTotalK(void)
722 EnterCriticalSection(&PerfDataCriticalSection
);
724 Paged
= SystemPerfInfo
.PoolPagedBytes
;
725 NonPaged
= SystemPerfInfo
.PoolNonPagedBytes
;
726 PageSize
= SystemBasicInfo
.uPageSize
;
728 LeaveCriticalSection(&PerfDataCriticalSection
);
730 Paged
= Paged
* (PageSize
/ 1024);
731 NonPaged
= NonPaged
* (PageSize
/ 1024);
733 Total
= Paged
+ NonPaged
;
738 ULONG
PerfDataGetKernelMemoryPagedK(void)
743 EnterCriticalSection(&PerfDataCriticalSection
);
745 Paged
= SystemPerfInfo
.PoolPagedBytes
;
746 PageSize
= SystemBasicInfo
.uPageSize
;
748 LeaveCriticalSection(&PerfDataCriticalSection
);
750 Paged
= Paged
* (PageSize
/ 1024);
755 ULONG
PerfDataGetKernelMemoryNonPagedK(void)
760 EnterCriticalSection(&PerfDataCriticalSection
);
762 NonPaged
= SystemPerfInfo
.PoolNonPagedBytes
;
763 PageSize
= SystemBasicInfo
.uPageSize
;
765 LeaveCriticalSection(&PerfDataCriticalSection
);
767 NonPaged
= NonPaged
* (PageSize
/ 1024);
772 ULONG
PerfDataGetPhysicalMemoryTotalK(void)
777 EnterCriticalSection(&PerfDataCriticalSection
);
779 Total
= SystemBasicInfo
.uMmNumberOfPhysicalPages
;
780 PageSize
= SystemBasicInfo
.uPageSize
;
782 LeaveCriticalSection(&PerfDataCriticalSection
);
784 Total
= Total
* (PageSize
/ 1024);
789 ULONG
PerfDataGetPhysicalMemoryAvailableK(void)
794 EnterCriticalSection(&PerfDataCriticalSection
);
796 Available
= SystemPerfInfo
.MmAvailablePages
;
797 PageSize
= SystemBasicInfo
.uPageSize
;
799 LeaveCriticalSection(&PerfDataCriticalSection
);
801 Available
= Available
* (PageSize
/ 1024);
806 ULONG
PerfDataGetPhysicalMemorySystemCacheK(void)
810 EnterCriticalSection(&PerfDataCriticalSection
);
812 SystemCache
= SystemCacheInfo
.CurrentSize
;
814 LeaveCriticalSection(&PerfDataCriticalSection
);
816 SystemCache
= SystemCache
/ 1024;
821 ULONG
PerfDataGetSystemHandleCount(void)
825 EnterCriticalSection(&PerfDataCriticalSection
);
827 HandleCount
= SystemHandleInfo
.Count
;
829 LeaveCriticalSection(&PerfDataCriticalSection
);
834 ULONG
PerfDataGetTotalThreadCount(void)
836 ULONG ThreadCount
= 0;
839 EnterCriticalSection(&PerfDataCriticalSection
);
841 for (i
=0; i
<ProcessCount
; i
++)
843 ThreadCount
+= pPerfData
[i
].ThreadCount
;
846 LeaveCriticalSection(&PerfDataCriticalSection
);