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.

225 lines
4.7 KiB

  1. // -*- c++ -*-
  2. // perflib.h
  3. //
  4. #ifndef __PERFLIB_H
  5. #define __PERFLIB_H
  6. #define MAX_PERF_NAME 16
  7. #define MAX_OBJECT_NAME 16
  8. #define MAX_INSTANCE_NAME 32
  9. typedef WCHAR OBJECTNAME[MAX_OBJECT_NAME];
  10. typedef WCHAR INSTANCENAME[MAX_INSTANCE_NAME];
  11. #define MAX_PERF_OBJECTS 16
  12. #define MAX_OBJECT_INSTANCES 64
  13. #define MAX_OBJECT_COUNTERS 64
  14. class PerfObjectInstance;
  15. class PerfCounterDefinition;
  16. class PerfObjectDefinition;
  17. struct INSTANCE_DATA
  18. {
  19. BOOL fActive;
  20. PERF_INSTANCE_DEFINITION perfInstDef;
  21. INSTANCENAME wszInstanceName;
  22. };
  23. class PerfLibrary
  24. {
  25. friend class PerfObjectDefinition;
  26. friend class PerfCounterDefinition;
  27. private:
  28. // name of this performance module
  29. WCHAR m_wszPerfName[MAX_PERF_NAME];
  30. // array of PerfObjectDefinition's and a count of how many there are.
  31. PerfObjectDefinition* m_rgpObjDef[MAX_PERF_OBJECTS];
  32. DWORD m_dwObjDef;
  33. // shared memory handle and pointer to base of shared memory
  34. HANDLE m_hMap;
  35. PBYTE m_pbMap;
  36. // pointers to places in the shared memory where we keep stuff
  37. DWORD* m_pdwObjectNames;
  38. OBJECTNAME* m_prgObjectNames;
  39. // base values for title text and help text for the library
  40. DWORD m_dwFirstHelp;
  41. DWORD m_dwFirstCounter;
  42. void AddPerfObjectDefinition( PerfObjectDefinition* pObjDef );
  43. public:
  44. PerfLibrary( LPCWSTR pcwstrPerfName = L"");
  45. ~PerfLibrary( void );
  46. void InitName( LPCWSTR pcwstrPerfName )
  47. {
  48. lstrcpynW( m_wszPerfName, pcwstrPerfName, MAX_PERF_NAME );
  49. }
  50. BOOL Init( void );
  51. };
  52. class PerfObjectDefinition
  53. {
  54. friend class PerfLibrary;
  55. friend class PerfCounterDefinition;
  56. friend class PerfObjectInstance;
  57. private:
  58. WCHAR m_wszObjectName[MAX_OBJECT_NAME];
  59. DWORD m_dwObjectNameIndex;
  60. DWORD m_dwMaxInstances;
  61. PerfCounterDefinition* m_rgpCounterDef[MAX_OBJECT_COUNTERS];
  62. DWORD m_dwCounters;
  63. DWORD m_dwDefinitionLength;
  64. DWORD m_dwCounterData;
  65. DWORD m_dwPerInstanceData;
  66. HANDLE m_hMap;
  67. void* m_pv;
  68. PERF_OBJECT_TYPE* m_pPerfObjectType;
  69. PERF_COUNTER_DEFINITION* m_rgPerfCounterDefinition;
  70. char* m_pCounterData;
  71. DWORD m_dwActiveInstances;
  72. BOOL Init( PerfLibrary* pPerfLib );
  73. void AddPerfCounterDefinition( PerfCounterDefinition* pcd );
  74. DWORD GetCounterOffset( DWORD dwId );
  75. void OnInstanceDestroyed( void );
  76. public:
  77. PerfObjectDefinition( PerfLibrary& rPerfLib,
  78. LPCWSTR pwcstrObjectName,
  79. DWORD dwObjectNameIndex,
  80. DWORD dwMaxInstances = PERF_NO_INSTANCES );
  81. PerfObjectDefinition( PerfLibrary& rPerfLib,
  82. DWORD dwObjectNameIndex,
  83. DWORD dwMaxInstances = PERF_NO_INSTANCES );
  84. void InitName( LPCWSTR pwcstrObjectName )
  85. {
  86. lstrcpynW( m_wszObjectName, pwcstrObjectName, MAX_OBJECT_NAME );
  87. }
  88. ~PerfObjectDefinition( void );
  89. PerfObjectInstance* CreateObjectInstance( LPCWSTR pwstrInstanceName );
  90. };
  91. class PerfCounterDefinition
  92. {
  93. friend class PerfObjectDefinition;
  94. private:
  95. PerfObjectDefinition* m_pObjDef;
  96. PerfCounterDefinition* m_pCtrRef;
  97. DWORD m_dwCounterNameIndex;
  98. LONG m_lDefaultScale;
  99. DWORD m_dwCounterType;
  100. DWORD m_dwCounterSize;
  101. DWORD m_dwOffset;
  102. void Init( PerfLibrary* pPerfLib,
  103. PERF_COUNTER_DEFINITION* pdef, PDWORD pdwOffset );
  104. public:
  105. PerfCounterDefinition( PerfObjectDefinition& robj,
  106. DWORD dwCounterNameIndex,
  107. DWORD dwCounterType = PERF_COUNTER_COUNTER,
  108. LONG lDefaultScale = 0 );
  109. PerfCounterDefinition( PerfCounterDefinition& pRefCtr,
  110. DWORD dwCounterNameIndex,
  111. DWORD dwCounterType = PERF_COUNTER_COUNTER,
  112. LONG lDefaultScale = 0 );
  113. };
  114. class PerfObjectInstance
  115. {
  116. private:
  117. PerfObjectDefinition* m_pObjDef;
  118. WCHAR m_wszInstanceName[MAX_INSTANCE_NAME];
  119. INSTANCE_DATA* m_pInstanceData;
  120. char* m_pCounterData;
  121. public:
  122. PerfObjectInstance( PerfObjectDefinition* pObjDef,
  123. LPCWSTR pwcstrInstanceName,
  124. char* pCounterData,
  125. INSTANCE_DATA* pInstanceData,
  126. LONG lID );
  127. ~PerfObjectInstance();
  128. DWORD* GetDwordCounter( DWORD dwId );
  129. LARGE_INTEGER* GetLargeIntegerCounter( DWORD dwId );
  130. };
  131. class CLongCounter
  132. {
  133. public:
  134. CLongCounter(): m_plCounter(NULL) {}
  135. ~CLongCounter() {}
  136. void Init(DWORD *pdwCounter)
  137. {
  138. m_plCounter = (LPLONG)pdwCounter;
  139. Reset();
  140. }
  141. void Increment() { if(m_plCounter) InterlockedIncrement(m_plCounter); }
  142. void Decrement() { if(m_plCounter) InterlockedDecrement(m_plCounter); }
  143. void Reset() { if(m_plCounter) InterlockedExchange(m_plCounter, 0); }
  144. void Set(DWORD dw) { if(m_plCounter) InterlockedExchange(m_plCounter, (LONG)dw); }
  145. void operator++() { Increment(); }
  146. void operator--() { Decrement(); }
  147. void operator =(DWORD dw) { Set(dw); }
  148. private:
  149. LPLONG m_plCounter;
  150. };
  151. #endif