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.

604 lines
14 KiB

  1. /*++
  2. Copyright (c) 1998-2001 Microsoft Corporation
  3. Module Name:
  4. uri.c
  5. Abstract:
  6. Dumps URI Cache structures.
  7. Author:
  8. Michael Courage (mcourage) 19-May-1999
  9. Environment:
  10. User Mode.
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. #include "..\drv\hashfn.h"
  15. #include "..\drv\hashp.h"
  16. //
  17. // Private prototypes.
  18. //
  19. //
  20. // Public functions.
  21. //
  22. DECLARE_API( uriglob )
  23. /*++
  24. Routine Description:
  25. Dumps global URI Cache structures.
  26. Arguments:
  27. None.
  28. Return Value:
  29. None.
  30. --*/
  31. {
  32. ULONG_PTR address = 0;
  33. BOOL Enabled = FALSE;
  34. UL_URI_CACHE_CONFIG config;
  35. UL_URI_CACHE_STATS stats;
  36. // UL_URI_CACHE_TABLE table;
  37. ULONG_PTR dataAddress;
  38. UL_NONPAGED_DATA data;
  39. BOOL gotData = FALSE;
  40. CHAR uriCacheResource[MAX_RESOURCE_STATE_LENGTH];
  41. CHAR uriZombieResource[MAX_RESOURCE_STATE_LENGTH];
  42. SNAPSHOT_EXTENSION_DATA();
  43. //
  44. // Dump cache configuration.
  45. //
  46. address = GetExpression( "&http!g_UriCacheConfig" );
  47. if (address) {
  48. if (ReadMemory(
  49. address,
  50. &config,
  51. sizeof(config),
  52. NULL
  53. ))
  54. {
  55. dprintf(
  56. "UL_URI_CACHE_CONFIG @ %p:\n"
  57. " EnableCache = %d\n"
  58. " MaxCacheUriCount = %d\n"
  59. " MaxCacheMegabyteCount = %d\n"
  60. " ScavengerPeriod = %d\n"
  61. " MaxUriBytes = %d\n"
  62. " HashTableBits = %d\n",
  63. address,
  64. config.EnableCache,
  65. config.MaxCacheUriCount,
  66. config.MaxCacheMegabyteCount,
  67. config.ScavengerPeriod,
  68. config.MaxUriBytes,
  69. config.HashTableBits
  70. );
  71. Enabled = config.EnableCache;
  72. } else {
  73. dprintf(
  74. "glob: cannot read memory for http!g_UriCacheConfig @ %p\n",
  75. address
  76. );
  77. }
  78. } else {
  79. dprintf(
  80. "uriglob: cannot find symbol for http!g_UriCacheConfig\n"
  81. );
  82. }
  83. if (!Enabled) {
  84. //
  85. // no point in going on..
  86. //
  87. return;
  88. }
  89. //
  90. // Dump Cache Statistics
  91. //
  92. address = GetExpression( "&http!g_UriCacheStats" );
  93. if (address) {
  94. if (ReadMemory(
  95. address,
  96. &stats,
  97. sizeof(stats),
  98. NULL
  99. ))
  100. {
  101. dprintf(
  102. "\n"
  103. "UL_URI_CACHE_STATS @ %p:\n"
  104. " UriCount = %d\n"
  105. " UriCountMax = %d\n"
  106. " UriAddedTotal = %I64d\n"
  107. " ByteCount = %I64d\n"
  108. " ByteCountMax = %I64d\n"
  109. " ZombieCount = %d\n"
  110. " ZombieCountMax = %d\n"
  111. " HitCount = %d\n"
  112. " MissTableCount = %d\n"
  113. " MissPrecondtionCount = %d\n"
  114. " MissConfigCount = %d\n"
  115. "\n",
  116. address,
  117. stats.UriCount,
  118. stats.UriCountMax,
  119. stats.UriAddedTotal,
  120. stats.ByteCount,
  121. stats.ByteCountMax,
  122. stats.ZombieCount,
  123. stats.ZombieCountMax,
  124. stats.HitCount,
  125. stats.MissTableCount,
  126. stats.MissPreconditionCount,
  127. stats.MissConfigCount
  128. );
  129. } else {
  130. dprintf(
  131. "glob: cannot read memory for http!g_UriCacheStats @ %p\n",
  132. address
  133. );
  134. }
  135. } else {
  136. dprintf(
  137. "uriglob: cannot find symbol for http!g_UriCacheStats\n"
  138. );
  139. }
  140. //
  141. // Read in resource info from non-paged data
  142. //
  143. address = GetExpression( "&http!g_pUlNonpagedData" );
  144. if (address) {
  145. if (ReadMemory(
  146. address,
  147. &dataAddress,
  148. sizeof(dataAddress),
  149. NULL
  150. ))
  151. {
  152. if (ReadMemory(
  153. dataAddress,
  154. &data,
  155. sizeof(data),
  156. NULL
  157. ))
  158. {
  159. gotData = TRUE;
  160. } else {
  161. dprintf(
  162. "uriglob: cannot read memory for http!g_pUlNonpagedData = %p\n",
  163. dataAddress
  164. );
  165. }
  166. } else {
  167. dprintf(
  168. "uriglob: cannot read memory for http!g_pUlNonpagedData @ %p\n",
  169. address
  170. );
  171. }
  172. } else {
  173. dprintf(
  174. "uriglob: cannot find symbol for http!g_pUlNonpagedData\n"
  175. );
  176. }
  177. #if 0
  178. // BUGBUG: GeorgeRe must fix
  179. //
  180. // Dump table info.
  181. //
  182. if (gotData) {
  183. dprintf(
  184. "UriCacheResource @ %p (%s)\n",
  185. REMOTE_OFFSET( dataAddress, UL_NONPAGED_DATA, UriCacheResource ),
  186. BuildResourceState( &data.UriCacheResource, uriCacheResource )
  187. );
  188. }
  189. address = GetExpression("&http!g_pUriCacheTable");
  190. if (address) {
  191. if (ReadMemory(
  192. address,
  193. &dataAddress,
  194. sizeof(dataAddress),
  195. NULL
  196. ))
  197. {
  198. if (ReadMemory(
  199. dataAddress,
  200. &table,
  201. sizeof(table),
  202. NULL
  203. ))
  204. {
  205. dprintf(
  206. "UL_URI_CACHE_TABLE @ %p:\n"
  207. " UriCount = %d\n"
  208. " ByteCount = %d\n"
  209. " BucketCount = %d\n"
  210. " Buckets @ %p\n"
  211. "\n",
  212. dataAddress,
  213. table.UriCount,
  214. table.ByteCount,
  215. table.BucketCount,
  216. REMOTE_OFFSET( dataAddress, UL_URI_CACHE_TABLE, Buckets )
  217. );
  218. } else {
  219. dprintf(
  220. "uriglob: cannot read memory for http!g_pUriCacheTable = %p\n",
  221. dataAddress
  222. );
  223. }
  224. } else {
  225. dprintf(
  226. "uriglob: cannot read memory for http!g_pUriCacheTable @ %p\n",
  227. address
  228. );
  229. }
  230. } else {
  231. dprintf(
  232. "uriglob: cannot find symbol for http!g_pUriCacheTable\n"
  233. );
  234. }
  235. #endif
  236. //
  237. // Dump Zombie list info.
  238. //
  239. if (gotData) {
  240. dprintf(
  241. "UriZombieResource @ %p (%s)\n",
  242. REMOTE_OFFSET( dataAddress, UL_NONPAGED_DATA, UriZombieResource ),
  243. BuildResourceState( &data.UriZombieResource, uriZombieResource )
  244. );
  245. }
  246. dprintf(
  247. "g_ZombieListHead @ %p\n"
  248. "\n",
  249. GetExpression("&http!g_ZombieListHead")
  250. );
  251. //
  252. // Dump reftrace info
  253. //
  254. address = GetExpression("&http!g_UriTraceLog");
  255. if (address) {
  256. if (ReadMemory(
  257. address,
  258. &dataAddress,
  259. sizeof(dataAddress),
  260. NULL
  261. ))
  262. {
  263. dprintf(
  264. "UL_URI_CACHE_ENTRY ref log: "
  265. "!ulkd.ref %x\n"
  266. "\n",
  267. dataAddress
  268. );
  269. }
  270. }
  271. } // uriglob
  272. DECLARE_API( uri )
  273. /*++
  274. Routine Description:
  275. Dumps a UL_URI_CACHE_ENTRY structure.
  276. Arguments:
  277. Address of structure
  278. Return Value:
  279. None.
  280. --*/
  281. {
  282. ULONG_PTR address = 0;
  283. CHAR star = 0;
  284. ULONG result;
  285. UL_URI_CACHE_ENTRY urientry;
  286. dprintf("BUGBUG: GeorgeRe needs to fix DumpAllUriEntries!\n");
  287. #if 0
  288. SNAPSHOT_EXTENSION_DATA();
  289. //
  290. // Snag the address from the command line.
  291. //
  292. address = GetExpression( args );
  293. if (address == 0)
  294. {
  295. sscanf( args, "%c", &star );
  296. if (star == '*') {
  297. DumpAllUriEntries();
  298. } else {
  299. PrintUsage( "uri" );
  300. }
  301. return;
  302. }
  303. //
  304. // Read the request header.
  305. //
  306. if (!ReadMemory(
  307. address,
  308. &urientry,
  309. sizeof(urientry),
  310. &result
  311. ))
  312. {
  313. dprintf(
  314. "uri: cannot read UL_URI_CACHE_ENTRY @ %p\n",
  315. address
  316. );
  317. return;
  318. }
  319. //
  320. // Dump it.
  321. //
  322. DumpUriEntry(
  323. "",
  324. "uri: ",
  325. address,
  326. &urientry
  327. );
  328. #endif
  329. } // uri
  330. VOID
  331. AnalysisHashTable(
  332. IN ULONG_PTR RemoteAddress,
  333. IN ULONG TableSize,
  334. IN ULONG CacheLineSize
  335. )
  336. {
  337. ULONG_PTR address = 0;
  338. HASHBUCKET bucket;
  339. ULONG i;
  340. ULONG max, min, zeros, total;
  341. FLOAT avg, avg_nonzero;
  342. ULONG result;
  343. max = 0;
  344. min = ULONG_MAX;
  345. total = 0;
  346. zeros = 0;
  347. for (i = 0; i < TableSize; i++)
  348. {
  349. address = (ULONG_PTR)(RemoteAddress + (i * CacheLineSize));
  350. if (!ReadMemory(
  351. address,
  352. &bucket,
  353. sizeof(bucket),
  354. &result
  355. ))
  356. {
  357. dprintf(
  358. "cannot read HASHBUCKET @ %p, i = %d\n",
  359. address,
  360. i
  361. );
  362. break;
  363. }
  364. total += (ULONG) bucket.Entries;
  365. if (bucket.Entries > max)
  366. {
  367. max = (ULONG) bucket.Entries;
  368. }
  369. if (bucket.Entries < min)
  370. {
  371. min = (ULONG) bucket.Entries;
  372. }
  373. if (bucket.Entries == 0)
  374. {
  375. ++zeros;
  376. }
  377. }
  378. avg = (FLOAT)total / (FLOAT)i;
  379. avg_nonzero = (FLOAT)total / (FLOAT)(i - zeros);
  380. dprintf(
  381. "Total Entries = %d:\n"
  382. "MAX Entries in a bucket = %d:\n"
  383. "MIN Entries in a bucket = %d:\n"
  384. "AVG Entries in a bucket = %f:\n"
  385. "ZERO buckets = %d:\n"
  386. "AVG NONZERO Entries in a bucket = %f:\n",
  387. total,
  388. max,
  389. min,
  390. avg,
  391. zeros,
  392. avg_nonzero
  393. );
  394. } // AnalysisHashTable
  395. DECLARE_API( urihash )
  396. /*++
  397. Routine Description:
  398. Dumps URI Cache Hash Table structures.
  399. Arguments:
  400. None.
  401. Return Value:
  402. None.
  403. --*/
  404. {
  405. ULONG_PTR address = 0;
  406. ULONG_PTR address2 = 0;
  407. ULONG_PTR address3 = 0;
  408. HASHTABLE table;
  409. ULONG tablesize;
  410. ULONG cachelinesize;
  411. SNAPSHOT_EXTENSION_DATA();
  412. //
  413. // Dump cache configuration.
  414. //
  415. address = GetExpression( "&http!g_UriCacheTable" );
  416. if (address)
  417. {
  418. if (ReadMemory(
  419. address,
  420. &table,
  421. sizeof(table),
  422. NULL
  423. ))
  424. {
  425. dprintf(
  426. "HASHTABLE @ %p:\n"
  427. " Signature = %d\n"
  428. " PoolType = %d\n"
  429. " NumberOfBytes = %d\n"
  430. " pAllocMem = %p\n"
  431. " pBuckets = %p\n",
  432. address,
  433. table.Signature,
  434. table.PoolType,
  435. table.NumberOfBytes,
  436. table.pAllocMem,
  437. table.pBuckets
  438. );
  439. address2 = GetExpression( "&http!g_UlHashTableSize" );
  440. if (address2)
  441. {
  442. if (ReadMemory(
  443. address2,
  444. &tablesize,
  445. sizeof(tablesize),
  446. NULL
  447. ))
  448. {
  449. address3 = GetExpression( "&http!g_UlCacheLineSize" );
  450. if (address3)
  451. {
  452. if (ReadMemory(
  453. address3,
  454. &cachelinesize,
  455. sizeof(cachelinesize),
  456. NULL
  457. ))
  458. {
  459. AnalysisHashTable((ULONG_PTR)table.pBuckets, tablesize, cachelinesize);
  460. }
  461. else
  462. {
  463. dprintf(
  464. "urihash: cannot read memory for http!g_UlCacheLineSize @ %p\n",
  465. address3
  466. );
  467. }
  468. }
  469. else
  470. {
  471. dprintf(
  472. "urihash: cannot find symbol for http!g_UlCacheLineSize\n"
  473. );
  474. }
  475. }
  476. else
  477. {
  478. dprintf(
  479. "urihash: cannot read memory for http!g_UlHashTableSize @ %p\n",
  480. address2
  481. );
  482. }
  483. }
  484. else
  485. {
  486. dprintf(
  487. "urihash: cannot find symbol for http!g_UlHashTableSize\n"
  488. );
  489. }
  490. }
  491. else
  492. {
  493. dprintf(
  494. "urihash: cannot read memory for http!g_UriCacheTable @ %p\n",
  495. address
  496. );
  497. }
  498. }
  499. else
  500. {
  501. dprintf(
  502. "urihash: cannot find symbol for http!g_UriCacheTable\n"
  503. );
  504. }
  505. } // urihash