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.

1968 lines
79 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. mminfo.c
  5. Abstract:
  6. This module monitor the system hard page fault.
  7. Author:
  8. Stephen Hsiao (shsiao) 4-8-96
  9. Environment:
  10. User Mode
  11. --*/
  12. #include <nt.h>
  13. #include <ntrtl.h>
  14. #include <nturtl.h>
  15. #include <windows.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <assert.h>
  20. #define NTMMPERF 1
  21. #if NTMMPERF
  22. typedef enum _KTHREAD_STATE {
  23. Initialized,
  24. Ready,
  25. Running,
  26. Standby,
  27. Terminated,
  28. Waiting,
  29. Transition
  30. } KTHREAD_STATE;
  31. char *ThreadState[] = {
  32. "Initialized",
  33. "Ready",
  34. "Running",
  35. "Standby",
  36. "Terminated",
  37. "Waiting",
  38. "Transition",
  39. };
  40. char *WaitReason[] = {
  41. "Executive",
  42. "FreePage",
  43. "PageIn",
  44. "PoolAllocation",
  45. "DelayExecution",
  46. "Suspended",
  47. "UserRequest",
  48. "WrExecutive",
  49. "WrFreePage",
  50. "WrPageIn",
  51. "WrPoolAllocation",
  52. "WrDelayExecution",
  53. "WrSuspended",
  54. "WrUserRequest",
  55. "WrEventPair",
  56. "WrQueue",
  57. "WrLpcReceive",
  58. "WrLpcReply",
  59. "WrVirtualMemory",
  60. "WrPageOut",
  61. "WrRendezvous",
  62. "Spare2",
  63. "Spare3",
  64. "Spare4",
  65. "Spare5",
  66. "Spare6",
  67. "WrKernel",
  68. "MaximumWaitReason"
  69. };
  70. PSZ PoolTypeNames[7] = {
  71. "NonPagedPool",
  72. "PagedPool ",
  73. "NonPagedMS ",
  74. "NotUsed ",
  75. "NonPagedCaAl",
  76. "PagedCaAl ",
  77. "NonPCaAlMS "
  78. };
  79. #define CM_KEY_NODE_SIGNATURE 0x6b6e // "kn"
  80. #define CM_LINK_NODE_SIGNATURE 0x6b6c // "kl"
  81. #define CM_KEY_VALUE_SIGNATURE 0x6b76 // "kv"
  82. #define CM_KEY_SECURITY_SIGNATURE 0x6b73 // "ks"
  83. #define CM_KEY_FAST_LEAF 0x666c // "fl"
  84. #define MAX_TASKS 256
  85. #define TableSize 4096
  86. #define PAGE_SIZE 4096
  87. CHAR Mark[MAX_MMINFO_MARK_SIZE];
  88. DWORD pid;
  89. CHAR pname[MAX_PATH];
  90. CHAR *MmInfoBuffer;
  91. SYSTEM_MMINFO_FILENAME_INFORMATION ImageHash[TableSize];
  92. SYSTEM_MMINFO_PROCESS_INFORMATION ProcessHash[TableSize];
  93. LONG ThreadHash[TableSize] = {-1};
  94. LONG BufferLength;
  95. BOOLEAN Debug=FALSE;
  96. ULONG MmInfoOnFlag=0;
  97. ULONG DefaultOnFlag=(MMINFO_LOG_MEMORY |
  98. MMINFO_LOG_WORKINGSET |
  99. MMINFO_LOG_HARDFAULT |
  100. MMINFO_LOG_PROCESS |
  101. MMINFO_LOG_THREAD);
  102. ULONG DefaultDetailedOnFlag=(MMINFO_LOG_MEMORY |
  103. MMINFO_LOG_WORKINGSET |
  104. MMINFO_LOG_HARDFAULT |
  105. MMINFO_LOG_SOFTFAULT |
  106. MMINFO_LOG_PROCESS |
  107. MMINFO_LOG_THREAD |
  108. MMINFO_LOG_CSWITCH |
  109. MMINFO_LOG_POOL |
  110. MMINFO_LOG_CHANGELIST);
  111. #ifdef WS_INSTRUMENTATION
  112. char * WsInfoHeaderFormat =
  113. " WsInfo, Process, WorkSet, Claim, Access, Age0, Age1, Age2, Age3, Shared, Mod, Faults, RecentF, Repl, URepl, Boosts, Prio\n";
  114. char * WsInfoDataFormat =
  115. " WsInfo, %24s, %8d, %8d, %8d, %8d, %8d, %8d, %8d, %8d, %8d, %8d, %8d, %8d, %8d, %8d, %8d\n";
  116. char * TrimHeaderFormat =
  117. " Trim, Process, WorkSet, Claim, Try, Got, Faults, RecentF, Repl, URepl, Boosts, Prio\n";
  118. char * TrimDataFormat =
  119. " Trim, %24s, %8d, %8d, %8d, %8d, %8d, %8d, %8d, %8d, %8d, %8d\n";
  120. char * WsManagerHeaderFormat =
  121. " WsManager, Time, Avail, Claim, Faults, LastPF, Counter, DesReduc, DesFree, Action\n";
  122. char * WsManagerDataFormat =
  123. " WsManager, %10I64d, %8d, %8d, %8d, %8d, %8d, %8d, %8d, %s\n";
  124. #else
  125. char * WsInfoHeaderFormat =
  126. " WsInfo, Process, WorkSet, Faults, Prio\n";
  127. char * WsInfoDataFormat =
  128. " WsInfo, %24s, %8d, %8d, %8d\n";
  129. char * TrimHeaderFormat =
  130. " Trim, Process, WorkSet, Faults, Prio\n";
  131. char * TrimDataFormat =
  132. " Trim, %24s, %8d, %8d, %8d\n";
  133. char * WsManagerHeaderFormat =
  134. " WsManager, Time, Avail, Faults, LastPF, Counter, DesReduc, DesFree, Action\n";
  135. char * WsManagerDataFormat =
  136. " WsManager, %10I64d, %8d, %8d, %8d, %8d, %8d, %8d, %s\n";
  137. #endif // WS_INSTRUMENTATION
  138. char * ImageLoadHeaderFormat =
  139. " ImageLoad, BaseAddr, EndAddr, SectNum, Process, Name\n";
  140. char * ImageLoadDataFormat =
  141. " ImageLoad, %08x, %08x, %-8x, %s, %S\n";
  142. char * SampleProfileHeaderFormat =
  143. " SampledProfile, EIP, Count\n";
  144. char * SampledProfileDataFormat =
  145. " SampledProfile, %08x, %-8d\n";
  146. char * GeneralHeaderFormat = "%12s,%10s,%22s,%12s,%12s,%8s,%30s,%12s,%10s,%10s,%10s\n";
  147. ULONG ToTurnOn=0;
  148. ULONG ToTurnOff=0;
  149. CHAR System[] = "System";
  150. #define MODE_NONE 0
  151. #define MODE_SLASH 1
  152. #define MODE_PLUS 2
  153. #define MODE_MINUS 3
  154. typedef struct Api_Address_St {
  155. ULONG Address;
  156. CHAR *ApiName;
  157. } Api_Address_t, *PApi_Address_t;
  158. typedef struct Dll_Address_St {
  159. ULONG StartingAddress;
  160. ULONG EndingAddress;
  161. CHAR *DllName;
  162. } Dll_Address_t, *PDll_Address_t;
  163. PApi_Address_t GlobalApiInfo;
  164. PDll_Address_t GlobalDllInfo;
  165. int NumGlobalApis=0;
  166. int NumGlobalDlls=0;
  167. int NumAllocatedGlobalApis=0;
  168. int NumAllocatedGlobalDlls=0;
  169. #define AllocationIncrement 1000
  170. VOID InsertDll(ULONG StartingAddress, ULONG EndingAddress, CHAR *DllName){
  171. if (NumGlobalDlls == NumAllocatedGlobalDlls ){
  172. if (NumGlobalDlls == 0 ){
  173. NumAllocatedGlobalDlls = AllocationIncrement;
  174. GlobalDllInfo = (PDll_Address_t)
  175. malloc( sizeof(Dll_Address_t) * NumAllocatedGlobalDlls);
  176. } else {
  177. NumAllocatedGlobalDlls += AllocationIncrement;
  178. GlobalDllInfo = (PDll_Address_t)
  179. realloc( GlobalDllInfo, sizeof(Dll_Address_t) * NumAllocatedGlobalDlls);
  180. }
  181. }
  182. if (GlobalDllInfo == NULL ){
  183. return;
  184. }
  185. GlobalDllInfo[ NumGlobalDlls ].StartingAddress = StartingAddress;
  186. GlobalDllInfo[ NumGlobalDlls ].EndingAddress = EndingAddress;
  187. GlobalDllInfo[ NumGlobalDlls ].DllName = DllName;
  188. NumGlobalDlls ++;
  189. }
  190. VOID InsertApi(ULONG Address, CHAR *ApiName){
  191. if (NumGlobalApis == NumAllocatedGlobalApis ){
  192. if (NumGlobalApis == 0 ){
  193. NumAllocatedGlobalApis = AllocationIncrement;
  194. GlobalApiInfo = (PApi_Address_t)
  195. malloc( sizeof(Api_Address_t) * NumAllocatedGlobalApis);
  196. } else {
  197. NumAllocatedGlobalApis += AllocationIncrement;
  198. GlobalApiInfo = (PApi_Address_t)
  199. realloc( GlobalApiInfo, sizeof(Api_Address_t) * NumAllocatedGlobalApis);
  200. }
  201. }
  202. if (GlobalApiInfo == NULL ){
  203. return;
  204. }
  205. GlobalApiInfo[ NumGlobalApis ].Address = Address;
  206. GlobalApiInfo[ NumGlobalApis ].ApiName = ApiName;
  207. NumGlobalApis ++;
  208. }
  209. CHAR *DllContainingAddress(ULONG Address){
  210. int i;
  211. for(i=0; i < NumGlobalDlls; i++){
  212. if ( GlobalDllInfo[ i ].StartingAddress <= Address &&
  213. Address <= GlobalDllInfo[ i ].EndingAddress){
  214. return GlobalDllInfo[ i ].DllName;
  215. }
  216. }
  217. return "DllNotFound";
  218. }
  219. CHAR *ApiAtAddress(ULONG Address){
  220. int i;
  221. for(i=0; i < NumGlobalApis; i++){
  222. if ( GlobalApiInfo[ i ].Address == Address ){
  223. return GlobalApiInfo[ i ].ApiName;
  224. }
  225. }
  226. return "ApiNotFound";
  227. }
  228. VOID
  229. ParseArgs (
  230. int argc,
  231. char *argv[]
  232. )
  233. {
  234. ULONG Mode=MODE_NONE;
  235. char *p;
  236. char *Usage="\
  237. Usage: mminfo -Option \n\
  238. /c Turn OFF hard fault clustering\n\
  239. /i Initialize MmInfo (Allocate buffer)\n\
  240. /u Uninitialize MmInfo (Free buffer) \n\
  241. /d Turn on debugging\n\
  242. /f Turn off monitoring (Keep log for later processing) \n\
  243. /F Set a Mark with workingsetflush now \n\
  244. /M Set a Mark now \n\
  245. /o Turn on default monitoring (h,m,t, and w)\n\
  246. /O Turn on detailed monitoring (plus a, l, p, and S)\n\
  247. +/- a Turn on/off context switch monitor\n\
  248. +/- e Turn on/off EmptyQ on every Mark\n\
  249. +/- E Turn on/off EmptyQDetail (Per Process footprint) on every Mark\n\
  250. +/- h Turn on/off hard fault monitor\n\
  251. +/- l Turn on/off memory list monitor\n\
  252. +/- m Turn on/off memory monitor\n\
  253. +/- p Turn on/off pool monitor\n\
  254. +/- P Turn on/off sampled profiling\n\
  255. +/- r Turn on/off registry monitor\n\
  256. +/- R Turn on/off registry Relocation\n\
  257. +/- s Turn on/off initial snap shot of memory\n\
  258. +/- S Turn on/off Soft (Demand zero and Trainsition) fault monitor\n\
  259. +/- t Turn on/off thread & process monitor\n\
  260. +/- T Turn on/off detailed trimming monitor\n\
  261. +/- w Turn on/off working set monitor\n\
  262. +/- z Turn on/off detailed working set info\n\
  263. +/- Z Turn on/off dumping working set entries\n\
  264. Default Dump bata (Also turn off monitoring)\n\
  265. ";
  266. NTSTATUS status;
  267. int i;
  268. argc--;
  269. *argv++;
  270. while ( argc-- > 0 ) {
  271. p = *argv++;
  272. switch (*p) {
  273. case '/':
  274. Mode = MODE_SLASH;
  275. break;
  276. case '+':
  277. Mode = MODE_PLUS;
  278. break;
  279. case '-':
  280. Mode = MODE_MINUS;
  281. break;
  282. default:
  283. fprintf(stderr,"%s\n", Usage);
  284. ExitProcess(1);
  285. }
  286. p++;
  287. while(*p != '\0') {
  288. if (Mode == MODE_SLASH) {
  289. switch (*p) {
  290. case 'c':
  291. ToTurnOn = ToTurnOn | MMINFO_LOG_NO_CLUSTERING;
  292. break;
  293. case 'd':
  294. Debug=TRUE;
  295. break;
  296. case 'f':
  297. status = NtSetSystemInformation (
  298. SystemMmInfoLogOffInformation,
  299. NULL,
  300. 0);
  301. if (!NT_SUCCESS (status)) {
  302. fprintf(stderr,"Set system information failed %lx\n",status);
  303. }else{
  304. fprintf(stderr,"Monitor Off\n");
  305. }
  306. ExitProcess(0);
  307. case 'i':
  308. status = NtSetSystemInformation (
  309. SystemMmInfoInitializeInformation,
  310. NULL,
  311. 0);
  312. if (!NT_SUCCESS (status)) {
  313. fprintf(stderr, "Set system information failed %lx\n",status);
  314. }else{
  315. fprintf(stderr,"buffer allocated\n");
  316. }
  317. ExitProcess(0);
  318. case 'F':
  319. case 'M':
  320. {
  321. BOOLEAN Flush = (*p == 'F') ? TRUE : FALSE;
  322. p++;
  323. while(*p == '\0') {
  324. p++;
  325. }
  326. i=-1;
  327. if (*p == '/' || *p == '+' || *p == '-') {
  328. // Nothing in the Mark
  329. fprintf(stderr, "Mark not set!\n");
  330. fprintf(stderr,"%s\n", Usage);
  331. ExitProcess(0);
  332. } else if (*p == '"') {
  333. p++;
  334. while(*p != '"') {
  335. if (i < MAX_MMINFO_MARK_SIZE) {
  336. i++;
  337. Mark[i] = *p;
  338. }
  339. p++;
  340. }
  341. } else {
  342. while (*p != '\0') {
  343. if (i < MAX_MMINFO_MARK_SIZE) {
  344. i++;
  345. Mark[i] = *p;
  346. }
  347. p++;
  348. }
  349. }
  350. status = NtSetSystemInformation (
  351. Flush ? SystemMmInfoMarkWithFlush
  352. : SystemMmInfoMark,
  353. Mark,
  354. MAX_MMINFO_MARK_SIZE);
  355. if (!NT_SUCCESS (status)) {
  356. fprintf(stderr, "Set system information failed %lx\n",status);
  357. }else{
  358. fprintf(stderr, "Mark set: %s\n", Mark);
  359. }
  360. ExitProcess(0);
  361. }
  362. case 'o':
  363. MmInfoOnFlag = DefaultOnFlag;
  364. break;
  365. case 'O':
  366. MmInfoOnFlag = DefaultDetailedOnFlag;
  367. break;
  368. case 'u':
  369. status = NtSetSystemInformation (
  370. SystemMmInfoUnInitializeInformation,
  371. NULL,
  372. 0);
  373. if (!NT_SUCCESS (status)) {
  374. fprintf(stderr,"Set system information failed %lx\n",status);
  375. }else{
  376. fprintf(stderr,"Unitialized\n");
  377. }
  378. ExitProcess(0);
  379. default:
  380. fprintf(stderr,"%s\n", Usage);
  381. ExitProcess(1);
  382. }
  383. } else if (Mode == MODE_PLUS) {
  384. switch (*p) {
  385. case 'a':
  386. ToTurnOn = ToTurnOn | MMINFO_LOG_PROCESS |
  387. MMINFO_LOG_THREAD | MMINFO_LOG_CSWITCH;
  388. break;
  389. case 'e':
  390. ToTurnOn = ToTurnOn | MMINFO_LOG_MEMORY | MMINFO_LOG_EMPTYQ | MMINFO_LOG_PROCESS;
  391. break;
  392. case 'E':
  393. ToTurnOn = ToTurnOn | MMINFO_LOG_MEMORY | MMINFO_LOG_EMPTYQ
  394. | MMINFO_LOG_EMPTYQDETAIL | MMINFO_LOG_PROCESS;
  395. break;
  396. case 'm':
  397. ToTurnOn = ToTurnOn | MMINFO_LOG_MEMORY | MMINFO_LOG_PROCESS;
  398. break;
  399. case 'p':
  400. ToTurnOn = ToTurnOn | MMINFO_LOG_POOL;
  401. break;
  402. case 'w':
  403. ToTurnOn = ToTurnOn | MMINFO_LOG_WORKINGSET | MMINFO_LOG_PROCESS;
  404. break;
  405. case 't':
  406. ToTurnOn = ToTurnOn | MMINFO_LOG_PROCESS | MMINFO_LOG_THREAD;
  407. break;
  408. case 'T':
  409. ToTurnOn = ToTurnOn | MMINFO_LOG_WSCHANGE |
  410. MMINFO_LOG_MEMORY | MMINFO_LOG_PROCESS;
  411. break;
  412. case 'h':
  413. ToTurnOn = ToTurnOn | MMINFO_LOG_HARDFAULT | MMINFO_LOG_PROCESS;
  414. break;
  415. case 'l':
  416. ToTurnOn = ToTurnOn | MMINFO_LOG_CHANGELIST | MMINFO_LOG_MEMORY;
  417. break;
  418. case 'r':
  419. ToTurnOn = ToTurnOn | MMINFO_LOG_REGISTRY;
  420. break;
  421. case 'R':
  422. status = NtSetSystemInformation (
  423. SystemRelocateCMCellOn,
  424. NULL,
  425. 0);
  426. if (!NT_SUCCESS (status)) {
  427. fprintf(stderr,"Set system information failed %lx\n",status);
  428. }else{
  429. fprintf(stderr,"Registry Relocation on\n");
  430. }
  431. ExitProcess(0);
  432. case 's':
  433. ToTurnOn = ToTurnOn | MMINFO_LOG_INIT_MEMSNAP;
  434. break;
  435. case 'S':
  436. ToTurnOn = ToTurnOn | MMINFO_LOG_SOFTFAULT |
  437. MMINFO_LOG_PROCESS | MMINFO_LOG_MEMORY;
  438. break;
  439. case 'z':
  440. ToTurnOn = ToTurnOn | MMINFO_LOG_WSDETAILS;
  441. break;
  442. case 'Z':
  443. ToTurnOn = ToTurnOn | MMINFO_LOG_WSENTRIES;
  444. break;
  445. case 'P':
  446. ToTurnOn = ToTurnOn | MMINFO_LOG_PROFILE;
  447. break;
  448. default:
  449. fprintf(stderr,"%s\n", Usage);
  450. ExitProcess(1);
  451. }
  452. } else if (Mode == MODE_MINUS) {
  453. switch (*p) {
  454. case 'a':
  455. ToTurnOff = ToTurnOff | MMINFO_LOG_CSWITCH ;
  456. break;
  457. case 'e':
  458. ToTurnOff = ToTurnOff | MMINFO_LOG_EMPTYQ;
  459. break;
  460. case 'E':
  461. ToTurnOff = ToTurnOff | MMINFO_LOG_EMPTYQDETAIL;
  462. break;
  463. case 'm':
  464. ToTurnOff = ToTurnOff | MMINFO_LOG_MEMORY ;
  465. break;
  466. case 'p':
  467. ToTurnOff = ToTurnOff | MMINFO_LOG_POOL;
  468. break;
  469. case 'w':
  470. ToTurnOff = ToTurnOff | MMINFO_LOG_WORKINGSET;
  471. break;
  472. case 't':
  473. ToTurnOff = ToTurnOff | MMINFO_LOG_PROCESS |
  474. MMINFO_LOG_THREAD | MMINFO_LOG_CSWITCH;
  475. break;
  476. case 'T':
  477. ToTurnOff = ToTurnOff | MMINFO_LOG_WSCHANGE;
  478. break;
  479. case 'h':
  480. ToTurnOff = ToTurnOff | MMINFO_LOG_HARDFAULT;
  481. break;
  482. case 'l':
  483. ToTurnOff = ToTurnOff | MMINFO_LOG_CHANGELIST;
  484. break;
  485. case 'r':
  486. ToTurnOff = ToTurnOff | MMINFO_LOG_REGISTRY;
  487. break;
  488. case 'R':
  489. status = NtSetSystemInformation (
  490. SystemRelocateCMCellOff,
  491. NULL,
  492. 0);
  493. if (!NT_SUCCESS (status)) {
  494. fprintf(stderr,"Set system information failed %lx\n",status);
  495. }else{
  496. fprintf(stderr,"Registry Relocation off\n");
  497. }
  498. ExitProcess(0);
  499. case 's':
  500. ToTurnOff = ToTurnOff | MMINFO_LOG_INIT_MEMSNAP;
  501. break;
  502. case 'S':
  503. ToTurnOff = ToTurnOff | MMINFO_LOG_SOFTFAULT;
  504. break;
  505. case 'z':
  506. ToTurnOff = ToTurnOff | MMINFO_LOG_WSDETAILS;
  507. break;
  508. case 'Z':
  509. ToTurnOff = ToTurnOff | MMINFO_LOG_WSENTRIES;
  510. break;
  511. case 'P':
  512. ToTurnOff = ToTurnOff | MMINFO_LOG_PROFILE;
  513. break;
  514. default:
  515. fprintf(stderr,"%s\n", Usage);
  516. ExitProcess(1);
  517. }
  518. }
  519. p++;
  520. }
  521. }
  522. }
  523. #endif //NTMMPERF
  524. int _cdecl
  525. main(
  526. int argc,
  527. char *argv[]
  528. )
  529. {
  530. #if NTMMPERF
  531. LPSTR p;
  532. NTSTATUS status;
  533. ULONG ImageStart, ImageEnd;
  534. ULONG ProcessStart, ProcessEnd;
  535. SYSTEM_BASIC_INFORMATION BasicInfo;
  536. ULONG TotalPageTable;
  537. ULONG TotalModified;
  538. ULONG TotalTransition;
  539. SYSTEMTIME Time;
  540. ULONG PageKb;
  541. ULONG LogSize;
  542. ULONG LogType;
  543. _int64 *TmpPint64;
  544. _int64 PerfCounter, PerfCounterStart;
  545. _int64 PerfFrequency;
  546. PerfHook_t *Hook, *NextHook;
  547. TimeStamp_t TS;
  548. PerfSize_t Size;
  549. PerfTag_t Tag;
  550. PerfData_t *Info;
  551. ULONG i;
  552. //
  553. // First parse the arguments and see what to do.
  554. //
  555. ParseArgs( argc, argv );
  556. if (ToTurnOn & ToTurnOff) {
  557. fprintf(stderr,"Cannot turn on and off the same flag, make up your mind !!!\n");
  558. }else{
  559. MmInfoOnFlag=((MmInfoOnFlag | ToTurnOn) & ~ToTurnOff);
  560. }
  561. //
  562. // If there is a flag to turn on. Do it.
  563. //
  564. if (MmInfoOnFlag) {
  565. status = NtSetSystemInformation (
  566. SystemMmInfoLogOnInformation,
  567. &MmInfoOnFlag,
  568. sizeof(ULONG));
  569. if (!NT_SUCCESS (status)) {
  570. fprintf(stderr,"Set system information failed ON %lx\n",status);
  571. return 1;
  572. }else{
  573. fprintf(stderr,"Monitor On\n");
  574. return 0;
  575. }
  576. }
  577. //
  578. // If we reach this point, we are do dump the log.
  579. // First turn off monitor.
  580. //
  581. status = NtSetSystemInformation (SystemMmInfoLogOffInformation,
  582. NULL,
  583. 0);
  584. if (!NT_SUCCESS (status)) {
  585. fprintf(stderr,"Set system information failed %lx\n",status);
  586. return 1;
  587. }
  588. //
  589. // HACK FIXFIX when doing MP stuff
  590. //
  591. ThreadHash[0] = 0;
  592. ProcessHash[0].ProcessID = 0;
  593. RtlCopyMemory(ProcessHash[0].ImageFileName, "Idle", 16);
  594. status = NtQuerySystemInformation(
  595. SystemBasicInformation,
  596. &BasicInfo,
  597. sizeof(BasicInfo),
  598. NULL
  599. );
  600. if (!NT_SUCCESS (status)) {
  601. fprintf(stderr,"query system basic information failed %lx\n",status);
  602. return 1;
  603. }
  604. PageKb = BasicInfo.PageSize / 1024;
  605. //
  606. // print the Headers
  607. //
  608. printf(WsManagerHeaderFormat);
  609. printf(WsInfoHeaderFormat);
  610. printf(TrimHeaderFormat );
  611. printf(ImageLoadHeaderFormat);
  612. printf(SampleProfileHeaderFormat);
  613. //
  614. // Mow dump the buffer.
  615. //
  616. NextHook = PerfNextHook();
  617. Hook = PerfFirstHook();
  618. LogSize = (ULONG) NextHook - (ULONG) Hook;
  619. // fprintf(stderr, "Size in Pages %8d\n", PerfQueryBufferSize4KPages());
  620. // fprintf(stderr, "Size in Bytes %8d\n", PerfQueryBufferSizeBytes());
  621. // fprintf(stderr, "Size in KBs %8d\n", PerfQueryBufferSizeKB());
  622. // fprintf(stderr, "Size in Bytes %8d (%8x - %8x) \n", NextHook - Hook, Hook, NextHook);
  623. while( Hook < NextHook ){
  624. ULONG LogType;
  625. Hook = (PerfHook_t *)PerfGetHook(Hook, &Tag, &TS, &Size, &Info );
  626. LogType = Tag.u.Bits.HookId;
  627. // LogType = Tag.u.Value;
  628. // PerfCounter = 0xffffffffffffffff;
  629. PerfCounter = TS;
  630. if (Debug) {
  631. // fprintf(stdout, "%8x: LogType %4d, Size:%4d, Time: %I64u\n",Hook, LogType, Size, PerfCounter);
  632. }
  633. switch(LogType) {
  634. printf ("LogType=%08x\n", LogType);
  635. case PERF_APIMON_DLL_ADDRESS:
  636. {
  637. PPerf_Apimon_Dll_Address_t DllInfo;
  638. DllInfo = (PPerf_Apimon_Dll_Address_t) Info;
  639. InsertDll(DllInfo->StartingAddress,
  640. DllInfo->EndingAddress,
  641. DllInfo->DllName);
  642. printf ("DllAddressName %08x %08x %s\n",
  643. DllInfo->StartingAddress,
  644. DllInfo->EndingAddress,
  645. DllInfo->DllName);
  646. }
  647. break;
  648. case PERF_APIMON_API_ADDRESS:
  649. {
  650. PPerf_Apimon_Api_Address_t ApiInfo;
  651. ApiInfo = (PPerf_Apimon_Api_Address_t) Info;
  652. InsertApi(ApiInfo->Address,
  653. ApiInfo->ApiName);
  654. printf ("ApiAddressName %08x %s\n",
  655. ApiInfo->Address,
  656. ApiInfo->ApiName);
  657. }
  658. break;
  659. case PERF_APIMON_ENTER:
  660. {
  661. PPerf_Apimon_Enter_t PEnter;
  662. PEnter = (PPerf_Apimon_Api_Address_t) Info;
  663. printf ("ApiEnter %08x %s %s\n",
  664. PEnter->Address,
  665. DllContainingAddress(PEnter->Address),
  666. ApiAtAddress(PEnter->Address));
  667. }
  668. break;
  669. case PERF_APIMON_EXIT:
  670. {
  671. PPerf_Apimon_Enter_t PExit;
  672. PExit = (PPerf_Apimon_Api_Address_t) Info;
  673. printf ("ApiExit %08x %s %s\n",
  674. PExit->Address,
  675. DllContainingAddress(PExit->Address),
  676. ApiAtAddress(PExit->Address));
  677. }
  678. break;
  679. case MMINFO_LOG_TYPE_VERSION:
  680. {
  681. PSYSTEM_MMINFO_VERSION_INFORMATION TmpPMmInfoVersion;
  682. TmpPMmInfoVersion = (PSYSTEM_MMINFO_VERSION_INFORMATION) Info;
  683. if (TmpPMmInfoVersion->Version != MMINFO_VERSION) {
  684. fprintf(stderr, "Kernel Version:%4d mismatch with User Version:%d\n",
  685. TmpPMmInfoVersion->Version,
  686. MMINFO_VERSION
  687. );
  688. ExitProcess(1);
  689. } else {
  690. fprintf(stderr, "Version: %4d, BufferSize = %6d KB\n",
  691. MMINFO_VERSION,
  692. LogSize/1024);
  693. fprintf(stdout, "Version, %4d, BufferSize, %6d KB\n",
  694. MMINFO_VERSION,
  695. LogSize/1024);
  696. }
  697. }
  698. break;
  699. case MMINFO_LOG_TYPE_PERFFREQUENCY:
  700. {
  701. PMMINFO_TIME_FREQUENCY TimeFreq;
  702. TimeFreq = (PMMINFO_TIME_FREQUENCY) Info;
  703. PerfFrequency = TimeFreq->Frequency;
  704. PerfCounterStart = TimeFreq->Time;
  705. printf("Log start at (Performance Counter), %I64d\n",
  706. PerfCounterStart*1000000/PerfFrequency);
  707. }
  708. break;
  709. case MMINFO_LOG_TYPE_FILENAMEBUFFER:
  710. {
  711. PSYSTEM_MMINFO_FILENAME_INFORMATION TmpPImage;
  712. TmpPImage = (PSYSTEM_MMINFO_FILENAME_INFORMATION) Info;
  713. while (TmpPImage->ImageKey) {
  714. i=TmpPImage->ImageKey%TableSize;
  715. while(ImageHash[i].ImageKey != 0) {
  716. if (ImageHash[i].ImageKey == TmpPImage->ImageKey) {
  717. break;
  718. }else{
  719. i = (i+1)%TableSize;
  720. }
  721. }
  722. ImageHash[i].ImageKey =TmpPImage->ImageKey;
  723. ImageHash[i].ImageName.Length =TmpPImage->ImageName.Length;
  724. ImageHash[i].ImageName.Buffer =TmpPImage->ImageBuffer;
  725. if (Debug) {
  726. printf("%12s,", "S-Created");
  727. }
  728. if (Debug) {
  729. printf("%10s,%22s,%12s,%12x,%8s,%30S,%12s,%10s,%10s\n",
  730. "",
  731. "",
  732. "",
  733. ImageHash[i].ImageKey,
  734. "",
  735. ImageHash[i].ImageName.Buffer,
  736. "",
  737. "",
  738. "");
  739. }
  740. TmpPImage++;
  741. }
  742. }
  743. break;
  744. case MMINFO_LOG_TYPE_PAGEFAULT:
  745. {
  746. PSYSTEM_HARDPAGEFAULT_INFORMATION TmpPMmInfoLog;
  747. TmpPMmInfoLog=(PSYSTEM_HARDPAGEFAULT_INFORMATION) Info;
  748. printf("%12s,","HardFault");
  749. printf("%10I64d,",
  750. (PerfCounter - PerfCounterStart)*1000000/PerfFrequency);
  751. if (TmpPMmInfoLog->ProcessID == 0) {
  752. printf("%22s,","System ( 0)");
  753. } else{
  754. ULONG i;
  755. i = TmpPMmInfoLog->ProcessID;
  756. if (ProcessHash[i].ProcessID == TmpPMmInfoLog->ProcessID) {
  757. printf("%16s ",ProcessHash[i].ImageFileName);
  758. printf("(%3d),",ProcessHash[i].ProcessID);
  759. }else{
  760. printf("Process %13u,",TmpPMmInfoLog->ProcessID);
  761. }
  762. }
  763. printf("%12u,",TmpPMmInfoLog->ThreadID);
  764. printf("%12x,",TmpPMmInfoLog->Va);
  765. printf("%8u,",TmpPMmInfoLog->Pfn);
  766. {
  767. ULONG i;
  768. i=TmpPMmInfoLog->ImageKey%TableSize;
  769. while(ImageHash[i].ImageKey != 0) {
  770. if (ImageHash[i].ImageKey == TmpPMmInfoLog->ImageKey) {
  771. printf("%30S,",ImageHash[i].ImageName.Buffer);
  772. break;
  773. }else{
  774. i = (i+1)%TableSize;
  775. }
  776. }
  777. if (ImageHash[i].ImageKey == 0) {
  778. if (TmpPMmInfoLog->Va >= 0x8000000) {
  779. printf("%30s,","pagefile.sys");
  780. } else {
  781. printf("%19s (%8x),","Image", TmpPMmInfoLog->ImageKey);
  782. }
  783. }
  784. }
  785. printf("%12I64d,",TmpPMmInfoLog->ReadOffset);
  786. printf("%10u,",TmpPMmInfoLog->ByteCount);
  787. if (TmpPMmInfoLog->FaultType == 3) {
  788. printf("%10s,","Read");
  789. } else if (TmpPMmInfoLog->FaultType == 2) {
  790. printf("%10s,","Code");
  791. } else if (TmpPMmInfoLog->FaultType == 1) {
  792. printf("%10s,","Data");
  793. } else {
  794. printf("%10s,","NA");
  795. }
  796. printf("%10I64d",
  797. (TmpPMmInfoLog->IoCompleteTime-PerfCounter)
  798. *1000000/PerfFrequency);
  799. printf("\n");
  800. // printf("Got Page Fault Log\n");
  801. break;
  802. }
  803. case MMINFO_LOG_TYPE_TRANSITIONFAULT:
  804. case MMINFO_LOG_TYPE_DEMANDZEROFAULT:
  805. case MMINFO_LOG_TYPE_ADDVALIDPAGETOWS:
  806. case MMINFO_LOG_TYPE_PROTOPTEFAULT:
  807. case MMINFO_LOG_TYPE_ADDTOWS:
  808. {
  809. PSYSTEM_MMINFO_SOFTFAULT_INFORMATION TmpPMmInfoLog;
  810. TmpPMmInfoLog=(PSYSTEM_MMINFO_SOFTFAULT_INFORMATION) Info;
  811. if (LogType == MMINFO_LOG_TYPE_TRANSITIONFAULT) {
  812. printf("%12s,","TransFault");
  813. } else if (LogType == MMINFO_LOG_TYPE_DEMANDZEROFAULT) {
  814. printf("%12s,","DeZeroFault");
  815. } else if (LogType == MMINFO_LOG_TYPE_ADDVALIDPAGETOWS) {
  816. printf("%12s,","AddValidToWS");
  817. } else if (LogType == MMINFO_LOG_TYPE_PROTOPTEFAULT) {
  818. printf("%12s,","ProtoFault");
  819. } else if (LogType == MMINFO_LOG_TYPE_ADDTOWS) {
  820. printf("%12s,","AddToWS");
  821. } else {
  822. printf("%12s,","Unknown");
  823. }
  824. printf("%10s,", "");
  825. if (TmpPMmInfoLog->ProcessID == -1) {
  826. printf("%22s,","SystemCache");
  827. } else{
  828. ULONG i;
  829. i = TmpPMmInfoLog->ProcessID;
  830. if (ProcessHash[i].ProcessID == TmpPMmInfoLog->ProcessID) {
  831. printf("%16s ",ProcessHash[i].ImageFileName);
  832. printf("(%3d),",ProcessHash[i].ProcessID);
  833. }else{
  834. printf("Process %13u,",TmpPMmInfoLog->ProcessID);
  835. }
  836. }
  837. printf("%12u,",TmpPMmInfoLog->ThreadID);
  838. printf("%12x,",TmpPMmInfoLog->Va);
  839. printf("%8u",TmpPMmInfoLog->Pfn);
  840. printf("\n");
  841. break;
  842. }
  843. case MMINFO_LOG_TYPE_WORKINGSETSNAP:
  844. {
  845. PSYSTEM_MMINFO_WSENTRY_INFORMATION TmpPWs;
  846. PMMINFO_WSENTRY TmpPWsEntry;
  847. ULONG Size;
  848. ULONG ii;
  849. UCHAR Process[22];
  850. TmpPWs = (PSYSTEM_MMINFO_WSENTRY_INFORMATION) Info;
  851. Size = TmpPWs->WsSize;
  852. TmpPWsEntry = TmpPWs->Ws;
  853. if (TmpPWs->ProcessID == -1) {
  854. sprintf(Process,"%22s","SystemCache");
  855. } else {
  856. ULONG i;
  857. i = TmpPWs->ProcessID;
  858. if (ProcessHash[i].ProcessID == TmpPWs->ProcessID) {
  859. sprintf(Process, "%16s (%3d)",
  860. ProcessHash[i].ImageFileName,
  861. ProcessHash[i].ProcessID);
  862. }else{
  863. sprintf(Process,"Process %13u",TmpPWs->ProcessID);
  864. }
  865. }
  866. for (ii = 1; ii <= Size; ii++) {
  867. printf("%12s,%10s,%22s,%12u,%12x,%8u,%s,%s",
  868. "WsSnap",
  869. "",
  870. Process,
  871. ii,
  872. TmpPWsEntry->Va.Page << 12,
  873. TmpPWsEntry->Pa.Page,
  874. TmpPWsEntry->Pa.Accessed ?
  875. "Accessed" : "NotAccessed",
  876. TmpPWsEntry->Pa.Modified ?
  877. "Modified" : "NotModified",
  878. TmpPWsEntry->Pa.Shared ?
  879. "Shared" : "NotShared"
  880. );
  881. #ifdef WS_INSTRUMENTATION_ACCESS_BIT
  882. printf(",%s",
  883. TmpPWsEntry->Pa.RecentlyUsed ?
  884. "RecentlyUsed" : "NotRecentlyUsed"
  885. );
  886. #endif // WS_INSTRUMENTATION_ACCESS_BIT
  887. printf("\n");
  888. TmpPWsEntry++;
  889. }
  890. // printf("Size = %d\n", Size);
  891. break;
  892. }
  893. case MMINFO_LOG_TYPE_OUTWS_REPLACEUSED:
  894. case MMINFO_LOG_TYPE_OUTWS_REPLACEUNUSED:
  895. case MMINFO_LOG_TYPE_OUTWS_VOLUNTRIM:
  896. case MMINFO_LOG_TYPE_OUTWS_FORCETRIM:
  897. case MMINFO_LOG_TYPE_OUTWS_ADJUSTWS:
  898. case MMINFO_LOG_TYPE_OUTWS_EMPTYQ:
  899. {
  900. PSYSTEM_MMINFO_WSCHANGE_INFORMATION TmpPMmInfoLog;
  901. TmpPMmInfoLog=(PSYSTEM_MMINFO_WSCHANGE_INFORMATION) Info;
  902. printf("%12s,","Out_Of_WS");
  903. if (LogType == MMINFO_LOG_TYPE_OUTWS_REPLACEUSED) {
  904. printf("%10s,","RepUsed");
  905. } else if (LogType == MMINFO_LOG_TYPE_OUTWS_REPLACEUNUSED) {
  906. printf("%10s,","RepUnUsed");
  907. } else if (LogType == MMINFO_LOG_TYPE_OUTWS_VOLUNTRIM) {
  908. printf("%10s,","VolunTrim");
  909. } else if (LogType == MMINFO_LOG_TYPE_OUTWS_FORCETRIM) {
  910. printf("%10s,","ForceTrim");
  911. } else if (LogType == MMINFO_LOG_TYPE_OUTWS_ADJUSTWS) {
  912. printf("%10s,","AdjustWs");
  913. } else if (LogType == MMINFO_LOG_TYPE_OUTWS_EMPTYQ) {
  914. printf("%10s,","EmptyQ");
  915. } else {
  916. printf("%10s,","Unknown");
  917. }
  918. if (TmpPMmInfoLog->ProcessID == 0) {
  919. printf("%22s,","SystemCache");
  920. } else{
  921. ULONG i;
  922. i = TmpPMmInfoLog->ProcessID;
  923. if (ProcessHash[i].ProcessID == TmpPMmInfoLog->ProcessID) {
  924. printf("%16s ",ProcessHash[i].ImageFileName);
  925. printf("(%3d),",ProcessHash[i].ProcessID);
  926. }else{
  927. printf("Process %13u,",TmpPMmInfoLog->ProcessID);
  928. }
  929. }
  930. printf("%12s,","");
  931. printf("%12x,",TmpPMmInfoLog->Entry.Va.Page << 12);
  932. printf("%8u",TmpPMmInfoLog->Entry.Pa.Page);
  933. printf("\n");
  934. break;
  935. }
  936. case MMINFO_LOG_TYPE_WSINFOCACHE:
  937. case MMINFO_LOG_TYPE_TRIMCACHE:
  938. case MMINFO_LOG_TYPE_WSINFOPROCESS:
  939. case MMINFO_LOG_TYPE_TRIMPROCESS:
  940. {
  941. PSYSTEM_MMINFO_TRIMPROCESS_INFORMATION TmpPMmInfoTrimProcess;
  942. TmpPMmInfoTrimProcess = (PSYSTEM_MMINFO_TRIMPROCESS_INFORMATION) Info;
  943. if ((LogType == MMINFO_LOG_TYPE_WSINFOPROCESS) ||
  944. (LogType == MMINFO_LOG_TYPE_WSINFOCACHE)) {
  945. printf("%12s,","WsInfo");
  946. } else {
  947. printf("%12s,","Triming");
  948. }
  949. printf("WS:%7d,", TmpPMmInfoTrimProcess->ProcessWorkingSet);
  950. if ((LogType == MMINFO_LOG_TYPE_TRIMCACHE) ||
  951. (LogType == MMINFO_LOG_TYPE_WSINFOCACHE)) {
  952. printf("%22s,","SystemCache");
  953. } else{
  954. if (TmpPMmInfoTrimProcess->ProcessID == 0) {
  955. printf("%30s,","System ( 0)");
  956. } else {
  957. ULONG i;
  958. i = TmpPMmInfoTrimProcess->ProcessID;
  959. if (ProcessHash[i].ProcessID == TmpPMmInfoTrimProcess->ProcessID) {
  960. printf("%16s ",ProcessHash[i].ImageFileName);
  961. printf("(%3d),",ProcessHash[i].ProcessID);
  962. }else{
  963. printf("Process %13u,",TmpPMmInfoTrimProcess->ProcessID);
  964. }
  965. }
  966. }
  967. printf("Need:%7d,", TmpPMmInfoTrimProcess->ToTrim);
  968. printf("Got:%8d,", TmpPMmInfoTrimProcess->ActualTrim);
  969. printf("Pri:%4d,", TmpPMmInfoTrimProcess->ProcessMemoryPriority);
  970. printf("PageFaults:%8d,",
  971. TmpPMmInfoTrimProcess->ProcessPageFaultCount-
  972. TmpPMmInfoTrimProcess->ProcessLastPageFaultCount);
  973. if ((LogType == MMINFO_LOG_TYPE_WSINFOPROCESS) ||
  974. (LogType == MMINFO_LOG_TYPE_WSINFOCACHE)) {
  975. printf("Acc:%4d,",
  976. TmpPMmInfoTrimProcess->ProcessAccessedCount);
  977. printf("Mod:%4d,",
  978. TmpPMmInfoTrimProcess->ProcessModifiedCount);
  979. printf("Shd:%4d,",
  980. TmpPMmInfoTrimProcess->ProcessSharedCount);
  981. #ifdef WS_INSTRUMENTATION_ACCESS_BIT
  982. printf("RUsed:%4d,",
  983. TmpPMmInfoTrimProcess->ProcessRecentlyUsedCount);
  984. #endif // WS_INSTRUMENTATION_ACCESS_BIT
  985. }
  986. #ifdef WS_INSTRUMENTATION
  987. printf("Replacments:%5d,",
  988. TmpPMmInfoTrimProcess->ProcessReplacementCount);
  989. printf("QuotaBoosts:%5d,",
  990. TmpPMmInfoTrimProcess->ProcessQuotaBoostCount);
  991. printf("UsedRepls:%5d,",
  992. TmpPMmInfoTrimProcess->ProcessSparecount3);
  993. printf("FaultsSinceQInc:%5d,",
  994. TmpPMmInfoTrimProcess->ProcessPageFaultCount-
  995. TmpPMmInfoTrimProcess->ProcessLastGrowthFaultCount);
  996. printf("FaultSinceFGTrim:%5d,",
  997. TmpPMmInfoTrimProcess->ProcessPageFaultCount -
  998. TmpPMmInfoTrimProcess->
  999. ProcessLastForegroundTrimFaultCount);
  1000. printf("Spare4:%5d,",
  1001. TmpPMmInfoTrimProcess->ProcessSparecount4);
  1002. printf("Spare5:%2d,",
  1003. TmpPMmInfoTrimProcess->ProcessSparecount5);
  1004. #endif // WS_INSTRUMENTATION
  1005. printf("\n");
  1006. break;
  1007. }
  1008. case MMINFO_LOG_TYPE_POOLSTAT:
  1009. case MMINFO_LOG_TYPE_ADDPOOLPAGE:
  1010. case MMINFO_LOG_TYPE_FREEPOOLPAGE:
  1011. {
  1012. PSYSTEM_MMINFO_POOL_INFORMATION TmpPMmInfoPool;
  1013. TmpPMmInfoPool = (PSYSTEM_MMINFO_POOL_INFORMATION) Info;
  1014. if (LogType == MMINFO_LOG_TYPE_ADDPOOLPAGE) {
  1015. printf("%12s,","AddPoolPage");
  1016. } else if (LogType == MMINFO_LOG_TYPE_FREEPOOLPAGE) {
  1017. printf("%12s,","FreePoolPage");
  1018. } else{
  1019. printf("%12s,","PoolSummary");
  1020. }
  1021. printf("%10s,%22d,%12s,%12x,%8d,%8d,%8d,%12d,%12d\n",
  1022. "",
  1023. (int) TmpPMmInfoPool->Pool /100,
  1024. PoolTypeNames[(TmpPMmInfoPool->Pool%100) & 7],
  1025. TmpPMmInfoPool->Entry,
  1026. TmpPMmInfoPool->Alloc,
  1027. TmpPMmInfoPool->DeAlloc,
  1028. TmpPMmInfoPool->TotalPages,
  1029. TmpPMmInfoPool->TotalBytes,
  1030. // TmpPMmInfoPool->TotalBytes*100/4096/TmpPMmInfoPool->TotalPages,
  1031. // TmpPMmInfoPool->TotalBigBytes,
  1032. TmpPMmInfoPool->TotalBigPages
  1033. // TmpPMmInfoPool->TotalBigBytes*100/4096/TmpPMmInfoPool->TotalBigPages
  1034. );
  1035. break;
  1036. }
  1037. case MMINFO_LOG_TYPE_WORKINGSETMANAGER:
  1038. {
  1039. PSYSTEM_WORKINGSETMANAGER_INFORMATION TmpPWorkingSetManager;
  1040. char *ActionString;
  1041. TmpPWorkingSetManager = (PSYSTEM_WORKINGSETMANAGER_INFORMATION) Info;
  1042. switch(TmpPWorkingSetManager->Action) {
  1043. case WS_ACTION_RESET_COUNTER:
  1044. ActionString = "Reset Counter";
  1045. break;
  1046. case WS_ACTION_NOTHING:
  1047. ActionString = "Nothing";
  1048. break;
  1049. case WS_ACTION_INCREMENT_COUNTER:
  1050. ActionString = "Increment Counter";
  1051. break;
  1052. case WS_ACTION_WILL_TRIM:
  1053. ActionString = "Start Trimming";
  1054. break;
  1055. case WS_ACTION_FORCE_TRIMMING_PROCESS:
  1056. ActionString = "Force Trim";
  1057. break;
  1058. case WS_ACTION_WAIT_FOR_WRITER:
  1059. ActionString = "Wait writter";
  1060. break;
  1061. case WS_ACTION_EXAMINED_ALL_PROCESS:
  1062. ActionString = "All Process Examed";
  1063. break;
  1064. case WS_ACTION_AMPLE_PAGES_EXIST:
  1065. ActionString = "Ample Pages Exist";
  1066. break;
  1067. case WS_ACTION_END_WALK_ENTRIES:
  1068. ActionString = "Finished Walking WsEntries";
  1069. break;
  1070. default:
  1071. ActionString = "Unknown Action";
  1072. break;
  1073. }
  1074. printf(WsManagerDataFormat,
  1075. (PerfCounter - PerfCounterStart) *1000000/PerfFrequency,
  1076. TmpPWorkingSetManager->Available,
  1077. TmpPWorkingSetManager->PageFaultCount,
  1078. TmpPWorkingSetManager->LastPageFaultCount,
  1079. TmpPWorkingSetManager->MiCheckCounter,
  1080. TmpPWorkingSetManager->DesiredReductionGoal,
  1081. TmpPWorkingSetManager->DesiredFreeGoal,
  1082. ActionString
  1083. );
  1084. break;
  1085. }
  1086. case MMINFO_LOG_TYPE_REMOVEPAGEFROMLIST:
  1087. case MMINFO_LOG_TYPE_REMOVEPAGEBYCOLOR:
  1088. case MMINFO_LOG_TYPE_PAGEINMEMORY:
  1089. case MMINFO_LOG_TYPE_MEMORYSNAP:
  1090. case MMINFO_LOG_TYPE_SETPFNDELETED:
  1091. case MMINFO_LOG_TYPE_DELETEKERNELSTACK:
  1092. {
  1093. PSYSTEM_REMOVEDPAGE_INFORMATION TmpPRemovedPage;
  1094. TmpPRemovedPage=(PSYSTEM_REMOVEDPAGE_INFORMATION) Info;
  1095. if (LogType == MMINFO_LOG_TYPE_PAGEINMEMORY) {
  1096. printf("%12s,","InMemory");
  1097. }else if (LogType == MMINFO_LOG_TYPE_MEMORYSNAP) {
  1098. printf("%12s,","MemSnap");
  1099. }else if (LogType == MMINFO_LOG_TYPE_SETPFNDELETED) {
  1100. printf("%12s,","PfnDeleted");
  1101. }else if (LogType == MMINFO_LOG_TYPE_DELETEKERNELSTACK) {
  1102. printf("%12s,","DeleteStack");
  1103. }else {
  1104. printf("%12s,","PageRemoved");
  1105. }
  1106. printf("%10I64d,",
  1107. (PerfCounter - PerfCounterStart)
  1108. *1000000/PerfFrequency);
  1109. printf("%22s,","");
  1110. printf("%12x,",TmpPRemovedPage->Pte);
  1111. // printf("%30S,",.ImageName.Buffer);
  1112. switch(TmpPRemovedPage->UsedFor) {
  1113. case MMINFO_PAGE_USED_FOR_PAGEDPOOL:
  1114. printf("%12x,",TmpPRemovedPage->Pte<<10);
  1115. printf("%8u,",TmpPRemovedPage->Pfn);
  1116. printf("%30s,","Paged Pool");
  1117. printf("%12s,%10s,%10s,","","","PagedPool");
  1118. break;
  1119. case MMINFO_PAGE_USED_FOR_NONPAGEDPOOL:
  1120. printf("%12x,",TmpPRemovedPage->Pte<<10);
  1121. printf("%8u,",TmpPRemovedPage->Pfn);
  1122. printf("%30s,","NonPaged Pool");
  1123. printf("%12s,%10s,%10s,","","","NonPagedP");
  1124. break;
  1125. case MMINFO_PAGE_USED_FOR_KERNELSTACK:
  1126. printf("%12x,",TmpPRemovedPage->Pte<<10);
  1127. printf("%8u,",TmpPRemovedPage->Pfn);
  1128. printf("%30s,","Kernel Stack");
  1129. printf("%12s,%10s,%10s,","","","K-Stack");
  1130. break;
  1131. case MMINFO_PAGE_USED_FOR_FREEPAGE:
  1132. printf("%12s,","");
  1133. printf("%8u,",TmpPRemovedPage->Pfn);
  1134. printf("%30s,","Free Page");
  1135. printf("%12s,%10s,%10s,","","","Free");
  1136. break;
  1137. case MMINFO_PAGE_USED_FOR_ZEROPAGE:
  1138. printf("%12s,","");
  1139. printf("%8u,",TmpPRemovedPage->Pfn);
  1140. printf("%30s,","Zero Page");
  1141. printf("%12s,%10s,%10s,","","","Zero");
  1142. break;
  1143. case MMINFO_PAGE_USED_FOR_BADPAGE:
  1144. printf("%12s,","");
  1145. printf("%8u,",TmpPRemovedPage->Pfn);
  1146. printf("%30s,","Bad Page");
  1147. printf("%12s,%10s,%10s,","","","Bad");
  1148. break;
  1149. case MMINFO_PAGE_USED_FOR_UNKNOWN:
  1150. printf("%12s,","");
  1151. printf("%8u,",TmpPRemovedPage->Pfn);
  1152. printf("%30s,","Unknown");
  1153. printf("%12s,%10s,%10s,","","","Unknown");
  1154. break;
  1155. case MMINFO_PAGE_USED_FOR_METAFILE:
  1156. printf("%12s,","");
  1157. printf("%8u,",TmpPRemovedPage->Pfn);
  1158. printf("%30s,","Meta File");
  1159. printf("%12s,%10s,%10s,","","","Meta");
  1160. break;
  1161. case MMINFO_PAGE_USED_FOR_NONAME:
  1162. printf("%12s,","");
  1163. printf("%8u,",TmpPRemovedPage->Pfn);
  1164. printf("%30s,","No Name");
  1165. printf("%12s,%10s,%10s,","","","Image");
  1166. break;
  1167. case MMINFO_PAGE_USED_FOR_PAGEFILEMAPPED:
  1168. printf("%12x,",TmpPRemovedPage->Pte<<10);
  1169. printf("%8u,",TmpPRemovedPage->Pfn);
  1170. printf("%30s,","Page File Mapped");
  1171. printf("%12s,%10s,%10s,","","","PFMapped");
  1172. break;
  1173. case MMINFO_PAGE_USED_FOR_FILE:
  1174. case MMINFO_PAGE_USED_FOR_KERNMAP:
  1175. {
  1176. ULONG i,j;
  1177. if (TmpPRemovedPage->UsedFor != MMINFO_PAGE_USED_FOR_KERNMAP) {
  1178. printf("%12s,","");
  1179. } else {
  1180. printf("%12x,",TmpPRemovedPage->Pte << 10);
  1181. }
  1182. printf("%8u,",TmpPRemovedPage->Pfn);
  1183. i=TmpPRemovedPage->ImageKey%TableSize;
  1184. while(ImageHash[i].ImageKey != 0) {
  1185. if (ImageHash[i].ImageKey == TmpPRemovedPage->ImageKey) {
  1186. printf("%30S,",ImageHash[i].ImageName.Buffer);
  1187. break;
  1188. }else{
  1189. i = (i+1)%TableSize;
  1190. }
  1191. }
  1192. if (Debug) {
  1193. // printf("(%4d %22x)",i,TmpPRemovedPage->ImageKey);
  1194. }
  1195. if (ImageHash[i].ImageKey == 0) {
  1196. if (TmpPRemovedPage->UsedFor != MMINFO_PAGE_USED_FOR_KERNMAP) {
  1197. printf("%19s (%8x),","Image", TmpPRemovedPage->ImageKey);
  1198. printf("%12I64d,",TmpPRemovedPage->Offset);
  1199. printf("%10s,","");
  1200. printf("%10s,","FILE");
  1201. }else{
  1202. printf("%19s (%8x),","KernMap", TmpPRemovedPage->ImageKey);
  1203. printf("%12s,%10s,","","");
  1204. printf("%10s,","Driver");
  1205. }
  1206. }else{
  1207. if (TmpPRemovedPage->UsedFor == MMINFO_PAGE_USED_FOR_KERNMAP) {
  1208. printf("%12I64d,",TmpPRemovedPage->Offset);
  1209. printf("%10s,","");
  1210. printf("%10s,","Driver");
  1211. }else if (TmpPRemovedPage->UsedFor == MMINFO_PAGE_USED_FOR_FILE) {
  1212. printf("%12I64d,",TmpPRemovedPage->Offset);
  1213. printf("%10s,","");
  1214. printf("%10s,","FILE");
  1215. }else{
  1216. printf("%12s,%10s,","","");
  1217. printf("%10s,","Unknown");
  1218. }
  1219. }
  1220. }
  1221. break;
  1222. case MMINFO_PAGE_USED_FOR_PROCESS:
  1223. case MMINFO_PAGE_USED_FOR_PAGETABLE:
  1224. {
  1225. ULONG i;
  1226. // Bug! Bug! The way to get VA can be wrong in the future.
  1227. if (TmpPRemovedPage->UsedFor == MMINFO_PAGE_USED_FOR_PAGETABLE) {
  1228. printf("%12x,",TmpPRemovedPage->Pte<<10);
  1229. printf("%8u,",TmpPRemovedPage->Pfn);
  1230. printf("(PT)");
  1231. }else{
  1232. printf("%12x,",TmpPRemovedPage->Pte<<10);
  1233. printf("%8u,",TmpPRemovedPage->Pfn);
  1234. printf(" ");
  1235. }
  1236. if (TmpPRemovedPage->ImageKey == 0) {
  1237. printf("%26s,","System ( 0)");
  1238. }else{
  1239. i = TmpPRemovedPage->ImageKey;
  1240. if (ProcessHash[i].ProcessID == TmpPRemovedPage->ImageKey) {
  1241. printf("%20s ",ProcessHash[i].ImageFileName);
  1242. printf("(%3d),",ProcessHash[i].ProcessID);
  1243. }else{
  1244. printf("Process %18u,",TmpPRemovedPage->ImageKey);
  1245. }
  1246. }
  1247. if (TmpPRemovedPage->UsedFor == MMINFO_PAGE_USED_FOR_PAGETABLE) {
  1248. // printf("%12I64d,",TmpPRemovedPage->Offset);
  1249. printf("%12s,%10s,%10s,","","","PageTable");
  1250. }else{
  1251. printf("%12s,%10s,%10s,","","","Process");
  1252. // printf("%30s,","Page Table");
  1253. }
  1254. }
  1255. break;
  1256. default:
  1257. printf("Error2 %22u,",TmpPRemovedPage->ImageKey);
  1258. break;
  1259. }
  1260. switch(TmpPRemovedPage->List) {
  1261. case MMINFO_PAGE_IN_LIST_FREEPAGE:
  1262. printf("%10s","Free List");
  1263. break;
  1264. case MMINFO_PAGE_IN_LIST_ZEROPAGE:
  1265. printf("%10s","Zero List");
  1266. break;
  1267. case MMINFO_PAGE_IN_LIST_BADPAGE:
  1268. printf("%10s","Bad List");
  1269. break;
  1270. case MMINFO_PAGE_IN_LIST_STANDBY:
  1271. printf("%10s","Standby");
  1272. break;
  1273. case MMINFO_PAGE_IN_LIST_TRANSITION:
  1274. printf("%10s","Transition");
  1275. break;
  1276. case MMINFO_PAGE_IN_LIST_MODIFIED:
  1277. printf("%10s","Modified");
  1278. break;
  1279. case MMINFO_PAGE_IN_LIST_MODIFIEDNOWRITE:
  1280. printf("%10s","ModNoWrite");
  1281. break;
  1282. case MMINFO_PAGE_IN_LIST_ACTIVEANDVALID:
  1283. printf("%10s","Valid");
  1284. break;
  1285. case MMINFO_PAGE_IN_LIST_VALIDANDPINNED:
  1286. printf("%10s","Valid_Pin");
  1287. break;
  1288. case MMINFO_PAGE_IN_LIST_UNKNOWN:
  1289. printf("%10s","Unknown");
  1290. break;
  1291. default:
  1292. // must be page table
  1293. printf("%10s","");
  1294. break;
  1295. }
  1296. printf("\n");
  1297. // printf("Got Removed Page Log\n");
  1298. break;
  1299. }
  1300. case MMINFO_LOG_TYPE_ZEROSHARECOUNT:
  1301. case MMINFO_LOG_TYPE_ZEROREFCOUNT:
  1302. case MMINFO_LOG_TYPE_DECREFCNT:
  1303. case MMINFO_LOG_TYPE_DECSHARCNT:
  1304. {
  1305. PSYSTEM_MMINFO_PFN_INFORMATION TmpPPfn;
  1306. TmpPPfn = (PSYSTEM_MMINFO_PFN_INFORMATION) Info;
  1307. if (LogType == MMINFO_LOG_TYPE_DECSHARCNT) {
  1308. printf("%12s,", "DecShareCnt");
  1309. } else if (LogType == MMINFO_LOG_TYPE_ZEROSHARECOUNT) {
  1310. printf("%12s,", "ZeroShareCnt");
  1311. } else if (LogType == MMINFO_LOG_TYPE_DECREFCNT) {
  1312. printf("%12s,", "DecRefCnt");
  1313. } else if (LogType == MMINFO_LOG_TYPE_ZEROREFCOUNT) {
  1314. printf("%12s,", "ZeroRefCnt");
  1315. } else {
  1316. printf("%12s,", "UNKNOWN");
  1317. }
  1318. printf("%10s,","");
  1319. printf("%22s,","");
  1320. printf("%12s,","");
  1321. printf("%12s,","");
  1322. printf("%8u\n",TmpPPfn->Pfn);
  1323. break;
  1324. }
  1325. case MMINFO_LOG_TYPE_INSERTINLIST:
  1326. case MMINFO_LOG_TYPE_INSERTATFRONT:
  1327. case MMINFO_LOG_TYPE_UNLINKFROMSTANDBY:
  1328. case MMINFO_LOG_TYPE_UNLINKFFREEORZERO:
  1329. {
  1330. PSYSTEM_MMINFO_STATE_INFORMATION TmpPMmInfoState;
  1331. TmpPMmInfoState=(PSYSTEM_MMINFO_STATE_INFORMATION) Info;
  1332. if (LogType == MMINFO_LOG_TYPE_INSERTINLIST) {
  1333. printf("%12s,%10s,","Insert-List", "");
  1334. }else if (LogType == MMINFO_LOG_TYPE_INSERTATFRONT) {
  1335. printf("%12s,%10s,","Insert-Front", "");
  1336. }else if (LogType == MMINFO_LOG_TYPE_UNLINKFROMSTANDBY) {
  1337. printf("%12s,%10s,","Unlink-From", "");
  1338. }else if (LogType == MMINFO_LOG_TYPE_UNLINKFFREEORZERO) {
  1339. printf("%12s,%10s,","Unlink-From", "");
  1340. }
  1341. printf("%22s,","");
  1342. printf("%12s,","");
  1343. printf("%12s,","");
  1344. printf("%8u,",TmpPMmInfoState->Pfn);
  1345. printf("%30s,","");
  1346. printf("%12s,%10s,%10s,","","","");
  1347. switch(TmpPMmInfoState->List) {
  1348. case MMINFO_PAGE_IN_LIST_FREEPAGE:
  1349. printf("%10s","Free List");
  1350. break;
  1351. case MMINFO_PAGE_IN_LIST_ZEROPAGE:
  1352. printf("%10s","Zero List");
  1353. break;
  1354. case MMINFO_PAGE_IN_LIST_BADPAGE:
  1355. printf("%10s","Bad List");
  1356. break;
  1357. case MMINFO_PAGE_IN_LIST_STANDBY:
  1358. printf("%10s","Standby");
  1359. break;
  1360. case MMINFO_PAGE_IN_LIST_TRANSITION:
  1361. printf("%10s","Transition");
  1362. break;
  1363. case MMINFO_PAGE_IN_LIST_MODIFIED:
  1364. printf("%10s","Modified");
  1365. break;
  1366. case MMINFO_PAGE_IN_LIST_MODIFIEDNOWRITE:
  1367. printf("%10s","ModNoWrite");
  1368. break;
  1369. case MMINFO_PAGE_IN_LIST_ACTIVEANDVALID:
  1370. printf("%10s","Valid");
  1371. break;
  1372. case MMINFO_PAGE_IN_LIST_VALIDANDPINNED:
  1373. printf("%10s","Valid_Pin");
  1374. break;
  1375. case MMINFO_PAGE_IN_LIST_UNKNOWN:
  1376. printf("%10s","Unknown");
  1377. break;
  1378. default:
  1379. // must be page table
  1380. printf("%10s","");
  1381. break;
  1382. }
  1383. printf("\n");
  1384. // printf("Got Removed Page Log\n");
  1385. break;
  1386. }
  1387. case MMINFO_LOG_TYPE_IMAGENAME:
  1388. case MMINFO_LOG_TYPE_SECTIONREMOVED:
  1389. {
  1390. PSYSTEM_MMINFO_FILENAME_INFORMATION TmpPImage;
  1391. ULONG i;
  1392. TmpPImage=(PSYSTEM_MMINFO_FILENAME_INFORMATION) Info;
  1393. // printf("Got Image Log\n");
  1394. i=TmpPImage->ImageKey%TableSize;
  1395. while(ImageHash[i].ImageKey != 0) {
  1396. if (ImageHash[i].ImageKey == TmpPImage->ImageKey) {
  1397. break;
  1398. }else{
  1399. i = (i+1)%TableSize;
  1400. }
  1401. }
  1402. if (LogType == MMINFO_LOG_TYPE_IMAGENAME) {
  1403. ImageHash[i].ImageKey
  1404. =TmpPImage->ImageKey;
  1405. ImageHash[i].ImageName.Length
  1406. =TmpPImage->ImageName.Length;
  1407. ImageHash[i].ImageName.Buffer
  1408. =TmpPImage->ImageBuffer;
  1409. if (Debug) {
  1410. printf("%12s,", "S-Created");
  1411. }
  1412. }else{
  1413. if (Debug) {
  1414. printf("%12s,", "S-Deleted");
  1415. }
  1416. }
  1417. if (Debug) {
  1418. printf("%10s,%22s,%12s,%12x,%8s,%30S,%12s,%10s,%10s\n",
  1419. "",
  1420. "",
  1421. "",
  1422. ImageHash[i].ImageKey,
  1423. "",
  1424. ImageHash[i].ImageName.Buffer,
  1425. "",
  1426. "",
  1427. "");
  1428. }
  1429. break;
  1430. }
  1431. case MMINFO_LOG_TYPE_PROCESSNAME:
  1432. case MMINFO_LOG_TYPE_DIEDPROCESS:
  1433. {
  1434. PSYSTEM_MMINFO_PROCESS_INFORMATION TmpPProcess;
  1435. ULONG i;
  1436. TmpPProcess=(PSYSTEM_MMINFO_PROCESS_INFORMATION) Info;
  1437. if (LogType == MMINFO_LOG_TYPE_PROCESSNAME) {
  1438. i = TmpPProcess->ProcessID;
  1439. ProcessHash[i].ProcessID
  1440. =TmpPProcess->ProcessID;
  1441. RtlCopyMemory(ProcessHash[i].ImageFileName,
  1442. TmpPProcess->ImageFileName, 16);
  1443. printf("%12s,", "P-Created");
  1444. }else{
  1445. printf("%12s,", "P-Deleted");
  1446. }
  1447. printf("%10s,%16s (%3d)\n",
  1448. "",
  1449. ProcessHash[TmpPProcess->ProcessID].ImageFileName,
  1450. ProcessHash[TmpPProcess->ProcessID].ProcessID);
  1451. // printf("Got Process Log\n");
  1452. break;
  1453. }
  1454. case MMINFO_LOG_TYPE_OUTSWAPPROCESS:
  1455. case MMINFO_LOG_TYPE_INSWAPPROCESS:
  1456. {
  1457. PSYSTEM_MMINFO_SWAPPROCESS_INFORMATION TmpPProc;
  1458. ULONG i;
  1459. TmpPProc=(PSYSTEM_MMINFO_SWAPPROCESS_INFORMATION) Info;
  1460. if (LogType == MMINFO_LOG_TYPE_OUTSWAPPROCESS) {
  1461. printf("%12s,", "P-OutSwap");
  1462. }else{
  1463. printf("%12s,", "P-InSwap");
  1464. }
  1465. if (PerfCounter) {
  1466. printf("%10I64d,", ((PerfCounter - PerfCounterStart) * 1000000) / PerfFrequency);
  1467. } else {
  1468. printf("%10s,", "");
  1469. }
  1470. printf("%16s (%3d)",
  1471. ProcessHash[TmpPProc->ProcessID].ImageFileName,
  1472. ProcessHash[TmpPProc->ProcessID].ProcessID);
  1473. printf("\n");
  1474. break;
  1475. }
  1476. case MMINFO_LOG_TYPE_OUTSWAPSTACK:
  1477. case MMINFO_LOG_TYPE_INSWAPSTACK:
  1478. {
  1479. PSYSTEM_MMINFO_SWAPTHREAD_INFORMATION TmpPThread;
  1480. ULONG i;
  1481. TmpPThread=(PSYSTEM_MMINFO_SWAPTHREAD_INFORMATION) Info;
  1482. if (LogType == MMINFO_LOG_TYPE_OUTSWAPSTACK) {
  1483. printf("%12s,", "KS-OutSwap");
  1484. }else{
  1485. printf("%12s,", "KS-InSwap");
  1486. }
  1487. printf("%10d,%16s (%3d)",
  1488. TmpPThread->ThreadID,
  1489. ProcessHash[TmpPThread->ProcessID].ImageFileName,
  1490. ProcessHash[TmpPThread->ProcessID].ProcessID);
  1491. if (PerfCounter) {
  1492. printf(",%12I64d", ((PerfCounter - PerfCounterStart) * 1000000) / PerfFrequency);
  1493. }
  1494. printf("\n");
  1495. break;
  1496. }
  1497. case MMINFO_LOG_TYPE_CREATETHREAD:
  1498. case MMINFO_LOG_TYPE_GROWKERNELSTACK:
  1499. case MMINFO_LOG_TYPE_TERMINATETHREAD:
  1500. case MMINFO_LOG_TYPE_CONVERTTOGUITHREAD:
  1501. {
  1502. PSYSTEM_MMINFO_THREAD_INFORMATION TmpPThread;
  1503. ULONG i;
  1504. TmpPThread=(PSYSTEM_MMINFO_THREAD_INFORMATION) Info;
  1505. if (LogType == MMINFO_LOG_TYPE_CREATETHREAD) {
  1506. printf("%12s,", "T-Created");
  1507. ThreadHash[TmpPThread->ThreadID] = TmpPThread->ProcessID;
  1508. }else if (LogType == MMINFO_LOG_TYPE_GROWKERNELSTACK) {
  1509. printf("%12s,", "GrowStack");
  1510. }else if (LogType == MMINFO_LOG_TYPE_CONVERTTOGUITHREAD) {
  1511. printf("%12s,", "T-GUI");
  1512. }else{
  1513. printf("%12s,", "T-Deleted");
  1514. //
  1515. // Threads are sometimes set as deleted while still
  1516. // running. If we mark them as dead here we have
  1517. // a problem when they are cswitched out.
  1518. //
  1519. //ThreadHash[TmpPThread->ThreadID] = -1;
  1520. }
  1521. printf("%10d,%16s (%3d)",
  1522. TmpPThread->ThreadID,
  1523. ProcessHash[TmpPThread->ProcessID].ImageFileName,
  1524. ProcessHash[TmpPThread->ProcessID].ProcessID);
  1525. // printf("Got Process Log\n");
  1526. if (LogType != MMINFO_LOG_TYPE_TERMINATETHREAD) {
  1527. printf(",%12x",TmpPThread->StackBase);
  1528. printf(",%12x",TmpPThread->StackLimit);
  1529. if (TmpPThread->UserStackBase) {
  1530. printf(",%12x",TmpPThread->UserStackBase);
  1531. printf(",%12x",TmpPThread->UserStackLimit);
  1532. } else {
  1533. printf(",%12s","");
  1534. printf(",%12s","");
  1535. }
  1536. if (TmpPThread->WaitMode >= 0) {
  1537. if (TmpPThread->WaitMode) {
  1538. printf(",%8s", "Swapable");
  1539. } else {
  1540. printf(",%8s", "NonSwap");
  1541. }
  1542. }
  1543. }
  1544. printf("\n");
  1545. break;
  1546. }
  1547. case MMINFO_LOG_TYPE_CSWITCH:
  1548. {
  1549. PSYSTEM_MMINFO_CSWITCH_INFORMATION TmpPMmInfo;
  1550. ULONG OldProcessId;
  1551. ULONG NewProcessId;
  1552. TmpPMmInfo = (PSYSTEM_MMINFO_CSWITCH_INFORMATION) Info;
  1553. OldProcessId = ThreadHash[TmpPMmInfo->OldThreadId];
  1554. NewProcessId = ThreadHash[TmpPMmInfo->NewThreadId];
  1555. if ((OldProcessId == -1) || (NewProcessId == -1)) {
  1556. printf("Error: Bad thread value %d or %d\n",
  1557. TmpPMmInfo->OldThreadId,
  1558. TmpPMmInfo->NewThreadId
  1559. );
  1560. break;
  1561. }
  1562. printf("%12s,%10I64d,%11s,%16s,%10d,%16s (%3d), %10d,%16s (%3d),%4d,%4d,%8s\n",
  1563. "CSwitch",
  1564. ((PerfCounter - PerfCounterStart) *
  1565. 1000000) / PerfFrequency,
  1566. ThreadState[TmpPMmInfo->OldState],
  1567. (TmpPMmInfo->OldState == Waiting) ?
  1568. WaitReason[TmpPMmInfo->WaitReason] :
  1569. "",
  1570. TmpPMmInfo->OldThreadId,
  1571. ProcessHash[OldProcessId].ImageFileName,
  1572. OldProcessId,
  1573. TmpPMmInfo->NewThreadId,
  1574. ProcessHash[NewProcessId].ImageFileName,
  1575. NewProcessId,
  1576. TmpPMmInfo->OldThreadPri,
  1577. TmpPMmInfo->NewThreadPri,
  1578. (TmpPMmInfo->OldWaitMode) ? "Swapable" : "NonSwap"
  1579. );
  1580. break;
  1581. }
  1582. case MMINFO_LOG_TYPE_POOLSNAP:
  1583. {
  1584. ULONG PoolTag[2]={0,0};
  1585. PMMINFO_POOL_TRACKER_TABLE TmpPMmInfopoolTrackTable;
  1586. TmpPMmInfopoolTrackTable=(PMMINFO_POOL_TRACKER_TABLE) Info;
  1587. PoolTag[0]=TmpPMmInfopoolTrackTable->Tag & ~PROTECTED_POOL;
  1588. // Data for Paged Pool
  1589. if (TmpPMmInfopoolTrackTable->PagedAllocs) {
  1590. printf("%12s,","PoolSnap");
  1591. printf("%10s,", PoolTag);
  1592. printf("%22s,","");
  1593. printf("%12s,%12s,","PagedPool","");
  1594. printf("%8u,%8u,%8u\n",
  1595. TmpPMmInfopoolTrackTable->PagedBytes,
  1596. TmpPMmInfopoolTrackTable->PagedAllocs,
  1597. TmpPMmInfopoolTrackTable->PagedFrees);
  1598. }
  1599. // Data for NonPaged Pool
  1600. if (TmpPMmInfopoolTrackTable->NonPagedAllocs) {
  1601. printf("%12s,","PoolSnap");
  1602. printf("%10s,", PoolTag);
  1603. printf("%22s,","");
  1604. printf("%12s,%12s,","NonPagedPool","");
  1605. printf("%8u,%8u,%8u\n",
  1606. TmpPMmInfopoolTrackTable->NonPagedBytes,
  1607. TmpPMmInfopoolTrackTable->NonPagedAllocs,
  1608. TmpPMmInfopoolTrackTable->NonPagedFrees);
  1609. }
  1610. break;
  1611. }
  1612. case MMINFO_LOG_TYPE_ALLOCATEPOOL:
  1613. case MMINFO_LOG_TYPE_BIGPOOLPAGE:
  1614. {
  1615. ULONG PoolTag[2]={0,0};
  1616. PSYSTEM_MMINFO_ALLOCATEPOOL_INFORMATION TmpPMmInfoAllocatePool;
  1617. TmpPMmInfoAllocatePool=(PSYSTEM_MMINFO_ALLOCATEPOOL_INFORMATION) Info;
  1618. PoolTag[0]=TmpPMmInfoAllocatePool->PoolTag & ~PROTECTED_POOL;
  1619. if (LogType == MMINFO_LOG_TYPE_ALLOCATEPOOL) {
  1620. printf("%12s,", "Pool_Alloc");
  1621. printf("%10s,", PoolTag);
  1622. if (TmpPMmInfoAllocatePool->ProcessID == 0) {
  1623. printf("%22s,","System ( 0)");
  1624. } else{
  1625. ULONG i;
  1626. i = TmpPMmInfoAllocatePool->ProcessID;
  1627. if (ProcessHash[i].ProcessID == TmpPMmInfoAllocatePool->ProcessID) {
  1628. printf("%16s ",ProcessHash[i].ImageFileName);
  1629. printf("(%3d),",ProcessHash[i].ProcessID);
  1630. }else{
  1631. printf("Process %13u,",TmpPMmInfoAllocatePool->ProcessID);
  1632. }
  1633. }
  1634. }else{
  1635. printf("%12s,","BigPoolPage");
  1636. printf("%10s,", PoolTag);
  1637. printf("%22s,","");
  1638. }
  1639. printf("%12s,%12x,%8u\n",
  1640. PoolTypeNames[TmpPMmInfoAllocatePool->PoolType & 7],
  1641. TmpPMmInfoAllocatePool->Entry,
  1642. TmpPMmInfoAllocatePool->Size);
  1643. break;
  1644. }
  1645. case MMINFO_LOG_TYPE_FREEPOOL:
  1646. {
  1647. PSYSTEM_MMINFO_FREEPOOL_INFORMATION TmpPMmInfoFreePool;
  1648. TmpPMmInfoFreePool=(PSYSTEM_MMINFO_FREEPOOL_INFORMATION) Info;
  1649. printf("%12s,%10s,%22s,%12s,%12x\n",
  1650. "Pool_Free",
  1651. "",
  1652. "",
  1653. "",
  1654. TmpPMmInfoFreePool->Entry);
  1655. break;
  1656. }
  1657. case MMINFO_LOG_TYPE_ASYNCMARK:
  1658. case MMINFO_LOG_TYPE_MARK:
  1659. {
  1660. PSYSTEM_MMINFO_MARK_INFORMATION TmpPMmInfo;
  1661. TmpPMmInfo = (PSYSTEM_MMINFO_MARK_INFORMATION) Info;
  1662. printf("%12s,%10I64d, %-s\n",
  1663. (LogType == MMINFO_LOG_TYPE_ASYNCMARK) ?
  1664. "AsyncMark" : "Mark",
  1665. ((PerfCounter - PerfCounterStart) *
  1666. 1000000) / PerfFrequency,
  1667. TmpPMmInfo->Name);
  1668. break;
  1669. }
  1670. case MMINFO_LOG_TYPE_CMCELLREFERRED:
  1671. {
  1672. PSYSTEM_MMINFO_CMCELL_INFORMATION TmpPMmInfoCmCell;
  1673. TmpPMmInfoCmCell=(PSYSTEM_MMINFO_CMCELL_INFORMATION) Info;
  1674. printf("%12s,%10s,","Cell_Used","");
  1675. switch(TmpPMmInfoCmCell->Signature) {
  1676. case CM_KEY_NODE_SIGNATURE:
  1677. printf("%22s,%12s","Key_Node","");
  1678. break;
  1679. case CM_LINK_NODE_SIGNATURE:
  1680. printf("%22s,%12s","Link_Node","");
  1681. break;
  1682. case CM_KEY_VALUE_SIGNATURE:
  1683. printf("%22s,%12s","Key_Value","");
  1684. break;
  1685. case CM_KEY_FAST_LEAF:
  1686. printf("%22s,%12s","Index_Leaf","");
  1687. break;
  1688. case CM_KEY_SECURITY_SIGNATURE:
  1689. printf("%22s,%12s","Key_Security","");
  1690. break;
  1691. default:
  1692. printf("%22s,%12s","Unknown","");
  1693. break;
  1694. }
  1695. printf(",%12x,%8d\n", TmpPMmInfoCmCell->Va, TmpPMmInfoCmCell->Size*-1);
  1696. break;
  1697. }
  1698. case MMINFO_LOG_TYPE_IMAGELOAD:
  1699. {
  1700. PMMINFO_IMAGELOAD_INFORMATION TmpPMmInfo;
  1701. char WsNameBuf[30];
  1702. char * WsName = &WsNameBuf[0];
  1703. TmpPMmInfo = (PMMINFO_IMAGELOAD_INFORMATION) Info;
  1704. Info = TmpPMmInfo + 1;
  1705. if (TmpPMmInfo->ProcessId == 0) {
  1706. WsName = "System ( 0)";
  1707. } else {
  1708. ULONG i;
  1709. i = TmpPMmInfo->ProcessId;
  1710. if (ProcessHash[i].ProcessID == TmpPMmInfo->ProcessId) {
  1711. sprintf(WsName, "%16s (%3d)",
  1712. ProcessHash[i].ImageFileName,
  1713. ProcessHash[i].ProcessID);
  1714. }else{
  1715. sprintf(WsName, "Process %13u", TmpPMmInfo->ProcessId);
  1716. }
  1717. }
  1718. printf(ImageLoadDataFormat,
  1719. TmpPMmInfo->ImageBase,
  1720. (ULONG)TmpPMmInfo->ImageBase + TmpPMmInfo->ImageSize,
  1721. TmpPMmInfo->ImageSectionNumber,
  1722. WsName,
  1723. TmpPMmInfo->ImageName
  1724. );
  1725. break;
  1726. }
  1727. case MMINFO_LOG_TYPE_SAMPLED_PROFILE:
  1728. {
  1729. PMMINFO_SAMPLED_PROFILE_INFORMATION TmpPMmInfo;
  1730. TmpPMmInfo = (PMMINFO_SAMPLED_PROFILE_INFORMATION) Info;
  1731. Info = TmpPMmInfo + 1;
  1732. printf(SampledProfileDataFormat,
  1733. TmpPMmInfo->InstructionPointer,
  1734. TmpPMmInfo->Count
  1735. );
  1736. break;
  1737. }
  1738. default:
  1739. // fprintf(stderr, "Tag Value %8d\n", Tag.u.Value);
  1740. // fprintf(stderr, "TimeStamp %8x %8x\n", TS.upper, TS.lower);
  1741. break;
  1742. }
  1743. }
  1744. #else //NTMMPERF
  1745. printf("Sorry but this is an internal tool!!!\n");
  1746. #endif //NTMMPERF
  1747. return 0;
  1748. }