ReactOS  0.4.15-dev-3440-g915569a
perfdata.c
Go to the documentation of this file.
1 /*
2  * ReactOS Task Manager
3  *
4  * perfdata.c
5  *
6  * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
7  * Copyright (C) 2014 Ismael Ferreras Morezuelas <swyterzone+ros@gmail.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #include "precomp.h"
25 
26 #define WIN32_LEAN_AND_MEAN
27 #include <aclapi.h>
28 
29 #define NTOS_MODE_USER
30 #include <ndk/psfuncs.h>
31 #include <ndk/exfuncs.h>
32 
34 PPERFDATA pPerfDataOld = NULL; /* Older perf data (saved to establish delta values) */
35 PPERFDATA pPerfData = NULL; /* Most recent copy of perf data */
38 double dbIdleTime;
39 double dbKernelTime;
40 double dbSystemTime;
42 double OldKernelTime = 0;
50 
52 
53 #define CMD_LINE_MIN(a, b) (a < b ? a - sizeof(WCHAR) : b)
54 
55 typedef struct _SIDTOUSERNAME
56 {
59  BYTE Data[0];
61 
63 
65 {
68 
70 
71  /*
72  * Get number of processors in the system
73  */
75  if (!NT_SUCCESS(status))
76  return FALSE;
77 
78  /*
79  * Create the SYSTEM Sid
80  */
82  return TRUE;
83 }
84 
86 {
89 
90  if (pPerfData != NULL)
92 
94 
95  if (SystemUserSid != NULL)
96  {
99  }
100 
101  /* Free user names cache list */
103  while (pCur != &SidToUserNameHead)
104  {
106  pCur = pCur->Flink;
108  }
109 
112  }
113 }
114 
115 static void SidToUserName(PSID Sid, LPWSTR szBuffer, DWORD BufferSize)
116 {
117  static WCHAR szDomainNameUnused[255];
118  DWORD DomainNameLen = sizeof(szDomainNameUnused) / sizeof(szDomainNameUnused[0]);
119  SID_NAME_USE Use;
120 
121  if (Sid != NULL)
122  LookupAccountSidW(NULL, Sid, szBuffer, &BufferSize, szDomainNameUnused, &DomainNameLen, &Use);
123 }
124 
125 VOID
126 WINAPI
128  PSID pSid,
131 {
134  ULONG cbSid, cwcUserName;
135 
136  cwcUserName = *pcwcUserName;
137 
138  /* Walk through the list */
141  pCur = pCur->Flink)
142  {
144  if (EqualSid((PSID)&pEntry->Data, pSid))
145  {
146  wcsncpy(pUserName, pEntry->pszName, cwcUserName);
148  return;
149  }
150  }
151 
152  /* We didn't find the SID in the list, get the name conventional */
153  SidToUserName(pSid, pUserName, cwcUserName);
155 
156  /* Allocate a new entry */
157  cwcUserName = *pcwcUserName + 1;
159  pEntry = HeapAlloc(GetProcessHeap(), 0, sizeof(SIDTOUSERNAME) + cbSid + cwcUserName * sizeof(WCHAR));
160 
161  /* Copy the Sid and name to our entry */
162  CopySid(cbSid, (PSID)&pEntry->Data, pSid);
163  pEntry->pszName = (LPWSTR)(pEntry->Data + cbSid);
164  wcsncpy(pEntry->pszName, pUserName, cwcUserName);
165 
166  /* Insert the new entry */
167  pEntry->List.Flink = &SidToUserNameHead;
169  SidToUserNameHead.Blink->Flink = &pEntry->List;
170  SidToUserNameHead.Blink = &pEntry->List;
171 
172  return;
173 }
174 
175 void PerfDataRefresh(void)
176 {
177  ULONG ulSize;
179  LPBYTE pBuffer;
182  PPERFDATA pPDOld;
183  ULONG Idx, Idx2;
185  HANDLE hProcessToken;
186  SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo;
187  SYSTEM_TIMEOFDAY_INFORMATION SysTimeInfo;
188  SYSTEM_FILECACHE_INFORMATION SysCacheInfo;
189  SYSTEM_HANDLE_INFORMATION SysHandleInfoData;
190  PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION SysProcessorTimeInfo;
191  double CurrentKernelTime;
192  PSECURITY_DESCRIPTOR ProcessSD;
193  PSID ProcessUser;
194  ULONG Buffer[64]; /* must be 4 bytes aligned! */
195  ULONG cwcUserName;
196 
197  /* Get new system time */
198  status = NtQuerySystemInformation(SystemTimeOfDayInformation, &SysTimeInfo, sizeof(SysTimeInfo), NULL);
199  if (!NT_SUCCESS(status))
200  return;
201 
202  /* Get new CPU's idle time */
203  status = NtQuerySystemInformation(SystemPerformanceInformation, &SysPerfInfo, sizeof(SysPerfInfo), NULL);
204  if (!NT_SUCCESS(status))
205  return;
206 
207  /* Get system cache information */
208  status = NtQuerySystemInformation(SystemFileCacheInformation, &SysCacheInfo, sizeof(SysCacheInfo), NULL);
209  if (!NT_SUCCESS(status))
210  return;
211 
212  /* Get processor time information */
215 
216  if (!NT_SUCCESS(status))
217  {
218  if (SysProcessorTimeInfo != NULL)
219  HeapFree(GetProcessHeap(), 0, SysProcessorTimeInfo);
220  return;
221  }
222 
223  /* Get handle information
224  * Number of handles is enough, no need for data array.
225  */
226  status = NtQuerySystemInformation(SystemHandleInformation, &SysHandleInfoData, sizeof(SysHandleInfoData), NULL);
227  /* On unexpected error, reuse previous value.
228  * STATUS_SUCCESS (0-1 handle) should never happen.
229  */
231  SysHandleInfoData.NumberOfHandles = SystemNumberOfHandles;
232 
233  /* Get process information
234  * We don't know how much data there is so just keep
235  * increasing the buffer size until the call succeeds
236  */
237  BufferSize = 0;
238  do
239  {
240  BufferSize += 0x10000;
242 
244 
247  }
248 
249  } while (status == STATUS_INFO_LENGTH_MISMATCH);
250 
252 
253  /*
254  * Save system performance info
255  */
256  memcpy(&SystemPerfInfo, &SysPerfInfo, sizeof(SYSTEM_PERFORMANCE_INFORMATION));
257 
258  /*
259  * Save system cache info
260  */
261  memcpy(&SystemCacheInfo, &SysCacheInfo, sizeof(SYSTEM_FILECACHE_INFORMATION));
262 
263  /*
264  * Save system processor time info
265  */
268  }
269  SystemProcessorTimeInfo = SysProcessorTimeInfo;
270 
271  /*
272  * Save system handle info
273  */
274  SystemNumberOfHandles = SysHandleInfoData.NumberOfHandles;
275 
276  for (CurrentKernelTime=0, Idx=0; Idx<(ULONG)SystemBasicInfo.NumberOfProcessors; Idx++) {
277  CurrentKernelTime += Li2Double(SystemProcessorTimeInfo[Idx].KernelTime);
278  CurrentKernelTime += Li2Double(SystemProcessorTimeInfo[Idx].DpcTime);
279  CurrentKernelTime += Li2Double(SystemProcessorTimeInfo[Idx].InterruptTime);
280  }
281 
282  /* If it's a first call - skip idle time calcs */
283  if (liOldIdleTime.QuadPart != 0) {
284  /* CurrentValue = NewValue - OldValue */
286  dbKernelTime = CurrentKernelTime - OldKernelTime;
288 
289  /* CurrentCpuIdle = IdleTime / SystemTime */
292 
293  /* CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) / NumberOfProcessors */
294  dbIdleTime = 100.0 - dbIdleTime * 100.0 / (double)SystemBasicInfo.NumberOfProcessors; /* + 0.5; */
295  dbKernelTime = 100.0 - dbKernelTime * 100.0 / (double)SystemBasicInfo.NumberOfProcessors; /* + 0.5; */
296  }
297 
298  /* Store new CPU's idle and system time */
299  liOldIdleTime = SysPerfInfo.IdleProcessTime;
300  liOldSystemTime = SysTimeInfo.CurrentTime;
301  OldKernelTime = CurrentKernelTime;
302 
303  /* Determine the process count
304  * We loop through the data we got from NtQuerySystemInformation
305  * and count how many structures there are (until RelativeOffset is 0)
306  */
308  ProcessCount = 0;
310  while (pSPI) {
311  ProcessCount++;
312  if (pSPI->NextEntryOffset == 0)
313  break;
314  pSPI = (PSYSTEM_PROCESS_INFORMATION)((LPBYTE)pSPI + pSPI->NextEntryOffset);
315  }
316 
317  /* Now alloc a new PERFDATA array and fill in the data */
319 
321  for (Idx=0; Idx<ProcessCount; Idx++) {
322  /* Get the old perf data for this process (if any) */
323  /* so that we can establish delta values */
324  pPDOld = NULL;
325  if (pPerfDataOld) {
326  for (Idx2=0; Idx2<ProcessCountOld; Idx2++) {
327  if (pPerfDataOld[Idx2].ProcessId == pSPI->UniqueProcessId) {
328  pPDOld = &pPerfDataOld[Idx2];
329  break;
330  }
331  }
332  }
333 
334  if (pSPI->ImageName.Buffer) {
335  /* Don't assume a UNICODE_STRING Buffer is zero terminated: */
336  int len = pSPI->ImageName.Length / 2;
337  /* Check against max size and allow for terminating zero (already zeroed): */
338  if(len >= MAX_PATH)len=MAX_PATH - 1;
340  } else {
342  sizeof(pPerfData[Idx].ImageName) / sizeof(pPerfData[Idx].ImageName[0]));
343  }
344 
345  pPerfData[Idx].ProcessId = pSPI->UniqueProcessId;
346 
347  if (pPDOld) {
348  double CurTime = Li2Double(pSPI->KernelTime) + Li2Double(pSPI->UserTime);
349  double OldTime = Li2Double(pPDOld->KernelTime) + Li2Double(pPDOld->UserTime);
350  double CpuTime = (CurTime - OldTime) / dbSystemTime;
351  CpuTime = CpuTime * 100.0 / (double)SystemBasicInfo.NumberOfProcessors; /* + 0.5; */
352  pPerfData[Idx].CPUUsage = (ULONG)CpuTime;
353  }
357  if (pPDOld)
359  else
362  if (pPDOld)
364  else
369  pPerfData[Idx].BasePriority = pSPI->BasePriority;
370  pPerfData[Idx].HandleCount = pSPI->HandleCount;
372  pPerfData[Idx].SessionId = pSPI->SessionId;
373  pPerfData[Idx].UserName[0] = UNICODE_NULL;
374  pPerfData[Idx].USERObjectCount = 0;
375  pPerfData[Idx].GDIObjectCount = 0;
376  ProcessUser = SystemUserSid;
377  ProcessSD = NULL;
378 
379  if (pSPI->UniqueProcessId != NULL) {
381  if (hProcess) {
382  /* don't query the information of the system process. It's possible but
383  returns Administrators as the owner of the process instead of SYSTEM */
384  if (pSPI->UniqueProcessId != (HANDLE)0x4)
385  {
386  if (OpenProcessToken(hProcess, TOKEN_QUERY, &hProcessToken))
387  {
388  DWORD RetLen = 0;
389  BOOL Ret;
390 
391  Ret = GetTokenInformation(hProcessToken, TokenUser, (LPVOID)Buffer, sizeof(Buffer), &RetLen);
392  CloseHandle(hProcessToken);
393 
394  if (Ret)
395  ProcessUser = ((PTOKEN_USER)Buffer)->User.Sid;
396  else
397  goto ReadProcOwner;
398  }
399  else
400  {
401 ReadProcOwner:
403  }
404 
405  pPerfData[Idx].USERObjectCount = GetGuiResources(hProcess, GR_USEROBJECTS);
406  pPerfData[Idx].GDIObjectCount = GetGuiResources(hProcess, GR_GDIOBJECTS);
407  }
408 
409  GetProcessIoCounters(hProcess, &pPerfData[Idx].IOCounters);
411  } else {
412  goto ClearInfo;
413  }
414  } else {
415 ClearInfo:
416  /* clear information we were unable to fetch */
417  ZeroMemory(&pPerfData[Idx].IOCounters, sizeof(IO_COUNTERS));
418  }
419 
420  cwcUserName = sizeof(pPerfData[0].UserName) / sizeof(pPerfData[0].UserName[0]);
421  CachedGetUserFromSid(ProcessUser, pPerfData[Idx].UserName, &cwcUserName);
422 
423  if (ProcessSD != NULL)
424  {
425  LocalFree((HLOCAL)ProcessSD);
426  }
427 
430  pSPI = (PSYSTEM_PROCESS_INFORMATION)((LPBYTE)pSPI + pSPI->NextEntryOffset);
431  }
433  if (pPerfDataOld) {
435  }
438 }
439 
441 {
442  ULONG idx;
443 
445 
446  for (idx = 0; idx < ProcessCount; idx++)
447  {
449  {
450  break;
451  }
452  }
453 
455 
456  if (idx == ProcessCount)
457  {
458  return -1;
459  }
460  return idx;
461 }
462 
464 {
465  ULONG Result;
469  return Result;
470 }
471 
473 {
474  ULONG Result;
478  return Result;
479 }
480 
482 {
483  ULONG Result;
487  return Result;
488 }
489 
491 {
492  BOOL bSuccessful;
493 
495 
496  if (Index < ProcessCount) {
497  wcsncpy(lpImageName, pPerfData[Index].ImageName, nMaxCount);
498  bSuccessful = TRUE;
499  } else {
500  bSuccessful = FALSE;
501  }
503  return bSuccessful;
504 }
505 
507 {
509 
511 
512  if (Index < ProcessCount)
514  else
515  ProcessId = 0;
516 
518 
519  return ProcessId;
520 }
521 
523 {
524  BOOL bSuccessful;
525 
527 
528  if (Index < ProcessCount) {
529  wcsncpy(lpUserName, pPerfData[Index].UserName, nMaxCount);
530  bSuccessful = TRUE;
531  } else {
532  bSuccessful = FALSE;
533  }
534 
536 
537  return bSuccessful;
538 }
539 
541 {
542  static const LPWSTR ellipsis = L"...";
543 
545  UNICODE_STRING CommandLineStr = {0};
546 
547  PVOID ProcessParams = NULL;
550 
552  BOOL result;
553 
554  PCMD_LINE_CACHE new_entry;
555  LPWSTR new_string;
556 
558 
559  /* [A] Search for a string already in cache? If so, use it */
560  while (cache && cache->pnext != NULL)
561  {
562  if (cache->idx == Index && cache->str != NULL)
563  {
564  /* Found it. Use it, and add some ellipsis at the very end to make it cute */
565  wcsncpy(lpCommandLine, cache->str, CMD_LINE_MIN(nMaxCount, cache->len));
566  wcscpy(lpCommandLine + CMD_LINE_MIN(nMaxCount, cache->len) - wcslen(ellipsis), ellipsis);
567  return TRUE;
568  }
569 
570  cache = cache->pnext;
571  }
572 
573  /* [B] We don't; let's allocate and load a value from the process mem... and cache it */
575 
576  /* Default blank command line in case things don't work out */
577  wcsncpy(lpCommandLine, L"", nMaxCount);
578 
579  /* Ask for a handle to the target process so that we can read its memory and query stuff */
581  if (!hProcess)
582  goto cleanup;
583 
584  /* First off, get the ProcessEnvironmentBlock location in that process' address space */
586  if (!NT_SUCCESS(Status))
587  goto cleanup;
588 
589  /* Then get the PEB.ProcessParameters member pointer */
591  (PVOID)((ULONG_PTR)pbi.PebBaseAddress + FIELD_OFFSET(PEB, ProcessParameters)),
592  &ProcessParams,
593  sizeof(ProcessParams),
594  NULL);
595  if (!result)
596  goto cleanup;
597 
598  /* Then copy the PEB->ProcessParameters.CommandLine member
599  to get the pointer to the string buffer and its size */
601  (PVOID)((ULONG_PTR)ProcessParams + FIELD_OFFSET(RTL_USER_PROCESS_PARAMETERS, CommandLine)),
602  &CommandLineStr,
603  sizeof(CommandLineStr),
604  NULL);
605  if (!result)
606  goto cleanup;
607 
608  /* Allocate the next cache entry and its accompanying string in one go */
609  new_entry = HeapAlloc(GetProcessHeap(),
611  sizeof(CMD_LINE_CACHE) + CommandLineStr.Length + sizeof(UNICODE_NULL));
612  if (!new_entry)
613  goto cleanup;
614 
615  new_string = (LPWSTR)((ULONG_PTR)new_entry + sizeof(CMD_LINE_CACHE));
616 
617  /* Bingo, the command line should be stored there,
618  copy the string from the other process */
620  CommandLineStr.Buffer,
621  new_string,
622  CommandLineStr.Length,
623  NULL);
624  if (!result)
625  {
626  /* Weird, after successfully reading the mem of that process
627  various times it fails now, forget it and bail out */
628  HeapFree(GetProcessHeap(), 0, new_entry);
629  goto cleanup;
630  }
631 
632  /* Add our pointer to the cache... */
633  new_entry->idx = Index;
634  new_entry->str = new_string;
635  new_entry->len = CommandLineStr.Length;
636 
637  if (!global_cache)
638  global_cache = new_entry;
639  else
640  cache->pnext = new_entry;
641 
642  /* ... and print the buffer for the first time */
643  wcsncpy(lpCommandLine, new_string, CMD_LINE_MIN(nMaxCount, CommandLineStr.Length));
644 
645 cleanup:
647  return TRUE;
648 }
649 
651 {
653  PCMD_LINE_CACHE cache_old;
654 
655  while (cache && cache->pnext != NULL)
656  {
657  cache_old = cache;
658  cache = cache->pnext;
659 
660  HeapFree(GetProcessHeap(), 0, cache_old);
661  }
662 }
663 
665 {
667 
669 
670  if (Index < ProcessCount)
672  else
673  SessionId = 0;
674 
676 
677  return SessionId;
678 }
679 
681 {
682  ULONG CpuUsage;
683 
685 
686  if (Index < ProcessCount)
687  CpuUsage = pPerfData[Index].CPUUsage;
688  else
689  CpuUsage = 0;
690 
692 
693  return CpuUsage;
694 }
695 
697 {
698  LARGE_INTEGER CpuTime = {{0,0}};
699 
701 
702  if (Index < ProcessCount)
703  CpuTime = pPerfData[Index].CPUTime;
704 
706 
707  return CpuTime;
708 }
709 
711 {
712  ULONG WorkingSetSizeBytes;
713 
715 
716  if (Index < ProcessCount)
717  WorkingSetSizeBytes = pPerfData[Index].WorkingSetSizeBytes;
718  else
719  WorkingSetSizeBytes = 0;
720 
722 
723  return WorkingSetSizeBytes;
724 }
725 
727 {
728  ULONG PeakWorkingSetSizeBytes;
729 
731 
732  if (Index < ProcessCount)
733  PeakWorkingSetSizeBytes = pPerfData[Index].PeakWorkingSetSizeBytes;
734  else
735  PeakWorkingSetSizeBytes = 0;
736 
738 
739  return PeakWorkingSetSizeBytes;
740 }
741 
743 {
744  ULONG WorkingSetSizeDelta;
745 
747 
748  if (Index < ProcessCount)
749  WorkingSetSizeDelta = pPerfData[Index].WorkingSetSizeDelta;
750  else
751  WorkingSetSizeDelta = 0;
752 
754 
755  return WorkingSetSizeDelta;
756 }
757 
759 {
760  ULONG PageFaultCount;
761 
763 
764  if (Index < ProcessCount)
765  PageFaultCount = pPerfData[Index].PageFaultCount;
766  else
767  PageFaultCount = 0;
768 
770 
771  return PageFaultCount;
772 }
773 
775 {
776  ULONG PageFaultCountDelta;
777 
779 
780  if (Index < ProcessCount)
781  PageFaultCountDelta = pPerfData[Index].PageFaultCountDelta;
782  else
783  PageFaultCountDelta = 0;
784 
786 
787  return PageFaultCountDelta;
788 }
789 
791 {
792  ULONG VirtualMemorySizeBytes;
793 
795 
796  if (Index < ProcessCount)
797  VirtualMemorySizeBytes = pPerfData[Index].VirtualMemorySizeBytes;
798  else
799  VirtualMemorySizeBytes = 0;
800 
802 
803  return VirtualMemorySizeBytes;
804 }
805 
807 {
808  ULONG PagedPoolUsage;
809 
811 
812  if (Index < ProcessCount)
813  PagedPoolUsage = pPerfData[Index].PagedPoolUsagePages;
814  else
815  PagedPoolUsage = 0;
816 
818 
819  return PagedPoolUsage;
820 }
821 
823 {
824  ULONG NonPagedPoolUsage;
825 
827 
828  if (Index < ProcessCount)
829  NonPagedPoolUsage = pPerfData[Index].NonPagedPoolUsagePages;
830  else
831  NonPagedPoolUsage = 0;
832 
834 
835  return NonPagedPoolUsage;
836 }
837 
839 {
840  ULONG BasePriority;
841 
843 
844  if (Index < ProcessCount)
845  BasePriority = pPerfData[Index].BasePriority;
846  else
847  BasePriority = 0;
848 
850 
851  return BasePriority;
852 }
853 
855 {
856  ULONG HandleCount;
857 
859 
860  if (Index < ProcessCount)
861  HandleCount = pPerfData[Index].HandleCount;
862  else
863  HandleCount = 0;
864 
866 
867  return HandleCount;
868 }
869 
871 {
872  ULONG ThreadCount;
873 
875 
876  if (Index < ProcessCount)
877  ThreadCount = pPerfData[Index].ThreadCount;
878  else
879  ThreadCount = 0;
880 
882 
883  return ThreadCount;
884 }
885 
887 {
888  ULONG USERObjectCount;
889 
891 
892  if (Index < ProcessCount)
893  USERObjectCount = pPerfData[Index].USERObjectCount;
894  else
895  USERObjectCount = 0;
896 
898 
899  return USERObjectCount;
900 }
901 
903 {
904  ULONG GDIObjectCount;
905 
907 
908  if (Index < ProcessCount)
909  GDIObjectCount = pPerfData[Index].GDIObjectCount;
910  else
911  GDIObjectCount = 0;
912 
914 
915  return GDIObjectCount;
916 }
917 
919 {
920  BOOL bSuccessful;
921 
923 
924  if (Index < ProcessCount)
925  {
926  memcpy(pIoCounters, &pPerfData[Index].IOCounters, sizeof(IO_COUNTERS));
927  bSuccessful = TRUE;
928  }
929  else
930  bSuccessful = FALSE;
931 
933 
934  return bSuccessful;
935 }
936 
938 {
939  ULONG Total;
940  ULONG PageSize;
941 
943 
945  PageSize = SystemBasicInfo.PageSize;
946 
948 
949  Total = Total * (PageSize / 1024);
950 
951  return Total;
952 }
953 
955 {
956  ULONG Limit;
957  ULONG PageSize;
958 
960 
962  PageSize = SystemBasicInfo.PageSize;
963 
965 
966  Limit = Limit * (PageSize / 1024);
967 
968  return Limit;
969 }
970 
972 {
973  ULONG Peak;
974  ULONG PageSize;
975 
977 
979  PageSize = SystemBasicInfo.PageSize;
980 
982 
983  Peak = Peak * (PageSize / 1024);
984 
985  return Peak;
986 }
987 
989 {
990  ULONG Total;
991  ULONG Paged;
992  ULONG NonPaged;
993  ULONG PageSize;
994 
996 
999  PageSize = SystemBasicInfo.PageSize;
1000 
1002 
1003  Paged = Paged * (PageSize / 1024);
1004  NonPaged = NonPaged * (PageSize / 1024);
1005 
1006  Total = Paged + NonPaged;
1007 
1008  return Total;
1009 }
1010 
1012 {
1013  ULONG Paged;
1014  ULONG PageSize;
1015 
1017 
1019  PageSize = SystemBasicInfo.PageSize;
1020 
1022 
1023  Paged = Paged * (PageSize / 1024);
1024 
1025  return Paged;
1026 }
1027 
1029 {
1030  ULONG NonPaged;
1031  ULONG PageSize;
1032 
1034 
1035  NonPaged = SystemPerfInfo.NonPagedPoolPages;
1036  PageSize = SystemBasicInfo.PageSize;
1037 
1039 
1040  NonPaged = NonPaged * (PageSize / 1024);
1041 
1042  return NonPaged;
1043 }
1044 
1046 {
1047  ULONG Total;
1048  ULONG PageSize;
1049 
1051 
1053  PageSize = SystemBasicInfo.PageSize;
1054 
1056 
1057  Total = Total * (PageSize / 1024);
1058 
1059  return Total;
1060 }
1061 
1063 {
1064  ULONG Available;
1065  ULONG PageSize;
1066 
1068 
1069  Available = SystemPerfInfo.AvailablePages;
1070  PageSize = SystemBasicInfo.PageSize;
1071 
1073 
1074  Available = Available * (PageSize / 1024);
1075 
1076  return Available;
1077 }
1078 
1080 {
1081  ULONG SystemCache;
1082  ULONG PageSize;
1083 
1085 
1086  PageSize = SystemBasicInfo.PageSize;
1087  SystemCache = SystemCacheInfo.CurrentSizeIncludingTransitionInPages * PageSize;
1088 
1090 
1091  return SystemCache / 1024;
1092 }
1093 
1095 {
1096  ULONG HandleCount;
1097 
1099 
1100  HandleCount = SystemNumberOfHandles;
1101 
1103 
1104  return HandleCount;
1105 }
1106 
1108 {
1109  ULONG ThreadCount = 0;
1110  ULONG i;
1111 
1113 
1114  for (i=0; i<ProcessCount; i++)
1115  {
1116  ThreadCount += pPerfData[i].ThreadCount;
1117  }
1118 
1120 
1121  return ThreadCount;
1122 }
1123 
1125 {
1126  BOOL bSuccessful = FALSE;
1127 
1129  if (Index < ProcessCount)
1130  {
1131  *lppData = pPerfData + Index;
1132  bSuccessful = TRUE;
1133  }
1135  return bSuccessful;
1136 }
1137 
ULONG PerfDataGetPhysicalMemorySystemCacheK(void)
Definition: perfdata.c:1079
#define CMD_LINE_MIN(a, b)
Definition: perfdata.c:53
ULONG PerfDataGetBasePriority(ULONG Index)
Definition: perfdata.c:838
Definition: cache.c:48
_In_ ULONG_PTR _In_ ULONG _Out_ ULONG_PTR * pid
Definition: winddi.h:3835
ULONG PerfDataGetKernelMemoryNonPagedK(void)
Definition: perfdata.c:1028
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ProcessId
Definition: fatprocs.h:2709
#define SECURITY_LOCAL_SYSTEM_RID
Definition: setypes.h:574
NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION SystemProcessorTimeInfo
Definition: perfdata.c:48
struct _PERFDATA * PPERFDATA
#define CloseHandle
Definition: compat.h:598
PSID SystemUserSid
Definition: perfdata.c:49
WCHAR UserName[MAX_PATH]
Definition: perfdata.h:35
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
enum _SID_NAME_USE SID_NAME_USE
GLuint64EXT * result
Definition: glext.h:11304
#define PROCESS_QUERY_INFORMATION
Definition: pstypes.h:166
#define TRUE
Definition: types.h:120
ULONG SystemNumberOfHandles
Definition: perfdata.c:47
ULONG PerfDataGetWorkingSetSizeBytes(ULONG Index)
Definition: perfdata.c:710
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
BOOL WINAPI EqualSid(PSID pSid1, PSID pSid2)
Definition: security.c:831
ULONG ProcessCountOld
Definition: perfdata.c:36
ULONG SessionId
Definition: dllmain.c:28
LONG NTSTATUS
Definition: precomp.h:26
ULONG PerfDataGetCPUUsage(ULONG Index)
Definition: perfdata.c:680
DWORD WINAPI GetSecurityInfo(HANDLE handle, SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo, PSID *ppsidOwner, PSID *ppsidGroup, PACL *ppDacl, PACL *ppSacl, PSECURITY_DESCRIPTOR *ppSecurityDescriptor)
Definition: misc.c:1244
ULONG SessionId
Definition: perfdata.h:36
ULONG PerfDataGetPageFaultCount(ULONG Index)
Definition: perfdata.c:758
BOOL PerfDataInitialize(void)
Definition: perfdata.c:64
ULONG PerfDataGetCommitChargePeakK(void)
Definition: perfdata.c:971
#define ZeroMemory
Definition: winbase.h:1664
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
EXTINLINE DWORD WINAPI GetGuiResources(HANDLE hProcess, DWORD uiFlags)
Definition: ntwrapper.h:64
ULONG USERObjectCount
Definition: perfdata.h:50
ULONG PerfDataGetProcessIndex(ULONG pid)
Definition: perfdata.c:440
#define ReadProcessMemory(a, b, c, d, e)
Definition: compat.h:617
ULONG PerfDataGetCommitChargeLimitK(void)
Definition: perfdata.c:954
ULONG PerfDataGetPageFaultCountDelta(ULONG Index)
Definition: perfdata.c:774
ULONG PerfDataGetTotalThreadCount(void)
Definition: perfdata.c:1107
ULONG PerfDataGetProcessorSystemUsage(void)
Definition: perfdata.c:481
ULONG CPUUsage
Definition: perfdata.h:37
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
struct _SIDTOUSERNAME * PSIDTOUSERNAME
void PerfDataUninitialize(void)
Definition: perfdata.c:85
ULONG PerfDataGetNonPagedPoolUsagePages(ULONG Index)
Definition: perfdata.c:822
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
ULONG PerfDataGetGDIObjectCount(ULONG Index)
Definition: perfdata.c:902
ULONG ProcessCount
Definition: perfdata.c:37
struct _SIDTOUSERNAME SIDTOUSERNAME
ULONG PerfDataGetSystemHandleCount(void)
Definition: perfdata.c:1094
uint32_t ULONG_PTR
Definition: typedefs.h:65
static LPWSTR PULONG pcwcUserName
ULONG PerfDataGetVirtualMemorySizeBytes(ULONG Index)
Definition: perfdata.c:790
LARGE_INTEGER CurrentTime
Definition: extypes.h:850
ULONG PerfDataGetPhysicalMemoryAvailableK(void)
Definition: perfdata.c:1062
#define L(x)
Definition: ntvdm.h:50
struct _SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
unsigned char * LPBYTE
Definition: typedefs.h:53
#define FALSE
Definition: types.h:117
#define UNICODE_NULL
unsigned int BOOL
Definition: ntddk_ex.h:94
SIZE_T CurrentSizeIncludingTransitionInPages
Definition: extypes.h:1119
long LONG
Definition: pedump.c:60
ULONG NonPagedPoolUsagePages
Definition: perfdata.h:46
PVOID WINAPI FreeSid(PSID pSid)
Definition: security.c:700
double dbKernelTime
Definition: perfdata.c:39
ULONG PerfDataGetKernelMemoryPagedK(void)
Definition: perfdata.c:1011
LARGE_INTEGER IdleProcessTime
Definition: memtest.h:11
unsigned int idx
Definition: utils.c:41
static const char mbstate_t *static wchar_t const char mbstate_t *static const wchar_t int *static double
Definition: string.c:80
BOOL PerfDataGetImageName(ULONG Index, LPWSTR lpImageName, ULONG nMaxCount)
Definition: perfdata.c:490
PPERFDATA pPerfData
Definition: perfdata.c:35
static LIST_ENTRY SidToUserNameHead
Definition: perfdata.c:62
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
PVOID pBuffer
static SID_IDENTIFIER_AUTHORITY NtSidAuthority
Definition: samrpc.c:14
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
_In_ LPCSTR _Out_writes_bytes_to_opt_ cbSid PSID _Inout_ LPDWORD cbSid
Definition: winbase.h:2721
_In_ ULONG _In_ ACCESS_MASK _In_ PSID Sid
Definition: rtlfuncs.h:1103
double OldKernelTime
Definition: perfdata.c:42
_Inout_ PERBANDINFO * pbi
Definition: winddi.h:3917
Definition: bufpool.h:45
#define SystemPerformanceInformation
Definition: memtest.h:87
ULONG WorkingSetSizeDelta
Definition: perfdata.h:41
BOOL WINAPI GetProcessIoCounters(IN HANDLE hProcess, OUT PIO_COUNTERS lpIoCounters)
Definition: proc.c:1862
#define SECURITY_NT_AUTHORITY
Definition: setypes.h:554
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define PtrToUlong(u)
Definition: config.h:107
ULONG PerfDataGetProcessCount(void)
Definition: perfdata.c:463
BOOL WINAPI LookupAccountSidW(LPCWSTR pSystemName, PSID pSid, LPWSTR pAccountName, LPDWORD pdwAccountName, LPWSTR pDomainName, LPDWORD pdwDomainName, PSID_NAME_USE peUse)
Definition: misc.c:537
BOOL PerfDataGetIOCounters(ULONG Index, PIO_COUNTERS pIoCounters)
Definition: perfdata.c:918
SYSTEM_PERFORMANCE_INFORMATION SystemPerfInfo
Definition: perfdata.c:44
LIST_ENTRY List
Definition: perfdata.c:57
ULONG HandleCount
Definition: perfdata.h:48
Status
Definition: gdiplustypes.h:24
static LPWSTR pUserName
ULONG PerfDataGetThreadCount(ULONG Index)
Definition: perfdata.c:870
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
double dbSystemTime
Definition: perfdata.c:40
#define GetProcessHeap()
Definition: compat.h:595
LARGE_INTEGER liOldIdleTime
Definition: perfdata.c:41
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define TOKEN_QUERY
Definition: setypes.h:906
__wchar_t WCHAR
Definition: xmlstorage.h:180
ULONG PageFaultCountDelta
Definition: perfdata.h:43
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
DWORD WINAPI GetLengthSid(PSID pSid)
Definition: security.c:921
_In_ WDFCOLLECTION _In_ ULONG Index
ULONG PerfDataGetProcessId(ULONG Index)
Definition: perfdata.c:506
SYSTEM_BASIC_INFORMATION SystemBasicInfo
Definition: perfdata.c:45
#define MAX_PATH
Definition: compat.h:34
#define WINAPI
Definition: msvc.h:6
VOID WINAPI CachedGetUserFromSid(PSID pSid, LPWSTR pUserName, PULONG pcwcUserName)
Definition: perfdata.c:127
ULONG BasePriority
Definition: perfdata.h:47
unsigned long DWORD
Definition: ntddk_ex.h:95
struct _SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION * PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
#define READ_CONTROL
Definition: nt_native.h:58
UNICODE_STRING ImageName
Definition: extypes.h:894
ULONG WorkingSetSizeBytes
Definition: perfdata.h:39
void PerfDataDeallocCommandLineCache()
Definition: perfdata.c:650
ULONG PerfDataGetPeakWorkingSetSizeBytes(ULONG Index)
Definition: perfdata.c:726
static const char * ImageName
Definition: image.c:34
LARGE_INTEGER liOldSystemTime
Definition: perfdata.c:43
LARGE_INTEGER PerfDataGetCPUTime(ULONG Index)
Definition: perfdata.c:696
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define IDS_IDLE_PROCESS
Definition: resource.h:3
static IOleCache * cache
Definition: ole2.c:75
struct _CMD_LINE_CACHE CMD_LINE_CACHE
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
struct _PERFDATA PERFDATA
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
Definition: typedefs.h:119
LARGE_INTEGER CPUTime
Definition: perfdata.h:38
SYSTEM_FILECACHE_INFORMATION SystemCacheInfo
Definition: perfdata.c:46
ULONG ThreadCount
Definition: perfdata.h:49
unsigned char BYTE
Definition: xxhash.c:193
ULONG PerfDataGetKernelMemoryTotalK(void)
Definition: perfdata.c:988
BOOL PerfDataGet(ULONG Index, PPERFDATA *lppData)
Definition: perfdata.c:1124
struct _SYSTEM_PROCESS_INFORMATION * PSYSTEM_PROCESS_INFORMATION
HANDLE ProcessId
Definition: perfdata.h:34
HANDLE WINAPI OpenProcess(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwProcessId)
Definition: proc.c:1227
HINSTANCE hInst
Definition: dxdiag.c:13
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
LARGE_INTEGER KernelTime
Definition: extypes.h:893
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
SINGLE_LIST_ENTRY * pCur
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
static void SidToUserName(PSID Sid, LPWSTR szBuffer, DWORD BufferSize)
Definition: perfdata.c:115
ULONG PeakWorkingSetSizeBytes
Definition: perfdata.h:40
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define OWNER_SECURITY_INFORMATION
Definition: setypes.h:123
unsigned int * PULONG
Definition: retypes.h:1
ULONG PageFaultCount
Definition: perfdata.h:42
ULONG PerfDataGetWorkingSetSizeDelta(ULONG Index)
Definition: perfdata.c:742
#define NULL
Definition: types.h:112
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:296
ULONG PerfDataGetSessionId(ULONG Index)
Definition: perfdata.c:664
PPERFDATA pPerfDataOld
Definition: perfdata.c:34
static PSID pSid
Definition: security.c:74
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
ULONG PerfDataGetCommitChargeTotalK(void)
Definition: perfdata.c:937
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
ULONG PerfDataGetPhysicalMemoryTotalK(void)
Definition: perfdata.c:1045
ULONG PerfDataGetHandleCount(ULONG Index)
Definition: perfdata.c:854
#define Li2Double(x)
Definition: perfdata.h:29
#define PROCESS_VM_READ
Definition: pstypes.h:161
CRITICAL_SECTION PerfDataCriticalSection
Definition: perfdata.c:33
BOOL PerfDataGetUserName(ULONG Index, LPWSTR lpUserName, ULONG nMaxCount)
Definition: perfdata.c:522
unsigned int ULONG
Definition: retypes.h:1
BOOL WINAPI GetTokenInformation(HANDLE TokenHandle, TOKEN_INFORMATION_CLASS TokenInformationClass, LPVOID TokenInformation, DWORD TokenInformationLength, PDWORD ReturnLength)
Definition: security.c:413
ULONG GDIObjectCount
Definition: perfdata.h:51
struct _TOKEN_USER * PTOKEN_USER
ULONG PerfDataGetProcessorUsage(void)
Definition: perfdata.c:472
LARGE_INTEGER UserTime
Definition: extypes.h:892
char * cleanup(char *str)
Definition: wpickclick.c:99
_Check_return_ long __cdecl labs(_In_ long x)
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
WCHAR * LPWSTR
Definition: xmlstorage.h:184
BOOL WINAPI CopySid(DWORD nDestinationSidLength, PSID pDestinationSid, PSID pSourceSid)
Definition: security.c:714
PLIST_ENTRY pEntry
Definition: fxioqueue.cpp:4484
LARGE_INTEGER KernelTime
Definition: perfdata.h:55
ULONG VirtualMemorySizeBytes
Definition: perfdata.h:44
static SERVICE_STATUS status
Definition: service.c:31
LARGE_INTEGER UserTime
Definition: perfdata.h:54
ULONG PerfDataGetUSERObjectCount(ULONG Index)
Definition: perfdata.c:886
_In_ int nMaxCount
Definition: winuser.h:4857
ULONG PerfDataGetPagedPoolUsagePages(ULONG Index)
Definition: perfdata.c:806
LPWSTR pszName
Definition: perfdata.c:58
_In_ LONG _In_ LONG Limit
Definition: kefuncs.h:315
#define HeapFree(x, y, z)
Definition: compat.h:594
PCMD_LINE_CACHE global_cache
Definition: perfdata.c:51
#define BufferSize
Definition: mmc.h:75
NTSTATUS NTAPI NtQueryInformationProcess(_In_ HANDLE ProcessHandle, _In_ PROCESSINFOCLASS ProcessInformationClass, _Out_ PVOID ProcessInformation, _In_ ULONG ProcessInformationLength, _Out_opt_ PULONG ReturnLength)
Definition: query.c:59
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:251
LONGLONG QuadPart
Definition: typedefs.h:114
double dbIdleTime
Definition: perfdata.c:38
void PerfDataRefresh(void)
Definition: perfdata.c:175
BOOL WINAPI AllocateAndInitializeSid(PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority, BYTE nSubAuthorityCount, DWORD nSubAuthority0, DWORD nSubAuthority1, DWORD nSubAuthority2, DWORD nSubAuthority3, DWORD nSubAuthority4, DWORD nSubAuthority5, DWORD nSubAuthority6, DWORD nSubAuthority7, PSID *pSid)
Definition: security.c:676
LPWSTR str
Definition: perfdata.h:61
ULONG PagedPoolUsagePages
Definition: perfdata.h:45
BOOL PerfDataGetCommandLine(ULONG Index, LPWSTR lpCommandLine, ULONG nMaxCount)
Definition: perfdata.c:540
Definition: ps.c:97