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.

233 lines
6.9 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. perfcach.c
  5. Abstract:
  6. This file implements an Performance Object that presents
  7. File System Cache data
  8. Created:
  9. Bob Watson 22-Oct-1996
  10. Revision History
  11. --*/
  12. //
  13. // Include Files
  14. //
  15. #include <nt.h>
  16. #include <ntrtl.h>
  17. #include <nturtl.h>
  18. #include <windows.h>
  19. #include <winperf.h>
  20. #include <ntprfctr.h>
  21. #include <perfutil.h>
  22. #include <assert.h>
  23. #include "perfos.h"
  24. #include "datacach.h"
  25. //
  26. // The following special defines are used to produce numbers for
  27. // cache measurement counters
  28. //
  29. #define SYNC_ASYNC(FLD) ((SysPerfInfo.FLD##Wait) + (SysPerfInfo.FLD##NoWait))
  30. //
  31. // Hit Rate Macro
  32. //
  33. #define HITRATE(FLD) (((Changes = SysPerfInfo.FLD) == 0) ? 0 : \
  34. ((Changes < (Misses = SysPerfInfo.FLD##Miss)) ? 0 : \
  35. (Changes - Misses) ))
  36. //
  37. // Hit Rate Macro combining Sync and Async cases
  38. //
  39. #define SYNC_ASYNC_HITRATE(FLD) (((Changes = SYNC_ASYNC(FLD)) == 0) ? 0 : \
  40. ((Changes < \
  41. (Misses = SysPerfInfo.FLD##WaitMiss + \
  42. SysPerfInfo.FLD##NoWaitMiss) \
  43. ) ? 0 : \
  44. (Changes - Misses) ))
  45. DWORD APIENTRY
  46. CollectCacheObjectData (
  47. IN OUT LPVOID *lppData,
  48. IN OUT LPDWORD lpcbTotalBytes,
  49. IN OUT LPDWORD lpNumObjectTypes
  50. )
  51. /*++
  52. Routine Description:
  53. This routine will return the data for the XXX object
  54. Arguments:
  55. IN OUT LPVOID *lppData
  56. IN: pointer to the address of the buffer to receive the completed
  57. PerfDataBlock and subordinate structures. This routine will
  58. append its data to the buffer starting at the point referenced
  59. by *lppData.
  60. OUT: points to the first byte after the data structure added by this
  61. routine. This routine updated the value at lppdata after appending
  62. its data.
  63. IN OUT LPDWORD lpcbTotalBytes
  64. IN: the address of the DWORD that tells the size in bytes of the
  65. buffer referenced by the lppData argument
  66. OUT: the number of bytes added by this routine is writted to the
  67. DWORD pointed to by this argument
  68. IN OUT LPDWORD NumObjectTypes
  69. IN: the address of the DWORD to receive the number of objects added
  70. by this routine
  71. OUT: the number of objects added by this routine is writted to the
  72. DWORD pointed to by this argument
  73. Returns:
  74. 0 if successful, else Win 32 error code of failure
  75. --*/
  76. {
  77. DWORD TotalLen; // Length of the total return block
  78. DWORD Changes; // Used by macros to compute cache
  79. DWORD Misses; // ...statistics
  80. PCACHE_DATA_DEFINITION pCacheDataDefinition;
  81. PCACHE_COUNTER_DATA pCCD;
  82. //
  83. // Check for enough space for cache data block
  84. //
  85. pCacheDataDefinition = (CACHE_DATA_DEFINITION *) *lppData;
  86. TotalLen = sizeof(CACHE_DATA_DEFINITION) +
  87. sizeof(CACHE_COUNTER_DATA);
  88. TotalLen = QWORD_MULTIPLE(TotalLen);
  89. if ( *lpcbTotalBytes < TotalLen ) {
  90. *lpcbTotalBytes = (DWORD) 0;
  91. *lpNumObjectTypes = (DWORD) 0;
  92. return ERROR_MORE_DATA;
  93. }
  94. //
  95. // Define cache data block
  96. //
  97. memcpy (pCacheDataDefinition,
  98. &CacheDataDefinition,
  99. sizeof(CACHE_DATA_DEFINITION));
  100. //
  101. // Format and collect memory data
  102. //
  103. pCCD = (PCACHE_COUNTER_DATA)&pCacheDataDefinition[1];
  104. // No need to align this since it is the only counter block
  105. // and the total byte will be aligned.
  106. pCCD->CounterBlock.ByteLength = sizeof(CACHE_COUNTER_DATA);
  107. //
  108. // The Data Map counter is the sum of the Wait/NoWait cases
  109. //
  110. pCCD->DataMaps = SYNC_ASYNC(CcMapData);
  111. pCCD->SyncDataMaps = SysPerfInfo.CcMapDataWait;
  112. pCCD->AsyncDataMaps = SysPerfInfo.CcMapDataNoWait;
  113. //
  114. // The Data Map Hits is a percentage of Data Maps that hit
  115. // the cache; second counter is the base (divisor)
  116. //
  117. pCCD->DataMapHits = SYNC_ASYNC_HITRATE(CcMapData);
  118. pCCD->DataMapHitsBase = SYNC_ASYNC(CcMapData);
  119. //
  120. // The next pair of counters forms a percentage of
  121. // Pins as a portion of Data Maps
  122. //
  123. pCCD->DataMapPins = SysPerfInfo.CcPinMappedDataCount;
  124. pCCD->DataMapPinsBase = SYNC_ASYNC(CcMapData);
  125. pCCD->PinReads = SYNC_ASYNC(CcPinRead);
  126. pCCD->SyncPinReads = SysPerfInfo.CcPinReadWait;
  127. pCCD->AsyncPinReads = SysPerfInfo.CcPinReadNoWait;
  128. //
  129. // The Pin Read Hits is a percentage of Pin Reads that hit
  130. // the cache; second counter is the base (divisor)
  131. //
  132. pCCD->PinReadHits = SYNC_ASYNC_HITRATE(CcPinRead);
  133. pCCD->PinReadHitsBase = SYNC_ASYNC(CcPinRead);
  134. pCCD->CopyReads = SYNC_ASYNC(CcCopyRead);
  135. pCCD->SyncCopyReads = SysPerfInfo.CcCopyReadWait;
  136. pCCD->AsyncCopyReads = SysPerfInfo.CcCopyReadNoWait;
  137. //
  138. // The Copy Read Hits is a percentage of Copy Reads that hit
  139. // the cache; second counter is the base (divisor)
  140. //
  141. pCCD->CopyReadHits = SYNC_ASYNC_HITRATE(CcCopyRead);
  142. pCCD->CopyReadHitsBase = SYNC_ASYNC(CcCopyRead);
  143. pCCD->MdlReads = SYNC_ASYNC(CcMdlRead);
  144. pCCD->SyncMdlReads = SysPerfInfo.CcMdlReadWait;
  145. pCCD->AsyncMdlReads = SysPerfInfo.CcMdlReadNoWait;
  146. //
  147. // The Mdl Read Hits is a percentage of Mdl Reads that hit
  148. // the cache; second counter is the base (divisor)
  149. //
  150. pCCD->MdlReadHits = SYNC_ASYNC_HITRATE(CcMdlRead);
  151. pCCD->MdlReadHitsBase = SYNC_ASYNC(CcMdlRead);
  152. pCCD->ReadAheads = SysPerfInfo.CcReadAheadIos;
  153. pCCD->FastReads = SYNC_ASYNC(CcFastRead);
  154. pCCD->SyncFastReads = SysPerfInfo.CcFastReadWait;
  155. pCCD->AsyncFastReads = SysPerfInfo.CcFastReadNoWait;
  156. pCCD->FastReadResourceMiss = SysPerfInfo.CcFastReadResourceMiss;
  157. pCCD->FastReadNotPossibles = SysPerfInfo.CcFastReadNotPossible;
  158. pCCD->LazyWriteFlushes = SysPerfInfo.CcLazyWriteIos;
  159. pCCD->LazyWritePages = SysPerfInfo.CcLazyWritePages;
  160. pCCD->DataFlushes = SysPerfInfo.CcDataFlushes;
  161. pCCD->DataPages = SysPerfInfo.CcDataPages;
  162. *lpcbTotalBytes =
  163. pCacheDataDefinition->CacheObjectType.TotalByteLength =
  164. (DWORD) QWORD_MULTIPLE(((LPBYTE) (& pCCD[1])) - (LPBYTE) pCacheDataDefinition);
  165. * lppData = (LPVOID) (((LPBYTE) pCacheDataDefinition) + * lpcbTotalBytes);
  166. assert(*lpcbTotalBytes == TotalLen);
  167. *lpNumObjectTypes = 1;
  168. return ERROR_SUCCESS;
  169. }