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.

207 lines
6.1 KiB

  1. #define BUFFER_SIZE 64*1024
  2. #define MAX_BUFFER_SIZE 10*1024*1024
  3. ULONG CurrentBufferSize;
  4. PUCHAR PreviousBuffer;
  5. PUCHAR CurrentBuffer;
  6. PUCHAR TempBuffer;
  7. BOOLEAN Interactive;
  8. ULONG NumberOfInputRecords;
  9. INPUT_RECORD InputRecord;
  10. HANDLE InputHandle;
  11. HANDLE OriginalOutputHandle;
  12. HANDLE OutputHandle;
  13. DWORD OriginalInputMode;
  14. ULONG NumberOfCols;
  15. ULONG NumberOfRows;
  16. ULONG NumberOfDetailLines;
  17. ULONG FirstDetailLine;
  18. CONSOLE_SCREEN_BUFFER_INFO OriginalConsoleInfo;
  19. BOOL
  20. WriteConsoleLine(
  21. HANDLE OutputHandle,
  22. WORD LineNumber,
  23. LPSTR Text,
  24. BOOL Highlight
  25. )
  26. {
  27. COORD WriteCoord;
  28. DWORD NumberWritten;
  29. DWORD TextLength;
  30. WriteCoord.X = 0;
  31. WriteCoord.Y = LineNumber;
  32. if (!FillConsoleOutputCharacter( OutputHandle,
  33. ' ',
  34. NumberOfCols,
  35. WriteCoord,
  36. &NumberWritten
  37. )
  38. )
  39. {
  40. return FALSE;
  41. }
  42. if (Text == NULL || (TextLength = strlen( Text )) == 0)
  43. {
  44. return TRUE;
  45. }
  46. else
  47. {
  48. return WriteConsoleOutputCharacter( OutputHandle,
  49. Text,
  50. TextLength,
  51. WriteCoord,
  52. &NumberWritten
  53. );
  54. }
  55. }
  56. int
  57. __cdecl main( argc, argv )
  58. int argc;
  59. char *argv[];
  60. {
  61. NTSTATUS Status;
  62. int i;
  63. ULONG DelayTimeMsec;
  64. ULONG DelayTimeTicks;
  65. ULONG LastCount;
  66. COORD cp;
  67. BOOLEAN Active;
  68. PSYSTEM_THREAD_INFORMATION Thread;
  69. SYSTEM_PERFORMANCE_INFORMATION PerfInfo;
  70. SYSTEM_FILECACHE_INFORMATION FileCache;
  71. SYSTEM_FILECACHE_INFORMATION PrevFileCache;
  72. CHAR OutputBuffer[ 512 ];
  73. UCHAR LastKey;
  74. LONG ScrollDelta;
  75. WORD DisplayLine, LastDetailRow;
  76. BOOLEAN DoQuit = FALSE;
  77. ULONG SkipLine;
  78. ULONG Hint;
  79. ULONG Offset1;
  80. SIZE_T SumCommit;
  81. int num;
  82. int lastnum;
  83. INPUT_RECORD InputRecord;
  84. DWORD NumRead;
  85. ULONG Cpu;
  86. ULONG NoScreenChanges = FALSE;
  87. InputHandle = GetStdHandle( STD_INPUT_HANDLE );
  88. OriginalOutputHandle = GetStdHandle( STD_OUTPUT_HANDLE );
  89. Interactive = TRUE;
  90. if (Interactive)
  91. {
  92. if (InputHandle == NULL ||
  93. OriginalOutputHandle == NULL ||
  94. !GetConsoleMode( InputHandle, &OriginalInputMode )
  95. )
  96. {
  97. Interactive = FALSE;
  98. }
  99. else
  100. {
  101. OutputHandle = CreateConsoleScreenBuffer( GENERIC_READ | GENERIC_WRITE,
  102. FILE_SHARE_WRITE | FILE_SHARE_READ,
  103. NULL,
  104. CONSOLE_TEXTMODE_BUFFER,
  105. NULL
  106. );
  107. if (OutputHandle == NULL ||
  108. !GetConsoleScreenBufferInfo( OriginalOutputHandle, &OriginalConsoleInfo ) ||
  109. !SetConsoleScreenBufferSize( OutputHandle, OriginalConsoleInfo.dwSize ) ||
  110. !SetConsoleActiveScreenBuffer( OutputHandle ) ||
  111. !SetConsoleMode( InputHandle, 0 )
  112. )
  113. {
  114. if (OutputHandle != NULL)
  115. {
  116. CloseHandle( OutputHandle );
  117. OutputHandle = NULL;
  118. }
  119. Interactive = FALSE;
  120. }
  121. else
  122. {
  123. NumberOfCols = OriginalConsoleInfo.dwSize.X;
  124. NumberOfRows = OriginalConsoleInfo.dwSize.Y;
  125. NumberOfDetailLines = NumberOfRows - 7;
  126. }
  127. }
  128. }
  129. DelayTimeMsec = 5000;
  130. DelayTimeTicks = DelayTimeMsec * 10000;
  131. Active = TRUE;
  132. while (TRUE)
  133. {
  134. DisplayLine = 0;
  135. sprintf (OutputBuffer,
  136. " Memory:%8ldK Avail:%7ldK PageFlts:%6ld InRam Kernel:%5ldK P:%5ldK",
  137. BasicInfo.NumberOfPhysicalPages*(BasicInfo.PageSize/1024),
  138. PerfInfo.AvailablePages*(BasicInfo.PageSize/1024),
  139. PerfInfo.PageFaultCount - LastCount,
  140. (PerfInfo.ResidentSystemCodePage + PerfInfo.ResidentSystemDriverPage)*(BasicInfo.PageSize/1024),
  141. (PerfInfo.ResidentPagedPoolPage)*(BasicInfo.PageSize/1024)
  142. );
  143. LastCount = PerfInfo.PageFaultCount;
  144. WriteConsoleLine( OutputHandle,
  145. DisplayLine++,
  146. OutputBuffer,
  147. FALSE
  148. );
  149. while (WaitForSingleObject( InputHandle, DelayTimeMsec ) == STATUS_WAIT_0)
  150. {
  151. //
  152. // Check for input record
  153. //
  154. if (ReadConsoleInput( InputHandle, &InputRecord, 1, &NumberOfInputRecords ) &&
  155. InputRecord.EventType == KEY_EVENT &&
  156. InputRecord.Event.KeyEvent.bKeyDown
  157. )
  158. {
  159. LastKey = InputRecord.Event.KeyEvent.uChar.AsciiChar;
  160. if (LastKey < ' ')
  161. {
  162. ScrollDelta = 0;
  163. if (LastKey == 'C'-'A'+1)
  164. {
  165. DoQuit = TRUE;
  166. }
  167. else switch (InputRecord.Event.KeyEvent.wVirtualKeyCode)
  168. {
  169. case VK_ESCAPE:
  170. DoQuit = TRUE;
  171. break;
  172. }
  173. }
  174. break;
  175. }
  176. }
  177. if (DoQuit)
  178. {
  179. if (Interactive)
  180. {
  181. SetConsoleActiveScreenBuffer( OriginalOutputHandle );
  182. SetConsoleMode( InputHandle, OriginalInputMode );
  183. CloseHandle( OutputHandle );
  184. }
  185. return 0;
  186. }
  187. }
  188. return 0;
  189. }