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.

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