advapi32/tests: Fix the backup tests when run in a non-administrator pre-Vista account.
[wine/multimedia.git] / programs / taskmgr / perfdata.c
blob110fe5ae600a0e7d1749bf93f92a1858de00ae0f
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 CRITICAL_SECTION PerfDataCriticalSection;
37 static PPERFDATA pPerfDataOld = NULL; /* Older perf data (saved to establish delta values) */
38 static PPERFDATA pPerfData = NULL; /* Most recent copy of perf data */
39 static ULONG ProcessCountOld = 0;
40 static ULONG ProcessCount = 0;
41 static double dbIdleTime;
42 static double dbKernelTime;
43 static double dbSystemTime;
44 static LARGE_INTEGER liOldIdleTime = {{0,0}};
45 static double OldKernelTime = 0;
46 static LARGE_INTEGER liOldSystemTime = {{0,0}};
47 static SYSTEM_PERFORMANCE_INFORMATION SystemPerfInfo;
48 static SYSTEM_BASIC_INFORMATION SystemBasicInfo;
49 static SYSTEM_CACHE_INFORMATION SystemCacheInfo;
50 static SYSTEM_HANDLE_INFORMATION SystemHandleInfo;
51 static PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION SystemProcessorTimeInfo = NULL;
53 BOOL PerfDataInitialize(void)
55 LONG status;
56 static const WCHAR wszNtdll[] = {'n','t','d','l','l','.','d','l','l',0};
57 static const WCHAR wszUser32[] = {'u','s','e','r','3','2','.','d','l','l',0};
58 static const WCHAR wszKernel32[] = {'k','e','r','n','e','l','3','2','.','d','l','l',0};
60 pNtQuerySystemInformation = (PROCNTQSI)GetProcAddress(GetModuleHandleW(wszNtdll), "NtQuerySystemInformation");
61 pGetGuiResources = (PROCGGR)GetProcAddress(GetModuleHandleW(wszUser32), "GetGuiResources");
62 pGetProcessIoCounters = (PROCGPIC)GetProcAddress(GetModuleHandleW(wszKernel32), "GetProcessIoCounters");
64 InitializeCriticalSection(&PerfDataCriticalSection);
66 if (!pNtQuerySystemInformation)
67 return FALSE;
70 * Get number of processors in the system
72 status = pNtQuerySystemInformation(SystemBasicInformation, &SystemBasicInfo, sizeof(SystemBasicInfo), NULL);
73 if (status != NO_ERROR)
74 return FALSE;
76 return TRUE;
79 void PerfDataRefresh(void)
81 ULONG ulSize;
82 LONG status;
83 LPBYTE pBuffer;
84 ULONG BufferSize;
85 PSYSTEM_PROCESS_INFORMATION pSPI;
86 PPERFDATA pPDOld;
87 ULONG Idx, Idx2;
88 HANDLE hProcess;
89 HANDLE hProcessToken;
90 WCHAR wszTemp[MAX_PATH];
91 DWORD dwSize;
92 SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo;
93 SYSTEM_TIMEOFDAY_INFORMATION SysTimeInfo;
94 SYSTEM_CACHE_INFORMATION SysCacheInfo;
95 LPBYTE SysHandleInfoData;
96 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION *SysProcessorTimeInfo;
97 double CurrentKernelTime;
100 /* Get new system time */
101 status = pNtQuerySystemInformation(SystemTimeOfDayInformation, &SysTimeInfo, sizeof(SysTimeInfo), 0);
102 if (status != NO_ERROR)
103 return;
105 /* Get new CPU's idle time */
106 status = pNtQuerySystemInformation(SystemPerformanceInformation, &SysPerfInfo, sizeof(SysPerfInfo), NULL);
107 if (status != NO_ERROR)
108 return;
110 /* Get system cache information */
111 status = pNtQuerySystemInformation(SystemCacheInformation, &SysCacheInfo, sizeof(SysCacheInfo), NULL);
112 if (status != NO_ERROR)
113 return;
115 /* Get processor time information */
116 SysProcessorTimeInfo = HeapAlloc(GetProcessHeap(), 0,
117 sizeof(*SysProcessorTimeInfo) * SystemBasicInfo.NumberOfProcessors);
118 status = pNtQuerySystemInformation(SystemProcessorPerformanceInformation, SysProcessorTimeInfo, sizeof(*SysProcessorTimeInfo) * SystemBasicInfo.NumberOfProcessors, &ulSize);
119 if (status != NO_ERROR) {
120 HeapFree(GetProcessHeap(), 0, SysProcessorTimeInfo);
121 return;
124 /* Get handle information
125 * We don't know how much data there is so just keep
126 * increasing the buffer size until the call succeeds
128 BufferSize = 0;
131 BufferSize += 0x10000;
132 SysHandleInfoData = HeapAlloc(GetProcessHeap(), 0, BufferSize);
134 status = pNtQuerySystemInformation(SystemHandleInformation, SysHandleInfoData, BufferSize, &ulSize);
136 if (status == 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/) {
137 HeapFree(GetProcessHeap(), 0, SysHandleInfoData);
140 } while (status == 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/);
142 /* Get process information
143 * We don't know how much data there is so just keep
144 * increasing the buffer size until the call succeeds
146 BufferSize = 0;
149 BufferSize += 0x10000;
150 pBuffer = HeapAlloc(GetProcessHeap(), 0, BufferSize);
152 status = pNtQuerySystemInformation(SystemProcessInformation, pBuffer, BufferSize, &ulSize);
154 if (status == 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/) {
155 HeapFree(GetProcessHeap(), 0, pBuffer);
158 } while (status == 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/);
160 EnterCriticalSection(&PerfDataCriticalSection);
163 * Save system performance info
165 memcpy(&SystemPerfInfo, &SysPerfInfo, sizeof(SYSTEM_PERFORMANCE_INFORMATION));
168 * Save system cache info
170 memcpy(&SystemCacheInfo, &SysCacheInfo, sizeof(SYSTEM_CACHE_INFORMATION));
173 * Save system processor time info
175 HeapFree(GetProcessHeap(), 0, SystemProcessorTimeInfo);
176 SystemProcessorTimeInfo = SysProcessorTimeInfo;
179 * Save system handle info
181 memcpy(&SystemHandleInfo, SysHandleInfoData, sizeof(SYSTEM_HANDLE_INFORMATION));
182 HeapFree(GetProcessHeap(), 0, SysHandleInfoData);
184 for (CurrentKernelTime=0, Idx=0; Idx<SystemBasicInfo.NumberOfProcessors; Idx++) {
185 CurrentKernelTime += Li2Double(SystemProcessorTimeInfo[Idx].KernelTime);
186 CurrentKernelTime += Li2Double(SystemProcessorTimeInfo[Idx].Reserved1[0]);
187 CurrentKernelTime += Li2Double(SystemProcessorTimeInfo[Idx].Reserved1[1]);
190 /* If it's a first call - skip idle time calcs */
191 if (liOldIdleTime.QuadPart != 0) {
192 /* CurrentValue = NewValue - OldValue */
193 dbIdleTime = Li2Double(SysPerfInfo.IdleTime) - Li2Double(liOldIdleTime);
194 dbKernelTime = CurrentKernelTime - OldKernelTime;
195 dbSystemTime = Li2Double(SysTimeInfo.liKeSystemTime) - Li2Double(liOldSystemTime);
197 /* CurrentCpuIdle = IdleTime / SystemTime */
198 dbIdleTime = dbIdleTime / dbSystemTime;
199 dbKernelTime = dbKernelTime / dbSystemTime;
201 /* CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) / NumberOfProcessors */
202 dbIdleTime = 100.0 - dbIdleTime * 100.0 / (double)SystemBasicInfo.NumberOfProcessors; /* + 0.5; */
203 dbKernelTime = 100.0 - dbKernelTime * 100.0 / (double)SystemBasicInfo.NumberOfProcessors; /* + 0.5; */
206 /* Store new CPU's idle and system time */
207 liOldIdleTime = SysPerfInfo.IdleTime;
208 liOldSystemTime = SysTimeInfo.liKeSystemTime;
209 OldKernelTime = CurrentKernelTime;
211 /* Determine the process count
212 * We loop through the data we got from NtQuerySystemInformation
213 * and count how many structures there are (until RelativeOffset is 0)
215 ProcessCountOld = ProcessCount;
216 ProcessCount = 0;
217 pSPI = (PSYSTEM_PROCESS_INFORMATION)pBuffer;
218 while (pSPI) {
219 ProcessCount++;
220 if (pSPI->NextEntryOffset == 0)
221 break;
222 pSPI = (PSYSTEM_PROCESS_INFORMATION)((LPBYTE)pSPI + pSPI->NextEntryOffset);
225 /* Now alloc a new PERFDATA array and fill in the data */
226 HeapFree(GetProcessHeap(), 0, pPerfDataOld);
227 pPerfDataOld = pPerfData;
228 pPerfData = HeapAlloc(GetProcessHeap(), 0, sizeof(PERFDATA) * ProcessCount);
229 pSPI = (PSYSTEM_PROCESS_INFORMATION)pBuffer;
230 for (Idx=0; Idx<ProcessCount; Idx++) {
231 /* Get the old perf data for this process (if any) */
232 /* so that we can establish delta values */
233 pPDOld = NULL;
234 for (Idx2=0; Idx2<ProcessCountOld; Idx2++) {
235 if (pPerfDataOld[Idx2].ProcessId == (DWORD_PTR)pSPI->UniqueProcessId) {
236 pPDOld = &pPerfDataOld[Idx2];
237 break;
241 /* Clear out process perf data structure */
242 memset(&pPerfData[Idx], 0, sizeof(PERFDATA));
244 if (pSPI->ProcessName.Buffer)
245 lstrcpyW(pPerfData[Idx].ImageName, pSPI->ProcessName.Buffer);
246 else
248 WCHAR idleW[255];
249 LoadStringW(hInst, IDS_SYSTEM_IDLE_PROCESS, idleW, sizeof(idleW)/sizeof(WCHAR));
250 lstrcpyW(pPerfData[Idx].ImageName, idleW );
253 pPerfData[Idx].ProcessId = (DWORD_PTR)pSPI->UniqueProcessId;
255 if (pPDOld) {
256 double CurTime = Li2Double(pSPI->KernelTime) + Li2Double(pSPI->UserTime);
257 double OldTime = Li2Double(pPDOld->KernelTime) + Li2Double(pPDOld->UserTime);
258 double CpuTime = (CurTime - OldTime) / dbSystemTime;
259 CpuTime = CpuTime * 100.0 / (double)SystemBasicInfo.NumberOfProcessors; /* + 0.5; */
260 pPerfData[Idx].CPUUsage = (ULONG)CpuTime;
263 pPerfData[Idx].CPUTime.QuadPart = pSPI->UserTime.QuadPart + pSPI->KernelTime.QuadPart;
264 pPerfData[Idx].vmCounters.WorkingSetSize = pSPI->vmCounters.WorkingSetSize;
265 pPerfData[Idx].vmCounters.PeakWorkingSetSize = pSPI->vmCounters.PeakWorkingSetSize;
266 if (pPDOld)
267 pPerfData[Idx].WorkingSetSizeDelta = labs(pSPI->vmCounters.WorkingSetSize - pPDOld->vmCounters.WorkingSetSize);
268 else
269 pPerfData[Idx].WorkingSetSizeDelta = 0;
270 pPerfData[Idx].vmCounters.PageFaultCount = pSPI->vmCounters.PageFaultCount;
271 if (pPDOld)
272 pPerfData[Idx].PageFaultCountDelta = labs(pSPI->vmCounters.PageFaultCount - pPDOld->vmCounters.PageFaultCount);
273 else
274 pPerfData[Idx].PageFaultCountDelta = 0;
275 pPerfData[Idx].vmCounters.VirtualSize = pSPI->vmCounters.VirtualSize;
276 pPerfData[Idx].vmCounters.QuotaPagedPoolUsage = pSPI->vmCounters.QuotaPagedPoolUsage;
277 pPerfData[Idx].vmCounters.QuotaNonPagedPoolUsage = pSPI->vmCounters.QuotaNonPagedPoolUsage;
278 pPerfData[Idx].BasePriority = pSPI->dwBasePriority;
279 pPerfData[Idx].HandleCount = pSPI->HandleCount;
280 pPerfData[Idx].ThreadCount = pSPI->dwThreadCount;
281 pPerfData[Idx].SessionId = pSPI->SessionId;
283 hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, (DWORD_PTR)pSPI->UniqueProcessId);
284 if (hProcess) {
285 if (OpenProcessToken(hProcess, TOKEN_QUERY|TOKEN_DUPLICATE|TOKEN_IMPERSONATE, &hProcessToken)) {
286 ImpersonateLoggedOnUser(hProcessToken);
287 memset(wszTemp, 0, sizeof(wszTemp));
288 dwSize = MAX_PATH;
289 GetUserNameW(wszTemp, &dwSize);
290 RevertToSelf();
291 CloseHandle(hProcessToken);
293 if (pGetGuiResources) {
294 pPerfData[Idx].USERObjectCount = pGetGuiResources(hProcess, GR_USEROBJECTS);
295 pPerfData[Idx].GDIObjectCount = pGetGuiResources(hProcess, GR_GDIOBJECTS);
297 if (pGetProcessIoCounters)
298 pGetProcessIoCounters(hProcess, &pPerfData[Idx].IOCounters);
299 CloseHandle(hProcess);
301 pPerfData[Idx].UserTime.QuadPart = pSPI->UserTime.QuadPart;
302 pPerfData[Idx].KernelTime.QuadPart = pSPI->KernelTime.QuadPart;
303 pSPI = (PSYSTEM_PROCESS_INFORMATION)((LPBYTE)pSPI + pSPI->NextEntryOffset);
305 HeapFree(GetProcessHeap(), 0, pBuffer);
306 LeaveCriticalSection(&PerfDataCriticalSection);
309 ULONG PerfDataGetProcessCount(void)
311 return ProcessCount;
314 ULONG PerfDataGetProcessorUsage(void)
316 if( dbIdleTime < 0.0 )
317 return 0;
318 if( dbIdleTime > 100.0 )
319 return 100;
320 return (ULONG)dbIdleTime;
323 ULONG PerfDataGetProcessorSystemUsage(void)
325 if( dbKernelTime < 0.0 )
326 return 0;
327 if( dbKernelTime > 100.0 )
328 return 100;
329 return (ULONG)dbKernelTime;
332 BOOL PerfDataGetImageName(ULONG Index, LPWSTR lpImageName, int nMaxCount)
334 BOOL bSuccessful;
336 EnterCriticalSection(&PerfDataCriticalSection);
338 if (Index < ProcessCount) {
339 wcsncpy(lpImageName, pPerfData[Index].ImageName, nMaxCount);
340 bSuccessful = TRUE;
341 } else {
342 bSuccessful = FALSE;
344 LeaveCriticalSection(&PerfDataCriticalSection);
345 return bSuccessful;
348 ULONG PerfDataGetProcessId(ULONG Index)
350 ULONG ProcessId;
352 EnterCriticalSection(&PerfDataCriticalSection);
354 if (Index < ProcessCount)
355 ProcessId = pPerfData[Index].ProcessId;
356 else
357 ProcessId = 0;
359 LeaveCriticalSection(&PerfDataCriticalSection);
361 return ProcessId;
364 BOOL PerfDataGetUserName(ULONG Index, LPWSTR lpUserName, int nMaxCount)
366 BOOL bSuccessful;
368 EnterCriticalSection(&PerfDataCriticalSection);
370 if (Index < ProcessCount) {
371 wcsncpy(lpUserName, pPerfData[Index].UserName, nMaxCount);
372 bSuccessful = TRUE;
373 } else {
374 bSuccessful = FALSE;
377 LeaveCriticalSection(&PerfDataCriticalSection);
379 return bSuccessful;
382 ULONG PerfDataGetSessionId(ULONG Index)
384 ULONG SessionId;
386 EnterCriticalSection(&PerfDataCriticalSection);
388 if (Index < ProcessCount)
389 SessionId = pPerfData[Index].SessionId;
390 else
391 SessionId = 0;
393 LeaveCriticalSection(&PerfDataCriticalSection);
395 return SessionId;
398 ULONG PerfDataGetCPUUsage(ULONG Index)
400 ULONG CpuUsage;
402 EnterCriticalSection(&PerfDataCriticalSection);
404 if (Index < ProcessCount)
405 CpuUsage = pPerfData[Index].CPUUsage;
406 else
407 CpuUsage = 0;
409 LeaveCriticalSection(&PerfDataCriticalSection);
411 return CpuUsage;
414 TIME PerfDataGetCPUTime(ULONG Index)
416 TIME CpuTime = {{0,0}};
418 EnterCriticalSection(&PerfDataCriticalSection);
420 if (Index < ProcessCount)
421 CpuTime = pPerfData[Index].CPUTime;
423 LeaveCriticalSection(&PerfDataCriticalSection);
425 return CpuTime;
428 ULONG PerfDataGetWorkingSetSizeBytes(ULONG Index)
430 ULONG WorkingSetSizeBytes;
432 EnterCriticalSection(&PerfDataCriticalSection);
434 if (Index < ProcessCount)
435 WorkingSetSizeBytes = pPerfData[Index].vmCounters.WorkingSetSize;
436 else
437 WorkingSetSizeBytes = 0;
439 LeaveCriticalSection(&PerfDataCriticalSection);
441 return WorkingSetSizeBytes;
444 ULONG PerfDataGetPeakWorkingSetSizeBytes(ULONG Index)
446 ULONG PeakWorkingSetSizeBytes;
448 EnterCriticalSection(&PerfDataCriticalSection);
450 if (Index < ProcessCount)
451 PeakWorkingSetSizeBytes = pPerfData[Index].vmCounters.PeakWorkingSetSize;
452 else
453 PeakWorkingSetSizeBytes = 0;
455 LeaveCriticalSection(&PerfDataCriticalSection);
457 return PeakWorkingSetSizeBytes;
460 ULONG PerfDataGetWorkingSetSizeDelta(ULONG Index)
462 ULONG WorkingSetSizeDelta;
464 EnterCriticalSection(&PerfDataCriticalSection);
466 if (Index < ProcessCount)
467 WorkingSetSizeDelta = pPerfData[Index].WorkingSetSizeDelta;
468 else
469 WorkingSetSizeDelta = 0;
471 LeaveCriticalSection(&PerfDataCriticalSection);
473 return WorkingSetSizeDelta;
476 ULONG PerfDataGetPageFaultCount(ULONG Index)
478 ULONG PageFaultCount;
480 EnterCriticalSection(&PerfDataCriticalSection);
482 if (Index < ProcessCount)
483 PageFaultCount = pPerfData[Index].vmCounters.PageFaultCount;
484 else
485 PageFaultCount = 0;
487 LeaveCriticalSection(&PerfDataCriticalSection);
489 return PageFaultCount;
492 ULONG PerfDataGetPageFaultCountDelta(ULONG Index)
494 ULONG PageFaultCountDelta;
496 EnterCriticalSection(&PerfDataCriticalSection);
498 if (Index < ProcessCount)
499 PageFaultCountDelta = pPerfData[Index].PageFaultCountDelta;
500 else
501 PageFaultCountDelta = 0;
503 LeaveCriticalSection(&PerfDataCriticalSection);
505 return PageFaultCountDelta;
508 ULONG PerfDataGetVirtualMemorySizeBytes(ULONG Index)
510 ULONG VirtualMemorySizeBytes;
512 EnterCriticalSection(&PerfDataCriticalSection);
514 if (Index < ProcessCount)
515 VirtualMemorySizeBytes = pPerfData[Index].vmCounters.VirtualSize;
516 else
517 VirtualMemorySizeBytes = 0;
519 LeaveCriticalSection(&PerfDataCriticalSection);
521 return VirtualMemorySizeBytes;
524 ULONG PerfDataGetPagedPoolUsagePages(ULONG Index)
526 ULONG PagedPoolUsagePages;
528 EnterCriticalSection(&PerfDataCriticalSection);
530 if (Index < ProcessCount)
531 PagedPoolUsagePages = pPerfData[Index].vmCounters.QuotaPagedPoolUsage;
532 else
533 PagedPoolUsagePages = 0;
535 LeaveCriticalSection(&PerfDataCriticalSection);
537 return PagedPoolUsagePages;
540 ULONG PerfDataGetNonPagedPoolUsagePages(ULONG Index)
542 ULONG NonPagedPoolUsagePages;
544 EnterCriticalSection(&PerfDataCriticalSection);
546 if (Index < ProcessCount)
547 NonPagedPoolUsagePages = pPerfData[Index].vmCounters.QuotaNonPagedPoolUsage;
548 else
549 NonPagedPoolUsagePages = 0;
551 LeaveCriticalSection(&PerfDataCriticalSection);
553 return NonPagedPoolUsagePages;
556 ULONG PerfDataGetBasePriority(ULONG Index)
558 ULONG BasePriority;
560 EnterCriticalSection(&PerfDataCriticalSection);
562 if (Index < ProcessCount)
563 BasePriority = pPerfData[Index].BasePriority;
564 else
565 BasePriority = 0;
567 LeaveCriticalSection(&PerfDataCriticalSection);
569 return BasePriority;
572 ULONG PerfDataGetHandleCount(ULONG Index)
574 ULONG HandleCount;
576 EnterCriticalSection(&PerfDataCriticalSection);
578 if (Index < ProcessCount)
579 HandleCount = pPerfData[Index].HandleCount;
580 else
581 HandleCount = 0;
583 LeaveCriticalSection(&PerfDataCriticalSection);
585 return HandleCount;
588 ULONG PerfDataGetThreadCount(ULONG Index)
590 ULONG ThreadCount;
592 EnterCriticalSection(&PerfDataCriticalSection);
594 if (Index < ProcessCount)
595 ThreadCount = pPerfData[Index].ThreadCount;
596 else
597 ThreadCount = 0;
599 LeaveCriticalSection(&PerfDataCriticalSection);
601 return ThreadCount;
604 ULONG PerfDataGetUSERObjectCount(ULONG Index)
606 ULONG USERObjectCount;
608 EnterCriticalSection(&PerfDataCriticalSection);
610 if (Index < ProcessCount)
611 USERObjectCount = pPerfData[Index].USERObjectCount;
612 else
613 USERObjectCount = 0;
615 LeaveCriticalSection(&PerfDataCriticalSection);
617 return USERObjectCount;
620 ULONG PerfDataGetGDIObjectCount(ULONG Index)
622 ULONG GDIObjectCount;
624 EnterCriticalSection(&PerfDataCriticalSection);
626 if (Index < ProcessCount)
627 GDIObjectCount = pPerfData[Index].GDIObjectCount;
628 else
629 GDIObjectCount = 0;
631 LeaveCriticalSection(&PerfDataCriticalSection);
633 return GDIObjectCount;
636 BOOL PerfDataGetIOCounters(ULONG Index, PIO_COUNTERS pIoCounters)
638 BOOL bSuccessful;
640 EnterCriticalSection(&PerfDataCriticalSection);
642 if (Index < ProcessCount)
644 memcpy(pIoCounters, &pPerfData[Index].IOCounters, sizeof(IO_COUNTERS));
645 bSuccessful = TRUE;
647 else
648 bSuccessful = FALSE;
650 LeaveCriticalSection(&PerfDataCriticalSection);
652 return bSuccessful;
655 ULONG PerfDataGetCommitChargeTotalK(void)
657 ULONG Total;
658 ULONG PageSize;
660 EnterCriticalSection(&PerfDataCriticalSection);
662 Total = SystemPerfInfo.TotalCommittedPages;
663 PageSize = SystemBasicInfo.PageSize;
665 LeaveCriticalSection(&PerfDataCriticalSection);
667 Total = Total * (PageSize / 1024);
669 return Total;
672 ULONG PerfDataGetCommitChargeLimitK(void)
674 ULONG Limit;
675 ULONG PageSize;
677 EnterCriticalSection(&PerfDataCriticalSection);
679 Limit = SystemPerfInfo.TotalCommitLimit;
680 PageSize = SystemBasicInfo.PageSize;
682 LeaveCriticalSection(&PerfDataCriticalSection);
684 Limit = Limit * (PageSize / 1024);
686 return Limit;
689 ULONG PerfDataGetCommitChargePeakK(void)
691 ULONG Peak;
692 ULONG PageSize;
694 EnterCriticalSection(&PerfDataCriticalSection);
696 Peak = SystemPerfInfo.PeakCommitment;
697 PageSize = SystemBasicInfo.PageSize;
699 LeaveCriticalSection(&PerfDataCriticalSection);
701 Peak = Peak * (PageSize / 1024);
703 return Peak;
706 ULONG PerfDataGetKernelMemoryTotalK(void)
708 ULONG Total;
709 ULONG Paged;
710 ULONG NonPaged;
711 ULONG PageSize;
713 EnterCriticalSection(&PerfDataCriticalSection);
715 Paged = SystemPerfInfo.PagedPoolUsage;
716 NonPaged = SystemPerfInfo.NonPagedPoolUsage;
717 PageSize = SystemBasicInfo.PageSize;
719 LeaveCriticalSection(&PerfDataCriticalSection);
721 Paged = Paged * (PageSize / 1024);
722 NonPaged = NonPaged * (PageSize / 1024);
724 Total = Paged + NonPaged;
726 return Total;
729 ULONG PerfDataGetKernelMemoryPagedK(void)
731 ULONG Paged;
732 ULONG PageSize;
734 EnterCriticalSection(&PerfDataCriticalSection);
736 Paged = SystemPerfInfo.PagedPoolUsage;
737 PageSize = SystemBasicInfo.PageSize;
739 LeaveCriticalSection(&PerfDataCriticalSection);
741 Paged = Paged * (PageSize / 1024);
743 return Paged;
746 ULONG PerfDataGetKernelMemoryNonPagedK(void)
748 ULONG NonPaged;
749 ULONG PageSize;
751 EnterCriticalSection(&PerfDataCriticalSection);
753 NonPaged = SystemPerfInfo.NonPagedPoolUsage;
754 PageSize = SystemBasicInfo.PageSize;
756 LeaveCriticalSection(&PerfDataCriticalSection);
758 NonPaged = NonPaged * (PageSize / 1024);
760 return NonPaged;
763 ULONG PerfDataGetPhysicalMemoryTotalK(void)
765 ULONG Total;
766 ULONG PageSize;
768 EnterCriticalSection(&PerfDataCriticalSection);
770 Total = SystemBasicInfo.MmNumberOfPhysicalPages;
771 PageSize = SystemBasicInfo.PageSize;
773 LeaveCriticalSection(&PerfDataCriticalSection);
775 Total = Total * (PageSize / 1024);
777 return Total;
780 ULONG PerfDataGetPhysicalMemoryAvailableK(void)
782 ULONG Available;
783 ULONG PageSize;
785 EnterCriticalSection(&PerfDataCriticalSection);
787 Available = SystemPerfInfo.AvailablePages;
788 PageSize = SystemBasicInfo.PageSize;
790 LeaveCriticalSection(&PerfDataCriticalSection);
792 Available = Available * (PageSize / 1024);
794 return Available;
797 ULONG PerfDataGetPhysicalMemorySystemCacheK(void)
799 ULONG SystemCache;
801 EnterCriticalSection(&PerfDataCriticalSection);
803 SystemCache = SystemCacheInfo.CurrentSize;
805 LeaveCriticalSection(&PerfDataCriticalSection);
807 SystemCache = SystemCache / 1024;
809 return SystemCache;
812 ULONG PerfDataGetSystemHandleCount(void)
814 ULONG HandleCount;
816 EnterCriticalSection(&PerfDataCriticalSection);
818 HandleCount = SystemHandleInfo.Count;
820 LeaveCriticalSection(&PerfDataCriticalSection);
822 return HandleCount;
825 ULONG PerfDataGetTotalThreadCount(void)
827 ULONG ThreadCount = 0;
828 ULONG i;
830 EnterCriticalSection(&PerfDataCriticalSection);
832 for (i=0; i<ProcessCount; i++)
834 ThreadCount += pPerfData[i].ThreadCount;
837 LeaveCriticalSection(&PerfDataCriticalSection);
839 return ThreadCount;