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 Street, Fifth Floor, Boston, MA 02110-1301 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_FILECACHE_INFORMATION SystemCacheInfo
;
39 SYSTEM_HANDLE_INFORMATION SystemHandleInfo
;
40 PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION SystemProcessorTimeInfo
= NULL
;
41 PSID SystemUserSid
= NULL
;
43 BOOL
PerfDataInitialize(void)
45 SID_IDENTIFIER_AUTHORITY NtSidAuthority
= {SECURITY_NT_AUTHORITY
};
48 InitializeCriticalSection(&PerfDataCriticalSection
);
51 * Get number of processors in the system
53 status
= NtQuerySystemInformation(SystemBasicInformation
, &SystemBasicInfo
, sizeof(SystemBasicInfo
), NULL
);
54 if (status
!= NO_ERROR
)
58 * Create the SYSTEM Sid
60 AllocateAndInitializeSid(&NtSidAuthority
, 1, SECURITY_LOCAL_SYSTEM_RID
, 0, 0, 0, 0, 0, 0, 0, &SystemUserSid
);
64 void PerfDataUninitialize(void)
67 if (pPerfData
!= NULL
)
68 HeapFree(GetProcessHeap(), 0, pPerfData
);
70 DeleteCriticalSection(&PerfDataCriticalSection
);
72 if (SystemUserSid
!= NULL
)
74 FreeSid(SystemUserSid
);
79 static void SidToUserName(PSID Sid
, LPWSTR szBuffer
, DWORD BufferSize
)
81 static WCHAR szDomainNameUnused
[255];
82 DWORD DomainNameLen
= sizeof(szDomainNameUnused
) / sizeof(szDomainNameUnused
[0]);
86 LookupAccountSidW(NULL
, Sid
, szBuffer
, &BufferSize
, szDomainNameUnused
, &DomainNameLen
, &Use
);
89 void PerfDataRefresh(void)
95 PSYSTEM_PROCESS_INFORMATION pSPI
;
100 SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo
;
101 SYSTEM_TIMEOFDAY_INFORMATION SysTimeInfo
;
102 SYSTEM_FILECACHE_INFORMATION SysCacheInfo
;
103 LPBYTE SysHandleInfoData
;
104 PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION SysProcessorTimeInfo
;
105 double CurrentKernelTime
;
106 PSECURITY_DESCRIPTOR ProcessSD
;
108 ULONG Buffer
[64]; /* must be 4 bytes aligned! */
110 /* Get new system time */
111 status
= NtQuerySystemInformation(SystemTimeOfDayInformation
, &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(SystemFileCacheInformation
, &SysCacheInfo
, sizeof(SysCacheInfo
), NULL
);
122 if (status
!= NO_ERROR
)
125 /* Get processor time information */
126 SysProcessorTimeInfo
= (PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
)HeapAlloc(GetProcessHeap(), 0, sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) * SystemBasicInfo
.NumberOfProcessors
);
127 status
= NtQuerySystemInformation(SystemProcessorPerformanceInformation
, SysProcessorTimeInfo
, sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) * SystemBasicInfo
.NumberOfProcessors
, &ulSize
);
129 if (status
!= NO_ERROR
)
131 if (SysProcessorTimeInfo
!= NULL
)
132 HeapFree(GetProcessHeap(), 0, SysProcessorTimeInfo
);
136 /* Get handle information
137 * We don't know how much data there is so just keep
138 * increasing the buffer size until the call succeeds
143 BufferSize
+= 0x10000;
144 SysHandleInfoData
= (LPBYTE
)HeapAlloc(GetProcessHeap(), 0, BufferSize
);
146 status
= NtQuerySystemInformation(SystemHandleInformation
, SysHandleInfoData
, BufferSize
, &ulSize
);
148 if (status
== STATUS_INFO_LENGTH_MISMATCH
) {
149 HeapFree(GetProcessHeap(), 0, SysHandleInfoData
);
152 } while (status
== STATUS_INFO_LENGTH_MISMATCH
);
154 /* Get process information
155 * We don't know how much data there is so just keep
156 * increasing the buffer size until the call succeeds
161 BufferSize
+= 0x10000;
162 pBuffer
= (LPBYTE
)HeapAlloc(GetProcessHeap(), 0, BufferSize
);
164 status
= NtQuerySystemInformation(SystemProcessInformation
, pBuffer
, BufferSize
, &ulSize
);
166 if (status
== STATUS_INFO_LENGTH_MISMATCH
) {
167 HeapFree(GetProcessHeap(), 0, pBuffer
);
170 } while (status
== STATUS_INFO_LENGTH_MISMATCH
);
172 EnterCriticalSection(&PerfDataCriticalSection
);
175 * Save system performance info
177 memcpy(&SystemPerfInfo
, &SysPerfInfo
, sizeof(SYSTEM_PERFORMANCE_INFORMATION
));
180 * Save system cache info
182 memcpy(&SystemCacheInfo
, &SysCacheInfo
, sizeof(SYSTEM_FILECACHE_INFORMATION
));
185 * Save system processor time info
187 if (SystemProcessorTimeInfo
) {
188 HeapFree(GetProcessHeap(), 0, SystemProcessorTimeInfo
);
190 SystemProcessorTimeInfo
= SysProcessorTimeInfo
;
193 * Save system handle info
195 memcpy(&SystemHandleInfo
, SysHandleInfoData
, sizeof(SYSTEM_HANDLE_INFORMATION
));
196 HeapFree(GetProcessHeap(), 0, SysHandleInfoData
);
198 for (CurrentKernelTime
=0, Idx
=0; Idx
<(ULONG
)SystemBasicInfo
.NumberOfProcessors
; Idx
++) {
199 CurrentKernelTime
+= Li2Double(SystemProcessorTimeInfo
[Idx
].KernelTime
);
200 CurrentKernelTime
+= Li2Double(SystemProcessorTimeInfo
[Idx
].DpcTime
);
201 CurrentKernelTime
+= Li2Double(SystemProcessorTimeInfo
[Idx
].InterruptTime
);
204 /* If it's a first call - skip idle time calcs */
205 if (liOldIdleTime
.QuadPart
!= 0) {
206 /* CurrentValue = NewValue - OldValue */
207 dbIdleTime
= Li2Double(SysPerfInfo
.IdleProcessTime
) - Li2Double(liOldIdleTime
);
208 dbKernelTime
= CurrentKernelTime
- OldKernelTime
;
209 dbSystemTime
= Li2Double(SysTimeInfo
.CurrentTime
) - Li2Double(liOldSystemTime
);
211 /* CurrentCpuIdle = IdleTime / SystemTime */
212 dbIdleTime
= dbIdleTime
/ dbSystemTime
;
213 dbKernelTime
= dbKernelTime
/ dbSystemTime
;
215 /* CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) / NumberOfProcessors */
216 dbIdleTime
= 100.0 - dbIdleTime
* 100.0 / (double)SystemBasicInfo
.NumberOfProcessors
; /* + 0.5; */
217 dbKernelTime
= 100.0 - dbKernelTime
* 100.0 / (double)SystemBasicInfo
.NumberOfProcessors
; /* + 0.5; */
220 /* Store new CPU's idle and system time */
221 liOldIdleTime
= SysPerfInfo
.IdleProcessTime
;
222 liOldSystemTime
= SysTimeInfo
.CurrentTime
;
223 OldKernelTime
= CurrentKernelTime
;
225 /* Determine the process count
226 * We loop through the data we got from NtQuerySystemInformation
227 * and count how many structures there are (until RelativeOffset is 0)
229 ProcessCountOld
= ProcessCount
;
231 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)pBuffer
;
234 if (pSPI
->NextEntryOffset
== 0)
236 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)((LPBYTE
)pSPI
+ pSPI
->NextEntryOffset
);
239 /* Now alloc a new PERFDATA array and fill in the data */
241 HeapFree(GetProcessHeap(), 0, pPerfDataOld
);
243 pPerfDataOld
= pPerfData
;
244 /* Clear out process perf data structures with HEAP_ZERO_MEMORY flag: */
245 pPerfData
= (PPERFDATA
)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(PERFDATA
) * ProcessCount
);
246 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)pBuffer
;
247 for (Idx
=0; Idx
<ProcessCount
; Idx
++) {
248 /* Get the old perf data for this process (if any) */
249 /* so that we can establish delta values */
251 for (Idx2
=0; Idx2
<ProcessCountOld
; Idx2
++) {
252 if (pPerfDataOld
[Idx2
].ProcessId
== pSPI
->UniqueProcessId
) {
253 pPDOld
= &pPerfDataOld
[Idx2
];
258 if (pSPI
->ImageName
.Buffer
) {
259 /* Don't assume a UNICODE_STRING Buffer is zero terminated: */
260 int len
= pSPI
->ImageName
.Length
/ 2;
261 /* Check against max size and allow for terminating zero (already zeroed): */
262 if(len
>= MAX_PATH
)len
=MAX_PATH
- 1;
263 wcsncpy(pPerfData
[Idx
].ImageName
, pSPI
->ImageName
.Buffer
, len
);
265 LoadStringW(hInst
, IDS_IDLE_PROCESS
, pPerfData
[Idx
].ImageName
,
266 sizeof(pPerfData
[Idx
].ImageName
) / sizeof(pPerfData
[Idx
].ImageName
[0]));
269 pPerfData
[Idx
].ProcessId
= pSPI
->UniqueProcessId
;
272 double CurTime
= Li2Double(pSPI
->KernelTime
) + Li2Double(pSPI
->UserTime
);
273 double OldTime
= Li2Double(pPDOld
->KernelTime
) + Li2Double(pPDOld
->UserTime
);
274 double CpuTime
= (CurTime
- OldTime
) / dbSystemTime
;
275 CpuTime
= CpuTime
* 100.0 / (double)SystemBasicInfo
.NumberOfProcessors
; /* + 0.5; */
276 pPerfData
[Idx
].CPUUsage
= (ULONG
)CpuTime
;
278 pPerfData
[Idx
].CPUTime
.QuadPart
= pSPI
->UserTime
.QuadPart
+ pSPI
->KernelTime
.QuadPart
;
279 pPerfData
[Idx
].WorkingSetSizeBytes
= pSPI
->WorkingSetSize
;
280 pPerfData
[Idx
].PeakWorkingSetSizeBytes
= pSPI
->PeakWorkingSetSize
;
282 pPerfData
[Idx
].WorkingSetSizeDelta
= labs((LONG
)pSPI
->WorkingSetSize
- (LONG
)pPDOld
->WorkingSetSizeBytes
);
284 pPerfData
[Idx
].WorkingSetSizeDelta
= 0;
285 pPerfData
[Idx
].PageFaultCount
= pSPI
->PageFaultCount
;
287 pPerfData
[Idx
].PageFaultCountDelta
= labs((LONG
)pSPI
->PageFaultCount
- (LONG
)pPDOld
->PageFaultCount
);
289 pPerfData
[Idx
].PageFaultCountDelta
= 0;
290 pPerfData
[Idx
].VirtualMemorySizeBytes
= pSPI
->VirtualSize
;
291 pPerfData
[Idx
].PagedPoolUsagePages
= pSPI
->QuotaPeakPagedPoolUsage
;
292 pPerfData
[Idx
].NonPagedPoolUsagePages
= pSPI
->QuotaPeakNonPagedPoolUsage
;
293 pPerfData
[Idx
].BasePriority
= pSPI
->BasePriority
;
294 pPerfData
[Idx
].HandleCount
= pSPI
->HandleCount
;
295 pPerfData
[Idx
].ThreadCount
= pSPI
->NumberOfThreads
;
296 pPerfData
[Idx
].SessionId
= pSPI
->SessionId
;
297 pPerfData
[Idx
].UserName
[0] = L
'\0';
298 pPerfData
[Idx
].USERObjectCount
= 0;
299 pPerfData
[Idx
].GDIObjectCount
= 0;
300 ProcessUser
= SystemUserSid
;
303 if (pSPI
->UniqueProcessId
!= NULL
) {
304 hProcess
= OpenProcess(PROCESS_QUERY_INFORMATION
| READ_CONTROL
, FALSE
, PtrToUlong(pSPI
->UniqueProcessId
));
306 /* don't query the information of the system process. It's possible but
307 returns Administrators as the owner of the process instead of SYSTEM */
308 if (pSPI
->UniqueProcessId
!= (HANDLE
)0x4)
310 if (OpenProcessToken(hProcess
, TOKEN_QUERY
, &hProcessToken
))
315 Ret
= GetTokenInformation(hProcessToken
, TokenUser
, (LPVOID
)Buffer
, sizeof(Buffer
), &RetLen
);
316 CloseHandle(hProcessToken
);
319 ProcessUser
= ((PTOKEN_USER
)Buffer
)->User
.Sid
;
326 GetSecurityInfo(hProcess
, SE_KERNEL_OBJECT
, OWNER_SECURITY_INFORMATION
, &ProcessUser
, NULL
, NULL
, NULL
, &ProcessSD
);
329 pPerfData
[Idx
].USERObjectCount
= GetGuiResources(hProcess
, GR_USEROBJECTS
);
330 pPerfData
[Idx
].GDIObjectCount
= GetGuiResources(hProcess
, GR_GDIOBJECTS
);
333 GetProcessIoCounters(hProcess
, &pPerfData
[Idx
].IOCounters
);
334 CloseHandle(hProcess
);
340 /* clear information we were unable to fetch */
341 ZeroMemory(&pPerfData
[Idx
].IOCounters
, sizeof(IO_COUNTERS
));
344 SidToUserName(ProcessUser
, pPerfData
[Idx
].UserName
, sizeof(pPerfData
[0].UserName
) / sizeof(pPerfData
[0].UserName
[0]));
346 if (ProcessSD
!= NULL
)
348 LocalFree((HLOCAL
)ProcessSD
);
351 pPerfData
[Idx
].UserTime
.QuadPart
= pSPI
->UserTime
.QuadPart
;
352 pPerfData
[Idx
].KernelTime
.QuadPart
= pSPI
->KernelTime
.QuadPart
;
353 pSPI
= (PSYSTEM_PROCESS_INFORMATION
)((LPBYTE
)pSPI
+ pSPI
->NextEntryOffset
);
355 HeapFree(GetProcessHeap(), 0, pBuffer
);
356 LeaveCriticalSection(&PerfDataCriticalSection
);
359 ULONG
PerfDataGetProcessCount(void)
364 ULONG
PerfDataGetProcessorUsage(void)
366 return (ULONG
)dbIdleTime
;
369 ULONG
PerfDataGetProcessorSystemUsage(void)
371 return (ULONG
)dbKernelTime
;
374 BOOL
PerfDataGetImageName(ULONG Index
, LPWSTR lpImageName
, int nMaxCount
)
378 EnterCriticalSection(&PerfDataCriticalSection
);
380 if (Index
< ProcessCount
) {
381 wcsncpy(lpImageName
, pPerfData
[Index
].ImageName
, nMaxCount
);
386 LeaveCriticalSection(&PerfDataCriticalSection
);
390 int PerfGetIndexByProcessId(DWORD dwProcessId
)
395 EnterCriticalSection(&PerfDataCriticalSection
);
397 for (Index
= 0; Index
< ProcessCount
; Index
++)
399 if (PtrToUlong(pPerfData
[Index
].ProcessId
) == dwProcessId
)
406 LeaveCriticalSection(&PerfDataCriticalSection
);
411 ULONG
PerfDataGetProcessId(ULONG Index
)
415 EnterCriticalSection(&PerfDataCriticalSection
);
417 if (Index
< ProcessCount
)
418 ProcessId
= PtrToUlong(pPerfData
[Index
].ProcessId
);
422 LeaveCriticalSection(&PerfDataCriticalSection
);
427 BOOL
PerfDataGetUserName(ULONG Index
, LPWSTR lpUserName
, int nMaxCount
)
431 EnterCriticalSection(&PerfDataCriticalSection
);
433 if (Index
< ProcessCount
) {
434 wcsncpy(lpUserName
, pPerfData
[Index
].UserName
, nMaxCount
);
440 LeaveCriticalSection(&PerfDataCriticalSection
);
445 ULONG
PerfDataGetSessionId(ULONG Index
)
449 EnterCriticalSection(&PerfDataCriticalSection
);
451 if (Index
< ProcessCount
)
452 SessionId
= pPerfData
[Index
].SessionId
;
456 LeaveCriticalSection(&PerfDataCriticalSection
);
461 ULONG
PerfDataGetCPUUsage(ULONG Index
)
465 EnterCriticalSection(&PerfDataCriticalSection
);
467 if (Index
< ProcessCount
)
468 CpuUsage
= pPerfData
[Index
].CPUUsage
;
472 LeaveCriticalSection(&PerfDataCriticalSection
);
477 LARGE_INTEGER
PerfDataGetCPUTime(ULONG Index
)
479 LARGE_INTEGER CpuTime
= {{0,0}};
481 EnterCriticalSection(&PerfDataCriticalSection
);
483 if (Index
< ProcessCount
)
484 CpuTime
= pPerfData
[Index
].CPUTime
;
486 LeaveCriticalSection(&PerfDataCriticalSection
);
491 ULONG
PerfDataGetWorkingSetSizeBytes(ULONG Index
)
493 ULONG WorkingSetSizeBytes
;
495 EnterCriticalSection(&PerfDataCriticalSection
);
497 if (Index
< ProcessCount
)
498 WorkingSetSizeBytes
= pPerfData
[Index
].WorkingSetSizeBytes
;
500 WorkingSetSizeBytes
= 0;
502 LeaveCriticalSection(&PerfDataCriticalSection
);
504 return WorkingSetSizeBytes
;
507 ULONG
PerfDataGetPeakWorkingSetSizeBytes(ULONG Index
)
509 ULONG PeakWorkingSetSizeBytes
;
511 EnterCriticalSection(&PerfDataCriticalSection
);
513 if (Index
< ProcessCount
)
514 PeakWorkingSetSizeBytes
= pPerfData
[Index
].PeakWorkingSetSizeBytes
;
516 PeakWorkingSetSizeBytes
= 0;
518 LeaveCriticalSection(&PerfDataCriticalSection
);
520 return PeakWorkingSetSizeBytes
;
523 ULONG
PerfDataGetWorkingSetSizeDelta(ULONG Index
)
525 ULONG WorkingSetSizeDelta
;
527 EnterCriticalSection(&PerfDataCriticalSection
);
529 if (Index
< ProcessCount
)
530 WorkingSetSizeDelta
= pPerfData
[Index
].WorkingSetSizeDelta
;
532 WorkingSetSizeDelta
= 0;
534 LeaveCriticalSection(&PerfDataCriticalSection
);
536 return WorkingSetSizeDelta
;
539 ULONG
PerfDataGetPageFaultCount(ULONG Index
)
541 ULONG PageFaultCount
;
543 EnterCriticalSection(&PerfDataCriticalSection
);
545 if (Index
< ProcessCount
)
546 PageFaultCount
= pPerfData
[Index
].PageFaultCount
;
550 LeaveCriticalSection(&PerfDataCriticalSection
);
552 return PageFaultCount
;
555 ULONG
PerfDataGetPageFaultCountDelta(ULONG Index
)
557 ULONG PageFaultCountDelta
;
559 EnterCriticalSection(&PerfDataCriticalSection
);
561 if (Index
< ProcessCount
)
562 PageFaultCountDelta
= pPerfData
[Index
].PageFaultCountDelta
;
564 PageFaultCountDelta
= 0;
566 LeaveCriticalSection(&PerfDataCriticalSection
);
568 return PageFaultCountDelta
;
571 ULONG
PerfDataGetVirtualMemorySizeBytes(ULONG Index
)
573 ULONG VirtualMemorySizeBytes
;
575 EnterCriticalSection(&PerfDataCriticalSection
);
577 if (Index
< ProcessCount
)
578 VirtualMemorySizeBytes
= pPerfData
[Index
].VirtualMemorySizeBytes
;
580 VirtualMemorySizeBytes
= 0;
582 LeaveCriticalSection(&PerfDataCriticalSection
);
584 return VirtualMemorySizeBytes
;
587 ULONG
PerfDataGetPagedPoolUsagePages(ULONG Index
)
589 ULONG PagedPoolUsage
;
591 EnterCriticalSection(&PerfDataCriticalSection
);
593 if (Index
< ProcessCount
)
594 PagedPoolUsage
= pPerfData
[Index
].PagedPoolUsagePages
;
598 LeaveCriticalSection(&PerfDataCriticalSection
);
600 return PagedPoolUsage
;
603 ULONG
PerfDataGetNonPagedPoolUsagePages(ULONG Index
)
605 ULONG NonPagedPoolUsage
;
607 EnterCriticalSection(&PerfDataCriticalSection
);
609 if (Index
< ProcessCount
)
610 NonPagedPoolUsage
= pPerfData
[Index
].NonPagedPoolUsagePages
;
612 NonPagedPoolUsage
= 0;
614 LeaveCriticalSection(&PerfDataCriticalSection
);
616 return NonPagedPoolUsage
;
619 ULONG
PerfDataGetBasePriority(ULONG Index
)
623 EnterCriticalSection(&PerfDataCriticalSection
);
625 if (Index
< ProcessCount
)
626 BasePriority
= pPerfData
[Index
].BasePriority
;
630 LeaveCriticalSection(&PerfDataCriticalSection
);
635 ULONG
PerfDataGetHandleCount(ULONG Index
)
639 EnterCriticalSection(&PerfDataCriticalSection
);
641 if (Index
< ProcessCount
)
642 HandleCount
= pPerfData
[Index
].HandleCount
;
646 LeaveCriticalSection(&PerfDataCriticalSection
);
651 ULONG
PerfDataGetThreadCount(ULONG Index
)
655 EnterCriticalSection(&PerfDataCriticalSection
);
657 if (Index
< ProcessCount
)
658 ThreadCount
= pPerfData
[Index
].ThreadCount
;
662 LeaveCriticalSection(&PerfDataCriticalSection
);
667 ULONG
PerfDataGetUSERObjectCount(ULONG Index
)
669 ULONG USERObjectCount
;
671 EnterCriticalSection(&PerfDataCriticalSection
);
673 if (Index
< ProcessCount
)
674 USERObjectCount
= pPerfData
[Index
].USERObjectCount
;
678 LeaveCriticalSection(&PerfDataCriticalSection
);
680 return USERObjectCount
;
683 ULONG
PerfDataGetGDIObjectCount(ULONG Index
)
685 ULONG GDIObjectCount
;
687 EnterCriticalSection(&PerfDataCriticalSection
);
689 if (Index
< ProcessCount
)
690 GDIObjectCount
= pPerfData
[Index
].GDIObjectCount
;
694 LeaveCriticalSection(&PerfDataCriticalSection
);
696 return GDIObjectCount
;
699 BOOL
PerfDataGetIOCounters(ULONG Index
, PIO_COUNTERS pIoCounters
)
703 EnterCriticalSection(&PerfDataCriticalSection
);
705 if (Index
< ProcessCount
)
707 memcpy(pIoCounters
, &pPerfData
[Index
].IOCounters
, sizeof(IO_COUNTERS
));
713 LeaveCriticalSection(&PerfDataCriticalSection
);
718 ULONG
PerfDataGetCommitChargeTotalK(void)
723 EnterCriticalSection(&PerfDataCriticalSection
);
725 Total
= SystemPerfInfo
.CommittedPages
;
726 PageSize
= SystemBasicInfo
.PageSize
;
728 LeaveCriticalSection(&PerfDataCriticalSection
);
730 Total
= Total
* (PageSize
/ 1024);
735 ULONG
PerfDataGetCommitChargeLimitK(void)
740 EnterCriticalSection(&PerfDataCriticalSection
);
742 Limit
= SystemPerfInfo
.CommitLimit
;
743 PageSize
= SystemBasicInfo
.PageSize
;
745 LeaveCriticalSection(&PerfDataCriticalSection
);
747 Limit
= Limit
* (PageSize
/ 1024);
752 ULONG
PerfDataGetCommitChargePeakK(void)
757 EnterCriticalSection(&PerfDataCriticalSection
);
759 Peak
= SystemPerfInfo
.PeakCommitment
;
760 PageSize
= SystemBasicInfo
.PageSize
;
762 LeaveCriticalSection(&PerfDataCriticalSection
);
764 Peak
= Peak
* (PageSize
/ 1024);
769 ULONG
PerfDataGetKernelMemoryTotalK(void)
776 EnterCriticalSection(&PerfDataCriticalSection
);
778 Paged
= SystemPerfInfo
.PagedPoolPages
;
779 NonPaged
= SystemPerfInfo
.NonPagedPoolPages
;
780 PageSize
= SystemBasicInfo
.PageSize
;
782 LeaveCriticalSection(&PerfDataCriticalSection
);
784 Paged
= Paged
* (PageSize
/ 1024);
785 NonPaged
= NonPaged
* (PageSize
/ 1024);
787 Total
= Paged
+ NonPaged
;
792 ULONG
PerfDataGetKernelMemoryPagedK(void)
797 EnterCriticalSection(&PerfDataCriticalSection
);
799 Paged
= SystemPerfInfo
.PagedPoolPages
;
800 PageSize
= SystemBasicInfo
.PageSize
;
802 LeaveCriticalSection(&PerfDataCriticalSection
);
804 Paged
= Paged
* (PageSize
/ 1024);
809 ULONG
PerfDataGetKernelMemoryNonPagedK(void)
814 EnterCriticalSection(&PerfDataCriticalSection
);
816 NonPaged
= SystemPerfInfo
.NonPagedPoolPages
;
817 PageSize
= SystemBasicInfo
.PageSize
;
819 LeaveCriticalSection(&PerfDataCriticalSection
);
821 NonPaged
= NonPaged
* (PageSize
/ 1024);
826 ULONG
PerfDataGetPhysicalMemoryTotalK(void)
831 EnterCriticalSection(&PerfDataCriticalSection
);
833 Total
= SystemBasicInfo
.NumberOfPhysicalPages
;
834 PageSize
= SystemBasicInfo
.PageSize
;
836 LeaveCriticalSection(&PerfDataCriticalSection
);
838 Total
= Total
* (PageSize
/ 1024);
843 ULONG
PerfDataGetPhysicalMemoryAvailableK(void)
848 EnterCriticalSection(&PerfDataCriticalSection
);
850 Available
= SystemPerfInfo
.AvailablePages
;
851 PageSize
= SystemBasicInfo
.PageSize
;
853 LeaveCriticalSection(&PerfDataCriticalSection
);
855 Available
= Available
* (PageSize
/ 1024);
860 ULONG
PerfDataGetPhysicalMemorySystemCacheK(void)
865 EnterCriticalSection(&PerfDataCriticalSection
);
867 PageSize
= SystemBasicInfo
.PageSize
;
868 SystemCache
= SystemCacheInfo
.CurrentSizeIncludingTransitionInPages
* PageSize
;
870 LeaveCriticalSection(&PerfDataCriticalSection
);
872 return SystemCache
/ 1024;
875 ULONG
PerfDataGetSystemHandleCount(void)
879 EnterCriticalSection(&PerfDataCriticalSection
);
881 HandleCount
= SystemHandleInfo
.NumberOfHandles
;
883 LeaveCriticalSection(&PerfDataCriticalSection
);
888 ULONG
PerfDataGetTotalThreadCount(void)
890 ULONG ThreadCount
= 0;
893 EnterCriticalSection(&PerfDataCriticalSection
);
895 for (i
=0; i
<ProcessCount
; i
++)
897 ThreadCount
+= pPerfData
[i
].ThreadCount
;
900 LeaveCriticalSection(&PerfDataCriticalSection
);
905 BOOL
PerfDataGet(ULONG Index
, PPERFDATA
*lppData
)
907 BOOL bSuccessful
= FALSE
;
909 EnterCriticalSection(&PerfDataCriticalSection
);
910 if (Index
< ProcessCount
)
912 *lppData
= pPerfData
+ Index
;
915 LeaveCriticalSection(&PerfDataCriticalSection
);