dpnet/tests: Add a trailing '\n' to some ok() calls.
[wine.git] / programs / taskmgr / perfdata.c
blobaa19914d61a0980783864a610d94703d399a836e
1 /*
2 * ReactOS Task Manager
4 * perfdata.c
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 #include <stdio.h>
24 #include <stdlib.h>
26 #include <windows.h>
27 #include <commctrl.h>
28 #include <winnt.h>
30 #include "taskmgr.h"
31 #include "perfdata.h"
33 static PROCNTQSI pNtQuerySystemInformation = NULL;
34 static PROCGGR pGetGuiResources = NULL;
35 static PROCGPIC pGetProcessIoCounters = NULL;
36 static PROCISW64 pIsWow64Process = 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_PROCESSOR_PERFORMANCE_INFORMATION SystemProcessorTimeInfo = NULL;
54 BOOL PerfDataInitialize(void)
56 LONG status;
57 static const WCHAR wszNtdll[] = {'n','t','d','l','l','.','d','l','l',0};
58 static const WCHAR wszUser32[] = {'u','s','e','r','3','2','.','d','l','l',0};
59 static const WCHAR wszKernel32[] = {'k','e','r','n','e','l','3','2','.','d','l','l',0};
61 pNtQuerySystemInformation = (PROCNTQSI)GetProcAddress(GetModuleHandleW(wszNtdll), "NtQuerySystemInformation");
62 pGetGuiResources = (PROCGGR)GetProcAddress(GetModuleHandleW(wszUser32), "GetGuiResources");
63 pGetProcessIoCounters = (PROCGPIC)GetProcAddress(GetModuleHandleW(wszKernel32), "GetProcessIoCounters");
64 pIsWow64Process = (PROCISW64)GetProcAddress(GetModuleHandleW(wszKernel32), "IsWow64Process");
66 InitializeCriticalSection(&PerfDataCriticalSection);
68 if (!pNtQuerySystemInformation)
69 return FALSE;
72 * Get number of processors in the system
74 status = pNtQuerySystemInformation(SystemBasicInformation, &SystemBasicInfo, sizeof(SystemBasicInfo), NULL);
75 if (status != NO_ERROR)
76 return FALSE;
78 return TRUE;
81 void PerfDataRefresh(void)
83 ULONG ulSize;
84 LONG status;
85 LPBYTE pBuffer;
86 ULONG BufferSize;
87 PSYSTEM_PROCESS_INFORMATION pSPI;
88 PPERFDATA pPDOld;
89 ULONG Idx, Idx2;
90 HANDLE hProcess;
91 HANDLE hProcessToken;
92 WCHAR wszTemp[MAX_PATH];
93 DWORD dwSize;
94 SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo;
95 SYSTEM_TIMEOFDAY_INFORMATION SysTimeInfo;
96 SYSTEM_CACHE_INFORMATION SysCacheInfo;
97 LPBYTE SysHandleInfoData;
98 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION *SysProcessorTimeInfo;
99 double CurrentKernelTime;
102 /* Get new system time */
103 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &SysTimeInfo, sizeof(SysTimeInfo), 0);
104 if (status != NO_ERROR)
105 return;
107 /* Get new CPU's idle time */
108 status = pNtQuerySystemInformation(SystemPerformanceInformation, &SysPerfInfo, sizeof(SysPerfInfo), NULL);
109 if (status != NO_ERROR)
110 return;
112 /* Get system cache information */
113 status = pNtQuerySystemInformation(SystemCacheInformation, &SysCacheInfo, sizeof(SysCacheInfo), NULL);
114 if (status != NO_ERROR)
115 return;
117 /* Get processor time information */
118 SysProcessorTimeInfo = HeapAlloc(GetProcessHeap(), 0,
119 sizeof(*SysProcessorTimeInfo) * SystemBasicInfo.NumberOfProcessors);
120 status = pNtQuerySystemInformation(SystemProcessorPerformanceInformation, SysProcessorTimeInfo, sizeof(*SysProcessorTimeInfo) * SystemBasicInfo.NumberOfProcessors, &ulSize);
121 if (status != NO_ERROR) {
122 HeapFree(GetProcessHeap(), 0, SysProcessorTimeInfo);
123 return;
126 /* Get handle information
127 * We don't know how much data there is so just keep
128 * increasing the buffer size until the call succeeds
130 BufferSize = 0;
133 BufferSize += 0x10000;
134 SysHandleInfoData = HeapAlloc(GetProcessHeap(), 0, BufferSize);
136 status = pNtQuerySystemInformation(SystemHandleInformation, SysHandleInfoData, BufferSize, &ulSize);
138 if (status == 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/) {
139 HeapFree(GetProcessHeap(), 0, SysHandleInfoData);
142 } while (status == 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/);
144 /* Get process information
145 * We don't know how much data there is so just keep
146 * increasing the buffer size until the call succeeds
148 BufferSize = 0;
151 BufferSize += 0x10000;
152 pBuffer = HeapAlloc(GetProcessHeap(), 0, BufferSize);
154 status = pNtQuerySystemInformation(SystemProcessInformation, pBuffer, BufferSize, &ulSize);
156 if (status == 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/) {
157 HeapFree(GetProcessHeap(), 0, pBuffer);
160 } while (status == 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/);
162 EnterCriticalSection(&PerfDataCriticalSection);
165 * Save system performance info
167 memcpy(&SystemPerfInfo, &SysPerfInfo, sizeof(SYSTEM_PERFORMANCE_INFORMATION));
170 * Save system cache info
172 memcpy(&SystemCacheInfo, &SysCacheInfo, sizeof(SYSTEM_CACHE_INFORMATION));
175 * Save system processor time info
177 HeapFree(GetProcessHeap(), 0, SystemProcessorTimeInfo);
178 SystemProcessorTimeInfo = SysProcessorTimeInfo;
181 * Save system handle info
183 memcpy(&SystemHandleInfo, SysHandleInfoData, sizeof(SYSTEM_HANDLE_INFORMATION));
184 HeapFree(GetProcessHeap(), 0, SysHandleInfoData);
186 for (CurrentKernelTime=0, Idx=0; Idx<SystemBasicInfo.NumberOfProcessors; Idx++) {
187 CurrentKernelTime += Li2Double(SystemProcessorTimeInfo[Idx].KernelTime);
188 CurrentKernelTime += Li2Double(SystemProcessorTimeInfo[Idx].Reserved1[0]);
189 CurrentKernelTime += Li2Double(SystemProcessorTimeInfo[Idx].Reserved1[1]);
192 /* If it's a first call - skip idle time calcs */
193 if (liOldIdleTime.QuadPart != 0) {
194 /* CurrentValue = NewValue - OldValue */
195 dbIdleTime = Li2Double(SysPerfInfo.IdleTime) - Li2Double(liOldIdleTime);
196 dbKernelTime = CurrentKernelTime - OldKernelTime;
197 dbSystemTime = Li2Double(SysTimeInfo.liKeSystemTime) - Li2Double(liOldSystemTime);
199 /* CurrentCpuIdle = IdleTime / SystemTime */
200 dbIdleTime = dbIdleTime / dbSystemTime;
201 dbKernelTime = dbKernelTime / dbSystemTime;
203 /* CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) / NumberOfProcessors */
204 dbIdleTime = 100.0 - dbIdleTime * 100.0 / (double)SystemBasicInfo.NumberOfProcessors; /* + 0.5; */
205 dbKernelTime = 100.0 - dbKernelTime * 100.0 / (double)SystemBasicInfo.NumberOfProcessors; /* + 0.5; */
208 /* Store new CPU's idle and system time */
209 liOldIdleTime = SysPerfInfo.IdleTime;
210 liOldSystemTime = SysTimeInfo.liKeSystemTime;
211 OldKernelTime = CurrentKernelTime;
213 /* Determine the process count
214 * We loop through the data we got from NtQuerySystemInformation
215 * and count how many structures there are (until RelativeOffset is 0)
217 ProcessCountOld = ProcessCount;
218 ProcessCount = 0;
219 pSPI = (PSYSTEM_PROCESS_INFORMATION)pBuffer;
220 while (pSPI) {
221 ProcessCount++;
222 if (pSPI->NextEntryOffset == 0)
223 break;
224 pSPI = (PSYSTEM_PROCESS_INFORMATION)((LPBYTE)pSPI + pSPI->NextEntryOffset);
227 /* Now alloc a new PERFDATA array and fill in the data */
228 HeapFree(GetProcessHeap(), 0, pPerfDataOld);
229 pPerfDataOld = pPerfData;
230 pPerfData = HeapAlloc(GetProcessHeap(), 0, sizeof(PERFDATA) * ProcessCount);
231 pSPI = (PSYSTEM_PROCESS_INFORMATION)pBuffer;
232 for (Idx=0; Idx<ProcessCount; Idx++) {
233 /* Get the old perf data for this process (if any) */
234 /* so that we can establish delta values */
235 pPDOld = NULL;
236 for (Idx2=0; Idx2<ProcessCountOld; Idx2++) {
237 if (pPerfDataOld[Idx2].ProcessId == (DWORD_PTR)pSPI->UniqueProcessId) {
238 pPDOld = &pPerfDataOld[Idx2];
239 break;
243 /* Clear out process perf data structure */
244 memset(&pPerfData[Idx], 0, sizeof(PERFDATA));
246 if (pSPI->ProcessName.Buffer)
247 lstrcpyW(pPerfData[Idx].ImageName, pSPI->ProcessName.Buffer);
248 else
250 WCHAR idleW[255];
251 LoadStringW(hInst, IDS_SYSTEM_IDLE_PROCESS, idleW, sizeof(idleW)/sizeof(WCHAR));
252 lstrcpyW(pPerfData[Idx].ImageName, idleW );
255 pPerfData[Idx].ProcessId = (DWORD_PTR)pSPI->UniqueProcessId;
257 if (pPDOld) {
258 double CurTime = Li2Double(pSPI->KernelTime) + Li2Double(pSPI->UserTime);
259 double OldTime = Li2Double(pPDOld->KernelTime) + Li2Double(pPDOld->UserTime);
260 double CpuTime = (CurTime - OldTime) / dbSystemTime;
261 CpuTime = CpuTime * 100.0 / (double)SystemBasicInfo.NumberOfProcessors; /* + 0.5; */
262 pPerfData[Idx].CPUUsage = (ULONG)CpuTime;
265 pPerfData[Idx].CPUTime.QuadPart = pSPI->UserTime.QuadPart + pSPI->KernelTime.QuadPart;
266 pPerfData[Idx].vmCounters.WorkingSetSize = pSPI->vmCounters.WorkingSetSize;
267 pPerfData[Idx].vmCounters.PeakWorkingSetSize = pSPI->vmCounters.PeakWorkingSetSize;
268 if (pPDOld)
269 pPerfData[Idx].WorkingSetSizeDelta = labs(pSPI->vmCounters.WorkingSetSize - pPDOld->vmCounters.WorkingSetSize);
270 else
271 pPerfData[Idx].WorkingSetSizeDelta = 0;
272 pPerfData[Idx].vmCounters.PageFaultCount = pSPI->vmCounters.PageFaultCount;
273 if (pPDOld)
274 pPerfData[Idx].PageFaultCountDelta = labs(pSPI->vmCounters.PageFaultCount - pPDOld->vmCounters.PageFaultCount);
275 else
276 pPerfData[Idx].PageFaultCountDelta = 0;
277 pPerfData[Idx].vmCounters.VirtualSize = pSPI->vmCounters.VirtualSize;
278 pPerfData[Idx].vmCounters.QuotaPagedPoolUsage = pSPI->vmCounters.QuotaPagedPoolUsage;
279 pPerfData[Idx].vmCounters.QuotaNonPagedPoolUsage = pSPI->vmCounters.QuotaNonPagedPoolUsage;
280 pPerfData[Idx].BasePriority = pSPI->dwBasePriority;
281 pPerfData[Idx].HandleCount = pSPI->HandleCount;
282 pPerfData[Idx].ThreadCount = pSPI->dwThreadCount;
283 pPerfData[Idx].SessionId = pSPI->SessionId;
285 hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, (DWORD_PTR)pSPI->UniqueProcessId);
286 if (hProcess) {
287 if (OpenProcessToken(hProcess, TOKEN_QUERY|TOKEN_DUPLICATE|TOKEN_IMPERSONATE, &hProcessToken)) {
288 ImpersonateLoggedOnUser(hProcessToken);
289 memset(wszTemp, 0, sizeof(wszTemp));
290 dwSize = MAX_PATH;
291 GetUserNameW(wszTemp, &dwSize);
292 RevertToSelf();
293 CloseHandle(hProcessToken);
295 if (pGetGuiResources) {
296 pPerfData[Idx].USERObjectCount = pGetGuiResources(hProcess, GR_USEROBJECTS);
297 pPerfData[Idx].GDIObjectCount = pGetGuiResources(hProcess, GR_GDIOBJECTS);
299 if (pGetProcessIoCounters)
300 pGetProcessIoCounters(hProcess, &pPerfData[Idx].IOCounters);
301 if (pIsWow64Process)
302 pIsWow64Process(hProcess, &pPerfData[Idx].Wow64Process);
303 CloseHandle(hProcess);
305 pPerfData[Idx].UserTime.QuadPart = pSPI->UserTime.QuadPart;
306 pPerfData[Idx].KernelTime.QuadPart = pSPI->KernelTime.QuadPart;
307 pSPI = (PSYSTEM_PROCESS_INFORMATION)((LPBYTE)pSPI + pSPI->NextEntryOffset);
309 HeapFree(GetProcessHeap(), 0, pBuffer);
310 LeaveCriticalSection(&PerfDataCriticalSection);
313 ULONG PerfDataGetProcessCount(void)
315 return ProcessCount;
318 ULONG PerfDataGetProcessorUsage(void)
320 if( dbIdleTime < 0.0 )
321 return 0;
322 if( dbIdleTime > 100.0 )
323 return 100;
324 return (ULONG)dbIdleTime;
327 ULONG PerfDataGetProcessorSystemUsage(void)
329 if( dbKernelTime < 0.0 )
330 return 0;
331 if( dbKernelTime > 100.0 )
332 return 100;
333 return (ULONG)dbKernelTime;
336 BOOL PerfDataGetImageName(ULONG Index, LPWSTR lpImageName, int nMaxCount)
338 static const WCHAR proc32W[] = {' ','*','3','2',0};
339 BOOL bSuccessful;
341 EnterCriticalSection(&PerfDataCriticalSection);
343 if (Index < ProcessCount) {
344 wcsncpy(lpImageName, pPerfData[Index].ImageName, nMaxCount);
345 if (pPerfData[Index].Wow64Process &&
346 nMaxCount - lstrlenW(lpImageName) > 4 /* =lstrlenW(proc32W) */)
347 lstrcatW(lpImageName, proc32W);
348 bSuccessful = TRUE;
349 } else {
350 bSuccessful = FALSE;
352 LeaveCriticalSection(&PerfDataCriticalSection);
353 return bSuccessful;
356 ULONG PerfDataGetProcessId(ULONG Index)
358 ULONG ProcessId;
360 EnterCriticalSection(&PerfDataCriticalSection);
362 if (Index < ProcessCount)
363 ProcessId = pPerfData[Index].ProcessId;
364 else
365 ProcessId = 0;
367 LeaveCriticalSection(&PerfDataCriticalSection);
369 return ProcessId;
372 BOOL PerfDataGetUserName(ULONG Index, LPWSTR lpUserName, int nMaxCount)
374 BOOL bSuccessful;
376 EnterCriticalSection(&PerfDataCriticalSection);
378 if (Index < ProcessCount) {
379 wcsncpy(lpUserName, pPerfData[Index].UserName, nMaxCount);
380 bSuccessful = TRUE;
381 } else {
382 bSuccessful = FALSE;
385 LeaveCriticalSection(&PerfDataCriticalSection);
387 return bSuccessful;
390 ULONG PerfDataGetSessionId(ULONG Index)
392 ULONG SessionId;
394 EnterCriticalSection(&PerfDataCriticalSection);
396 if (Index < ProcessCount)
397 SessionId = pPerfData[Index].SessionId;
398 else
399 SessionId = 0;
401 LeaveCriticalSection(&PerfDataCriticalSection);
403 return SessionId;
406 ULONG PerfDataGetCPUUsage(ULONG Index)
408 ULONG CpuUsage;
410 EnterCriticalSection(&PerfDataCriticalSection);
412 if (Index < ProcessCount)
413 CpuUsage = pPerfData[Index].CPUUsage;
414 else
415 CpuUsage = 0;
417 LeaveCriticalSection(&PerfDataCriticalSection);
419 return CpuUsage;
422 TIME PerfDataGetCPUTime(ULONG Index)
424 TIME CpuTime = {{0,0}};
426 EnterCriticalSection(&PerfDataCriticalSection);
428 if (Index < ProcessCount)
429 CpuTime = pPerfData[Index].CPUTime;
431 LeaveCriticalSection(&PerfDataCriticalSection);
433 return CpuTime;
436 ULONG PerfDataGetWorkingSetSizeBytes(ULONG Index)
438 ULONG WorkingSetSizeBytes;
440 EnterCriticalSection(&PerfDataCriticalSection);
442 if (Index < ProcessCount)
443 WorkingSetSizeBytes = pPerfData[Index].vmCounters.WorkingSetSize;
444 else
445 WorkingSetSizeBytes = 0;
447 LeaveCriticalSection(&PerfDataCriticalSection);
449 return WorkingSetSizeBytes;
452 ULONG PerfDataGetPeakWorkingSetSizeBytes(ULONG Index)
454 ULONG PeakWorkingSetSizeBytes;
456 EnterCriticalSection(&PerfDataCriticalSection);
458 if (Index < ProcessCount)
459 PeakWorkingSetSizeBytes = pPerfData[Index].vmCounters.PeakWorkingSetSize;
460 else
461 PeakWorkingSetSizeBytes = 0;
463 LeaveCriticalSection(&PerfDataCriticalSection);
465 return PeakWorkingSetSizeBytes;
468 ULONG PerfDataGetWorkingSetSizeDelta(ULONG Index)
470 ULONG WorkingSetSizeDelta;
472 EnterCriticalSection(&PerfDataCriticalSection);
474 if (Index < ProcessCount)
475 WorkingSetSizeDelta = pPerfData[Index].WorkingSetSizeDelta;
476 else
477 WorkingSetSizeDelta = 0;
479 LeaveCriticalSection(&PerfDataCriticalSection);
481 return WorkingSetSizeDelta;
484 ULONG PerfDataGetPageFaultCount(ULONG Index)
486 ULONG PageFaultCount;
488 EnterCriticalSection(&PerfDataCriticalSection);
490 if (Index < ProcessCount)
491 PageFaultCount = pPerfData[Index].vmCounters.PageFaultCount;
492 else
493 PageFaultCount = 0;
495 LeaveCriticalSection(&PerfDataCriticalSection);
497 return PageFaultCount;
500 ULONG PerfDataGetPageFaultCountDelta(ULONG Index)
502 ULONG PageFaultCountDelta;
504 EnterCriticalSection(&PerfDataCriticalSection);
506 if (Index < ProcessCount)
507 PageFaultCountDelta = pPerfData[Index].PageFaultCountDelta;
508 else
509 PageFaultCountDelta = 0;
511 LeaveCriticalSection(&PerfDataCriticalSection);
513 return PageFaultCountDelta;
516 ULONG PerfDataGetVirtualMemorySizeBytes(ULONG Index)
518 ULONG VirtualMemorySizeBytes;
520 EnterCriticalSection(&PerfDataCriticalSection);
522 if (Index < ProcessCount)
523 VirtualMemorySizeBytes = pPerfData[Index].vmCounters.VirtualSize;
524 else
525 VirtualMemorySizeBytes = 0;
527 LeaveCriticalSection(&PerfDataCriticalSection);
529 return VirtualMemorySizeBytes;
532 ULONG PerfDataGetPagedPoolUsagePages(ULONG Index)
534 ULONG PagedPoolUsagePages;
536 EnterCriticalSection(&PerfDataCriticalSection);
538 if (Index < ProcessCount)
539 PagedPoolUsagePages = pPerfData[Index].vmCounters.QuotaPagedPoolUsage;
540 else
541 PagedPoolUsagePages = 0;
543 LeaveCriticalSection(&PerfDataCriticalSection);
545 return PagedPoolUsagePages;
548 ULONG PerfDataGetNonPagedPoolUsagePages(ULONG Index)
550 ULONG NonPagedPoolUsagePages;
552 EnterCriticalSection(&PerfDataCriticalSection);
554 if (Index < ProcessCount)
555 NonPagedPoolUsagePages = pPerfData[Index].vmCounters.QuotaNonPagedPoolUsage;
556 else
557 NonPagedPoolUsagePages = 0;
559 LeaveCriticalSection(&PerfDataCriticalSection);
561 return NonPagedPoolUsagePages;
564 ULONG PerfDataGetBasePriority(ULONG Index)
566 ULONG BasePriority;
568 EnterCriticalSection(&PerfDataCriticalSection);
570 if (Index < ProcessCount)
571 BasePriority = pPerfData[Index].BasePriority;
572 else
573 BasePriority = 0;
575 LeaveCriticalSection(&PerfDataCriticalSection);
577 return BasePriority;
580 ULONG PerfDataGetHandleCount(ULONG Index)
582 ULONG HandleCount;
584 EnterCriticalSection(&PerfDataCriticalSection);
586 if (Index < ProcessCount)
587 HandleCount = pPerfData[Index].HandleCount;
588 else
589 HandleCount = 0;
591 LeaveCriticalSection(&PerfDataCriticalSection);
593 return HandleCount;
596 ULONG PerfDataGetThreadCount(ULONG Index)
598 ULONG ThreadCount;
600 EnterCriticalSection(&PerfDataCriticalSection);
602 if (Index < ProcessCount)
603 ThreadCount = pPerfData[Index].ThreadCount;
604 else
605 ThreadCount = 0;
607 LeaveCriticalSection(&PerfDataCriticalSection);
609 return ThreadCount;
612 ULONG PerfDataGetUSERObjectCount(ULONG Index)
614 ULONG USERObjectCount;
616 EnterCriticalSection(&PerfDataCriticalSection);
618 if (Index < ProcessCount)
619 USERObjectCount = pPerfData[Index].USERObjectCount;
620 else
621 USERObjectCount = 0;
623 LeaveCriticalSection(&PerfDataCriticalSection);
625 return USERObjectCount;
628 ULONG PerfDataGetGDIObjectCount(ULONG Index)
630 ULONG GDIObjectCount;
632 EnterCriticalSection(&PerfDataCriticalSection);
634 if (Index < ProcessCount)
635 GDIObjectCount = pPerfData[Index].GDIObjectCount;
636 else
637 GDIObjectCount = 0;
639 LeaveCriticalSection(&PerfDataCriticalSection);
641 return GDIObjectCount;
644 BOOL PerfDataGetIOCounters(ULONG Index, PIO_COUNTERS pIoCounters)
646 BOOL bSuccessful;
648 EnterCriticalSection(&PerfDataCriticalSection);
650 if (Index < ProcessCount)
652 memcpy(pIoCounters, &pPerfData[Index].IOCounters, sizeof(IO_COUNTERS));
653 bSuccessful = TRUE;
655 else
656 bSuccessful = FALSE;
658 LeaveCriticalSection(&PerfDataCriticalSection);
660 return bSuccessful;
663 ULONG PerfDataGetCommitChargeTotalK(void)
665 ULONG Total;
666 ULONG PageSize;
668 EnterCriticalSection(&PerfDataCriticalSection);
670 Total = SystemPerfInfo.TotalCommittedPages;
671 PageSize = SystemBasicInfo.PageSize;
673 LeaveCriticalSection(&PerfDataCriticalSection);
675 Total = Total * (PageSize / 1024);
677 return Total;
680 ULONG PerfDataGetCommitChargeLimitK(void)
682 ULONG Limit;
683 ULONG PageSize;
685 EnterCriticalSection(&PerfDataCriticalSection);
687 Limit = SystemPerfInfo.TotalCommitLimit;
688 PageSize = SystemBasicInfo.PageSize;
690 LeaveCriticalSection(&PerfDataCriticalSection);
692 Limit = Limit * (PageSize / 1024);
694 return Limit;
697 ULONG PerfDataGetCommitChargePeakK(void)
699 ULONG Peak;
700 ULONG PageSize;
702 EnterCriticalSection(&PerfDataCriticalSection);
704 Peak = SystemPerfInfo.PeakCommitment;
705 PageSize = SystemBasicInfo.PageSize;
707 LeaveCriticalSection(&PerfDataCriticalSection);
709 Peak = Peak * (PageSize / 1024);
711 return Peak;
714 ULONG PerfDataGetKernelMemoryTotalK(void)
716 ULONG Total;
717 ULONG Paged;
718 ULONG NonPaged;
719 ULONG PageSize;
721 EnterCriticalSection(&PerfDataCriticalSection);
723 Paged = SystemPerfInfo.PagedPoolUsage;
724 NonPaged = SystemPerfInfo.NonPagedPoolUsage;
725 PageSize = SystemBasicInfo.PageSize;
727 LeaveCriticalSection(&PerfDataCriticalSection);
729 Paged = Paged * (PageSize / 1024);
730 NonPaged = NonPaged * (PageSize / 1024);
732 Total = Paged + NonPaged;
734 return Total;
737 ULONG PerfDataGetKernelMemoryPagedK(void)
739 ULONG Paged;
740 ULONG PageSize;
742 EnterCriticalSection(&PerfDataCriticalSection);
744 Paged = SystemPerfInfo.PagedPoolUsage;
745 PageSize = SystemBasicInfo.PageSize;
747 LeaveCriticalSection(&PerfDataCriticalSection);
749 Paged = Paged * (PageSize / 1024);
751 return Paged;
754 ULONG PerfDataGetKernelMemoryNonPagedK(void)
756 ULONG NonPaged;
757 ULONG PageSize;
759 EnterCriticalSection(&PerfDataCriticalSection);
761 NonPaged = SystemPerfInfo.NonPagedPoolUsage;
762 PageSize = SystemBasicInfo.PageSize;
764 LeaveCriticalSection(&PerfDataCriticalSection);
766 NonPaged = NonPaged * (PageSize / 1024);
768 return NonPaged;
771 ULONG PerfDataGetPhysicalMemoryTotalK(void)
773 ULONG Total;
774 ULONG PageSize;
776 EnterCriticalSection(&PerfDataCriticalSection);
778 Total = SystemBasicInfo.MmNumberOfPhysicalPages;
779 PageSize = SystemBasicInfo.PageSize;
781 LeaveCriticalSection(&PerfDataCriticalSection);
783 Total = Total * (PageSize / 1024);
785 return Total;
788 ULONG PerfDataGetPhysicalMemoryAvailableK(void)
790 ULONG Available;
791 ULONG PageSize;
793 EnterCriticalSection(&PerfDataCriticalSection);
795 Available = SystemPerfInfo.AvailablePages;
796 PageSize = SystemBasicInfo.PageSize;
798 LeaveCriticalSection(&PerfDataCriticalSection);
800 Available = Available * (PageSize / 1024);
802 return Available;
805 ULONG PerfDataGetPhysicalMemorySystemCacheK(void)
807 ULONG SystemCache;
809 EnterCriticalSection(&PerfDataCriticalSection);
811 SystemCache = SystemCacheInfo.CurrentSize;
813 LeaveCriticalSection(&PerfDataCriticalSection);
815 SystemCache = SystemCache / 1024;
817 return SystemCache;
820 ULONG PerfDataGetSystemHandleCount(void)
822 ULONG HandleCount;
824 EnterCriticalSection(&PerfDataCriticalSection);
826 HandleCount = SystemHandleInfo.Count;
828 LeaveCriticalSection(&PerfDataCriticalSection);
830 return HandleCount;
833 ULONG PerfDataGetTotalThreadCount(void)
835 ULONG ThreadCount = 0;
836 ULONG i;
838 EnterCriticalSection(&PerfDataCriticalSection);
840 for (i=0; i<ProcessCount; i++)
842 ThreadCount += pPerfData[i].ThreadCount;
845 LeaveCriticalSection(&PerfDataCriticalSection);
847 return ThreadCount;