Leaked source code of windows server 2003
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.

119 lines
3.8 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1997.
  5. //
  6. // File: memsnap.cxx
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions: void memsnap( FILE* ) a function for sending a snapshot of
  13. // all the processes in memory to a file stream
  14. //
  15. // Coupling:
  16. //
  17. // Notes: This function is used by CLog::Log when compiled with NO_NTLOG
  18. // If you plan on using ntlog.dll, you do not even need this module
  19. //
  20. // History: 10-22-1996 ericne Created
  21. //
  22. //----------------------------------------------------------------------------
  23. #include "pch.cxx"
  24. #pragma hdrstop
  25. #include "memsnap.hxx"
  26. // from pmon
  27. #define BUFFER_SIZE 64*1024
  28. //+---------------------------------------------------------------------------
  29. //
  30. // Function: memsnap
  31. //
  32. // Synopsis: Sends a snapshot of the current memory state to the indicated
  33. // file stream
  34. //
  35. // Arguments: [pLogFile] -- File stream pointer
  36. //
  37. // Returns: (none)
  38. //
  39. // History: 10-22-1996 ericne Created
  40. //
  41. // Notes:
  42. //
  43. //----------------------------------------------------------------------------
  44. void memsnap( FILE* pLogFile )
  45. {
  46. ULONG Offset1;
  47. PUCHAR CurrentBuffer;
  48. NTSTATUS Status;
  49. PSYSTEM_PROCESS_INFORMATION ProcessInfo;
  50. _ftprintf( pLogFile, _T("%10s%20s%10s%10s%10s%10s%10s%10s%10s\r\n"),
  51. _T("Process ID"), _T("Proc.Name"), _T("Wrkng.Set"),
  52. _T("PagedPool"), _T("NonPgdPl"), _T("Pagefile"), _T("Commit"),
  53. _T("Handles"), _T("Threads") );
  54. // grab all process information
  55. // log line format, all comma delimited,CR delimited:
  56. // pid,name,WorkingSetSize,QuotaPagedPoolUsage,QuotaNonPagedPoolUsage,
  57. // PagefileUsage,CommitCharge<CR> log all process information
  58. // from pmon
  59. Offset1 = 0;
  60. CurrentBuffer = (PUCHAR) VirtualAlloc( NULL,
  61. BUFFER_SIZE,
  62. MEM_COMMIT,
  63. PAGE_READWRITE );
  64. if( NULL == CurrentBuffer )
  65. {
  66. _tprintf( _T("VirtualAlloc Error!\r\n") );
  67. return;
  68. }
  69. // from pmon
  70. // get commit charge
  71. // get all of the status information
  72. Status = NtQuerySystemInformation( SystemProcessInformation,
  73. CurrentBuffer,
  74. BUFFER_SIZE,
  75. NULL );
  76. if( STATUS_SUCCESS == Status )
  77. {
  78. while( 1 )
  79. {
  80. // get process info from buffer
  81. ProcessInfo = (PSYSTEM_PROCESS_INFORMATION) &CurrentBuffer[Offset1];
  82. Offset1 += ProcessInfo->NextEntryOffset;
  83. // print in file
  84. _ftprintf( pLogFile,_T("%10i%20ws%10u%10u%10u%10u%10u%10u%10u\r\n"),
  85. ProcessInfo->UniqueProcessId,
  86. ProcessInfo->ImageName.Buffer,
  87. ProcessInfo->WorkingSetSize,
  88. ProcessInfo->QuotaPagedPoolUsage,
  89. ProcessInfo->QuotaNonPagedPoolUsage,
  90. ProcessInfo->PagefileUsage,
  91. ProcessInfo->PrivatePageCount,
  92. ProcessInfo->HandleCount,
  93. ProcessInfo->NumberOfThreads );
  94. if( 0 == ProcessInfo->NextEntryOffset )
  95. break;
  96. }
  97. }
  98. else
  99. {
  100. _ftprintf( pLogFile, _T("NtQuerySystemInformation call failed!\r\n") );
  101. }
  102. // Free the memory
  103. VirtualFree( CurrentBuffer, 0, MEM_RELEASE );
  104. } //memsnap