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.

186 lines
4.8 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. perfhelp.h
  5. Abstract:
  6. <abstract>
  7. --*/
  8. #ifndef _PERFHELP_H_
  9. #define _PERFHELP_H_
  10. #include <winperf.h>
  11. __inline
  12. PERF_OBJECT_TYPE *
  13. FirstObject(IN PERF_DATA_BLOCK * pPerfData)
  14. {
  15. PERF_OBJECT_TYPE * pReturn;
  16. LPBYTE pEndOfBuffer;
  17. pReturn = (PPERF_OBJECT_TYPE)((PBYTE)(pPerfData) + (pPerfData)->HeaderLength);
  18. pEndOfBuffer = (LPBYTE)((LPBYTE)pPerfData + pPerfData->TotalByteLength);
  19. if ((LPBYTE)pReturn >= pEndOfBuffer) pReturn = NULL;
  20. return (pReturn);
  21. }
  22. #define NextObject(pObject) \
  23. (PPERF_OBJECT_TYPE)((pObject)->TotalByteLength != 0 ? (PPERF_OBJECT_TYPE)((PBYTE)(pObject) + (pObject)->TotalByteLength) : NULL)
  24. #define FirstInstance(pObjectDef) \
  25. (PERF_INSTANCE_DEFINITION *)((PCHAR) pObjectDef + pObjectDef->DefinitionLength)
  26. // the return of this macro must be cast to the correct type of pointer by the caller
  27. #define EndOfObject(pObjectDef) \
  28. ((PCHAR) pObjectDef + pObjectDef->TotalByteLength)
  29. __inline
  30. PERF_INSTANCE_DEFINITION *
  31. NextInstance(
  32. IN PERF_INSTANCE_DEFINITION *pInstDef
  33. )
  34. {
  35. PERF_COUNTER_BLOCK *pCounterBlock;
  36. pCounterBlock = (PERF_COUNTER_BLOCK *)
  37. ((PCHAR) pInstDef + pInstDef->ByteLength);
  38. return (PERF_INSTANCE_DEFINITION *)
  39. ((PCHAR) pCounterBlock + pCounterBlock->ByteLength);
  40. }
  41. #define PERF_TIMER_TYPE_FIELD \
  42. (PERF_TIMER_TICK | PERF_TIMER_100NS | PERF_OBJECT_TIMER)
  43. class PerfHelper
  44. {
  45. static void GetInstances(
  46. LPBYTE pBuf,
  47. CClassMapInfo *pClassMap,
  48. IWbemObjectSink *pSink
  49. );
  50. static void RefreshInstances(
  51. LPBYTE pBuf,
  52. CNt5Refresher *pRef
  53. );
  54. static PERF_INSTANCE_DEFINITION * GetInstanceByName(
  55. PERF_DATA_BLOCK *pDataBlock,
  56. PERF_OBJECT_TYPE *pObjectDef,
  57. LPWSTR pInstanceName,
  58. LPWSTR pParentName,
  59. DWORD dwIndex);
  60. static PERF_INSTANCE_DEFINITION * GetInstanceByNameUsingParentTitleIndex(
  61. PERF_DATA_BLOCK *pDataBlock,
  62. PERF_OBJECT_TYPE *pObjectDef,
  63. LPWSTR pInstanceName,
  64. LPWSTR pParentName,
  65. DWORD dwIndex);
  66. static DWORD GetInstanceNameStr (
  67. PPERF_INSTANCE_DEFINITION pInstance,
  68. LPWSTR lpszInstance,
  69. size_t cchBufferSize,
  70. DWORD dwCodePage);
  71. static DWORD GetUnicodeInstanceName (
  72. PPERF_INSTANCE_DEFINITION pInstance,
  73. LPWSTR lpszInstance, size_t cchBufferSize );
  74. static LPWSTR GetInstanceName(PPERF_INSTANCE_DEFINITION pInstDef)
  75. {
  76. return (LPWSTR) ((PCHAR) pInstDef + pInstDef->NameOffset);
  77. }
  78. static DWORD GetAnsiInstanceName (
  79. PPERF_INSTANCE_DEFINITION pInstance,
  80. LPWSTR lpszInstance,
  81. size_t cchBufferSize,
  82. DWORD dwCodePage);
  83. static PERF_INSTANCE_DEFINITION * GetInstanceByUniqueId (
  84. PERF_OBJECT_TYPE *pObjectDef,
  85. LONG InstanceUniqueId);
  86. static PERF_INSTANCE_DEFINITION * GetInstance(
  87. PERF_OBJECT_TYPE *pObjectDef,
  88. LONG InstanceNumber);
  89. static PERF_OBJECT_TYPE * GetObjectDefByName (
  90. PERF_DATA_BLOCK *pDataBlock,
  91. DWORD dwLastNameIndex,
  92. LPCWSTR *NameArray,
  93. LPCWSTR szObjectName);
  94. static PERF_OBJECT_TYPE * GetObjectDefByTitleIndex (
  95. PERF_DATA_BLOCK *pDataBlock,
  96. DWORD ObjectTypeTitleIndex);
  97. static BOOL PerfHelper::IsMatchingInstance (
  98. PERF_INSTANCE_DEFINITION *pInstanceDef,
  99. DWORD dwCodePage,
  100. LPWSTR szInstanceNameToMatch,
  101. DWORD dwInstanceNameLength);
  102. static void RefreshEnumeratorInstances (
  103. IN RefresherCacheEl *pThisCacheEl,
  104. IN PERF_DATA_BLOCK *PerfData,
  105. IN PERF_OBJECT_TYPE *PerfObj);
  106. public:
  107. static BOOL ParseInstanceName (
  108. LPCWSTR szInstanceString,
  109. LPWSTR szInstanceName,
  110. size_t cchInstanceName,
  111. LPWSTR szParentName,
  112. size_t cchParentName,
  113. LPDWORD lpIndex);
  114. static DWORD GetFullInstanceNameStr (
  115. PERF_DATA_BLOCK *pPerfData,
  116. PERF_OBJECT_TYPE *pObjectDef,
  117. PERF_INSTANCE_DEFINITION *pInstanceDef,
  118. LPWSTR szInstanceName,
  119. size_t cchInstanceName );
  120. static BOOL QueryInstances(
  121. CPerfObjectAccess *pPerfObj,
  122. CClassMapInfo *pClassMap,
  123. IWbemObjectSink *pSink
  124. );
  125. static BOOL RefreshInstances(
  126. CNt5Refresher *pRef
  127. );
  128. static VOID UpdateTimers(
  129. CClassMapInfo *pClassMap,
  130. IWbemObjectAccess *pInst,
  131. PPERF_DATA_BLOCK PerfData,
  132. PPERF_OBJECT_TYPE PerfObj
  133. );
  134. };
  135. __inline
  136. LONG64
  137. Assign64(
  138. IN PLARGE_INTEGER Unaligned
  139. )
  140. {
  141. PLARGE_INTEGER pAligned;
  142. LONG64 llVal;
  143. pAligned = (PLARGE_INTEGER) &llVal;
  144. pAligned->LowPart = Unaligned->LowPart;
  145. pAligned->HighPart = Unaligned->HighPart;
  146. return llVal;
  147. }
  148. #endif