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.

229 lines
6.5 KiB

  1. #ifndef _PCLIB_H_
  2. #define _PCLIB_H_
  3. #include <winperf.h>
  4. // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  5. //
  6. // PCLIB.H
  7. //
  8. // Public interface to PCLIB to be used by perf counter data
  9. // generating and monitoring components.
  10. //
  11. // Copyright 1986-1998 Microsoft Corporation, All Rights Reserved
  12. //
  13. //
  14. // A signature that uniquely identifies the component whose perf counters are
  15. // being implemented. This must be identical to the value of the drivername
  16. // key in the [info] section of the perf counter INI file. It is used to
  17. // locate the counters' "first counter" information in the registry.
  18. //
  19. EXTERN_C const WCHAR gc_wszPerfdataSource[];
  20. // The signature of the perf counter dll.
  21. // NOTE: This is usually NOT the same as the monitor component signature above!
  22. // This variable is defined to MATCH the definition in \cal\src\inc\eventlog.h.
  23. //
  24. EXTERN_C const WCHAR gc_wszSignature[];
  25. // Gives the count of elements in an array
  26. //
  27. #ifndef CElems
  28. #define CElems(_rg) (sizeof(_rg)/sizeof(_rg[0]))
  29. #endif // !CElems
  30. // ************************************************************************
  31. //
  32. // INTERFACE for counter data generating processes
  33. //
  34. // ========================================================================
  35. //
  36. // CLASS IPerfCounterBlock
  37. //
  38. // Created by IPerfObject::NewInstance(). A perf counter block
  39. // encapsulates the set of counters for a given instance. The
  40. // methods of this interface define the mechanism for changing
  41. // the values of the counters in the counter block.
  42. //
  43. class IPerfCounterBlock
  44. {
  45. public:
  46. // CREATORS
  47. //
  48. virtual ~IPerfCounterBlock() = 0;
  49. // MANIPULATORS
  50. //
  51. virtual VOID IncrementCounter( UINT iCounter ) = 0;
  52. virtual VOID DecrementCounter( UINT iCounter ) = 0;
  53. virtual VOID SetCounter( UINT iCounter, LONG lValue ) = 0;
  54. };
  55. // ========================================================================
  56. //
  57. // CLASS IPerfObject
  58. //
  59. // Created by PCLIB::NewPerfObject(). A perf object defines a set of
  60. // counters. In terms of the NT perf counter structures, a perf object
  61. // encapsulates a PERF_OBJECT_TYPE and its PERF_COUNTER_DEFINITIONs.
  62. //
  63. // IPerfObject::NewInstance() creates a new instance of this perf object
  64. // from a PERF_INSTANCE_DEFINITION and a PERF_COUNTER_BLOCK. All values
  65. // of both structures must be properly initialized prior to calling
  66. // IPerfObject::NewInstance() following standard conventions for these
  67. // structures. I.e. the instance name must immediately follow the
  68. // PERF_INSTANCE_DEFINITION structure, and the PERF_COUNTER_BLOCK must
  69. // be DWORD-aligned following the name. The PERF_COUNTER_BLOCK should
  70. // be followed by the counters themselves. Read the documentation for
  71. // these structures if you're confused.
  72. //
  73. class IPerfObject
  74. {
  75. public:
  76. // CREATORS
  77. //
  78. virtual ~IPerfObject() = 0;
  79. // MANIPULATORS
  80. //
  81. virtual IPerfCounterBlock *
  82. NewInstance( const PERF_INSTANCE_DEFINITION& pid,
  83. const PERF_COUNTER_BLOCK& pcb ) = 0;
  84. };
  85. // ========================================================================
  86. //
  87. // NAMESPACE PCLIB
  88. //
  89. // The top level of the PCLIB interface. PCLIB::FInitialize() should be
  90. // called once per process to initialize the library. Similarly,
  91. // PCLIB::Deinitialize() should be called once per process to deinitialize
  92. // it. NOTE: To simplify your error code cleanup, it is safe to call
  93. // PCLIB::Deinitialize() even if you did not call PCLIB::FInitialize().
  94. //
  95. // PCLIB::NewPerfObject() creates a new perf object from a
  96. // PERF_OBJECT_TYPE and subsequent PERF_COUNTER_DEFINITIONs. All values
  97. // of both structures must be properly initialized prior to calling
  98. // PCLIB::NewPerfObject() following standard conventions for these
  99. // structures, with one exception: PERF_OBJECT_TYPE::NumInstances and
  100. // PERF_OBJECT_TYPE::TotalByteLength should both be initialized to 0.
  101. // These values are computed in the monitor process because the number
  102. // of instances is not generally fixed at the time the object is created.
  103. //
  104. namespace PCLIB
  105. {
  106. //
  107. // Initialization/Deinitialization
  108. //
  109. BOOL __fastcall FInitialize( LPCWSTR lpwszSignature );
  110. VOID __fastcall Deinitialize();
  111. //
  112. // Instance registration
  113. //
  114. IPerfObject * __fastcall NewPerfObject( const PERF_OBJECT_TYPE& pot );
  115. };
  116. // ========================================================================
  117. //
  118. // CLASS CPclibInit
  119. //
  120. // PCLIB initializer class. Simplifies PCLIB initialization and
  121. // deinitialization.
  122. //
  123. class CPclibInit
  124. {
  125. // NOT IMPLEMENTED
  126. //
  127. CPclibInit& operator=( const CPclibInit& );
  128. CPclibInit( const CPclibInit& );
  129. public:
  130. CPclibInit()
  131. {
  132. }
  133. BOOL FInitialize( LPCWSTR lpwszSignature )
  134. {
  135. return PCLIB::FInitialize( lpwszSignature );
  136. }
  137. ~CPclibInit()
  138. {
  139. PCLIB::Deinitialize();
  140. }
  141. };
  142. // ************************************************************************
  143. //
  144. // INTERFACE for counter monitors
  145. //
  146. // ------------------------------------------------------------------------
  147. //
  148. // The interface for monitors *IS* the perfmon interface!
  149. // Just define these as EXPORTS for your monitor DLL and you're done.
  150. //
  151. EXTERN_C DWORD APIENTRY
  152. PclibOpenPerformanceData( LPCWSTR );
  153. EXTERN_C DWORD APIENTRY
  154. PclibCollectPerformanceData( LPCWSTR lpwszCounterIndices,
  155. LPVOID * plpvPerfData,
  156. LPDWORD lpdwcbPerfData,
  157. LPDWORD lpcObjectTypes );
  158. EXTERN_C DWORD APIENTRY
  159. PclibClosePerformanceData();
  160. EXTERN_C STDAPI
  161. PclibDllRegisterServer(VOID);
  162. EXTERN_C STDAPI
  163. PclibDllUnregisterServer(VOID);
  164. // ------------------------------------------------------------------------
  165. //
  166. // Or, for the do-it-yourself'er....
  167. //
  168. // Step 1) Initialize shared memory (see inc\smh.h)
  169. // Step 2) Call NewCounterPublisher() or NewCounterMonitor() (depending
  170. // on which you are!) passing in the string you used in Step 1.
  171. //
  172. class ICounterData
  173. {
  174. protected:
  175. // CREATORS
  176. // Only create this object through it's descendents!
  177. //
  178. ICounterData() {};
  179. public:
  180. // CREATORS
  181. //
  182. virtual ~ICounterData() = 0;
  183. // MANIPULATORS
  184. //
  185. virtual IPerfObject *
  186. CreatePerfObject( const PERF_OBJECT_TYPE& pot ) = 0;
  187. virtual DWORD
  188. DwCollectData( LPCWSTR lpwszCounterIndices,
  189. DWORD dwFirstCounter,
  190. LPVOID * plpvPerfData,
  191. LPDWORD lpdwcbPerfData,
  192. LPDWORD lpcObjectTypes ) = 0;
  193. };
  194. ICounterData * __fastcall
  195. NewCounterPublisher( LPCWSTR lpwszSignature );
  196. ICounterData * __fastcall
  197. NewCounterMonitor( LPCWSTR lpwszSignature );
  198. #endif // !defined(_PCLIB_H_)