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.

576 lines
11 KiB

  1. /*++
  2. Copyright (c) 1998-2001 Microsoft Corporation
  3. Module Name:
  4. counters.h
  5. Abstract:
  6. Contains the performance monitoring counter management
  7. function declarations
  8. Author:
  9. Eric Stenson (ericsten) 25-Sep-2000
  10. Revision History:
  11. --*/
  12. #ifndef __COUNTERS_H__
  13. #define __COUNTERS_H__
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. //
  18. // structure to hold info for Site Counters.
  19. //
  20. typedef struct _UL_SITE_COUNTER_ENTRY {
  21. //
  22. // Signature is UL_SITE_COUNTER_ENTRY_POOL_TAG
  23. //
  24. ULONG Signature;
  25. //
  26. // Ref count for this Site Counter Entry
  27. //
  28. LONG RefCount;
  29. //
  30. // Lock protets whole entry; used primarily when touching
  31. // 64-bit counters
  32. //
  33. FAST_MUTEX EntryMutex;
  34. //
  35. // links all site counter entries
  36. //
  37. LIST_ENTRY ListEntry;
  38. //
  39. // the block which actually contains the counter data to be
  40. // passed back to WAS
  41. //
  42. HTTP_SITE_COUNTERS Counters;
  43. } UL_SITE_COUNTER_ENTRY, *PUL_SITE_COUNTER_ENTRY;
  44. #define IS_VALID_SITE_COUNTER_ENTRY( entry ) \
  45. ( (entry != NULL) && ((entry)->Signature == UL_SITE_COUNTER_ENTRY_POOL_TAG) )
  46. //
  47. // Private globals
  48. //
  49. extern BOOLEAN g_InitCountersCalled;
  50. extern HTTP_GLOBAL_COUNTERS g_UlGlobalCounters;
  51. extern FAST_MUTEX g_SiteCounterListMutex;
  52. extern LIST_ENTRY g_SiteCounterListHead;
  53. extern LONG g_SiteCounterListCount;
  54. extern HTTP_PROP_DESC aIISULGlobalDescription[];
  55. extern HTTP_PROP_DESC aIISULSiteDescription[];
  56. //
  57. // Init
  58. //
  59. NTSTATUS
  60. UlInitializeCounters(
  61. VOID
  62. );
  63. VOID
  64. UlTerminateCounters(
  65. VOID
  66. );
  67. //
  68. // Site Counter Entry
  69. //
  70. NTSTATUS
  71. UlCreateSiteCounterEntry(
  72. IN OUT PUL_CONFIG_GROUP_OBJECT pConfigGroup,
  73. IN ULONG SiteId
  74. );
  75. #if REFERENCE_DEBUG
  76. VOID
  77. UlDereferenceSiteCounterEntry(
  78. IN PUL_SITE_COUNTER_ENTRY pEntry
  79. REFERENCE_DEBUG_FORMAL_PARAMS
  80. );
  81. #define DEREFERENCE_SITE_COUNTER_ENTRY( pSC ) \
  82. UlDereferenceSiteCounterEntry( \
  83. (pSC) \
  84. REFERENCE_DEBUG_ACTUAL_PARAMS \
  85. )
  86. VOID
  87. UlReferenceSiteCounterEntry(
  88. IN PUL_SITE_COUNTER_ENTRY pEntry
  89. REFERENCE_DEBUG_FORMAL_PARAMS
  90. );
  91. #define REFERENCE_SITE_COUNTER_ENTRY( pSC ) \
  92. UlReferenceSiteCounterEntry( \
  93. (pSC) \
  94. REFERENCE_DEBUG_ACTUAL_PARAMS \
  95. )
  96. #else
  97. __inline
  98. VOID
  99. FASTCALL
  100. UlReferenceSiteCounterEntry(
  101. IN PUL_SITE_COUNTER_ENTRY pEntry
  102. )
  103. {
  104. InterlockedIncrement(&pEntry->RefCount);
  105. }
  106. __inline
  107. VOID
  108. FASTCALL
  109. UlDereferenceSiteCounterEntry(
  110. IN PUL_SITE_COUNTER_ENTRY pEntry
  111. )
  112. {
  113. if (InterlockedDecrement(&pEntry->RefCount) == 0)
  114. {
  115. ExAcquireFastMutex(&g_SiteCounterListMutex);
  116. RemoveEntryList(&pEntry->ListEntry);
  117. pEntry->ListEntry.Flink = pEntry->ListEntry.Blink = NULL;
  118. g_SiteCounterListCount--;
  119. ExReleaseFastMutex(&g_SiteCounterListMutex);
  120. UL_FREE_POOL_WITH_SIG(pEntry, UL_SITE_COUNTER_ENTRY_POOL_TAG);
  121. }
  122. }
  123. #define REFERENCE_SITE_COUNTER_ENTRY UlReferenceSiteCounterEntry
  124. #define DEREFERENCE_SITE_COUNTER_ENTRY UlDereferenceSiteCounterEntry
  125. #endif
  126. //
  127. // Global (cache) counters
  128. //
  129. #if REFERENCE_DEBUG
  130. VOID
  131. UlIncCounter(
  132. HTTP_GLOBAL_COUNTER_ID Ctr
  133. );
  134. VOID
  135. UlDecCounter(
  136. HTTP_GLOBAL_COUNTER_ID Ctr
  137. );
  138. VOID
  139. UlAddCounter(
  140. HTTP_GLOBAL_COUNTER_ID Ctr,
  141. ULONG Value
  142. );
  143. VOID
  144. UlResetCounter(
  145. HTTP_GLOBAL_COUNTER_ID Ctr
  146. );
  147. #else
  148. __inline
  149. VOID
  150. FASTCALL
  151. UlIncCounter(
  152. IN HTTP_GLOBAL_COUNTER_ID CounterId
  153. )
  154. {
  155. PCHAR pCounter;
  156. pCounter = (PCHAR)&g_UlGlobalCounters;
  157. pCounter += aIISULGlobalDescription[CounterId].Offset;
  158. if (sizeof(ULONG) == aIISULGlobalDescription[CounterId].Size)
  159. {
  160. InterlockedIncrement((PLONG)pCounter);
  161. }
  162. else
  163. {
  164. UlInterlockedIncrement64((PLONGLONG)pCounter);
  165. }
  166. }
  167. __inline
  168. VOID
  169. FASTCALL
  170. UlDecCounter(
  171. IN HTTP_GLOBAL_COUNTER_ID CounterId
  172. )
  173. {
  174. PCHAR pCounter;
  175. pCounter = (PCHAR)&g_UlGlobalCounters;
  176. pCounter += aIISULGlobalDescription[CounterId].Offset;
  177. if (sizeof(ULONG) == aIISULGlobalDescription[CounterId].Size)
  178. {
  179. InterlockedDecrement((PLONG)pCounter);
  180. }
  181. else
  182. {
  183. UlInterlockedDecrement64((PLONGLONG)pCounter);
  184. }
  185. }
  186. __inline
  187. VOID
  188. FASTCALL
  189. UlAddCounter(
  190. IN HTTP_GLOBAL_COUNTER_ID CounterId,
  191. IN ULONG Value
  192. )
  193. {
  194. PCHAR pCounter;
  195. pCounter = (PCHAR)&g_UlGlobalCounters;
  196. pCounter += aIISULGlobalDescription[CounterId].Offset;
  197. if (sizeof(ULONG) == aIISULGlobalDescription[CounterId].Size)
  198. {
  199. InterlockedExchangeAdd((PLONG)pCounter, Value);
  200. }
  201. else
  202. {
  203. UlInterlockedAdd64((PLONGLONG)pCounter, Value);
  204. }
  205. }
  206. __inline
  207. VOID
  208. FASTCALL
  209. UlResetCounter(
  210. IN HTTP_GLOBAL_COUNTER_ID CounterId
  211. )
  212. {
  213. PCHAR pCounter;
  214. pCounter = (PCHAR)&g_UlGlobalCounters;
  215. pCounter += aIISULGlobalDescription[CounterId].Offset;
  216. if (sizeof(ULONG) == aIISULGlobalDescription[CounterId].Size)
  217. {
  218. InterlockedExchange((PLONG)pCounter, 0);
  219. }
  220. else
  221. {
  222. UlInterlockedExchange64((PLONGLONG)pCounter, 0);
  223. }
  224. }
  225. #endif
  226. //
  227. // Instance (site) counters
  228. //
  229. #if REFERENCE_DEBUG
  230. VOID
  231. UlIncSiteNonCriticalCounterUlong(
  232. PUL_SITE_COUNTER_ENTRY pEntry,
  233. HTTP_SITE_COUNTER_ID CounterId
  234. );
  235. VOID
  236. UlIncSiteNonCriticalCounterUlonglong(
  237. PUL_SITE_COUNTER_ENTRY pEntry,
  238. HTTP_SITE_COUNTER_ID CounterId
  239. );
  240. LONGLONG
  241. UlIncSiteCounter(
  242. PUL_SITE_COUNTER_ENTRY pEntry,
  243. HTTP_SITE_COUNTER_ID Ctr
  244. );
  245. VOID
  246. UlDecSiteCounter(
  247. PUL_SITE_COUNTER_ENTRY pEntry,
  248. HTTP_SITE_COUNTER_ID Ctr
  249. );
  250. VOID
  251. UlAddSiteCounter(
  252. PUL_SITE_COUNTER_ENTRY pEntry,
  253. HTTP_SITE_COUNTER_ID Ctr,
  254. ULONG Value
  255. );
  256. VOID
  257. UlAddSiteCounter64(
  258. PUL_SITE_COUNTER_ENTRY pEntry,
  259. HTTP_SITE_COUNTER_ID Ctr,
  260. ULONGLONG llValue
  261. );
  262. VOID
  263. UlResetSiteCounter(
  264. PUL_SITE_COUNTER_ENTRY pEntry,
  265. HTTP_SITE_COUNTER_ID Ctr
  266. );
  267. VOID
  268. UlMaxSiteCounter(
  269. PUL_SITE_COUNTER_ENTRY pEntry,
  270. HTTP_SITE_COUNTER_ID Ctr,
  271. ULONG Value
  272. );
  273. VOID
  274. UlMaxSiteCounter64(
  275. PUL_SITE_COUNTER_ENTRY pEntry,
  276. HTTP_SITE_COUNTER_ID Ctr,
  277. LONGLONG llValue
  278. );
  279. #else
  280. __inline
  281. VOID
  282. UlIncSiteNonCriticalCounterUlong(
  283. PUL_SITE_COUNTER_ENTRY pEntry,
  284. HTTP_SITE_COUNTER_ID CounterId
  285. )
  286. {
  287. PCHAR pCounter;
  288. PLONG plValue;
  289. pCounter = (PCHAR) &(pEntry->Counters);
  290. pCounter += aIISULSiteDescription[CounterId].Offset;
  291. plValue = (PLONG) pCounter;
  292. ++(*plValue);
  293. }
  294. __inline
  295. VOID
  296. UlIncSiteNonCriticalCounterUlonglong(
  297. PUL_SITE_COUNTER_ENTRY pEntry,
  298. HTTP_SITE_COUNTER_ID CounterId
  299. )
  300. {
  301. PCHAR pCounter;
  302. PLONGLONG pllValue;
  303. pCounter = (PCHAR) &(pEntry->Counters);
  304. pCounter += aIISULSiteDescription[CounterId].Offset;
  305. pllValue = (PLONGLONG) pCounter;
  306. ++(*pllValue);
  307. }
  308. __inline
  309. LONGLONG
  310. FASTCALL
  311. UlIncSiteCounter(
  312. IN PUL_SITE_COUNTER_ENTRY pEntry,
  313. IN HTTP_SITE_COUNTER_ID CounterId
  314. )
  315. {
  316. PCHAR pCounter;
  317. pCounter = (PCHAR)&pEntry->Counters;
  318. pCounter += aIISULSiteDescription[CounterId].Offset;
  319. if (sizeof(ULONG) == aIISULSiteDescription[CounterId].Size)
  320. {
  321. return (LONGLONG)InterlockedIncrement((PLONG)pCounter);
  322. }
  323. else
  324. {
  325. return UlInterlockedIncrement64((PLONGLONG)pCounter);
  326. }
  327. }
  328. __inline
  329. VOID
  330. FASTCALL
  331. UlDecSiteCounter(
  332. IN PUL_SITE_COUNTER_ENTRY pEntry,
  333. IN HTTP_SITE_COUNTER_ID CounterId
  334. )
  335. {
  336. PCHAR pCounter;
  337. pCounter = (PCHAR)&pEntry->Counters;
  338. pCounter += aIISULSiteDescription[CounterId].Offset;
  339. if (sizeof(ULONG) == aIISULSiteDescription[CounterId].Size)
  340. {
  341. InterlockedDecrement((PLONG)pCounter);
  342. }
  343. else
  344. {
  345. UlInterlockedDecrement64((PLONGLONG)pCounter);
  346. }
  347. }
  348. __inline
  349. VOID
  350. FASTCALL
  351. UlAddSiteCounter(
  352. IN PUL_SITE_COUNTER_ENTRY pEntry,
  353. IN HTTP_SITE_COUNTER_ID CounterId,
  354. IN ULONG Value
  355. )
  356. {
  357. PCHAR pCounter;
  358. pCounter = (PCHAR)&pEntry->Counters;
  359. pCounter += aIISULSiteDescription[CounterId].Offset;
  360. InterlockedExchangeAdd((PLONG)pCounter, Value);
  361. }
  362. __inline
  363. VOID
  364. FASTCALL
  365. UlAddSiteCounter64(
  366. IN PUL_SITE_COUNTER_ENTRY pEntry,
  367. IN HTTP_SITE_COUNTER_ID CounterId,
  368. IN ULONGLONG Value
  369. )
  370. {
  371. PCHAR pCounter;
  372. pCounter = (PCHAR)&pEntry->Counters;
  373. pCounter += aIISULSiteDescription[CounterId].Offset;
  374. UlInterlockedAdd64((PLONGLONG)pCounter, Value);
  375. }
  376. __inline
  377. VOID
  378. FASTCALL
  379. UlResetSiteCounter(
  380. IN PUL_SITE_COUNTER_ENTRY pEntry,
  381. IN HTTP_SITE_COUNTER_ID CounterId
  382. )
  383. {
  384. PCHAR pCounter;
  385. pCounter = (PCHAR)&pEntry->Counters;
  386. pCounter += aIISULSiteDescription[CounterId].Offset;
  387. if (sizeof(ULONG) == aIISULSiteDescription[CounterId].Size)
  388. {
  389. InterlockedExchange((PLONG)pCounter, 0);
  390. }
  391. else
  392. {
  393. UlInterlockedExchange64((PLONGLONG)pCounter, 0);
  394. }
  395. }
  396. __inline
  397. VOID
  398. FASTCALL
  399. UlMaxSiteCounter(
  400. IN PUL_SITE_COUNTER_ENTRY pEntry,
  401. IN HTTP_SITE_COUNTER_ID CounterId,
  402. IN ULONG Value
  403. )
  404. {
  405. PCHAR pCounter;
  406. LONG LocalMaxed;
  407. pCounter = (PCHAR)&pEntry->Counters;
  408. pCounter += aIISULSiteDescription[CounterId].Offset;
  409. do {
  410. LocalMaxed = *((volatile LONG *)pCounter);
  411. if ((LONG)Value <= LocalMaxed)
  412. {
  413. break;
  414. }
  415. } while (LocalMaxed != InterlockedCompareExchange(
  416. (PLONG)pCounter,
  417. Value,
  418. LocalMaxed
  419. ));
  420. }
  421. __inline
  422. VOID
  423. FASTCALL
  424. UlMaxSiteCounter64(
  425. IN PUL_SITE_COUNTER_ENTRY pEntry,
  426. IN HTTP_SITE_COUNTER_ID CounterId,
  427. IN LONGLONG Value
  428. )
  429. {
  430. PCHAR pCounter;
  431. LONGLONG LocalMaxed;
  432. pCounter = (PCHAR)&pEntry->Counters;
  433. pCounter += aIISULSiteDescription[CounterId].Offset;
  434. do {
  435. LocalMaxed = *((volatile LONGLONG *)pCounter);
  436. if (Value <= LocalMaxed)
  437. {
  438. break;
  439. }
  440. } while (LocalMaxed != InterlockedCompareExchange64(
  441. (PLONGLONG)pCounter,
  442. Value,
  443. LocalMaxed
  444. ));
  445. }
  446. #endif
  447. //
  448. // Collection
  449. //
  450. NTSTATUS
  451. UlGetGlobalCounters(
  452. PVOID IN OUT pCounter,
  453. ULONG IN BlockSize,
  454. PULONG OUT pBytesWritten
  455. );
  456. NTSTATUS
  457. UlGetSiteCounters(
  458. PVOID IN OUT pCounter,
  459. ULONG IN BlockSize,
  460. PULONG OUT pBytesWritten,
  461. PULONG OUT pBlocksWritten
  462. );
  463. #ifdef __cplusplus
  464. }; // extern "C"
  465. #endif
  466. #endif // __COUNTERS_H__