wined3d: Move WINED3DRS_LOCALVIEWER to the state table.
[wine/gsoc_dplay.git] / programs / taskmgr / perfdata.c
blob85001b3f2445abcb7c2ef18c6906300f30b08f1c
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 #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
24 #include <windows.h>
25 #include <commctrl.h>
26 #include <stdlib.h>
27 #include <malloc.h>
28 #include <memory.h>
29 #include <tchar.h>
30 #include <stdio.h>
31 #include <winnt.h>
32 #include "taskmgr.h"
33 #include "perfdata.h"
35 PROCNTQSI NtQuerySystemInformation = NULL;
36 PROCGGR pGetGuiResources = NULL;
37 PROCGPIC pGetProcessIoCounters = NULL;
38 CRITICAL_SECTION PerfDataCriticalSection;
39 PPERFDATA pPerfDataOld = NULL; /* Older perf data (saved to establish delta values) */
40 PPERFDATA pPerfData = NULL; /* Most recent copy of perf data */
41 ULONG ProcessCountOld = 0;
42 ULONG ProcessCount = 0;
43 double dbIdleTime;
44 double dbKernelTime;
45 double dbSystemTime;
46 LARGE_INTEGER liOldIdleTime = {{0,0}};
47 double OldKernelTime = 0;
48 LARGE_INTEGER liOldSystemTime = {{0,0}};
49 SYSTEM_PERFORMANCE_INFORMATION SystemPerfInfo;
50 SYSTEM_BASIC_INFORMATION SystemBasicInfo;
51 SYSTEM_CACHE_INFORMATION SystemCacheInfo;
52 SYSTEM_HANDLE_INFORMATION SystemHandleInfo;
53 PSYSTEM_PROCESSORTIME_INFO SystemProcessorTimeInfo = NULL;
55 BOOL PerfDataInitialize(void)
57 LONG status;
59 NtQuerySystemInformation = (PROCNTQSI)GetProcAddress(GetModuleHandle(_T("ntdll.dll")), "NtQuerySystemInformation");
60 pGetGuiResources = (PROCGGR)GetProcAddress(GetModuleHandle(_T("user32.dll")), "GetGuiResources");
61 pGetProcessIoCounters = (PROCGPIC)GetProcAddress(GetModuleHandle(_T("kernel32.dll")), "GetProcessIoCounters");
63 InitializeCriticalSection(&PerfDataCriticalSection);
65 if (!NtQuerySystemInformation)
66 return FALSE;
69 * Get number of processors in the system
71 status = NtQuerySystemInformation(SystemBasicInformation, &SystemBasicInfo, sizeof(SystemBasicInfo), NULL);
72 if (status != NO_ERROR)
73 return FALSE;
75 return TRUE;
78 void PerfDataUninitialize(void)
80 NtQuerySystemInformation = NULL;
82 DeleteCriticalSection(&PerfDataCriticalSection);
85 void PerfDataRefresh(void)
87 ULONG ulSize;
88 LONG status;
89 LPBYTE pBuffer;
90 ULONG BufferSize;
91 PSYSTEM_PROCESS_INFORMATION pSPI;
92 PPERFDATA pPDOld;
93 ULONG Idx, Idx2;
94 HANDLE hProcess;
95 HANDLE hProcessToken;
96 TCHAR szTemp[MAX_PATH];
97 DWORD dwSize;
98 SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo;
99 SYSTEM_TIME_INFORMATION SysTimeInfo;
100 SYSTEM_CACHE_INFORMATION SysCacheInfo;
101 LPBYTE SysHandleInfoData;
102 PSYSTEM_PROCESSORTIME_INFO SysProcessorTimeInfo;
103 double CurrentKernelTime;
106 if (!NtQuerySystemInformation)
107 return;
109 /* Get new system time */
110 status = NtQuerySystemInformation(SystemTimeInformation, &SysTimeInfo, sizeof(SysTimeInfo), 0);
111 if (status != NO_ERROR)
112 return;
114 /* Get new CPU's idle time */
115 status = NtQuerySystemInformation(SystemPerformanceInformation, &SysPerfInfo, sizeof(SysPerfInfo), NULL);
116 if (status != NO_ERROR)
117 return;
119 /* Get system cache information */
120 status = NtQuerySystemInformation(SystemCacheInformation, &SysCacheInfo, sizeof(SysCacheInfo), NULL);
121 if (status != NO_ERROR)
122 return;
124 /* Get processor time information */
125 SysProcessorTimeInfo = (PSYSTEM_PROCESSORTIME_INFO)malloc(sizeof(SYSTEM_PROCESSORTIME_INFO) * SystemBasicInfo.bKeNumberProcessors);
126 status = NtQuerySystemInformation(SystemProcessorTimeInformation, SysProcessorTimeInfo, sizeof(SYSTEM_PROCESSORTIME_INFO) * SystemBasicInfo.bKeNumberProcessors, &ulSize);
127 if (status != NO_ERROR)
128 return;
130 /* Get handle information
131 * We don't know how much data there is so just keep
132 * increasing the buffer size until the call succeeds
134 BufferSize = 0;
137 BufferSize += 0x10000;
138 SysHandleInfoData = (LPBYTE)malloc(BufferSize);
140 status = NtQuerySystemInformation(SystemHandleInformation, SysHandleInfoData, BufferSize, &ulSize);
142 if (status == 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/) {
143 free(SysHandleInfoData);
146 } while (status == 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/);
148 /* Get process information
149 * We don't know how much data there is so just keep
150 * increasing the buffer size until the call succeeds
152 BufferSize = 0;
155 BufferSize += 0x10000;
156 pBuffer = (LPBYTE)malloc(BufferSize);
158 status = NtQuerySystemInformation(SystemProcessInformation, pBuffer, BufferSize, &ulSize);
160 if (status == 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/) {
161 free(pBuffer);
164 } while (status == 0xC0000004 /*STATUS_INFO_LENGTH_MISMATCH*/);
166 EnterCriticalSection(&PerfDataCriticalSection);
169 * Save system performance info
171 memcpy(&SystemPerfInfo, &SysPerfInfo, sizeof(SYSTEM_PERFORMANCE_INFORMATION));
174 * Save system cache info
176 memcpy(&SystemCacheInfo, &SysCacheInfo, sizeof(SYSTEM_CACHE_INFORMATION));
179 * Save system processor time info
181 free(SystemProcessorTimeInfo);
182 SystemProcessorTimeInfo = SysProcessorTimeInfo;
185 * Save system handle info
187 memcpy(&SystemHandleInfo, SysHandleInfoData, sizeof(SYSTEM_HANDLE_INFORMATION));
188 free(SysHandleInfoData);
190 for (CurrentKernelTime=0, Idx=0; Idx<SystemBasicInfo.bKeNumberProcessors; Idx++) {
191 CurrentKernelTime += Li2Double(SystemProcessorTimeInfo[Idx].KernelTime);
192 CurrentKernelTime += Li2Double(SystemProcessorTimeInfo[Idx].DpcTime);
193 CurrentKernelTime += Li2Double(SystemProcessorTimeInfo[Idx].InterruptTime);
196 /* If it's a first call - skip idle time calcs */
197 if (liOldIdleTime.QuadPart != 0) {
198 /* CurrentValue = NewValue - OldValue */
199 dbIdleTime = Li2Double(SysPerfInfo.liIdleTime) - Li2Double(liOldIdleTime);
200 dbKernelTime = CurrentKernelTime - OldKernelTime;
201 dbSystemTime = Li2Double(SysTimeInfo.liKeSystemTime) - Li2Double(liOldSystemTime);
203 /* CurrentCpuIdle = IdleTime / SystemTime */
204 dbIdleTime = dbIdleTime / dbSystemTime;
205 dbKernelTime = dbKernelTime / dbSystemTime;
207 /* CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) / NumberOfProcessors */
208 dbIdleTime = 100.0 - dbIdleTime * 100.0 / (double)SystemBasicInfo.bKeNumberProcessors; /* + 0.5; */
209 dbKernelTime = 100.0 - dbKernelTime * 100.0 / (double)SystemBasicInfo.bKeNumberProcessors; /* + 0.5; */
212 /* Store new CPU's idle and system time */
213 liOldIdleTime = SysPerfInfo.liIdleTime;
214 liOldSystemTime = SysTimeInfo.liKeSystemTime;
215 OldKernelTime = CurrentKernelTime;
217 /* Determine the process count
218 * We loop through the data we got from NtQuerySystemInformation
219 * and count how many structures there are (until RelativeOffset is 0)
221 ProcessCountOld = ProcessCount;
222 ProcessCount = 0;
223 pSPI = (PSYSTEM_PROCESS_INFORMATION)pBuffer;
224 while (pSPI) {
225 ProcessCount++;
226 if (pSPI->RelativeOffset == 0)
227 break;
228 pSPI = (PSYSTEM_PROCESS_INFORMATION)((LPBYTE)pSPI + pSPI->RelativeOffset);
231 /* Now alloc a new PERFDATA array and fill in the data */
232 free(pPerfDataOld);
233 pPerfDataOld = pPerfData;
234 pPerfData = (PPERFDATA)malloc(sizeof(PERFDATA) * ProcessCount);
235 pSPI = (PSYSTEM_PROCESS_INFORMATION)pBuffer;
236 for (Idx=0; Idx<ProcessCount; Idx++) {
237 /* Get the old perf data for this process (if any) */
238 /* so that we can establish delta values */
239 pPDOld = NULL;
240 for (Idx2=0; Idx2<ProcessCountOld; Idx2++) {
241 if (pPerfDataOld[Idx2].ProcessId == pSPI->ProcessId) {
242 pPDOld = &pPerfDataOld[Idx2];
243 break;
247 /* Clear out process perf data structure */
248 memset(&pPerfData[Idx], 0, sizeof(PERFDATA));
250 if (pSPI->Name.Buffer)
251 lstrcpyW(pPerfData[Idx].ImageName, pSPI->Name.Buffer);
252 else
254 static const WCHAR idleW[] = {'S','y','s','t','e','m',' ','I','d','l','e',' ','P','r','o','c','e','s','s',0};
255 lstrcpyW(pPerfData[Idx].ImageName, idleW );
258 pPerfData[Idx].ProcessId = pSPI->ProcessId;
260 if (pPDOld) {
261 double CurTime = Li2Double(pSPI->KernelTime) + Li2Double(pSPI->UserTime);
262 double OldTime = Li2Double(pPDOld->KernelTime) + Li2Double(pPDOld->UserTime);
263 double CpuTime = (CurTime - OldTime) / dbSystemTime;
264 CpuTime = CpuTime * 100.0 / (double)SystemBasicInfo.bKeNumberProcessors; /* + 0.5; */
265 pPerfData[Idx].CPUUsage = (ULONG)CpuTime;
267 pPerfData[Idx].CPUTime.QuadPart = pSPI->UserTime.QuadPart + pSPI->KernelTime.QuadPart;
268 pPerfData[Idx].WorkingSetSizeBytes = pSPI->TotalWorkingSetSizeBytes;
269 pPerfData[Idx].PeakWorkingSetSizeBytes = pSPI->PeakWorkingSetSizeBytes;
270 if (pPDOld)
271 pPerfData[Idx].WorkingSetSizeDelta = labs((LONG)pSPI->TotalWorkingSetSizeBytes - (LONG)pPDOld->WorkingSetSizeBytes);
272 else
273 pPerfData[Idx].WorkingSetSizeDelta = 0;
274 pPerfData[Idx].PageFaultCount = pSPI->PageFaultCount;
275 if (pPDOld)
276 pPerfData[Idx].PageFaultCountDelta = labs((LONG)pSPI->PageFaultCount - (LONG)pPDOld->PageFaultCount);
277 else
278 pPerfData[Idx].PageFaultCountDelta = 0;
279 pPerfData[Idx].VirtualMemorySizeBytes = pSPI->TotalVirtualSizeBytes;
280 pPerfData[Idx].PagedPoolUsagePages = pSPI->TotalPagedPoolUsagePages;
281 pPerfData[Idx].NonPagedPoolUsagePages = pSPI->TotalNonPagedPoolUsagePages;
282 pPerfData[Idx].BasePriority = pSPI->BasePriority;
283 pPerfData[Idx].HandleCount = pSPI->HandleCount;
284 pPerfData[Idx].ThreadCount = pSPI->ThreadCount;
285 pPerfData[Idx].SessionId = pSPI->SessionId;
287 hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pSPI->ProcessId);
288 if (hProcess) {
289 if (OpenProcessToken(hProcess, TOKEN_QUERY|TOKEN_DUPLICATE|TOKEN_IMPERSONATE, &hProcessToken)) {
290 ImpersonateLoggedOnUser(hProcessToken);
291 memset(szTemp, 0, sizeof(TCHAR[MAX_PATH]));
292 dwSize = MAX_PATH;
293 GetUserName(szTemp, &dwSize);
294 #ifndef UNICODE
295 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szTemp, -1, pPerfData[Idx].UserName, MAX_PATH);
297 int MultiByteToWideChar(
298 UINT CodePage, // code page
299 DWORD dwFlags, // character-type options
300 LPCSTR lpMultiByteStr, // string to map
301 int cbMultiByte, // number of bytes in string
302 LPWSTR lpWideCharStr, // wide-character buffer
303 int cchWideChar // size of buffer
306 #endif
307 RevertToSelf();
308 CloseHandle(hProcessToken);
310 if (pGetGuiResources) {
311 pPerfData[Idx].USERObjectCount = pGetGuiResources(hProcess, GR_USEROBJECTS);
312 pPerfData[Idx].GDIObjectCount = pGetGuiResources(hProcess, GR_GDIOBJECTS);
314 if (pGetProcessIoCounters)
315 pGetProcessIoCounters(hProcess, &pPerfData[Idx].IOCounters);
316 CloseHandle(hProcess);
318 pPerfData[Idx].UserTime.QuadPart = pSPI->UserTime.QuadPart;
319 pPerfData[Idx].KernelTime.QuadPart = pSPI->KernelTime.QuadPart;
320 pSPI = (PSYSTEM_PROCESS_INFORMATION)((LPBYTE)pSPI + pSPI->RelativeOffset);
322 free(pBuffer);
323 LeaveCriticalSection(&PerfDataCriticalSection);
326 ULONG PerfDataGetProcessCount(void)
328 return ProcessCount;
331 ULONG PerfDataGetProcessorUsage(void)
333 return (ULONG)dbIdleTime;
336 ULONG PerfDataGetProcessorSystemUsage(void)
338 return (ULONG)dbKernelTime;
341 BOOL PerfDataGetImageName(ULONG Index, LPTSTR lpImageName, int nMaxCount)
343 BOOL bSuccessful;
345 EnterCriticalSection(&PerfDataCriticalSection);
347 if (Index < ProcessCount) {
348 #ifdef _UNICODE
349 wcsncpy(lpImageName, pPerfData[Index].ImageName, nMaxCount);
350 #else
351 WideCharToMultiByte(CP_ACP, 0, pPerfData[Index].ImageName, -1, lpImageName, nMaxCount, NULL, NULL);
352 #endif
354 bSuccessful = TRUE;
355 } else {
356 bSuccessful = FALSE;
358 LeaveCriticalSection(&PerfDataCriticalSection);
359 return bSuccessful;
362 ULONG PerfDataGetProcessId(ULONG Index)
364 ULONG ProcessId;
366 EnterCriticalSection(&PerfDataCriticalSection);
368 if (Index < ProcessCount)
369 ProcessId = pPerfData[Index].ProcessId;
370 else
371 ProcessId = 0;
373 LeaveCriticalSection(&PerfDataCriticalSection);
375 return ProcessId;
378 BOOL PerfDataGetUserName(ULONG Index, LPTSTR lpUserName, int nMaxCount)
380 BOOL bSuccessful;
382 EnterCriticalSection(&PerfDataCriticalSection);
384 if (Index < ProcessCount) {
385 #ifdef _UNICODE
386 wcsncpy(lpUserName, pPerfData[Index].UserName, nMaxCount);
387 #else
388 WideCharToMultiByte(CP_ACP, 0, pPerfData[Index].UserName, -1, lpUserName, nMaxCount, NULL, NULL);
389 #endif
391 bSuccessful = TRUE;
392 } else {
393 bSuccessful = FALSE;
396 LeaveCriticalSection(&PerfDataCriticalSection);
398 return bSuccessful;
401 ULONG PerfDataGetSessionId(ULONG Index)
403 ULONG SessionId;
405 EnterCriticalSection(&PerfDataCriticalSection);
407 if (Index < ProcessCount)
408 SessionId = pPerfData[Index].SessionId;
409 else
410 SessionId = 0;
412 LeaveCriticalSection(&PerfDataCriticalSection);
414 return SessionId;
417 ULONG PerfDataGetCPUUsage(ULONG Index)
419 ULONG CpuUsage;
421 EnterCriticalSection(&PerfDataCriticalSection);
423 if (Index < ProcessCount)
424 CpuUsage = pPerfData[Index].CPUUsage;
425 else
426 CpuUsage = 0;
428 LeaveCriticalSection(&PerfDataCriticalSection);
430 return CpuUsage;
433 TIME PerfDataGetCPUTime(ULONG Index)
435 TIME CpuTime = {{0,0}};
437 EnterCriticalSection(&PerfDataCriticalSection);
439 if (Index < ProcessCount)
440 CpuTime = pPerfData[Index].CPUTime;
442 LeaveCriticalSection(&PerfDataCriticalSection);
444 return CpuTime;
447 ULONG PerfDataGetWorkingSetSizeBytes(ULONG Index)
449 ULONG WorkingSetSizeBytes;
451 EnterCriticalSection(&PerfDataCriticalSection);
453 if (Index < ProcessCount)
454 WorkingSetSizeBytes = pPerfData[Index].WorkingSetSizeBytes;
455 else
456 WorkingSetSizeBytes = 0;
458 LeaveCriticalSection(&PerfDataCriticalSection);
460 return WorkingSetSizeBytes;
463 ULONG PerfDataGetPeakWorkingSetSizeBytes(ULONG Index)
465 ULONG PeakWorkingSetSizeBytes;
467 EnterCriticalSection(&PerfDataCriticalSection);
469 if (Index < ProcessCount)
470 PeakWorkingSetSizeBytes = pPerfData[Index].PeakWorkingSetSizeBytes;
471 else
472 PeakWorkingSetSizeBytes = 0;
474 LeaveCriticalSection(&PerfDataCriticalSection);
476 return PeakWorkingSetSizeBytes;
479 ULONG PerfDataGetWorkingSetSizeDelta(ULONG Index)
481 ULONG WorkingSetSizeDelta;
483 EnterCriticalSection(&PerfDataCriticalSection);
485 if (Index < ProcessCount)
486 WorkingSetSizeDelta = pPerfData[Index].WorkingSetSizeDelta;
487 else
488 WorkingSetSizeDelta = 0;
490 LeaveCriticalSection(&PerfDataCriticalSection);
492 return WorkingSetSizeDelta;
495 ULONG PerfDataGetPageFaultCount(ULONG Index)
497 ULONG PageFaultCount;
499 EnterCriticalSection(&PerfDataCriticalSection);
501 if (Index < ProcessCount)
502 PageFaultCount = pPerfData[Index].PageFaultCount;
503 else
504 PageFaultCount = 0;
506 LeaveCriticalSection(&PerfDataCriticalSection);
508 return PageFaultCount;
511 ULONG PerfDataGetPageFaultCountDelta(ULONG Index)
513 ULONG PageFaultCountDelta;
515 EnterCriticalSection(&PerfDataCriticalSection);
517 if (Index < ProcessCount)
518 PageFaultCountDelta = pPerfData[Index].PageFaultCountDelta;
519 else
520 PageFaultCountDelta = 0;
522 LeaveCriticalSection(&PerfDataCriticalSection);
524 return PageFaultCountDelta;
527 ULONG PerfDataGetVirtualMemorySizeBytes(ULONG Index)
529 ULONG VirtualMemorySizeBytes;
531 EnterCriticalSection(&PerfDataCriticalSection);
533 if (Index < ProcessCount)
534 VirtualMemorySizeBytes = pPerfData[Index].VirtualMemorySizeBytes;
535 else
536 VirtualMemorySizeBytes = 0;
538 LeaveCriticalSection(&PerfDataCriticalSection);
540 return VirtualMemorySizeBytes;
543 ULONG PerfDataGetPagedPoolUsagePages(ULONG Index)
545 ULONG PagedPoolUsagePages;
547 EnterCriticalSection(&PerfDataCriticalSection);
549 if (Index < ProcessCount)
550 PagedPoolUsagePages = pPerfData[Index].PagedPoolUsagePages;
551 else
552 PagedPoolUsagePages = 0;
554 LeaveCriticalSection(&PerfDataCriticalSection);
556 return PagedPoolUsagePages;
559 ULONG PerfDataGetNonPagedPoolUsagePages(ULONG Index)
561 ULONG NonPagedPoolUsagePages;
563 EnterCriticalSection(&PerfDataCriticalSection);
565 if (Index < ProcessCount)
566 NonPagedPoolUsagePages = pPerfData[Index].NonPagedPoolUsagePages;
567 else
568 NonPagedPoolUsagePages = 0;
570 LeaveCriticalSection(&PerfDataCriticalSection);
572 return NonPagedPoolUsagePages;
575 ULONG PerfDataGetBasePriority(ULONG Index)
577 ULONG BasePriority;
579 EnterCriticalSection(&PerfDataCriticalSection);
581 if (Index < ProcessCount)
582 BasePriority = pPerfData[Index].BasePriority;
583 else
584 BasePriority = 0;
586 LeaveCriticalSection(&PerfDataCriticalSection);
588 return BasePriority;
591 ULONG PerfDataGetHandleCount(ULONG Index)
593 ULONG HandleCount;
595 EnterCriticalSection(&PerfDataCriticalSection);
597 if (Index < ProcessCount)
598 HandleCount = pPerfData[Index].HandleCount;
599 else
600 HandleCount = 0;
602 LeaveCriticalSection(&PerfDataCriticalSection);
604 return HandleCount;
607 ULONG PerfDataGetThreadCount(ULONG Index)
609 ULONG ThreadCount;
611 EnterCriticalSection(&PerfDataCriticalSection);
613 if (Index < ProcessCount)
614 ThreadCount = pPerfData[Index].ThreadCount;
615 else
616 ThreadCount = 0;
618 LeaveCriticalSection(&PerfDataCriticalSection);
620 return ThreadCount;
623 ULONG PerfDataGetUSERObjectCount(ULONG Index)
625 ULONG USERObjectCount;
627 EnterCriticalSection(&PerfDataCriticalSection);
629 if (Index < ProcessCount)
630 USERObjectCount = pPerfData[Index].USERObjectCount;
631 else
632 USERObjectCount = 0;
634 LeaveCriticalSection(&PerfDataCriticalSection);
636 return USERObjectCount;
639 ULONG PerfDataGetGDIObjectCount(ULONG Index)
641 ULONG GDIObjectCount;
643 EnterCriticalSection(&PerfDataCriticalSection);
645 if (Index < ProcessCount)
646 GDIObjectCount = pPerfData[Index].GDIObjectCount;
647 else
648 GDIObjectCount = 0;
650 LeaveCriticalSection(&PerfDataCriticalSection);
652 return GDIObjectCount;
655 BOOL PerfDataGetIOCounters(ULONG Index, PIO_COUNTERS pIoCounters)
657 BOOL bSuccessful;
659 EnterCriticalSection(&PerfDataCriticalSection);
661 if (Index < ProcessCount)
663 memcpy(pIoCounters, &pPerfData[Index].IOCounters, sizeof(IO_COUNTERS));
664 bSuccessful = TRUE;
666 else
667 bSuccessful = FALSE;
669 LeaveCriticalSection(&PerfDataCriticalSection);
671 return bSuccessful;
674 ULONG PerfDataGetCommitChargeTotalK(void)
676 ULONG Total;
677 ULONG PageSize;
679 EnterCriticalSection(&PerfDataCriticalSection);
681 Total = SystemPerfInfo.MmTotalCommittedPages;
682 PageSize = SystemBasicInfo.uPageSize;
684 LeaveCriticalSection(&PerfDataCriticalSection);
686 Total = Total * (PageSize / 1024);
688 return Total;
691 ULONG PerfDataGetCommitChargeLimitK(void)
693 ULONG Limit;
694 ULONG PageSize;
696 EnterCriticalSection(&PerfDataCriticalSection);
698 Limit = SystemPerfInfo.MmTotalCommitLimit;
699 PageSize = SystemBasicInfo.uPageSize;
701 LeaveCriticalSection(&PerfDataCriticalSection);
703 Limit = Limit * (PageSize / 1024);
705 return Limit;
708 ULONG PerfDataGetCommitChargePeakK(void)
710 ULONG Peak;
711 ULONG PageSize;
713 EnterCriticalSection(&PerfDataCriticalSection);
715 Peak = SystemPerfInfo.MmPeakLimit;
716 PageSize = SystemBasicInfo.uPageSize;
718 LeaveCriticalSection(&PerfDataCriticalSection);
720 Peak = Peak * (PageSize / 1024);
722 return Peak;
725 ULONG PerfDataGetKernelMemoryTotalK(void)
727 ULONG Total;
728 ULONG Paged;
729 ULONG NonPaged;
730 ULONG PageSize;
732 EnterCriticalSection(&PerfDataCriticalSection);
734 Paged = SystemPerfInfo.PoolPagedBytes;
735 NonPaged = SystemPerfInfo.PoolNonPagedBytes;
736 PageSize = SystemBasicInfo.uPageSize;
738 LeaveCriticalSection(&PerfDataCriticalSection);
740 Paged = Paged * (PageSize / 1024);
741 NonPaged = NonPaged * (PageSize / 1024);
743 Total = Paged + NonPaged;
745 return Total;
748 ULONG PerfDataGetKernelMemoryPagedK(void)
750 ULONG Paged;
751 ULONG PageSize;
753 EnterCriticalSection(&PerfDataCriticalSection);
755 Paged = SystemPerfInfo.PoolPagedBytes;
756 PageSize = SystemBasicInfo.uPageSize;
758 LeaveCriticalSection(&PerfDataCriticalSection);
760 Paged = Paged * (PageSize / 1024);
762 return Paged;
765 ULONG PerfDataGetKernelMemoryNonPagedK(void)
767 ULONG NonPaged;
768 ULONG PageSize;
770 EnterCriticalSection(&PerfDataCriticalSection);
772 NonPaged = SystemPerfInfo.PoolNonPagedBytes;
773 PageSize = SystemBasicInfo.uPageSize;
775 LeaveCriticalSection(&PerfDataCriticalSection);
777 NonPaged = NonPaged * (PageSize / 1024);
779 return NonPaged;
782 ULONG PerfDataGetPhysicalMemoryTotalK(void)
784 ULONG Total;
785 ULONG PageSize;
787 EnterCriticalSection(&PerfDataCriticalSection);
789 Total = SystemBasicInfo.uMmNumberOfPhysicalPages;
790 PageSize = SystemBasicInfo.uPageSize;
792 LeaveCriticalSection(&PerfDataCriticalSection);
794 Total = Total * (PageSize / 1024);
796 return Total;
799 ULONG PerfDataGetPhysicalMemoryAvailableK(void)
801 ULONG Available;
802 ULONG PageSize;
804 EnterCriticalSection(&PerfDataCriticalSection);
806 Available = SystemPerfInfo.MmAvailablePages;
807 PageSize = SystemBasicInfo.uPageSize;
809 LeaveCriticalSection(&PerfDataCriticalSection);
811 Available = Available * (PageSize / 1024);
813 return Available;
816 ULONG PerfDataGetPhysicalMemorySystemCacheK(void)
818 ULONG SystemCache;
819 ULONG PageSize;
821 EnterCriticalSection(&PerfDataCriticalSection);
823 SystemCache = SystemCacheInfo.CurrentSize;
824 PageSize = SystemBasicInfo.uPageSize;
826 LeaveCriticalSection(&PerfDataCriticalSection);
828 /* SystemCache = SystemCache * (PageSize / 1024); */
829 SystemCache = SystemCache / 1024;
831 return SystemCache;
834 ULONG PerfDataGetSystemHandleCount(void)
836 ULONG HandleCount;
838 EnterCriticalSection(&PerfDataCriticalSection);
840 HandleCount = SystemHandleInfo.Count;
842 LeaveCriticalSection(&PerfDataCriticalSection);
844 return HandleCount;
847 ULONG PerfDataGetTotalThreadCount(void)
849 ULONG ThreadCount = 0;
850 ULONG i;
852 EnterCriticalSection(&PerfDataCriticalSection);
854 for (i=0; i<ProcessCount; i++)
856 ThreadCount += pPerfData[i].ThreadCount;
859 LeaveCriticalSection(&PerfDataCriticalSection);
861 return ThreadCount;