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.

308 lines
9.7 KiB

  1. /*==========================================================================*\
  2. Module: exprflib.h
  3. Copyright Microsoft Corporation 1998, All Rights Reserved.
  4. Author: WayneC
  5. Descriptions: This is the header for exprflib.h a perf library. This
  6. is the code that runs in the app exporting the counters.
  7. \*==========================================================================*/
  8. #ifndef __PERFLIB_H__
  9. #define __PERFLIB_H__
  10. ///////////////////////////////////////////////////////////////////////////////
  11. //
  12. // Includes
  13. //
  14. ///////////////////////////////////////////////////////////////////////////////
  15. #include <windows.h>
  16. #include <winperf.h>
  17. #include <stdio.h>
  18. #ifdef STAXMEM
  19. #include <exchmem.h>
  20. #endif
  21. ///////////////////////////////////////////////////////////////////////////////
  22. //
  23. // Data Structures / typedefs / misc defines
  24. //
  25. ///////////////////////////////////////////////////////////////////////////////
  26. #define MAX_PERF_NAME 16
  27. #define MAX_OBJECT_NAME 16
  28. #define MAX_INSTANCE_NAME 16
  29. #define MAX_PERF_OBJECTS 16
  30. #define MAX_OBJECT_COUNTERS 200
  31. #define SHMEM_MAPPING_SIZE 32768
  32. typedef WCHAR OBJECTNAME[MAX_OBJECT_NAME];
  33. typedef WCHAR INSTANCENAME[MAX_INSTANCE_NAME];
  34. typedef unsigned __int64 QWORD;
  35. struct INSTANCE_DATA
  36. {
  37. BOOL fActive;
  38. PERF_INSTANCE_DEFINITION perfInstDef;
  39. INSTANCENAME wszInstanceName;
  40. };
  41. ///////////////////////////////////////////////////////////////////////////////
  42. //
  43. // Forward class declarations
  44. //
  45. ///////////////////////////////////////////////////////////////////////////////
  46. class PerfObjectInstance;
  47. class PerfCounterDefinition;
  48. class PerfObjectDefinition;
  49. ///////////////////////////////////////////////////////////////////////////////
  50. //
  51. // Local memory management
  52. //
  53. ///////////////////////////////////////////////////////////////////////////////
  54. #ifdef STAXMEM
  55. #undef new
  56. #endif
  57. class MemoryModule
  58. {
  59. public:
  60. #ifdef STAXMEM
  61. #ifdef DEBUG
  62. void* operator new (size_t cb, char * szFile, DWORD dwLine)
  63. { return ExchMHeapAllocDebug (cb, szFile, dwLine); }
  64. #else //!DEBUG
  65. void* operator new (size_t cb)
  66. { return ExchMHeapAlloc (cb); }
  67. #endif
  68. void operator delete(void* pv)
  69. { ExchMHeapFree (pv); };
  70. #endif
  71. };
  72. #ifdef STAXMEM
  73. #ifdef DEBUG
  74. #define new new(__FILE__, __LINE__)
  75. #endif
  76. #endif
  77. ///////////////////////////////////////////////////////////////////////////////
  78. //
  79. // Shared memory management
  80. //
  81. ///////////////////////////////////////////////////////////////////////////////
  82. typedef struct _SharedMemorySegment : public MemoryModule
  83. {
  84. HANDLE m_hMap;
  85. PBYTE m_pbMap;
  86. struct _SharedMemorySegment * m_pSMSNext;
  87. } SharedMemorySegment;
  88. ///////////////////////////////////////////////////////////////////////////////
  89. //
  90. // PerfLibrary class declaration. There is one perf library instance per linkee.
  91. //
  92. ///////////////////////////////////////////////////////////////////////////////
  93. class PerfLibrary : public MemoryModule
  94. {
  95. friend class PerfObjectDefinition;
  96. friend class PerfCounterDefinition;
  97. private:
  98. // Name of this performance module
  99. WCHAR m_wszPerfName[MAX_PERF_NAME];
  100. // Array of PerfObjectDefinition's and a count of how many there are.
  101. PerfObjectDefinition* m_rgpObjDef[MAX_PERF_OBJECTS];
  102. DWORD m_dwObjDef;
  103. // Shared memory handle and pointer to base of shared memory
  104. HANDLE m_hMap;
  105. PBYTE m_pbMap;
  106. // Pointers to places in the shared memory where we keep stuff
  107. DWORD* m_pdwObjectNames;
  108. OBJECTNAME* m_prgObjectNames;
  109. // Base values for title text and help text for the library
  110. DWORD m_dwFirstHelp;
  111. DWORD m_dwFirstCounter;
  112. void AddPerfObjectDefinition (PerfObjectDefinition* pObjDef);
  113. public:
  114. PerfLibrary (LPCWSTR pcwstrPerfName);
  115. ~PerfLibrary (void);
  116. PerfObjectDefinition* AddPerfObjectDefinition (LPCWSTR pcwstrObjectName,
  117. DWORD dwObjectNameIndex,
  118. BOOL fInstances);
  119. BOOL Init (void);
  120. void DeInit (void);
  121. };
  122. ///////////////////////////////////////////////////////////////////////////////
  123. //
  124. // PerfObjectDefinition class declaration. There is one of these for each
  125. // perfmon object exported. Generally there is just one, but not neccessarily.
  126. //
  127. ///////////////////////////////////////////////////////////////////////////////
  128. class PerfObjectDefinition : public MemoryModule
  129. {
  130. friend class PerfLibrary;
  131. friend class PerfCounterDefinition;
  132. friend class PerfObjectInstance;
  133. private:
  134. WCHAR m_wszObjectName[MAX_OBJECT_NAME];
  135. DWORD m_dwObjectNameIndex;
  136. BOOL m_fInstances;
  137. PerfCounterDefinition* m_rgpCounterDef[MAX_OBJECT_COUNTERS];
  138. DWORD m_dwCounters;
  139. DWORD m_dwDefinitionLength;
  140. DWORD m_dwCounterData;
  141. DWORD m_dwPerInstanceData;
  142. PERF_OBJECT_TYPE* m_pPerfObjectType;
  143. PERF_COUNTER_DEFINITION* m_rgPerfCounterDefinition;
  144. DWORD m_dwActiveInstances;
  145. SharedMemorySegment* m_pSMS;
  146. DWORD m_dwShmemMappingSize;
  147. DWORD m_dwInstancesPerMapping;
  148. DWORD m_dwInstances1stMapping;
  149. CRITICAL_SECTION m_csPerfObjInst;
  150. BOOL m_fCSInit;
  151. PerfObjectInstance* m_pPoiTotal;
  152. BOOL Init (PerfLibrary* pPerfLib);
  153. void DeInit (void);
  154. void AddPerfCounterDefinition (PerfCounterDefinition* pcd);
  155. DWORD GetCounterOffset (DWORD dwId);
  156. public:
  157. PerfObjectDefinition (LPCWSTR pwcstrObjectName,
  158. DWORD dwObjectNameIndex,
  159. BOOL fInstances = FALSE);
  160. ~PerfObjectDefinition (void);
  161. PerfCounterDefinition* AddPerfCounterDefinition (
  162. DWORD dwCounterNameIndex,
  163. DWORD dwCounterType,
  164. LONG lDefaultScale = 0);
  165. PerfCounterDefinition* AddPerfCounterDefinition (
  166. PerfCounterDefinition * pCtrRef,
  167. DWORD dwCounterNameIndex,
  168. DWORD dwCounterType,
  169. LONG lDefaultScale = 0);
  170. PerfObjectInstance* AddPerfObjectInstance (LPCWSTR pwcstrInstanceName);
  171. void DeletePerfObjectInstance ();
  172. };
  173. ///////////////////////////////////////////////////////////////////////////////
  174. //
  175. // PerfCounterDefinition class declaration. There is one of these per counter.
  176. //
  177. ///////////////////////////////////////////////////////////////////////////////
  178. class PerfCounterDefinition : public MemoryModule
  179. {
  180. friend class PerfObjectDefinition;
  181. private:
  182. PerfObjectDefinition* m_pObjDef;
  183. PerfCounterDefinition* m_pCtrRef;
  184. DWORD m_dwCounterNameIndex;
  185. LONG m_lDefaultScale;
  186. DWORD m_dwCounterType;
  187. DWORD m_dwCounterSize;
  188. DWORD m_dwOffset;
  189. void Init (PerfLibrary* pPerfLib,
  190. PERF_COUNTER_DEFINITION* pdef,
  191. PDWORD pdwOffset);
  192. public:
  193. PerfCounterDefinition (DWORD dwCounterNameIndex,
  194. DWORD dwCounterType = PERF_COUNTER_COUNTER,
  195. LONG lDefaultScale = 0);
  196. PerfCounterDefinition (PerfCounterDefinition* pRefCtr,
  197. DWORD dwCounterNameIndex,
  198. DWORD dwCounterType = PERF_COUNTER_COUNTER,
  199. LONG lDefaultScale = 0);
  200. };
  201. ///////////////////////////////////////////////////////////////////////////////
  202. //
  203. // PerfObjectInstance class declaration. There is one of these per instance
  204. // of an object. There is one if there are no instances (the global instance.)
  205. //
  206. // NOTE: User is responsible for allocating space and Init this object after
  207. // the PerfLibrary is initialized. When destroying the perf counters,
  208. // this object must be destroyed before the PerfLibrary is deinitialized.
  209. //
  210. ///////////////////////////////////////////////////////////////////////////////
  211. class PerfObjectInstance : public MemoryModule
  212. {
  213. friend class PerfObjectDefinition;
  214. private:
  215. PerfObjectDefinition* m_pObjDef;
  216. WCHAR m_wszInstanceName[MAX_INSTANCE_NAME];
  217. INSTANCE_DATA* m_pInstanceData;
  218. char* m_pCounterData;
  219. BOOL m_fInitialized;
  220. void Init (char* pCounterData,
  221. INSTANCE_DATA* pInstData,
  222. LONG lID);
  223. public:
  224. PerfObjectInstance (PerfObjectDefinition* pObjDef,
  225. LPCWSTR pwcstrInstanceName);
  226. ~PerfObjectInstance () { DeInit(); };
  227. VOID DeInit (void);
  228. BOOL FIsInitialized () {return m_fInitialized; };
  229. DWORD * GetDwordCounter (DWORD dwId);
  230. LARGE_INTEGER * GetLargeIntegerCounter (DWORD dwId);
  231. QWORD * GetQwordCounter (DWORD dwId);
  232. PERF_OBJECT_TYPE * GetPerfObjectType ();
  233. };
  234. #endif