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
23 #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
35 static PROCNTQSI NtQuerySystemInformation
= NULL
;
36 static PROCGGR pGetGuiResources
= NULL
;
37 static PROCGPIC pGetProcessIoCounters
= NULL
;
38 static CRITICAL_SECTION PerfDataCriticalSection
;
39 static PPERFDATA pPerfDataOld
= NULL
; /* Older perf data (saved to establish delta values) */
40 static PPERFDATA pPerfData
= NULL
; /* Most recent copy of perf data */
41 static ULONG ProcessCountOld
= 0;
42 static ULONG ProcessCount
= 0;
43 static double dbIdleTime
;
44 static double dbKernelTime
;
45 static double dbSystemTime
;
46 static LARGE_INTEGER liOldIdleTime
= {{0,0}};
47 static double OldKernelTime
= 0;
48 static LARGE_INTEGER liOldSystemTime
= {{0,0}};
49 static SYSTEM_PERFORMANCE_INFORMATION SystemPerfInfo
;
50 static SYSTEM_BASIC_INFORMATION SystemBasicInfo
;
51 static SYSTEM_CACHE_INFORMATION SystemCacheInfo
;
52 static SYSTEM_HANDLE_INFORMATION SystemHandleInfo
;
53 static PSYSTEM_PROCESSORTIME_INFO SystemProcessorTimeInfo
= NULL
;
55 BOOL
PerfDataInitialize(void)
59 NtQuerySystemInformation
= (PROCNTQSI
)GetProcAddress(GetModuleHandle(_T("ntdll.dll")), "NtQuerySystemInformation");
60 pGetGuiResources
= (PROCGGR
)GetProcAddress(GetModuleHandle(_T("user32.dll")), "GetGuiResources");
61 pGetProcessIoCounters
= (PROCGPIC
)GetProcAddress(GetModuleHandle(_T("kernel32.dll")), "GetProcessIoCounters");
63 InitializeCriticalSection(&PerfDataCriticalSection
);
65 if (!NtQuerySystemInformation
)
69 * Get number of processors in the system
71 status
= NtQuerySystemInformation(SystemBasicInformation
, &SystemBasicInfo
, sizeof(SystemBasicInfo
), NULL
);
72 if (status
!= NO_ERROR
)
78 void PerfDataUninitialize(void)
80 NtQuerySystemInformation
= NULL
;
82 DeleteCriticalSection(&PerfDataCriticalSection
);
85 void PerfDataRefresh(void)
91 PSYSTEM_PROCESS_INFORMATION pSPI
;
96 TCHAR szTemp
[MAX_PATH
];
98 SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo
;
99 SYSTEM_TIME_INFORMATION SysTimeInfo
;
100 SYSTEM_CACHE_INFORMATION SysCacheInfo
;
101 LPBYTE SysHandleInfoData
;
102 PSYSTEM_PROCESSORTIME_INFO SysProcessorTimeInfo
;
103 double CurrentKernelTime
;
106 if (!NtQuerySystemInformation
)
109 /* Get new system time */
110 status
= NtQuerySystemInformation(SystemTimeInformation
, &SysTimeInfo
, sizeof(SysTimeInfo
), 0);
111 if (status
!= NO_ERROR
)
114 /* Get new CPU's idle time */
115 status
= NtQuerySystemInformation(SystemPerformanceInformation
, &SysPerfInfo
, sizeof(SysPerfInfo
), NULL
);
116 if (status
!= NO_ERROR
)
119 /* Get system cache information */
120 status
= NtQuerySystemInformation(SystemCacheInformation
, &SysCacheInfo
, sizeof(SysCacheInfo
), NULL
);
121 if (status
!= NO_ERROR
)
124 /* Get processor time information */
125 SysProcessorTimeInfo
= (PSYSTEM_PROCESSORTIME_INFO
)malloc(sizeof(SYSTEM_PROCESSORTIME_INFO
) * SystemBasicInfo
.bKeNumberProcessors
);
126 status
= NtQuerySystemInformation(SystemProcessorTimeInformation
, SysProcessorTimeInfo
, sizeof(SYSTEM_PROCESSORTIME_INFO
) * SystemBasicInfo
.bKeNumberProcessors
, &ulSize
);
127 if (status
!= NO_ERROR
) {
128 free(SysProcessorTimeInfo
);
132 /* Get handle information
133 * We don't know how much data there is so just keep
134 * increasing the buffer size until the call succeeds
139 BufferSize
+= 0x10000;
140 SysHandleInfoData
= (LPBYTE
)malloc(BufferSize
);
142 status
= NtQuerySystemInformation(SystemHandleInformation
, SysHandleInfoData
, BufferSize
, &ulSize
);
144 if (status
== 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/) {
145 free(SysHandleInfoData
);
148 } while (status
== 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/);
150 /* Get process information
151 * We don't know how much data there is so just keep
152 * increasing the buffer size until the call succeeds
157 BufferSize
+= 0x10000;
158 pBuffer
= (LPBYTE
)malloc(BufferSize
);
160 status
= NtQuerySystemInformation(SystemProcessInformation
, pBuffer
, BufferSize
, &ulSize
);
162 if (status
== 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/) {
166 } while (status
== 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/);
168 EnterCriticalSection(&PerfDataCriticalSection
);
171 * Save system performance info
173 memcpy(&SystemPerfInfo
, &SysPerfInfo
, sizeof(SYSTEM_PERFORMANCE_INFORMATION
));
176 * Save system cache info
178 memcpy(&SystemCacheInfo
, &SysCacheInfo
, sizeof(SYSTEM_CACHE_INFORMATION
));
181 * Save system processor time info
183 free(SystemProcessorTimeInfo
);
184 SystemProcessorTimeInfo
= SysProcessorTimeInfo
;
187 * Save system handle info
189 memcpy(&SystemHandleInfo
, SysHandleInfoData
, sizeof(SYSTEM_HANDLE_INFORMATION
));
190 free(SysHandleInfoData
);
192 for (CurrentKernelTime
=0, Idx
=0; Idx
<SystemBasicInfo
.bKeNumberProcessors
; Idx
++) {
193 CurrentKernelTime
+= Li2Double(SystemProcessorTimeInfo
[Idx
].KernelTime
);
194 CurrentKernelTime
+= Li2Double(SystemProcessorTimeInfo
[Idx
].DpcTime
);
195 CurrentKernelTime
+= Li2Double(SystemProcessorTimeInfo
[Idx
].InterruptTime
);
198 /* If it's a first call - skip idle time calcs */
199 if (liOldIdleTime
.QuadPart
!= 0) {
200 /* CurrentValue = NewValue - OldValue */
201 dbIdleTime
= Li2Double(SysPerfInfo
.liIdleTime
) - Li2Double(liOldIdleTime
);
202 dbKernelTime
= CurrentKernelTime
- OldKernelTime
;
203 dbSystemTime
= Li2Double(SysTimeInfo
.liKeSystemTime
) - Li2Double(liOldSystemTime
);
205 /* CurrentCpuIdle = IdleTime / SystemTime */
206 dbIdleTime
= dbIdleTime
/ dbSystemTime
;
207 dbKernelTime
= dbKernelTime
/ dbSystemTime
;
209 /* CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) / NumberOfProcessors */
210 dbIdleTime
= 100.0 - dbIdleTime
* 100.0 / (double)SystemBasicInfo
.bKeNumberProcessors
; /* + 0.5; */
211 dbKernelTime
= 100.0 - dbKernelTime
* 100.0 / (double)SystemBasicInfo
.bKeNumberProcessors
; /* + 0.5; */
214 /* Store new CPU's idle and system time */
215 liOldIdleTime
= SysPerfInfo
.liIdleTime
;
216 liOldSystemTime
= SysTimeInfo
.liKeSystemTime
;
217 OldKernelTime
= CurrentKernelTime
;
219 /* Determine the process count
220 * We loop through the data we got from NtQuerySystemInformation
221 * and count how many structures there are (until RelativeOffset is 0)
223 ProcessCountOld
= ProcessCount
;
225 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)pBuffer
;
228 if (pSPI
->RelativeOffset
== 0)
230 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)((LPBYTE
)pSPI
+ pSPI
->RelativeOffset
);
233 /* Now alloc a new PERFDATA array and fill in the data */
235 pPerfDataOld
= pPerfData
;
236 pPerfData
= (PPERFDATA
)malloc(sizeof(PERFDATA
) * ProcessCount
);
237 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)pBuffer
;
238 for (Idx
=0; Idx
<ProcessCount
; Idx
++) {
239 /* Get the old perf data for this process (if any) */
240 /* so that we can establish delta values */
242 for (Idx2
=0; Idx2
<ProcessCountOld
; Idx2
++) {
243 if (pPerfDataOld
[Idx2
].ProcessId
== pSPI
->ProcessId
) {
244 pPDOld
= &pPerfDataOld
[Idx2
];
249 /* Clear out process perf data structure */
250 memset(&pPerfData
[Idx
], 0, sizeof(PERFDATA
));
252 if (pSPI
->Name
.Buffer
)
253 lstrcpyW(pPerfData
[Idx
].ImageName
, pSPI
->Name
.Buffer
);
256 static const WCHAR idleW
[] = {'S','y','s','t','e','m',' ','I','d','l','e',' ','P','r','o','c','e','s','s',0};
257 lstrcpyW(pPerfData
[Idx
].ImageName
, idleW
);
260 pPerfData
[Idx
].ProcessId
= pSPI
->ProcessId
;
263 double CurTime
= Li2Double(pSPI
->KernelTime
) + Li2Double(pSPI
->UserTime
);
264 double OldTime
= Li2Double(pPDOld
->KernelTime
) + Li2Double(pPDOld
->UserTime
);
265 double CpuTime
= (CurTime
- OldTime
) / dbSystemTime
;
266 CpuTime
= CpuTime
* 100.0 / (double)SystemBasicInfo
.bKeNumberProcessors
; /* + 0.5; */
267 pPerfData
[Idx
].CPUUsage
= (ULONG
)CpuTime
;
269 pPerfData
[Idx
].CPUTime
.QuadPart
= pSPI
->UserTime
.QuadPart
+ pSPI
->KernelTime
.QuadPart
;
270 pPerfData
[Idx
].WorkingSetSizeBytes
= pSPI
->TotalWorkingSetSizeBytes
;
271 pPerfData
[Idx
].PeakWorkingSetSizeBytes
= pSPI
->PeakWorkingSetSizeBytes
;
273 pPerfData
[Idx
].WorkingSetSizeDelta
= labs((LONG
)pSPI
->TotalWorkingSetSizeBytes
- (LONG
)pPDOld
->WorkingSetSizeBytes
);
275 pPerfData
[Idx
].WorkingSetSizeDelta
= 0;
276 pPerfData
[Idx
].PageFaultCount
= pSPI
->PageFaultCount
;
278 pPerfData
[Idx
].PageFaultCountDelta
= labs((LONG
)pSPI
->PageFaultCount
- (LONG
)pPDOld
->PageFaultCount
);
280 pPerfData
[Idx
].PageFaultCountDelta
= 0;
281 pPerfData
[Idx
].VirtualMemorySizeBytes
= pSPI
->TotalVirtualSizeBytes
;
282 pPerfData
[Idx
].PagedPoolUsagePages
= pSPI
->TotalPagedPoolUsagePages
;
283 pPerfData
[Idx
].NonPagedPoolUsagePages
= pSPI
->TotalNonPagedPoolUsagePages
;
284 pPerfData
[Idx
].BasePriority
= pSPI
->BasePriority
;
285 pPerfData
[Idx
].HandleCount
= pSPI
->HandleCount
;
286 pPerfData
[Idx
].ThreadCount
= pSPI
->ThreadCount
;
287 pPerfData
[Idx
].SessionId
= pSPI
->SessionId
;
289 hProcess
= OpenProcess(PROCESS_QUERY_INFORMATION
, FALSE
, pSPI
->ProcessId
);
291 if (OpenProcessToken(hProcess
, TOKEN_QUERY
|TOKEN_DUPLICATE
|TOKEN_IMPERSONATE
, &hProcessToken
)) {
292 ImpersonateLoggedOnUser(hProcessToken
);
293 memset(szTemp
, 0, sizeof(TCHAR
[MAX_PATH
]));
295 GetUserName(szTemp
, &dwSize
);
297 MultiByteToWideChar(CP_ACP
, MB_PRECOMPOSED
, szTemp
, -1, pPerfData
[Idx
].UserName
, MAX_PATH
);
299 int MultiByteToWideChar(
300 UINT CodePage, // code page
301 DWORD dwFlags, // character-type options
302 LPCSTR lpMultiByteStr, // string to map
303 int cbMultiByte, // number of bytes in string
304 LPWSTR lpWideCharStr, // wide-character buffer
305 int cchWideChar // size of buffer
310 CloseHandle(hProcessToken
);
312 if (pGetGuiResources
) {
313 pPerfData
[Idx
].USERObjectCount
= pGetGuiResources(hProcess
, GR_USEROBJECTS
);
314 pPerfData
[Idx
].GDIObjectCount
= pGetGuiResources(hProcess
, GR_GDIOBJECTS
);
316 if (pGetProcessIoCounters
)
317 pGetProcessIoCounters(hProcess
, &pPerfData
[Idx
].IOCounters
);
318 CloseHandle(hProcess
);
320 pPerfData
[Idx
].UserTime
.QuadPart
= pSPI
->UserTime
.QuadPart
;
321 pPerfData
[Idx
].KernelTime
.QuadPart
= pSPI
->KernelTime
.QuadPart
;
322 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)((LPBYTE
)pSPI
+ pSPI
->RelativeOffset
);
325 LeaveCriticalSection(&PerfDataCriticalSection
);
328 ULONG
PerfDataGetProcessCount(void)
333 ULONG
PerfDataGetProcessorUsage(void)
335 if( dbIdleTime
< 0.0 )
337 if( dbIdleTime
> 100.0 )
339 return (ULONG
)dbIdleTime
;
342 ULONG
PerfDataGetProcessorSystemUsage(void)
344 if( dbKernelTime
< 0.0 )
346 if( dbKernelTime
> 100.0 )
348 return (ULONG
)dbKernelTime
;
351 BOOL
PerfDataGetImageName(ULONG Index
, LPTSTR lpImageName
, int nMaxCount
)
355 EnterCriticalSection(&PerfDataCriticalSection
);
357 if (Index
< ProcessCount
) {
359 wcsncpy(lpImageName
, pPerfData
[Index
].ImageName
, nMaxCount
);
361 WideCharToMultiByte(CP_ACP
, 0, pPerfData
[Index
].ImageName
, -1, lpImageName
, nMaxCount
, NULL
, NULL
);
368 LeaveCriticalSection(&PerfDataCriticalSection
);
372 ULONG
PerfDataGetProcessId(ULONG Index
)
376 EnterCriticalSection(&PerfDataCriticalSection
);
378 if (Index
< ProcessCount
)
379 ProcessId
= pPerfData
[Index
].ProcessId
;
383 LeaveCriticalSection(&PerfDataCriticalSection
);
388 BOOL
PerfDataGetUserName(ULONG Index
, LPTSTR lpUserName
, int nMaxCount
)
392 EnterCriticalSection(&PerfDataCriticalSection
);
394 if (Index
< ProcessCount
) {
396 wcsncpy(lpUserName
, pPerfData
[Index
].UserName
, nMaxCount
);
398 WideCharToMultiByte(CP_ACP
, 0, pPerfData
[Index
].UserName
, -1, lpUserName
, nMaxCount
, NULL
, NULL
);
406 LeaveCriticalSection(&PerfDataCriticalSection
);
411 ULONG
PerfDataGetSessionId(ULONG Index
)
415 EnterCriticalSection(&PerfDataCriticalSection
);
417 if (Index
< ProcessCount
)
418 SessionId
= pPerfData
[Index
].SessionId
;
422 LeaveCriticalSection(&PerfDataCriticalSection
);
427 ULONG
PerfDataGetCPUUsage(ULONG Index
)
431 EnterCriticalSection(&PerfDataCriticalSection
);
433 if (Index
< ProcessCount
)
434 CpuUsage
= pPerfData
[Index
].CPUUsage
;
438 LeaveCriticalSection(&PerfDataCriticalSection
);
443 TIME
PerfDataGetCPUTime(ULONG Index
)
445 TIME CpuTime
= {{0,0}};
447 EnterCriticalSection(&PerfDataCriticalSection
);
449 if (Index
< ProcessCount
)
450 CpuTime
= pPerfData
[Index
].CPUTime
;
452 LeaveCriticalSection(&PerfDataCriticalSection
);
457 ULONG
PerfDataGetWorkingSetSizeBytes(ULONG Index
)
459 ULONG WorkingSetSizeBytes
;
461 EnterCriticalSection(&PerfDataCriticalSection
);
463 if (Index
< ProcessCount
)
464 WorkingSetSizeBytes
= pPerfData
[Index
].WorkingSetSizeBytes
;
466 WorkingSetSizeBytes
= 0;
468 LeaveCriticalSection(&PerfDataCriticalSection
);
470 return WorkingSetSizeBytes
;
473 ULONG
PerfDataGetPeakWorkingSetSizeBytes(ULONG Index
)
475 ULONG PeakWorkingSetSizeBytes
;
477 EnterCriticalSection(&PerfDataCriticalSection
);
479 if (Index
< ProcessCount
)
480 PeakWorkingSetSizeBytes
= pPerfData
[Index
].PeakWorkingSetSizeBytes
;
482 PeakWorkingSetSizeBytes
= 0;
484 LeaveCriticalSection(&PerfDataCriticalSection
);
486 return PeakWorkingSetSizeBytes
;
489 ULONG
PerfDataGetWorkingSetSizeDelta(ULONG Index
)
491 ULONG WorkingSetSizeDelta
;
493 EnterCriticalSection(&PerfDataCriticalSection
);
495 if (Index
< ProcessCount
)
496 WorkingSetSizeDelta
= pPerfData
[Index
].WorkingSetSizeDelta
;
498 WorkingSetSizeDelta
= 0;
500 LeaveCriticalSection(&PerfDataCriticalSection
);
502 return WorkingSetSizeDelta
;
505 ULONG
PerfDataGetPageFaultCount(ULONG Index
)
507 ULONG PageFaultCount
;
509 EnterCriticalSection(&PerfDataCriticalSection
);
511 if (Index
< ProcessCount
)
512 PageFaultCount
= pPerfData
[Index
].PageFaultCount
;
516 LeaveCriticalSection(&PerfDataCriticalSection
);
518 return PageFaultCount
;
521 ULONG
PerfDataGetPageFaultCountDelta(ULONG Index
)
523 ULONG PageFaultCountDelta
;
525 EnterCriticalSection(&PerfDataCriticalSection
);
527 if (Index
< ProcessCount
)
528 PageFaultCountDelta
= pPerfData
[Index
].PageFaultCountDelta
;
530 PageFaultCountDelta
= 0;
532 LeaveCriticalSection(&PerfDataCriticalSection
);
534 return PageFaultCountDelta
;
537 ULONG
PerfDataGetVirtualMemorySizeBytes(ULONG Index
)
539 ULONG VirtualMemorySizeBytes
;
541 EnterCriticalSection(&PerfDataCriticalSection
);
543 if (Index
< ProcessCount
)
544 VirtualMemorySizeBytes
= pPerfData
[Index
].VirtualMemorySizeBytes
;
546 VirtualMemorySizeBytes
= 0;
548 LeaveCriticalSection(&PerfDataCriticalSection
);
550 return VirtualMemorySizeBytes
;
553 ULONG
PerfDataGetPagedPoolUsagePages(ULONG Index
)
555 ULONG PagedPoolUsagePages
;
557 EnterCriticalSection(&PerfDataCriticalSection
);
559 if (Index
< ProcessCount
)
560 PagedPoolUsagePages
= pPerfData
[Index
].PagedPoolUsagePages
;
562 PagedPoolUsagePages
= 0;
564 LeaveCriticalSection(&PerfDataCriticalSection
);
566 return PagedPoolUsagePages
;
569 ULONG
PerfDataGetNonPagedPoolUsagePages(ULONG Index
)
571 ULONG NonPagedPoolUsagePages
;
573 EnterCriticalSection(&PerfDataCriticalSection
);
575 if (Index
< ProcessCount
)
576 NonPagedPoolUsagePages
= pPerfData
[Index
].NonPagedPoolUsagePages
;
578 NonPagedPoolUsagePages
= 0;
580 LeaveCriticalSection(&PerfDataCriticalSection
);
582 return NonPagedPoolUsagePages
;
585 ULONG
PerfDataGetBasePriority(ULONG Index
)
589 EnterCriticalSection(&PerfDataCriticalSection
);
591 if (Index
< ProcessCount
)
592 BasePriority
= pPerfData
[Index
].BasePriority
;
596 LeaveCriticalSection(&PerfDataCriticalSection
);
601 ULONG
PerfDataGetHandleCount(ULONG Index
)
605 EnterCriticalSection(&PerfDataCriticalSection
);
607 if (Index
< ProcessCount
)
608 HandleCount
= pPerfData
[Index
].HandleCount
;
612 LeaveCriticalSection(&PerfDataCriticalSection
);
617 ULONG
PerfDataGetThreadCount(ULONG Index
)
621 EnterCriticalSection(&PerfDataCriticalSection
);
623 if (Index
< ProcessCount
)
624 ThreadCount
= pPerfData
[Index
].ThreadCount
;
628 LeaveCriticalSection(&PerfDataCriticalSection
);
633 ULONG
PerfDataGetUSERObjectCount(ULONG Index
)
635 ULONG USERObjectCount
;
637 EnterCriticalSection(&PerfDataCriticalSection
);
639 if (Index
< ProcessCount
)
640 USERObjectCount
= pPerfData
[Index
].USERObjectCount
;
644 LeaveCriticalSection(&PerfDataCriticalSection
);
646 return USERObjectCount
;
649 ULONG
PerfDataGetGDIObjectCount(ULONG Index
)
651 ULONG GDIObjectCount
;
653 EnterCriticalSection(&PerfDataCriticalSection
);
655 if (Index
< ProcessCount
)
656 GDIObjectCount
= pPerfData
[Index
].GDIObjectCount
;
660 LeaveCriticalSection(&PerfDataCriticalSection
);
662 return GDIObjectCount
;
665 BOOL
PerfDataGetIOCounters(ULONG Index
, PIO_COUNTERS pIoCounters
)
669 EnterCriticalSection(&PerfDataCriticalSection
);
671 if (Index
< ProcessCount
)
673 memcpy(pIoCounters
, &pPerfData
[Index
].IOCounters
, sizeof(IO_COUNTERS
));
679 LeaveCriticalSection(&PerfDataCriticalSection
);
684 ULONG
PerfDataGetCommitChargeTotalK(void)
689 EnterCriticalSection(&PerfDataCriticalSection
);
691 Total
= SystemPerfInfo
.MmTotalCommittedPages
;
692 PageSize
= SystemBasicInfo
.uPageSize
;
694 LeaveCriticalSection(&PerfDataCriticalSection
);
696 Total
= Total
* (PageSize
/ 1024);
701 ULONG
PerfDataGetCommitChargeLimitK(void)
706 EnterCriticalSection(&PerfDataCriticalSection
);
708 Limit
= SystemPerfInfo
.MmTotalCommitLimit
;
709 PageSize
= SystemBasicInfo
.uPageSize
;
711 LeaveCriticalSection(&PerfDataCriticalSection
);
713 Limit
= Limit
* (PageSize
/ 1024);
718 ULONG
PerfDataGetCommitChargePeakK(void)
723 EnterCriticalSection(&PerfDataCriticalSection
);
725 Peak
= SystemPerfInfo
.MmPeakLimit
;
726 PageSize
= SystemBasicInfo
.uPageSize
;
728 LeaveCriticalSection(&PerfDataCriticalSection
);
730 Peak
= Peak
* (PageSize
/ 1024);
735 ULONG
PerfDataGetKernelMemoryTotalK(void)
742 EnterCriticalSection(&PerfDataCriticalSection
);
744 Paged
= SystemPerfInfo
.PoolPagedBytes
;
745 NonPaged
= SystemPerfInfo
.PoolNonPagedBytes
;
746 PageSize
= SystemBasicInfo
.uPageSize
;
748 LeaveCriticalSection(&PerfDataCriticalSection
);
750 Paged
= Paged
* (PageSize
/ 1024);
751 NonPaged
= NonPaged
* (PageSize
/ 1024);
753 Total
= Paged
+ NonPaged
;
758 ULONG
PerfDataGetKernelMemoryPagedK(void)
763 EnterCriticalSection(&PerfDataCriticalSection
);
765 Paged
= SystemPerfInfo
.PoolPagedBytes
;
766 PageSize
= SystemBasicInfo
.uPageSize
;
768 LeaveCriticalSection(&PerfDataCriticalSection
);
770 Paged
= Paged
* (PageSize
/ 1024);
775 ULONG
PerfDataGetKernelMemoryNonPagedK(void)
780 EnterCriticalSection(&PerfDataCriticalSection
);
782 NonPaged
= SystemPerfInfo
.PoolNonPagedBytes
;
783 PageSize
= SystemBasicInfo
.uPageSize
;
785 LeaveCriticalSection(&PerfDataCriticalSection
);
787 NonPaged
= NonPaged
* (PageSize
/ 1024);
792 ULONG
PerfDataGetPhysicalMemoryTotalK(void)
797 EnterCriticalSection(&PerfDataCriticalSection
);
799 Total
= SystemBasicInfo
.uMmNumberOfPhysicalPages
;
800 PageSize
= SystemBasicInfo
.uPageSize
;
802 LeaveCriticalSection(&PerfDataCriticalSection
);
804 Total
= Total
* (PageSize
/ 1024);
809 ULONG
PerfDataGetPhysicalMemoryAvailableK(void)
814 EnterCriticalSection(&PerfDataCriticalSection
);
816 Available
= SystemPerfInfo
.MmAvailablePages
;
817 PageSize
= SystemBasicInfo
.uPageSize
;
819 LeaveCriticalSection(&PerfDataCriticalSection
);
821 Available
= Available
* (PageSize
/ 1024);
826 ULONG
PerfDataGetPhysicalMemorySystemCacheK(void)
831 EnterCriticalSection(&PerfDataCriticalSection
);
833 SystemCache
= SystemCacheInfo
.CurrentSize
;
834 PageSize
= SystemBasicInfo
.uPageSize
;
836 LeaveCriticalSection(&PerfDataCriticalSection
);
838 /* SystemCache = SystemCache * (PageSize / 1024); */
839 SystemCache
= SystemCache
/ 1024;
844 ULONG
PerfDataGetSystemHandleCount(void)
848 EnterCriticalSection(&PerfDataCriticalSection
);
850 HandleCount
= SystemHandleInfo
.Count
;
852 LeaveCriticalSection(&PerfDataCriticalSection
);
857 ULONG
PerfDataGetTotalThreadCount(void)
859 ULONG ThreadCount
= 0;
862 EnterCriticalSection(&PerfDataCriticalSection
);
864 for (i
=0; i
<ProcessCount
; i
++)
866 ThreadCount
+= pPerfData
[i
].ThreadCount
;
869 LeaveCriticalSection(&PerfDataCriticalSection
);