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 */
34 static PROCNTQSI NtQuerySystemInformation
= NULL
;
35 static PROCGGR pGetGuiResources
= NULL
;
36 static PROCGPIC pGetProcessIoCounters
= NULL
;
37 static CRITICAL_SECTION PerfDataCriticalSection
;
38 static PPERFDATA pPerfDataOld
= NULL
; /* Older perf data (saved to establish delta values) */
39 static PPERFDATA pPerfData
= NULL
; /* Most recent copy of perf data */
40 static ULONG ProcessCountOld
= 0;
41 static ULONG ProcessCount
= 0;
42 static double dbIdleTime
;
43 static double dbKernelTime
;
44 static double dbSystemTime
;
45 static LARGE_INTEGER liOldIdleTime
= {{0,0}};
46 static double OldKernelTime
= 0;
47 static LARGE_INTEGER liOldSystemTime
= {{0,0}};
48 static SYSTEM_PERFORMANCE_INFORMATION SystemPerfInfo
;
49 static SYSTEM_BASIC_INFORMATION SystemBasicInfo
;
50 static SYSTEM_CACHE_INFORMATION SystemCacheInfo
;
51 static SYSTEM_HANDLE_INFORMATION SystemHandleInfo
;
52 static PSYSTEM_PROCESSORTIME_INFO SystemProcessorTimeInfo
= NULL
;
54 BOOL
PerfDataInitialize(void)
58 NtQuerySystemInformation
= (PROCNTQSI
)GetProcAddress(GetModuleHandle(_T("ntdll.dll")), "NtQuerySystemInformation");
59 pGetGuiResources
= (PROCGGR
)GetProcAddress(GetModuleHandle(_T("user32.dll")), "GetGuiResources");
60 pGetProcessIoCounters
= (PROCGPIC
)GetProcAddress(GetModuleHandle(_T("kernel32.dll")), "GetProcessIoCounters");
62 InitializeCriticalSection(&PerfDataCriticalSection
);
64 if (!NtQuerySystemInformation
)
68 * Get number of processors in the system
70 status
= NtQuerySystemInformation(SystemBasicInformation
, &SystemBasicInfo
, sizeof(SystemBasicInfo
), NULL
);
71 if (status
!= NO_ERROR
)
77 void PerfDataUninitialize(void)
79 NtQuerySystemInformation
= NULL
;
81 DeleteCriticalSection(&PerfDataCriticalSection
);
84 void PerfDataRefresh(void)
90 PSYSTEM_PROCESS_INFORMATION pSPI
;
95 TCHAR szTemp
[MAX_PATH
];
97 SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo
;
98 SYSTEM_TIME_INFORMATION SysTimeInfo
;
99 SYSTEM_CACHE_INFORMATION SysCacheInfo
;
100 LPBYTE SysHandleInfoData
;
101 PSYSTEM_PROCESSORTIME_INFO SysProcessorTimeInfo
;
102 double CurrentKernelTime
;
105 if (!NtQuerySystemInformation
)
108 /* Get new system time */
109 status
= NtQuerySystemInformation(SystemTimeInformation
, &SysTimeInfo
, sizeof(SysTimeInfo
), 0);
110 if (status
!= NO_ERROR
)
113 /* Get new CPU's idle time */
114 status
= NtQuerySystemInformation(SystemPerformanceInformation
, &SysPerfInfo
, sizeof(SysPerfInfo
), NULL
);
115 if (status
!= NO_ERROR
)
118 /* Get system cache information */
119 status
= NtQuerySystemInformation(SystemCacheInformation
, &SysCacheInfo
, sizeof(SysCacheInfo
), NULL
);
120 if (status
!= NO_ERROR
)
123 /* Get processor time information */
124 SysProcessorTimeInfo
= HeapAlloc(GetProcessHeap(), 0,
125 sizeof(SYSTEM_PROCESSORTIME_INFO
) * SystemBasicInfo
.bKeNumberProcessors
);
126 status
= NtQuerySystemInformation(SystemProcessorTimeInformation
, SysProcessorTimeInfo
, sizeof(SYSTEM_PROCESSORTIME_INFO
) * SystemBasicInfo
.bKeNumberProcessors
, &ulSize
);
127 if (status
!= NO_ERROR
) {
128 HeapFree(GetProcessHeap(), 0, 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
= HeapAlloc(GetProcessHeap(), 0, BufferSize
);
142 status
= NtQuerySystemInformation(SystemHandleInformation
, SysHandleInfoData
, BufferSize
, &ulSize
);
144 if (status
== 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/) {
145 HeapFree(GetProcessHeap(), 0, 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
= HeapAlloc(GetProcessHeap(), 0, BufferSize
);
160 status
= NtQuerySystemInformation(SystemProcessInformation
, pBuffer
, BufferSize
, &ulSize
);
162 if (status
== 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/) {
163 HeapFree(GetProcessHeap(), 0, pBuffer
);
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 HeapFree(GetProcessHeap(), 0, SystemProcessorTimeInfo
);
184 SystemProcessorTimeInfo
= SysProcessorTimeInfo
;
187 * Save system handle info
189 memcpy(&SystemHandleInfo
, SysHandleInfoData
, sizeof(SYSTEM_HANDLE_INFORMATION
));
190 HeapFree(GetProcessHeap(), 0, 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 */
234 HeapFree(GetProcessHeap(), 0, pPerfDataOld
);
235 pPerfDataOld
= pPerfData
;
236 pPerfData
= HeapAlloc(GetProcessHeap(), 0, 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
);
257 LoadStringW(hInst
, IDS_SYSTEM_IDLE_PROCESS
, idleW
, sizeof(idleW
)/sizeof(WCHAR
));
258 lstrcpyW(pPerfData
[Idx
].ImageName
, idleW
);
261 pPerfData
[Idx
].ProcessId
= pSPI
->ProcessId
;
264 double CurTime
= Li2Double(pSPI
->KernelTime
) + Li2Double(pSPI
->UserTime
);
265 double OldTime
= Li2Double(pPDOld
->KernelTime
) + Li2Double(pPDOld
->UserTime
);
266 double CpuTime
= (CurTime
- OldTime
) / dbSystemTime
;
267 CpuTime
= CpuTime
* 100.0 / (double)SystemBasicInfo
.bKeNumberProcessors
; /* + 0.5; */
268 pPerfData
[Idx
].CPUUsage
= (ULONG
)CpuTime
;
270 pPerfData
[Idx
].CPUTime
.QuadPart
= pSPI
->UserTime
.QuadPart
+ pSPI
->KernelTime
.QuadPart
;
271 pPerfData
[Idx
].WorkingSetSizeBytes
= pSPI
->TotalWorkingSetSizeBytes
;
272 pPerfData
[Idx
].PeakWorkingSetSizeBytes
= pSPI
->PeakWorkingSetSizeBytes
;
274 pPerfData
[Idx
].WorkingSetSizeDelta
= labs((LONG
)pSPI
->TotalWorkingSetSizeBytes
- (LONG
)pPDOld
->WorkingSetSizeBytes
);
276 pPerfData
[Idx
].WorkingSetSizeDelta
= 0;
277 pPerfData
[Idx
].PageFaultCount
= pSPI
->PageFaultCount
;
279 pPerfData
[Idx
].PageFaultCountDelta
= labs((LONG
)pSPI
->PageFaultCount
- (LONG
)pPDOld
->PageFaultCount
);
281 pPerfData
[Idx
].PageFaultCountDelta
= 0;
282 pPerfData
[Idx
].VirtualMemorySizeBytes
= pSPI
->TotalVirtualSizeBytes
;
283 pPerfData
[Idx
].PagedPoolUsagePages
= pSPI
->TotalPagedPoolUsagePages
;
284 pPerfData
[Idx
].NonPagedPoolUsagePages
= pSPI
->TotalNonPagedPoolUsagePages
;
285 pPerfData
[Idx
].BasePriority
= pSPI
->BasePriority
;
286 pPerfData
[Idx
].HandleCount
= pSPI
->HandleCount
;
287 pPerfData
[Idx
].ThreadCount
= pSPI
->ThreadCount
;
288 pPerfData
[Idx
].SessionId
= pSPI
->SessionId
;
290 hProcess
= OpenProcess(PROCESS_QUERY_INFORMATION
, FALSE
, pSPI
->ProcessId
);
292 if (OpenProcessToken(hProcess
, TOKEN_QUERY
|TOKEN_DUPLICATE
|TOKEN_IMPERSONATE
, &hProcessToken
)) {
293 ImpersonateLoggedOnUser(hProcessToken
);
294 memset(szTemp
, 0, sizeof(TCHAR
[MAX_PATH
]));
296 GetUserName(szTemp
, &dwSize
);
298 MultiByteToWideChar(CP_ACP
, MB_PRECOMPOSED
, szTemp
, -1, pPerfData
[Idx
].UserName
, MAX_PATH
);
300 int MultiByteToWideChar(
301 UINT CodePage, // code page
302 DWORD dwFlags, // character-type options
303 LPCSTR lpMultiByteStr, // string to map
304 int cbMultiByte, // number of bytes in string
305 LPWSTR lpWideCharStr, // wide-character buffer
306 int cchWideChar // size of buffer
311 CloseHandle(hProcessToken
);
313 if (pGetGuiResources
) {
314 pPerfData
[Idx
].USERObjectCount
= pGetGuiResources(hProcess
, GR_USEROBJECTS
);
315 pPerfData
[Idx
].GDIObjectCount
= pGetGuiResources(hProcess
, GR_GDIOBJECTS
);
317 if (pGetProcessIoCounters
)
318 pGetProcessIoCounters(hProcess
, &pPerfData
[Idx
].IOCounters
);
319 CloseHandle(hProcess
);
321 pPerfData
[Idx
].UserTime
.QuadPart
= pSPI
->UserTime
.QuadPart
;
322 pPerfData
[Idx
].KernelTime
.QuadPart
= pSPI
->KernelTime
.QuadPart
;
323 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)((LPBYTE
)pSPI
+ pSPI
->RelativeOffset
);
325 HeapFree(GetProcessHeap(), 0, pBuffer
);
326 LeaveCriticalSection(&PerfDataCriticalSection
);
329 ULONG
PerfDataGetProcessCount(void)
334 ULONG
PerfDataGetProcessorUsage(void)
336 if( dbIdleTime
< 0.0 )
338 if( dbIdleTime
> 100.0 )
340 return (ULONG
)dbIdleTime
;
343 ULONG
PerfDataGetProcessorSystemUsage(void)
345 if( dbKernelTime
< 0.0 )
347 if( dbKernelTime
> 100.0 )
349 return (ULONG
)dbKernelTime
;
352 BOOL
PerfDataGetImageName(ULONG Index
, LPTSTR lpImageName
, int nMaxCount
)
356 EnterCriticalSection(&PerfDataCriticalSection
);
358 if (Index
< ProcessCount
) {
360 wcsncpy(lpImageName
, pPerfData
[Index
].ImageName
, nMaxCount
);
362 WideCharToMultiByte(CP_ACP
, 0, pPerfData
[Index
].ImageName
, -1, lpImageName
, nMaxCount
, NULL
, NULL
);
369 LeaveCriticalSection(&PerfDataCriticalSection
);
373 ULONG
PerfDataGetProcessId(ULONG Index
)
377 EnterCriticalSection(&PerfDataCriticalSection
);
379 if (Index
< ProcessCount
)
380 ProcessId
= pPerfData
[Index
].ProcessId
;
384 LeaveCriticalSection(&PerfDataCriticalSection
);
389 BOOL
PerfDataGetUserName(ULONG Index
, LPTSTR lpUserName
, int nMaxCount
)
393 EnterCriticalSection(&PerfDataCriticalSection
);
395 if (Index
< ProcessCount
) {
397 wcsncpy(lpUserName
, pPerfData
[Index
].UserName
, nMaxCount
);
399 WideCharToMultiByte(CP_ACP
, 0, pPerfData
[Index
].UserName
, -1, lpUserName
, nMaxCount
, NULL
, NULL
);
407 LeaveCriticalSection(&PerfDataCriticalSection
);
412 ULONG
PerfDataGetSessionId(ULONG Index
)
416 EnterCriticalSection(&PerfDataCriticalSection
);
418 if (Index
< ProcessCount
)
419 SessionId
= pPerfData
[Index
].SessionId
;
423 LeaveCriticalSection(&PerfDataCriticalSection
);
428 ULONG
PerfDataGetCPUUsage(ULONG Index
)
432 EnterCriticalSection(&PerfDataCriticalSection
);
434 if (Index
< ProcessCount
)
435 CpuUsage
= pPerfData
[Index
].CPUUsage
;
439 LeaveCriticalSection(&PerfDataCriticalSection
);
444 TIME
PerfDataGetCPUTime(ULONG Index
)
446 TIME CpuTime
= {{0,0}};
448 EnterCriticalSection(&PerfDataCriticalSection
);
450 if (Index
< ProcessCount
)
451 CpuTime
= pPerfData
[Index
].CPUTime
;
453 LeaveCriticalSection(&PerfDataCriticalSection
);
458 ULONG
PerfDataGetWorkingSetSizeBytes(ULONG Index
)
460 ULONG WorkingSetSizeBytes
;
462 EnterCriticalSection(&PerfDataCriticalSection
);
464 if (Index
< ProcessCount
)
465 WorkingSetSizeBytes
= pPerfData
[Index
].WorkingSetSizeBytes
;
467 WorkingSetSizeBytes
= 0;
469 LeaveCriticalSection(&PerfDataCriticalSection
);
471 return WorkingSetSizeBytes
;
474 ULONG
PerfDataGetPeakWorkingSetSizeBytes(ULONG Index
)
476 ULONG PeakWorkingSetSizeBytes
;
478 EnterCriticalSection(&PerfDataCriticalSection
);
480 if (Index
< ProcessCount
)
481 PeakWorkingSetSizeBytes
= pPerfData
[Index
].PeakWorkingSetSizeBytes
;
483 PeakWorkingSetSizeBytes
= 0;
485 LeaveCriticalSection(&PerfDataCriticalSection
);
487 return PeakWorkingSetSizeBytes
;
490 ULONG
PerfDataGetWorkingSetSizeDelta(ULONG Index
)
492 ULONG WorkingSetSizeDelta
;
494 EnterCriticalSection(&PerfDataCriticalSection
);
496 if (Index
< ProcessCount
)
497 WorkingSetSizeDelta
= pPerfData
[Index
].WorkingSetSizeDelta
;
499 WorkingSetSizeDelta
= 0;
501 LeaveCriticalSection(&PerfDataCriticalSection
);
503 return WorkingSetSizeDelta
;
506 ULONG
PerfDataGetPageFaultCount(ULONG Index
)
508 ULONG PageFaultCount
;
510 EnterCriticalSection(&PerfDataCriticalSection
);
512 if (Index
< ProcessCount
)
513 PageFaultCount
= pPerfData
[Index
].PageFaultCount
;
517 LeaveCriticalSection(&PerfDataCriticalSection
);
519 return PageFaultCount
;
522 ULONG
PerfDataGetPageFaultCountDelta(ULONG Index
)
524 ULONG PageFaultCountDelta
;
526 EnterCriticalSection(&PerfDataCriticalSection
);
528 if (Index
< ProcessCount
)
529 PageFaultCountDelta
= pPerfData
[Index
].PageFaultCountDelta
;
531 PageFaultCountDelta
= 0;
533 LeaveCriticalSection(&PerfDataCriticalSection
);
535 return PageFaultCountDelta
;
538 ULONG
PerfDataGetVirtualMemorySizeBytes(ULONG Index
)
540 ULONG VirtualMemorySizeBytes
;
542 EnterCriticalSection(&PerfDataCriticalSection
);
544 if (Index
< ProcessCount
)
545 VirtualMemorySizeBytes
= pPerfData
[Index
].VirtualMemorySizeBytes
;
547 VirtualMemorySizeBytes
= 0;
549 LeaveCriticalSection(&PerfDataCriticalSection
);
551 return VirtualMemorySizeBytes
;
554 ULONG
PerfDataGetPagedPoolUsagePages(ULONG Index
)
556 ULONG PagedPoolUsagePages
;
558 EnterCriticalSection(&PerfDataCriticalSection
);
560 if (Index
< ProcessCount
)
561 PagedPoolUsagePages
= pPerfData
[Index
].PagedPoolUsagePages
;
563 PagedPoolUsagePages
= 0;
565 LeaveCriticalSection(&PerfDataCriticalSection
);
567 return PagedPoolUsagePages
;
570 ULONG
PerfDataGetNonPagedPoolUsagePages(ULONG Index
)
572 ULONG NonPagedPoolUsagePages
;
574 EnterCriticalSection(&PerfDataCriticalSection
);
576 if (Index
< ProcessCount
)
577 NonPagedPoolUsagePages
= pPerfData
[Index
].NonPagedPoolUsagePages
;
579 NonPagedPoolUsagePages
= 0;
581 LeaveCriticalSection(&PerfDataCriticalSection
);
583 return NonPagedPoolUsagePages
;
586 ULONG
PerfDataGetBasePriority(ULONG Index
)
590 EnterCriticalSection(&PerfDataCriticalSection
);
592 if (Index
< ProcessCount
)
593 BasePriority
= pPerfData
[Index
].BasePriority
;
597 LeaveCriticalSection(&PerfDataCriticalSection
);
602 ULONG
PerfDataGetHandleCount(ULONG Index
)
606 EnterCriticalSection(&PerfDataCriticalSection
);
608 if (Index
< ProcessCount
)
609 HandleCount
= pPerfData
[Index
].HandleCount
;
613 LeaveCriticalSection(&PerfDataCriticalSection
);
618 ULONG
PerfDataGetThreadCount(ULONG Index
)
622 EnterCriticalSection(&PerfDataCriticalSection
);
624 if (Index
< ProcessCount
)
625 ThreadCount
= pPerfData
[Index
].ThreadCount
;
629 LeaveCriticalSection(&PerfDataCriticalSection
);
634 ULONG
PerfDataGetUSERObjectCount(ULONG Index
)
636 ULONG USERObjectCount
;
638 EnterCriticalSection(&PerfDataCriticalSection
);
640 if (Index
< ProcessCount
)
641 USERObjectCount
= pPerfData
[Index
].USERObjectCount
;
645 LeaveCriticalSection(&PerfDataCriticalSection
);
647 return USERObjectCount
;
650 ULONG
PerfDataGetGDIObjectCount(ULONG Index
)
652 ULONG GDIObjectCount
;
654 EnterCriticalSection(&PerfDataCriticalSection
);
656 if (Index
< ProcessCount
)
657 GDIObjectCount
= pPerfData
[Index
].GDIObjectCount
;
661 LeaveCriticalSection(&PerfDataCriticalSection
);
663 return GDIObjectCount
;
666 BOOL
PerfDataGetIOCounters(ULONG Index
, PIO_COUNTERS pIoCounters
)
670 EnterCriticalSection(&PerfDataCriticalSection
);
672 if (Index
< ProcessCount
)
674 memcpy(pIoCounters
, &pPerfData
[Index
].IOCounters
, sizeof(IO_COUNTERS
));
680 LeaveCriticalSection(&PerfDataCriticalSection
);
685 ULONG
PerfDataGetCommitChargeTotalK(void)
690 EnterCriticalSection(&PerfDataCriticalSection
);
692 Total
= SystemPerfInfo
.MmTotalCommittedPages
;
693 PageSize
= SystemBasicInfo
.uPageSize
;
695 LeaveCriticalSection(&PerfDataCriticalSection
);
697 Total
= Total
* (PageSize
/ 1024);
702 ULONG
PerfDataGetCommitChargeLimitK(void)
707 EnterCriticalSection(&PerfDataCriticalSection
);
709 Limit
= SystemPerfInfo
.MmTotalCommitLimit
;
710 PageSize
= SystemBasicInfo
.uPageSize
;
712 LeaveCriticalSection(&PerfDataCriticalSection
);
714 Limit
= Limit
* (PageSize
/ 1024);
719 ULONG
PerfDataGetCommitChargePeakK(void)
724 EnterCriticalSection(&PerfDataCriticalSection
);
726 Peak
= SystemPerfInfo
.MmPeakLimit
;
727 PageSize
= SystemBasicInfo
.uPageSize
;
729 LeaveCriticalSection(&PerfDataCriticalSection
);
731 Peak
= Peak
* (PageSize
/ 1024);
736 ULONG
PerfDataGetKernelMemoryTotalK(void)
743 EnterCriticalSection(&PerfDataCriticalSection
);
745 Paged
= SystemPerfInfo
.PoolPagedBytes
;
746 NonPaged
= SystemPerfInfo
.PoolNonPagedBytes
;
747 PageSize
= SystemBasicInfo
.uPageSize
;
749 LeaveCriticalSection(&PerfDataCriticalSection
);
751 Paged
= Paged
* (PageSize
/ 1024);
752 NonPaged
= NonPaged
* (PageSize
/ 1024);
754 Total
= Paged
+ NonPaged
;
759 ULONG
PerfDataGetKernelMemoryPagedK(void)
764 EnterCriticalSection(&PerfDataCriticalSection
);
766 Paged
= SystemPerfInfo
.PoolPagedBytes
;
767 PageSize
= SystemBasicInfo
.uPageSize
;
769 LeaveCriticalSection(&PerfDataCriticalSection
);
771 Paged
= Paged
* (PageSize
/ 1024);
776 ULONG
PerfDataGetKernelMemoryNonPagedK(void)
781 EnterCriticalSection(&PerfDataCriticalSection
);
783 NonPaged
= SystemPerfInfo
.PoolNonPagedBytes
;
784 PageSize
= SystemBasicInfo
.uPageSize
;
786 LeaveCriticalSection(&PerfDataCriticalSection
);
788 NonPaged
= NonPaged
* (PageSize
/ 1024);
793 ULONG
PerfDataGetPhysicalMemoryTotalK(void)
798 EnterCriticalSection(&PerfDataCriticalSection
);
800 Total
= SystemBasicInfo
.uMmNumberOfPhysicalPages
;
801 PageSize
= SystemBasicInfo
.uPageSize
;
803 LeaveCriticalSection(&PerfDataCriticalSection
);
805 Total
= Total
* (PageSize
/ 1024);
810 ULONG
PerfDataGetPhysicalMemoryAvailableK(void)
815 EnterCriticalSection(&PerfDataCriticalSection
);
817 Available
= SystemPerfInfo
.MmAvailablePages
;
818 PageSize
= SystemBasicInfo
.uPageSize
;
820 LeaveCriticalSection(&PerfDataCriticalSection
);
822 Available
= Available
* (PageSize
/ 1024);
827 ULONG
PerfDataGetPhysicalMemorySystemCacheK(void)
832 EnterCriticalSection(&PerfDataCriticalSection
);
834 SystemCache
= SystemCacheInfo
.CurrentSize
;
835 PageSize
= SystemBasicInfo
.uPageSize
;
837 LeaveCriticalSection(&PerfDataCriticalSection
);
839 /* SystemCache = SystemCache * (PageSize / 1024); */
840 SystemCache
= SystemCache
/ 1024;
845 ULONG
PerfDataGetSystemHandleCount(void)
849 EnterCriticalSection(&PerfDataCriticalSection
);
851 HandleCount
= SystemHandleInfo
.Count
;
853 LeaveCriticalSection(&PerfDataCriticalSection
);
858 ULONG
PerfDataGetTotalThreadCount(void)
860 ULONG ThreadCount
= 0;
863 EnterCriticalSection(&PerfDataCriticalSection
);
865 for (i
=0; i
<ProcessCount
; i
++)
867 ThreadCount
+= pPerfData
[i
].ThreadCount
;
870 LeaveCriticalSection(&PerfDataCriticalSection
);