Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1999.
  5. //
  6. // File: procinfo.cxx
  7. //
  8. // Contents: performance test program
  9. //
  10. // History: 16 March 1996 dlee Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #include "pch.cxx"
  14. #pragma hdrstop
  15. extern "C"
  16. {
  17. #include <nt.h>
  18. #include <ntioapi.h>
  19. #include <ntrtl.h>
  20. #include <nturtl.h>
  21. #include <ntexapi.h>
  22. }
  23. #include <windows.h>
  24. #include <stdio.h>
  25. void GetProcessInfo(
  26. WCHAR * pwcImage,
  27. LARGE_INTEGER & liUserTime,
  28. LARGE_INTEGER & liKernelTime,
  29. ULONG & cHandles,
  30. ULONGLONG & cbWorkingSet,
  31. ULONGLONG & cbPeakWorkingSet,
  32. ULONGLONG & cbPeakVirtualSize,
  33. ULONGLONG & cbNonPagedPoolUsage,
  34. ULONGLONG & cbPeakNonPagedPoolUsage )
  35. {
  36. BYTE ab[81920];
  37. NTSTATUS status = NtQuerySystemInformation( SystemProcessInformation,
  38. ab,
  39. sizeof ab,
  40. NULL );
  41. if ( NT_SUCCESS( status ) )
  42. {
  43. DWORD dwProcId = GetCurrentProcessId();
  44. DWORD cbOffset = 0;
  45. PSYSTEM_PROCESS_INFORMATION pCurrent = 0;
  46. do
  47. {
  48. pCurrent = (PSYSTEM_PROCESS_INFORMATION)&(ab[cbOffset]);
  49. //printf(" image: '%ws'\n", pCurrent->ImageName.Buffer );
  50. if ( ( 0 == pwcImage && pCurrent->UniqueProcessId == LongToHandle( dwProcId ) ) ||
  51. ( 0 != pwcImage && 0 != pCurrent->ImageName.Buffer && !_wcsicmp( pwcImage, pCurrent->ImageName.Buffer ) ) )
  52. {
  53. liUserTime = pCurrent->UserTime;
  54. liKernelTime = pCurrent->KernelTime;
  55. cHandles = pCurrent->HandleCount;
  56. cbWorkingSet = pCurrent->WorkingSetSize;
  57. cbPeakWorkingSet = pCurrent->PeakWorkingSetSize;
  58. cbPeakVirtualSize = pCurrent->PeakVirtualSize;
  59. cbNonPagedPoolUsage = pCurrent->QuotaNonPagedPoolUsage;
  60. cbPeakNonPagedPoolUsage = pCurrent->QuotaPeakNonPagedPoolUsage;
  61. return;
  62. }
  63. cbOffset += pCurrent->NextEntryOffset;
  64. } while (pCurrent->NextEntryOffset);
  65. }
  66. }
  67. #if 0
  68. void PrintProcessInfo()
  69. {
  70. ULONG cHandles;
  71. ULONG cbWorkingSet;
  72. ULONG cbPeakWorkingSet;
  73. ULONG cbPeakVirtualSize;
  74. ULONG cbNonPagedPoolUsage;
  75. ULONG cbPeakNonPagedPoolUsage;
  76. GetProcessInfo( cHandles,
  77. cbWorkingSet,
  78. cbPeakWorkingSet,
  79. cbPeakVirtualSize,
  80. cbNonPagedPoolUsage,
  81. cbPeakNonPagedPoolUsage );
  82. printf( "info:\n cbWorkingSet %d\n"
  83. " cbPeakWorkingSet %d\n"
  84. " cbPeakVirtualSize %d\n"
  85. " cbNonPagedPoolUsage %d\n"
  86. " cbPeakNonPagedPoolUsage %d\n"
  87. " cHandles: %d\n",
  88. cbWorkingSet,
  89. cbPeakWorkingSet,
  90. cbPeakVirtualSize,
  91. cbNonPagedPoolUsage,
  92. cbPeakNonPagedPoolUsage,
  93. cHandles );
  94. }
  95. #endif