6 * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program 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
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
40 PROCNTQSI NtQuerySystemInformation
= NULL
;
41 PROCGGR pGetGuiResources
= NULL
;
42 PROCGPIC pGetProcessIoCounters
= NULL
;
43 CRITICAL_SECTION PerfDataCriticalSection
;
44 PPERFDATA pPerfDataOld
= NULL
; // Older perf data (saved to establish delta values)
45 PPERFDATA pPerfData
= NULL
; // Most recent copy of perf data
46 ULONG ProcessCountOld
= 0;
47 ULONG ProcessCount
= 0;
51 LARGE_INTEGER liOldIdleTime
= {0,0};
52 double OldKernelTime
= 0;
53 LARGE_INTEGER liOldSystemTime
= {0,0};
54 SYSTEM_PERFORMANCE_INFORMATION SystemPerfInfo
;
55 SYSTEM_BASIC_INFORMATION SystemBasicInfo
;
56 SYSTEM_CACHE_INFORMATION SystemCacheInfo
;
57 SYSTEM_HANDLE_INFORMATION SystemHandleInfo
;
58 PSYSTEM_PROCESSORTIME_INFO SystemProcessorTimeInfo
= NULL
;
60 BOOL
PerfDataInitialize(void)
64 NtQuerySystemInformation
= (PROCNTQSI
)GetProcAddress(GetModuleHandle("ntdll.dll"), "NtQuerySystemInformation");
65 pGetGuiResources
= (PROCGGR
)GetProcAddress(GetModuleHandle("user32.dll"), "GetGuiResources");
66 pGetProcessIoCounters
= (PROCGPIC
)GetProcAddress(GetModuleHandle("kernel32.dll"), "GetProcessIoCounters");
68 InitializeCriticalSection(&PerfDataCriticalSection
);
70 if (!NtQuerySystemInformation
)
74 // Get number of processors in the system
76 status
= NtQuerySystemInformation(SystemBasicInformation
, &SystemBasicInfo
, sizeof(SystemBasicInfo
), NULL
);
77 if (status
!= NO_ERROR
)
83 void PerfDataUninitialize(void)
85 NtQuerySystemInformation
= NULL
;
87 DeleteCriticalSection(&PerfDataCriticalSection
);
90 void PerfDataRefresh(void)
96 PSYSTEM_PROCESS_INFORMATION pSPI
;
100 HANDLE hProcessToken
;
101 TCHAR szTemp
[MAX_PATH
];
103 SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo
;
104 SYSTEM_TIME_INFORMATION SysTimeInfo
;
105 SYSTEM_CACHE_INFORMATION SysCacheInfo
;
106 LPBYTE SysHandleInfoData
;
107 PSYSTEM_PROCESSORTIME_INFO SysProcessorTimeInfo
;
108 double CurrentKernelTime
;
111 if (!NtQuerySystemInformation
)
114 // Get new system time
115 status
= NtQuerySystemInformation(SystemTimeInformation
, &SysTimeInfo
, sizeof(SysTimeInfo
), 0);
116 if (status
!= NO_ERROR
)
119 // Get new CPU's idle time
120 status
= NtQuerySystemInformation(SystemPerformanceInformation
, &SysPerfInfo
, sizeof(SysPerfInfo
), NULL
);
121 if (status
!= NO_ERROR
)
124 // Get system cache information
125 status
= NtQuerySystemInformation(SystemCacheInformation
, &SysCacheInfo
, sizeof(SysCacheInfo
), NULL
);
126 if (status
!= NO_ERROR
)
129 // Get processor time information
130 SysProcessorTimeInfo
= new SYSTEM_PROCESSORTIME_INFO
[SystemBasicInfo
.bKeNumberProcessors
];
131 status
= NtQuerySystemInformation(SystemProcessorTimeInformation
, SysProcessorTimeInfo
, sizeof(SYSTEM_PROCESSORTIME_INFO
) * SystemBasicInfo
.bKeNumberProcessors
, &ulSize
);
132 if (status
!= NO_ERROR
)
135 // Get handle information
136 // We don't know how much data there is so just keep
137 // increasing the buffer size until the call succeeds
141 BufferSize
+= 0x10000;
142 SysHandleInfoData
= new BYTE
[BufferSize
];
144 status
= NtQuerySystemInformation(SystemHandleInformation
, SysHandleInfoData
, BufferSize
, &ulSize
);
146 if (status
== 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/)
147 delete[] SysHandleInfoData
;
149 } while (status
== 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/);
151 // Get process information
152 // We don't know how much data there is so just keep
153 // increasing the buffer size until the call succeeds
157 BufferSize
+= 0x10000;
158 pBuffer
= new BYTE
[BufferSize
];
160 status
= NtQuerySystemInformation(SystemProcessInformation
, pBuffer
, BufferSize
, &ulSize
);
162 if (status
== 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/)
165 } while (status
== 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/);
167 EnterCriticalSection(&PerfDataCriticalSection
);
170 // Save system performance info
172 memcpy(&SystemPerfInfo
, &SysPerfInfo
, sizeof(SYSTEM_PERFORMANCE_INFORMATION
));
175 // Save system cache info
177 memcpy(&SystemCacheInfo
, &SysCacheInfo
, sizeof(SYSTEM_CACHE_INFORMATION
));
180 // Save system processor time info
182 if (SystemProcessorTimeInfo
)
184 delete[] SystemProcessorTimeInfo
;
186 SystemProcessorTimeInfo
= SysProcessorTimeInfo
;
189 // Save system handle info
191 memcpy(&SystemHandleInfo
, SysHandleInfoData
, sizeof(SYSTEM_HANDLE_INFORMATION
));
192 delete[] SysHandleInfoData
;
194 for (CurrentKernelTime
=0, Idx
=0; Idx
<SystemBasicInfo
.bKeNumberProcessors
; Idx
++)
196 CurrentKernelTime
+= Li2Double(SystemProcessorTimeInfo
[Idx
].KernelTime
);
197 CurrentKernelTime
+= Li2Double(SystemProcessorTimeInfo
[Idx
].DpcTime
);
198 CurrentKernelTime
+= Li2Double(SystemProcessorTimeInfo
[Idx
].InterruptTime
);
201 // If it's a first call - skip idle time calcs
202 if (liOldIdleTime
.QuadPart
!= 0)
204 // CurrentValue = NewValue - OldValue
205 dbIdleTime
= Li2Double(SysPerfInfo
.liIdleTime
) - Li2Double(liOldIdleTime
);
206 dbKernelTime
= CurrentKernelTime
- OldKernelTime
;
207 dbSystemTime
= Li2Double(SysTimeInfo
.liKeSystemTime
) - Li2Double(liOldSystemTime
);
209 // CurrentCpuIdle = IdleTime / SystemTime
210 dbIdleTime
= dbIdleTime
/ dbSystemTime
;
211 dbKernelTime
= dbKernelTime
/ dbSystemTime
;
213 // CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) / NumberOfProcessors
214 dbIdleTime
= 100.0 - dbIdleTime
* 100.0 / (double)SystemBasicInfo
.bKeNumberProcessors
;// + 0.5;
215 dbKernelTime
= 100.0 - dbKernelTime
* 100.0 / (double)SystemBasicInfo
.bKeNumberProcessors
;// + 0.5;
218 // Store new CPU's idle and system time
219 liOldIdleTime
= SysPerfInfo
.liIdleTime
;
220 liOldSystemTime
= SysTimeInfo
.liKeSystemTime
;
221 OldKernelTime
= CurrentKernelTime
;
223 // Determine the process count
224 // We loop through the data we got from NtQuerySystemInformation
225 // and count how many structures there are (until RelativeOffset is 0)
226 ProcessCountOld
= ProcessCount
;
228 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)pBuffer
;
233 if (pSPI
->RelativeOffset
== 0)
236 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)((LPBYTE
)pSPI
+ pSPI
->RelativeOffset
);
239 // Now alloc a new PERFDATA array and fill in the data
241 delete[] pPerfDataOld
;
242 pPerfDataOld
= pPerfData
;
243 pPerfData
= new PERFDATA
[ProcessCount
];
244 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)pBuffer
;
245 for (Idx
=0; Idx
<ProcessCount
; Idx
++)
247 // Get the old perf data for this process (if any)
248 // so that we can establish delta values
250 for (Idx2
=0; Idx2
<ProcessCountOld
; Idx2
++)
252 if (pPerfDataOld
[Idx2
].ProcessId
== pSPI
->ProcessId
)
254 pPDOld
= &pPerfDataOld
[Idx2
];
259 // Clear out process perf data structure
260 memset(&pPerfData
[Idx
], 0, sizeof(PERFDATA
));
262 if (pSPI
->Name
.Buffer
)
263 wcscpy(pPerfData
[Idx
].ImageName
, pSPI
->Name
.Buffer
);
265 wcscpy(pPerfData
[Idx
].ImageName
, L
"System Idle Process");
267 pPerfData
[Idx
].ProcessId
= pSPI
->ProcessId
;
271 double CurTime
= Li2Double(pSPI
->KernelTime
) + Li2Double(pSPI
->UserTime
);
272 double OldTime
= Li2Double(pPDOld
->KernelTime
) + Li2Double(pPDOld
->UserTime
);
274 double CpuTime
= (CurTime
- OldTime
) / dbSystemTime
;
276 CpuTime
= CpuTime
* 100.0 / (double)SystemBasicInfo
.bKeNumberProcessors
;// + 0.5;
278 pPerfData
[Idx
].CPUUsage
= (ULONG
)CpuTime
;
280 pPerfData
[Idx
].CPUTime
.QuadPart
= pSPI
->UserTime
.QuadPart
+ pSPI
->KernelTime
.QuadPart
;
281 pPerfData
[Idx
].WorkingSetSizeBytes
= pSPI
->TotalWorkingSetSizeBytes
;
282 pPerfData
[Idx
].PeakWorkingSetSizeBytes
= pSPI
->PeakWorkingSetSizeBytes
;
284 pPerfData
[Idx
].WorkingSetSizeDelta
= labs((LONG
)pSPI
->TotalWorkingSetSizeBytes
- (LONG
)pPDOld
->WorkingSetSizeBytes
);
286 pPerfData
[Idx
].WorkingSetSizeDelta
= 0;
287 pPerfData
[Idx
].PageFaultCount
= pSPI
->PageFaultCount
;
289 pPerfData
[Idx
].PageFaultCountDelta
= labs((LONG
)pSPI
->PageFaultCount
- (LONG
)pPDOld
->PageFaultCount
);
291 pPerfData
[Idx
].PageFaultCountDelta
= 0;
292 pPerfData
[Idx
].VirtualMemorySizeBytes
= pSPI
->TotalVirtualSizeBytes
;
293 pPerfData
[Idx
].PagedPoolUsagePages
= pSPI
->TotalPagedPoolUsagePages
;
294 pPerfData
[Idx
].NonPagedPoolUsagePages
= pSPI
->TotalNonPagedPoolUsagePages
;
295 pPerfData
[Idx
].BasePriority
= pSPI
->BasePriority
;
296 pPerfData
[Idx
].HandleCount
= pSPI
->HandleCount
;
297 pPerfData
[Idx
].ThreadCount
= pSPI
->ThreadCount
;
299 pPerfData
[Idx
].SessionId
= pSPI
->SessionId
;
301 hProcess
= OpenProcess(PROCESS_QUERY_INFORMATION
, FALSE
, pSPI
->ProcessId
);
304 if (OpenProcessToken(hProcess
, TOKEN_QUERY
|TOKEN_DUPLICATE
|TOKEN_IMPERSONATE
, &hProcessToken
))
306 ImpersonateLoggedOnUser(hProcessToken
);
307 memset(szTemp
, 0, sizeof(TCHAR
[MAX_PATH
]));
309 GetUserName(szTemp
, &dwSize
);
310 MultiByteToWideChar(CP_ACP
, MB_PRECOMPOSED
, szTemp
, -1, pPerfData
[Idx
].UserName
, MAX_PATH
);
313 CloseHandle(hProcessToken
);
316 if (pGetGuiResources
)
318 pPerfData
[Idx
].USERObjectCount
= pGetGuiResources(hProcess
, GR_USEROBJECTS
);
319 pPerfData
[Idx
].GDIObjectCount
= pGetGuiResources(hProcess
, GR_GDIOBJECTS
);
321 if (pGetProcessIoCounters
)
322 pGetProcessIoCounters(hProcess
, &pPerfData
[Idx
].IOCounters
);
324 CloseHandle(hProcess
);
327 pPerfData
[Idx
].UserTime
.QuadPart
= pSPI
->UserTime
.QuadPart
;
328 pPerfData
[Idx
].KernelTime
.QuadPart
= pSPI
->KernelTime
.QuadPart
;
330 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)((LPBYTE
)pSPI
+ pSPI
->RelativeOffset
);
335 LeaveCriticalSection(&PerfDataCriticalSection
);
338 ULONG
PerfDataGetProcessCount(void)
343 ULONG
PerfDataGetProcessorUsage(void)
345 return (ULONG
)dbIdleTime
;
348 ULONG
PerfDataGetProcessorSystemUsage(void)
350 return (ULONG
)dbKernelTime
;
353 BOOL
PerfDataGetImageName(ULONG Index
, LPTSTR lpImageName
, int nMaxCount
)
357 EnterCriticalSection(&PerfDataCriticalSection
);
359 if (Index
< ProcessCount
)
362 wcsncpy(lpImageName
, pPerfData
[Index
].ImageName
, nMaxCount
);
364 WideCharToMultiByte(CP_ACP
, 0, pPerfData
[Index
].ImageName
, -1, lpImageName
, nMaxCount
, NULL
, NULL
);
372 LeaveCriticalSection(&PerfDataCriticalSection
);
377 ULONG
PerfDataGetProcessId(ULONG Index
)
381 EnterCriticalSection(&PerfDataCriticalSection
);
383 if (Index
< ProcessCount
)
384 ProcessId
= pPerfData
[Index
].ProcessId
;
388 LeaveCriticalSection(&PerfDataCriticalSection
);
393 BOOL
PerfDataGetUserName(ULONG Index
, LPTSTR lpUserName
, int nMaxCount
)
397 EnterCriticalSection(&PerfDataCriticalSection
);
399 if (Index
< ProcessCount
)
402 wcsncpy(lpUserName
, pPerfData
[Index
].UserName
, nMaxCount
);
404 WideCharToMultiByte(CP_ACP
, 0, pPerfData
[Index
].UserName
, -1, lpUserName
, nMaxCount
, NULL
, NULL
);
412 LeaveCriticalSection(&PerfDataCriticalSection
);
417 ULONG
PerfDataGetSessionId(ULONG Index
)
421 EnterCriticalSection(&PerfDataCriticalSection
);
423 if (Index
< ProcessCount
)
424 SessionId
= pPerfData
[Index
].SessionId
;
428 LeaveCriticalSection(&PerfDataCriticalSection
);
433 ULONG
PerfDataGetCPUUsage(ULONG Index
)
437 EnterCriticalSection(&PerfDataCriticalSection
);
439 if (Index
< ProcessCount
)
440 CpuUsage
= pPerfData
[Index
].CPUUsage
;
444 LeaveCriticalSection(&PerfDataCriticalSection
);
449 TIME
PerfDataGetCPUTime(ULONG Index
)
451 TIME CpuTime
= {0,0};
453 EnterCriticalSection(&PerfDataCriticalSection
);
455 if (Index
< ProcessCount
)
456 CpuTime
= pPerfData
[Index
].CPUTime
;
458 LeaveCriticalSection(&PerfDataCriticalSection
);
463 ULONG
PerfDataGetWorkingSetSizeBytes(ULONG Index
)
465 ULONG WorkingSetSizeBytes
;
467 EnterCriticalSection(&PerfDataCriticalSection
);
469 if (Index
< ProcessCount
)
470 WorkingSetSizeBytes
= pPerfData
[Index
].WorkingSetSizeBytes
;
472 WorkingSetSizeBytes
= 0;
474 LeaveCriticalSection(&PerfDataCriticalSection
);
476 return WorkingSetSizeBytes
;
479 ULONG
PerfDataGetPeakWorkingSetSizeBytes(ULONG Index
)
481 ULONG PeakWorkingSetSizeBytes
;
483 EnterCriticalSection(&PerfDataCriticalSection
);
485 if (Index
< ProcessCount
)
486 PeakWorkingSetSizeBytes
= pPerfData
[Index
].PeakWorkingSetSizeBytes
;
488 PeakWorkingSetSizeBytes
= 0;
490 LeaveCriticalSection(&PerfDataCriticalSection
);
492 return PeakWorkingSetSizeBytes
;
495 ULONG
PerfDataGetWorkingSetSizeDelta(ULONG Index
)
497 ULONG WorkingSetSizeDelta
;
499 EnterCriticalSection(&PerfDataCriticalSection
);
501 if (Index
< ProcessCount
)
502 WorkingSetSizeDelta
= pPerfData
[Index
].WorkingSetSizeDelta
;
504 WorkingSetSizeDelta
= 0;
506 LeaveCriticalSection(&PerfDataCriticalSection
);
508 return WorkingSetSizeDelta
;
511 ULONG
PerfDataGetPageFaultCount(ULONG Index
)
513 ULONG PageFaultCount
;
515 EnterCriticalSection(&PerfDataCriticalSection
);
517 if (Index
< ProcessCount
)
518 PageFaultCount
= pPerfData
[Index
].PageFaultCount
;
522 LeaveCriticalSection(&PerfDataCriticalSection
);
524 return PageFaultCount
;
527 ULONG
PerfDataGetPageFaultCountDelta(ULONG Index
)
529 ULONG PageFaultCountDelta
;
531 EnterCriticalSection(&PerfDataCriticalSection
);
533 if (Index
< ProcessCount
)
534 PageFaultCountDelta
= pPerfData
[Index
].PageFaultCountDelta
;
536 PageFaultCountDelta
= 0;
538 LeaveCriticalSection(&PerfDataCriticalSection
);
540 return PageFaultCountDelta
;
543 ULONG
PerfDataGetVirtualMemorySizeBytes(ULONG Index
)
545 ULONG VirtualMemorySizeBytes
;
547 EnterCriticalSection(&PerfDataCriticalSection
);
549 if (Index
< ProcessCount
)
550 VirtualMemorySizeBytes
= pPerfData
[Index
].VirtualMemorySizeBytes
;
552 VirtualMemorySizeBytes
= 0;
554 LeaveCriticalSection(&PerfDataCriticalSection
);
556 return VirtualMemorySizeBytes
;
559 ULONG
PerfDataGetPagedPoolUsagePages(ULONG Index
)
561 ULONG PagedPoolUsagePages
;
563 EnterCriticalSection(&PerfDataCriticalSection
);
565 if (Index
< ProcessCount
)
566 PagedPoolUsagePages
= pPerfData
[Index
].PagedPoolUsagePages
;
568 PagedPoolUsagePages
= 0;
570 LeaveCriticalSection(&PerfDataCriticalSection
);
572 return PagedPoolUsagePages
;
575 ULONG
PerfDataGetNonPagedPoolUsagePages(ULONG Index
)
577 ULONG NonPagedPoolUsagePages
;
579 EnterCriticalSection(&PerfDataCriticalSection
);
581 if (Index
< ProcessCount
)
582 NonPagedPoolUsagePages
= pPerfData
[Index
].NonPagedPoolUsagePages
;
584 NonPagedPoolUsagePages
= 0;
586 LeaveCriticalSection(&PerfDataCriticalSection
);
588 return NonPagedPoolUsagePages
;
591 ULONG
PerfDataGetBasePriority(ULONG Index
)
595 EnterCriticalSection(&PerfDataCriticalSection
);
597 if (Index
< ProcessCount
)
598 BasePriority
= pPerfData
[Index
].BasePriority
;
602 LeaveCriticalSection(&PerfDataCriticalSection
);
607 ULONG
PerfDataGetHandleCount(ULONG Index
)
611 EnterCriticalSection(&PerfDataCriticalSection
);
613 if (Index
< ProcessCount
)
614 HandleCount
= pPerfData
[Index
].HandleCount
;
618 LeaveCriticalSection(&PerfDataCriticalSection
);
623 ULONG
PerfDataGetThreadCount(ULONG Index
)
627 EnterCriticalSection(&PerfDataCriticalSection
);
629 if (Index
< ProcessCount
)
630 ThreadCount
= pPerfData
[Index
].ThreadCount
;
634 LeaveCriticalSection(&PerfDataCriticalSection
);
639 ULONG
PerfDataGetUSERObjectCount(ULONG Index
)
641 ULONG USERObjectCount
;
643 EnterCriticalSection(&PerfDataCriticalSection
);
645 if (Index
< ProcessCount
)
646 USERObjectCount
= pPerfData
[Index
].USERObjectCount
;
650 LeaveCriticalSection(&PerfDataCriticalSection
);
652 return USERObjectCount
;
655 ULONG
PerfDataGetGDIObjectCount(ULONG Index
)
657 ULONG GDIObjectCount
;
659 EnterCriticalSection(&PerfDataCriticalSection
);
661 if (Index
< ProcessCount
)
662 GDIObjectCount
= pPerfData
[Index
].GDIObjectCount
;
666 LeaveCriticalSection(&PerfDataCriticalSection
);
668 return GDIObjectCount
;
671 BOOL
PerfDataGetIOCounters(ULONG Index
, PIO_COUNTERS pIoCounters
)
675 EnterCriticalSection(&PerfDataCriticalSection
);
677 if (Index
< ProcessCount
)
679 memcpy(pIoCounters
, &pPerfData
[Index
].IOCounters
, sizeof(IO_COUNTERS
));
685 LeaveCriticalSection(&PerfDataCriticalSection
);
690 ULONG
PerfDataGetCommitChargeTotalK(void)
695 EnterCriticalSection(&PerfDataCriticalSection
);
697 Total
= SystemPerfInfo
.MmTotalCommitedPages
;
698 PageSize
= SystemBasicInfo
.uPageSize
;
700 LeaveCriticalSection(&PerfDataCriticalSection
);
702 Total
= Total
* (PageSize
/ 1024);
707 ULONG
PerfDataGetCommitChargeLimitK(void)
712 EnterCriticalSection(&PerfDataCriticalSection
);
714 Limit
= SystemPerfInfo
.MmTotalCommitLimit
;
715 PageSize
= SystemBasicInfo
.uPageSize
;
717 LeaveCriticalSection(&PerfDataCriticalSection
);
719 Limit
= Limit
* (PageSize
/ 1024);
724 ULONG
PerfDataGetCommitChargePeakK(void)
729 EnterCriticalSection(&PerfDataCriticalSection
);
731 Peak
= SystemPerfInfo
.MmPeakLimit
;
732 PageSize
= SystemBasicInfo
.uPageSize
;
734 LeaveCriticalSection(&PerfDataCriticalSection
);
736 Peak
= Peak
* (PageSize
/ 1024);
741 ULONG
PerfDataGetKernelMemoryTotalK(void)
748 EnterCriticalSection(&PerfDataCriticalSection
);
750 Paged
= SystemPerfInfo
.PoolPagedBytes
;
751 NonPaged
= SystemPerfInfo
.PoolNonPagedBytes
;
752 PageSize
= SystemBasicInfo
.uPageSize
;
754 LeaveCriticalSection(&PerfDataCriticalSection
);
756 Paged
= Paged
* (PageSize
/ 1024);
757 NonPaged
= NonPaged
* (PageSize
/ 1024);
759 Total
= Paged
+ NonPaged
;
764 ULONG
PerfDataGetKernelMemoryPagedK(void)
769 EnterCriticalSection(&PerfDataCriticalSection
);
771 Paged
= SystemPerfInfo
.PoolPagedBytes
;
772 PageSize
= SystemBasicInfo
.uPageSize
;
774 LeaveCriticalSection(&PerfDataCriticalSection
);
776 Paged
= Paged
* (PageSize
/ 1024);
781 ULONG
PerfDataGetKernelMemoryNonPagedK(void)
786 EnterCriticalSection(&PerfDataCriticalSection
);
788 NonPaged
= SystemPerfInfo
.PoolNonPagedBytes
;
789 PageSize
= SystemBasicInfo
.uPageSize
;
791 LeaveCriticalSection(&PerfDataCriticalSection
);
793 NonPaged
= NonPaged
* (PageSize
/ 1024);
798 ULONG
PerfDataGetPhysicalMemoryTotalK(void)
803 EnterCriticalSection(&PerfDataCriticalSection
);
805 Total
= SystemBasicInfo
.uMmNumberOfPhysicalPages
;
806 PageSize
= SystemBasicInfo
.uPageSize
;
808 LeaveCriticalSection(&PerfDataCriticalSection
);
810 Total
= Total
* (PageSize
/ 1024);
815 ULONG
PerfDataGetPhysicalMemoryAvailableK(void)
820 EnterCriticalSection(&PerfDataCriticalSection
);
822 Available
= SystemPerfInfo
.MmAvailablePages
;
823 PageSize
= SystemBasicInfo
.uPageSize
;
825 LeaveCriticalSection(&PerfDataCriticalSection
);
827 Available
= Available
* (PageSize
/ 1024);
832 ULONG
PerfDataGetPhysicalMemorySystemCacheK(void)
837 EnterCriticalSection(&PerfDataCriticalSection
);
839 SystemCache
= SystemCacheInfo
.CurrentSize
;
840 PageSize
= SystemBasicInfo
.uPageSize
;
842 LeaveCriticalSection(&PerfDataCriticalSection
);
844 //SystemCache = SystemCache * (PageSize / 1024);
845 SystemCache
= SystemCache
/ 1024;
850 ULONG
PerfDataGetSystemHandleCount(void)
854 EnterCriticalSection(&PerfDataCriticalSection
);
856 HandleCount
= SystemHandleInfo
.Count
;
858 LeaveCriticalSection(&PerfDataCriticalSection
);
863 ULONG
PerfDataGetTotalThreadCount(void)
865 ULONG ThreadCount
= 0;
868 EnterCriticalSection(&PerfDataCriticalSection
);
870 for (i
=0; i
<ProcessCount
; i
++)
872 ThreadCount
+= pPerfData
[i
].ThreadCount
;
875 LeaveCriticalSection(&PerfDataCriticalSection
);