Release 1.6-rc2.
[wine/testsucceed.git] / programs / taskmgr / perfdata.c
blob95516def297096ce6dd67fe0e7c5db1aadf062e1
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 NtQuerySystemInformation = 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_PROCESSORTIME_INFO 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 NtQuerySystemInformation = (PROCNTQSI)GetProcAddress(GetModuleHandleW(wszNtdll), "NtQuerySystemInformation");
61 pGetGuiResources = (PROCGGR)GetProcAddress(GetModuleHandleW(wszUser32), "GetGuiResources");
62 pGetProcessIoCounters = (PROCGPIC)GetProcAddress(GetModuleHandleW(wszKernel32), "GetProcessIoCounters");
64 InitializeCriticalSection(&PerfDataCriticalSection);
66 if (!NtQuerySystemInformation)
67 return FALSE;
70 * Get number of processors in the system
72 status = NtQuerySystemInformation(SystemBasicInformation, &SystemBasicInfo, sizeof(SystemBasicInfo), NULL);
73 if (status != NO_ERROR)
74 return FALSE;
76 return TRUE;
79 void PerfDataUninitialize(void)
81 NtQuerySystemInformation = NULL;
83 DeleteCriticalSection(&PerfDataCriticalSection);
86 void PerfDataRefresh(void)
88 ULONG ulSize;
89 LONG status;
90 LPBYTE pBuffer;
91 ULONG BufferSize;
92 PSYSTEM_PROCESS_INFORMATION pSPI;
93 PPERFDATA pPDOld;
94 ULONG Idx, Idx2;
95 HANDLE hProcess;
96 HANDLE hProcessToken;
97 WCHAR wszTemp[MAX_PATH];
98 DWORD dwSize;
99 SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo;
100 SYSTEM_TIME_INFORMATION SysTimeInfo;
101 SYSTEM_CACHE_INFORMATION SysCacheInfo;
102 LPBYTE SysHandleInfoData;
103 PSYSTEM_PROCESSORTIME_INFO SysProcessorTimeInfo;
104 double CurrentKernelTime;
107 if (!NtQuerySystemInformation)
108 return;
110 /* Get new system time */
111 status = NtQuerySystemInformation(SystemTimeInformation, &SysTimeInfo, sizeof(SysTimeInfo), 0);
112 if (status != NO_ERROR)
113 return;
115 /* Get new CPU's idle time */
116 status = NtQuerySystemInformation(SystemPerformanceInformation, &SysPerfInfo, sizeof(SysPerfInfo), NULL);
117 if (status != NO_ERROR)
118 return;
120 /* Get system cache information */
121 status = NtQuerySystemInformation(SystemCacheInformation, &SysCacheInfo, sizeof(SysCacheInfo), NULL);
122 if (status != NO_ERROR)
123 return;
125 /* Get processor time information */
126 SysProcessorTimeInfo = HeapAlloc(GetProcessHeap(), 0,
127 sizeof(SYSTEM_PROCESSORTIME_INFO) * SystemBasicInfo.bKeNumberProcessors);
128 status = NtQuerySystemInformation(SystemProcessorTimeInformation, SysProcessorTimeInfo, sizeof(SYSTEM_PROCESSORTIME_INFO) * SystemBasicInfo.bKeNumberProcessors, &ulSize);
129 if (status != NO_ERROR) {
130 HeapFree(GetProcessHeap(), 0, SysProcessorTimeInfo);
131 return;
134 /* Get handle information
135 * We don't know how much data there is so just keep
136 * increasing the buffer size until the call succeeds
138 BufferSize = 0;
141 BufferSize += 0x10000;
142 SysHandleInfoData = HeapAlloc(GetProcessHeap(), 0, BufferSize);
144 status = NtQuerySystemInformation(SystemHandleInformation, SysHandleInfoData, BufferSize, &ulSize);
146 if (status == 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/) {
147 HeapFree(GetProcessHeap(), 0, SysHandleInfoData);
150 } while (status == 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/);
152 /* Get process information
153 * We don't know how much data there is so just keep
154 * increasing the buffer size until the call succeeds
156 BufferSize = 0;
159 BufferSize += 0x10000;
160 pBuffer = HeapAlloc(GetProcessHeap(), 0, BufferSize);
162 status = NtQuerySystemInformation(SystemProcessInformation, pBuffer, BufferSize, &ulSize);
164 if (status == 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/) {
165 HeapFree(GetProcessHeap(), 0, pBuffer);
168 } while (status == 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/);
170 EnterCriticalSection(&PerfDataCriticalSection);
173 * Save system performance info
175 memcpy(&SystemPerfInfo, &SysPerfInfo, sizeof(SYSTEM_PERFORMANCE_INFORMATION));
178 * Save system cache info
180 memcpy(&SystemCacheInfo, &SysCacheInfo, sizeof(SYSTEM_CACHE_INFORMATION));
183 * Save system processor time info
185 HeapFree(GetProcessHeap(), 0, SystemProcessorTimeInfo);
186 SystemProcessorTimeInfo = SysProcessorTimeInfo;
189 * Save system handle info
191 memcpy(&SystemHandleInfo, SysHandleInfoData, sizeof(SYSTEM_HANDLE_INFORMATION));
192 HeapFree(GetProcessHeap(), 0, SysHandleInfoData);
194 for (CurrentKernelTime=0, Idx=0; Idx<SystemBasicInfo.bKeNumberProcessors; Idx++) {
195 CurrentKernelTime += Li2Double(SystemProcessorTimeInfo[Idx].KernelTime);
196 CurrentKernelTime += Li2Double(SystemProcessorTimeInfo[Idx].DpcTime);
197 CurrentKernelTime += Li2Double(SystemProcessorTimeInfo[Idx].InterruptTime);
200 /* If it's a first call - skip idle time calcs */
201 if (liOldIdleTime.QuadPart != 0) {
202 /* CurrentValue = NewValue - OldValue */
203 dbIdleTime = Li2Double(SysPerfInfo.liIdleTime) - Li2Double(liOldIdleTime);
204 dbKernelTime = CurrentKernelTime - OldKernelTime;
205 dbSystemTime = Li2Double(SysTimeInfo.liKeSystemTime) - Li2Double(liOldSystemTime);
207 /* CurrentCpuIdle = IdleTime / SystemTime */
208 dbIdleTime = dbIdleTime / dbSystemTime;
209 dbKernelTime = dbKernelTime / dbSystemTime;
211 /* CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) / NumberOfProcessors */
212 dbIdleTime = 100.0 - dbIdleTime * 100.0 / (double)SystemBasicInfo.bKeNumberProcessors; /* + 0.5; */
213 dbKernelTime = 100.0 - dbKernelTime * 100.0 / (double)SystemBasicInfo.bKeNumberProcessors; /* + 0.5; */
216 /* Store new CPU's idle and system time */
217 liOldIdleTime = SysPerfInfo.liIdleTime;
218 liOldSystemTime = SysTimeInfo.liKeSystemTime;
219 OldKernelTime = CurrentKernelTime;
221 /* Determine the process count
222 * We loop through the data we got from NtQuerySystemInformation
223 * and count how many structures there are (until RelativeOffset is 0)
225 ProcessCountOld = ProcessCount;
226 ProcessCount = 0;
227 pSPI = (PSYSTEM_PROCESS_INFORMATION)pBuffer;
228 while (pSPI) {
229 ProcessCount++;
230 if (pSPI->RelativeOffset == 0)
231 break;
232 pSPI = (PSYSTEM_PROCESS_INFORMATION)((LPBYTE)pSPI + pSPI->RelativeOffset);
235 /* Now alloc a new PERFDATA array and fill in the data */
236 HeapFree(GetProcessHeap(), 0, pPerfDataOld);
237 pPerfDataOld = pPerfData;
238 pPerfData = HeapAlloc(GetProcessHeap(), 0, sizeof(PERFDATA) * ProcessCount);
239 pSPI = (PSYSTEM_PROCESS_INFORMATION)pBuffer;
240 for (Idx=0; Idx<ProcessCount; Idx++) {
241 /* Get the old perf data for this process (if any) */
242 /* so that we can establish delta values */
243 pPDOld = NULL;
244 for (Idx2=0; Idx2<ProcessCountOld; Idx2++) {
245 if (pPerfDataOld[Idx2].ProcessId == pSPI->ProcessId) {
246 pPDOld = &pPerfDataOld[Idx2];
247 break;
251 /* Clear out process perf data structure */
252 memset(&pPerfData[Idx], 0, sizeof(PERFDATA));
254 if (pSPI->Name.Buffer)
255 lstrcpyW(pPerfData[Idx].ImageName, pSPI->Name.Buffer);
256 else
258 WCHAR idleW[255];
259 LoadStringW(hInst, IDS_SYSTEM_IDLE_PROCESS, idleW, sizeof(idleW)/sizeof(WCHAR));
260 lstrcpyW(pPerfData[Idx].ImageName, idleW );
263 pPerfData[Idx].ProcessId = pSPI->ProcessId;
265 if (pPDOld) {
266 double CurTime = Li2Double(pSPI->KernelTime) + Li2Double(pSPI->UserTime);
267 double OldTime = Li2Double(pPDOld->KernelTime) + Li2Double(pPDOld->UserTime);
268 double CpuTime = (CurTime - OldTime) / dbSystemTime;
269 CpuTime = CpuTime * 100.0 / (double)SystemBasicInfo.bKeNumberProcessors; /* + 0.5; */
270 pPerfData[Idx].CPUUsage = (ULONG)CpuTime;
272 pPerfData[Idx].CPUTime.QuadPart = pSPI->UserTime.QuadPart + pSPI->KernelTime.QuadPart;
273 pPerfData[Idx].WorkingSetSizeBytes = pSPI->TotalWorkingSetSizeBytes;
274 pPerfData[Idx].PeakWorkingSetSizeBytes = pSPI->PeakWorkingSetSizeBytes;
275 if (pPDOld)
276 pPerfData[Idx].WorkingSetSizeDelta = labs((LONG)pSPI->TotalWorkingSetSizeBytes - (LONG)pPDOld->WorkingSetSizeBytes);
277 else
278 pPerfData[Idx].WorkingSetSizeDelta = 0;
279 pPerfData[Idx].PageFaultCount = pSPI->PageFaultCount;
280 if (pPDOld)
281 pPerfData[Idx].PageFaultCountDelta = labs((LONG)pSPI->PageFaultCount - (LONG)pPDOld->PageFaultCount);
282 else
283 pPerfData[Idx].PageFaultCountDelta = 0;
284 pPerfData[Idx].VirtualMemorySizeBytes = pSPI->TotalVirtualSizeBytes;
285 pPerfData[Idx].PagedPoolUsagePages = pSPI->TotalPagedPoolUsagePages;
286 pPerfData[Idx].NonPagedPoolUsagePages = pSPI->TotalNonPagedPoolUsagePages;
287 pPerfData[Idx].BasePriority = pSPI->BasePriority;
288 pPerfData[Idx].HandleCount = pSPI->HandleCount;
289 pPerfData[Idx].ThreadCount = pSPI->ThreadCount;
290 pPerfData[Idx].SessionId = pSPI->SessionId;
292 hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pSPI->ProcessId);
293 if (hProcess) {
294 if (OpenProcessToken(hProcess, TOKEN_QUERY|TOKEN_DUPLICATE|TOKEN_IMPERSONATE, &hProcessToken)) {
295 ImpersonateLoggedOnUser(hProcessToken);
296 memset(wszTemp, 0, sizeof(wszTemp));
297 dwSize = MAX_PATH;
298 GetUserNameW(wszTemp, &dwSize);
299 RevertToSelf();
300 CloseHandle(hProcessToken);
302 if (pGetGuiResources) {
303 pPerfData[Idx].USERObjectCount = pGetGuiResources(hProcess, GR_USEROBJECTS);
304 pPerfData[Idx].GDIObjectCount = pGetGuiResources(hProcess, GR_GDIOBJECTS);
306 if (pGetProcessIoCounters)
307 pGetProcessIoCounters(hProcess, &pPerfData[Idx].IOCounters);
308 CloseHandle(hProcess);
310 pPerfData[Idx].UserTime.QuadPart = pSPI->UserTime.QuadPart;
311 pPerfData[Idx].KernelTime.QuadPart = pSPI->KernelTime.QuadPart;
312 pSPI = (PSYSTEM_PROCESS_INFORMATION)((LPBYTE)pSPI + pSPI->RelativeOffset);
314 HeapFree(GetProcessHeap(), 0, pBuffer);
315 LeaveCriticalSection(&PerfDataCriticalSection);
318 ULONG PerfDataGetProcessCount(void)
320 return ProcessCount;
323 ULONG PerfDataGetProcessorUsage(void)
325 if( dbIdleTime < 0.0 )
326 return 0;
327 if( dbIdleTime > 100.0 )
328 return 100;
329 return (ULONG)dbIdleTime;
332 ULONG PerfDataGetProcessorSystemUsage(void)
334 if( dbKernelTime < 0.0 )
335 return 0;
336 if( dbKernelTime > 100.0 )
337 return 100;
338 return (ULONG)dbKernelTime;
341 BOOL PerfDataGetImageName(ULONG Index, LPWSTR lpImageName, int nMaxCount)
343 BOOL bSuccessful;
345 EnterCriticalSection(&PerfDataCriticalSection);
347 if (Index < ProcessCount) {
348 wcsncpy(lpImageName, pPerfData[Index].ImageName, nMaxCount);
349 bSuccessful = TRUE;
350 } else {
351 bSuccessful = FALSE;
353 LeaveCriticalSection(&PerfDataCriticalSection);
354 return bSuccessful;
357 ULONG PerfDataGetProcessId(ULONG Index)
359 ULONG ProcessId;
361 EnterCriticalSection(&PerfDataCriticalSection);
363 if (Index < ProcessCount)
364 ProcessId = pPerfData[Index].ProcessId;
365 else
366 ProcessId = 0;
368 LeaveCriticalSection(&PerfDataCriticalSection);
370 return ProcessId;
373 BOOL PerfDataGetUserName(ULONG Index, LPWSTR lpUserName, int nMaxCount)
375 BOOL bSuccessful;
377 EnterCriticalSection(&PerfDataCriticalSection);
379 if (Index < ProcessCount) {
380 wcsncpy(lpUserName, pPerfData[Index].UserName, nMaxCount);
381 bSuccessful = TRUE;
382 } else {
383 bSuccessful = FALSE;
386 LeaveCriticalSection(&PerfDataCriticalSection);
388 return bSuccessful;
391 ULONG PerfDataGetSessionId(ULONG Index)
393 ULONG SessionId;
395 EnterCriticalSection(&PerfDataCriticalSection);
397 if (Index < ProcessCount)
398 SessionId = pPerfData[Index].SessionId;
399 else
400 SessionId = 0;
402 LeaveCriticalSection(&PerfDataCriticalSection);
404 return SessionId;
407 ULONG PerfDataGetCPUUsage(ULONG Index)
409 ULONG CpuUsage;
411 EnterCriticalSection(&PerfDataCriticalSection);
413 if (Index < ProcessCount)
414 CpuUsage = pPerfData[Index].CPUUsage;
415 else
416 CpuUsage = 0;
418 LeaveCriticalSection(&PerfDataCriticalSection);
420 return CpuUsage;
423 TIME PerfDataGetCPUTime(ULONG Index)
425 TIME CpuTime = {{0,0}};
427 EnterCriticalSection(&PerfDataCriticalSection);
429 if (Index < ProcessCount)
430 CpuTime = pPerfData[Index].CPUTime;
432 LeaveCriticalSection(&PerfDataCriticalSection);
434 return CpuTime;
437 ULONG PerfDataGetWorkingSetSizeBytes(ULONG Index)
439 ULONG WorkingSetSizeBytes;
441 EnterCriticalSection(&PerfDataCriticalSection);
443 if (Index < ProcessCount)
444 WorkingSetSizeBytes = pPerfData[Index].WorkingSetSizeBytes;
445 else
446 WorkingSetSizeBytes = 0;
448 LeaveCriticalSection(&PerfDataCriticalSection);
450 return WorkingSetSizeBytes;
453 ULONG PerfDataGetPeakWorkingSetSizeBytes(ULONG Index)
455 ULONG PeakWorkingSetSizeBytes;
457 EnterCriticalSection(&PerfDataCriticalSection);
459 if (Index < ProcessCount)
460 PeakWorkingSetSizeBytes = pPerfData[Index].PeakWorkingSetSizeBytes;
461 else
462 PeakWorkingSetSizeBytes = 0;
464 LeaveCriticalSection(&PerfDataCriticalSection);
466 return PeakWorkingSetSizeBytes;
469 ULONG PerfDataGetWorkingSetSizeDelta(ULONG Index)
471 ULONG WorkingSetSizeDelta;
473 EnterCriticalSection(&PerfDataCriticalSection);
475 if (Index < ProcessCount)
476 WorkingSetSizeDelta = pPerfData[Index].WorkingSetSizeDelta;
477 else
478 WorkingSetSizeDelta = 0;
480 LeaveCriticalSection(&PerfDataCriticalSection);
482 return WorkingSetSizeDelta;
485 ULONG PerfDataGetPageFaultCount(ULONG Index)
487 ULONG PageFaultCount;
489 EnterCriticalSection(&PerfDataCriticalSection);
491 if (Index < ProcessCount)
492 PageFaultCount = pPerfData[Index].PageFaultCount;
493 else
494 PageFaultCount = 0;
496 LeaveCriticalSection(&PerfDataCriticalSection);
498 return PageFaultCount;
501 ULONG PerfDataGetPageFaultCountDelta(ULONG Index)
503 ULONG PageFaultCountDelta;
505 EnterCriticalSection(&PerfDataCriticalSection);
507 if (Index < ProcessCount)
508 PageFaultCountDelta = pPerfData[Index].PageFaultCountDelta;
509 else
510 PageFaultCountDelta = 0;
512 LeaveCriticalSection(&PerfDataCriticalSection);
514 return PageFaultCountDelta;
517 ULONG PerfDataGetVirtualMemorySizeBytes(ULONG Index)
519 ULONG VirtualMemorySizeBytes;
521 EnterCriticalSection(&PerfDataCriticalSection);
523 if (Index < ProcessCount)
524 VirtualMemorySizeBytes = pPerfData[Index].VirtualMemorySizeBytes;
525 else
526 VirtualMemorySizeBytes = 0;
528 LeaveCriticalSection(&PerfDataCriticalSection);
530 return VirtualMemorySizeBytes;
533 ULONG PerfDataGetPagedPoolUsagePages(ULONG Index)
535 ULONG PagedPoolUsagePages;
537 EnterCriticalSection(&PerfDataCriticalSection);
539 if (Index < ProcessCount)
540 PagedPoolUsagePages = pPerfData[Index].PagedPoolUsagePages;
541 else
542 PagedPoolUsagePages = 0;
544 LeaveCriticalSection(&PerfDataCriticalSection);
546 return PagedPoolUsagePages;
549 ULONG PerfDataGetNonPagedPoolUsagePages(ULONG Index)
551 ULONG NonPagedPoolUsagePages;
553 EnterCriticalSection(&PerfDataCriticalSection);
555 if (Index < ProcessCount)
556 NonPagedPoolUsagePages = pPerfData[Index].NonPagedPoolUsagePages;
557 else
558 NonPagedPoolUsagePages = 0;
560 LeaveCriticalSection(&PerfDataCriticalSection);
562 return NonPagedPoolUsagePages;
565 ULONG PerfDataGetBasePriority(ULONG Index)
567 ULONG BasePriority;
569 EnterCriticalSection(&PerfDataCriticalSection);
571 if (Index < ProcessCount)
572 BasePriority = pPerfData[Index].BasePriority;
573 else
574 BasePriority = 0;
576 LeaveCriticalSection(&PerfDataCriticalSection);
578 return BasePriority;
581 ULONG PerfDataGetHandleCount(ULONG Index)
583 ULONG HandleCount;
585 EnterCriticalSection(&PerfDataCriticalSection);
587 if (Index < ProcessCount)
588 HandleCount = pPerfData[Index].HandleCount;
589 else
590 HandleCount = 0;
592 LeaveCriticalSection(&PerfDataCriticalSection);
594 return HandleCount;
597 ULONG PerfDataGetThreadCount(ULONG Index)
599 ULONG ThreadCount;
601 EnterCriticalSection(&PerfDataCriticalSection);
603 if (Index < ProcessCount)
604 ThreadCount = pPerfData[Index].ThreadCount;
605 else
606 ThreadCount = 0;
608 LeaveCriticalSection(&PerfDataCriticalSection);
610 return ThreadCount;
613 ULONG PerfDataGetUSERObjectCount(ULONG Index)
615 ULONG USERObjectCount;
617 EnterCriticalSection(&PerfDataCriticalSection);
619 if (Index < ProcessCount)
620 USERObjectCount = pPerfData[Index].USERObjectCount;
621 else
622 USERObjectCount = 0;
624 LeaveCriticalSection(&PerfDataCriticalSection);
626 return USERObjectCount;
629 ULONG PerfDataGetGDIObjectCount(ULONG Index)
631 ULONG GDIObjectCount;
633 EnterCriticalSection(&PerfDataCriticalSection);
635 if (Index < ProcessCount)
636 GDIObjectCount = pPerfData[Index].GDIObjectCount;
637 else
638 GDIObjectCount = 0;
640 LeaveCriticalSection(&PerfDataCriticalSection);
642 return GDIObjectCount;
645 BOOL PerfDataGetIOCounters(ULONG Index, PIO_COUNTERS pIoCounters)
647 BOOL bSuccessful;
649 EnterCriticalSection(&PerfDataCriticalSection);
651 if (Index < ProcessCount)
653 memcpy(pIoCounters, &pPerfData[Index].IOCounters, sizeof(IO_COUNTERS));
654 bSuccessful = TRUE;
656 else
657 bSuccessful = FALSE;
659 LeaveCriticalSection(&PerfDataCriticalSection);
661 return bSuccessful;
664 ULONG PerfDataGetCommitChargeTotalK(void)
666 ULONG Total;
667 ULONG PageSize;
669 EnterCriticalSection(&PerfDataCriticalSection);
671 Total = SystemPerfInfo.MmTotalCommittedPages;
672 PageSize = SystemBasicInfo.uPageSize;
674 LeaveCriticalSection(&PerfDataCriticalSection);
676 Total = Total * (PageSize / 1024);
678 return Total;
681 ULONG PerfDataGetCommitChargeLimitK(void)
683 ULONG Limit;
684 ULONG PageSize;
686 EnterCriticalSection(&PerfDataCriticalSection);
688 Limit = SystemPerfInfo.MmTotalCommitLimit;
689 PageSize = SystemBasicInfo.uPageSize;
691 LeaveCriticalSection(&PerfDataCriticalSection);
693 Limit = Limit * (PageSize / 1024);
695 return Limit;
698 ULONG PerfDataGetCommitChargePeakK(void)
700 ULONG Peak;
701 ULONG PageSize;
703 EnterCriticalSection(&PerfDataCriticalSection);
705 Peak = SystemPerfInfo.MmPeakLimit;
706 PageSize = SystemBasicInfo.uPageSize;
708 LeaveCriticalSection(&PerfDataCriticalSection);
710 Peak = Peak * (PageSize / 1024);
712 return Peak;
715 ULONG PerfDataGetKernelMemoryTotalK(void)
717 ULONG Total;
718 ULONG Paged;
719 ULONG NonPaged;
720 ULONG PageSize;
722 EnterCriticalSection(&PerfDataCriticalSection);
724 Paged = SystemPerfInfo.PoolPagedBytes;
725 NonPaged = SystemPerfInfo.PoolNonPagedBytes;
726 PageSize = SystemBasicInfo.uPageSize;
728 LeaveCriticalSection(&PerfDataCriticalSection);
730 Paged = Paged * (PageSize / 1024);
731 NonPaged = NonPaged * (PageSize / 1024);
733 Total = Paged + NonPaged;
735 return Total;
738 ULONG PerfDataGetKernelMemoryPagedK(void)
740 ULONG Paged;
741 ULONG PageSize;
743 EnterCriticalSection(&PerfDataCriticalSection);
745 Paged = SystemPerfInfo.PoolPagedBytes;
746 PageSize = SystemBasicInfo.uPageSize;
748 LeaveCriticalSection(&PerfDataCriticalSection);
750 Paged = Paged * (PageSize / 1024);
752 return Paged;
755 ULONG PerfDataGetKernelMemoryNonPagedK(void)
757 ULONG NonPaged;
758 ULONG PageSize;
760 EnterCriticalSection(&PerfDataCriticalSection);
762 NonPaged = SystemPerfInfo.PoolNonPagedBytes;
763 PageSize = SystemBasicInfo.uPageSize;
765 LeaveCriticalSection(&PerfDataCriticalSection);
767 NonPaged = NonPaged * (PageSize / 1024);
769 return NonPaged;
772 ULONG PerfDataGetPhysicalMemoryTotalK(void)
774 ULONG Total;
775 ULONG PageSize;
777 EnterCriticalSection(&PerfDataCriticalSection);
779 Total = SystemBasicInfo.uMmNumberOfPhysicalPages;
780 PageSize = SystemBasicInfo.uPageSize;
782 LeaveCriticalSection(&PerfDataCriticalSection);
784 Total = Total * (PageSize / 1024);
786 return Total;
789 ULONG PerfDataGetPhysicalMemoryAvailableK(void)
791 ULONG Available;
792 ULONG PageSize;
794 EnterCriticalSection(&PerfDataCriticalSection);
796 Available = SystemPerfInfo.MmAvailablePages;
797 PageSize = SystemBasicInfo.uPageSize;
799 LeaveCriticalSection(&PerfDataCriticalSection);
801 Available = Available * (PageSize / 1024);
803 return Available;
806 ULONG PerfDataGetPhysicalMemorySystemCacheK(void)
808 ULONG SystemCache;
810 EnterCriticalSection(&PerfDataCriticalSection);
812 SystemCache = SystemCacheInfo.CurrentSize;
814 LeaveCriticalSection(&PerfDataCriticalSection);
816 SystemCache = SystemCache / 1024;
818 return SystemCache;
821 ULONG PerfDataGetSystemHandleCount(void)
823 ULONG HandleCount;
825 EnterCriticalSection(&PerfDataCriticalSection);
827 HandleCount = SystemHandleInfo.Count;
829 LeaveCriticalSection(&PerfDataCriticalSection);
831 return HandleCount;
834 ULONG PerfDataGetTotalThreadCount(void)
836 ULONG ThreadCount = 0;
837 ULONG i;
839 EnterCriticalSection(&PerfDataCriticalSection);
841 for (i=0; i<ProcessCount; i++)
843 ThreadCount += pPerfData[i].ThreadCount;
846 LeaveCriticalSection(&PerfDataCriticalSection);
848 return ThreadCount;