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.

148 lines
4.3 KiB

  1. /*++
  2. Copyright (c) 1994-1998 Microsoft Corporation
  3. Module Name:
  4. emptyq.c
  5. Abstract:
  6. This module implements a working set empty application.
  7. Author:
  8. Lou Perazzoli (loup) 20-May-1994
  9. Wesley Witt (wesw) 20-May-1994
  10. Environment:
  11. User Mode
  12. --*/
  13. #include "pch.h"
  14. #pragma hdrstop
  15. TASK_LIST tlist[MAX_TASKS];
  16. CHAR buffer[64*1024];
  17. int __cdecl
  18. main(
  19. int argc,
  20. char *argv[]
  21. )
  22. {
  23. DWORD i;
  24. DWORD numTasks;
  25. int rval = 0;
  26. TASK_LIST_ENUM te;
  27. char tname[PROCESS_SIZE];
  28. LPSTR p;
  29. ULONG first = FALSE;
  30. NTSTATUS status;
  31. PSYSTEM_MEMORY_INFORMATION MemInfo;
  32. PSYSTEM_MEMORY_INFO Info;
  33. PSYSTEM_MEMORY_INFO InfoEnd;
  34. PUCHAR String;
  35. ULONG TotalValid;
  36. ULONG TotalPageTable;
  37. SYSTEMTIME Time;
  38. //
  39. // let's be god
  40. //
  41. EnableDebugPriv();
  42. for (; ; ) {
  43. SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
  44. if (first) {
  45. status = NtQuerySystemInformation (SystemSummaryMemoryInformation,
  46. &buffer,
  47. 64*1024,
  48. NULL);
  49. if (!NT_SUCCESS (status)) {
  50. printf("query system information failed %lx\n",status);
  51. return 1;
  52. }
  53. GetLocalTime (&Time);
  54. TotalValid = 0;
  55. TotalPageTable = 0;
  56. MemInfo = (PSYSTEM_MEMORY_INFORMATION)buffer;
  57. Info = &MemInfo->Memory[0];
  58. InfoEnd = (PSYSTEM_MEMORY_INFO)MemInfo->StringStart;
  59. printf(" time: %ld %2ld:%2ld.%03ld\n",
  60. Time.wHour,
  61. Time.wMinute,
  62. Time.wSecond,
  63. Time.wMilliseconds);
  64. while (Info < InfoEnd) {
  65. if (Info->PageTableCount &&
  66. ((Info->PageTableCount + 2) >= Info->ValidCount)) {
  67. Info += 1;
  68. continue;
  69. }
  70. if (Info->StringOffset != 0) {
  71. if (*(PUCHAR)(Info->StringOffset + 1) != 0) {
  72. printf("%4ld. %4ld. %s\n",Info->ValidCount*4,
  73. Info->PageTableCount*4,
  74. Info->StringOffset);
  75. } else {
  76. printf("%4ld. %4ld. %ws\n",Info->ValidCount*4,
  77. Info->PageTableCount*4,
  78. (wchar_t *)Info->StringOffset);
  79. }
  80. } else {
  81. printf("%4ld. %4ld. unable to get name\n",Info->ValidCount*4,
  82. Info->PageTableCount*4);
  83. }
  84. TotalValid += Info->ValidCount;
  85. TotalPageTable += Info->PageTableCount;
  86. Info += 1;
  87. }
  88. printf("\n%4ld. %4ld. ** TOTAL **\n\n\n",
  89. TotalValid*4,
  90. TotalPageTable*4);
  91. }
  92. first = TRUE;
  93. //
  94. // get the task list for the system
  95. //
  96. numTasks = GetTaskList( tlist, MAX_TASKS );
  97. //
  98. // enumerate all windows and try to get the window
  99. // titles for each task
  100. //
  101. te.tlist = tlist;
  102. te.numtasks = numTasks;
  103. GetWindowTitles( &te );
  104. for (i=0; i<numTasks; i++) {
  105. if (!EmptyProcessWorkingSet( tlist[i].dwProcessId )) {
  106. //printf( "could not empty working set for process #%d [%s]\n", tlist[i].dwProcessId, tlist[i].ProcessName );
  107. rval = 1;
  108. }
  109. }
  110. if (!EmptySystemWorkingSet()) {
  111. //printf( "could not empty working set for process #%d [%s]\n",0,&System );
  112. }
  113. Sleep (1000);
  114. }
  115. return 0;
  116. }