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.

181 lines
4.4 KiB

  1. /*++
  2. Copyright (C) 1998-1999 Microsoft Corporation
  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. DWORD dwCodePage);
  70. static DWORD GetUnicodeInstanceName (
  71. PPERF_INSTANCE_DEFINITION pInstance,
  72. LPWSTR lpszInstance);
  73. static LPWSTR GetInstanceName(PPERF_INSTANCE_DEFINITION pInstDef)
  74. {
  75. return (LPWSTR) ((PCHAR) pInstDef + pInstDef->NameOffset);
  76. }
  77. static DWORD GetAnsiInstanceName (
  78. PPERF_INSTANCE_DEFINITION pInstance,
  79. LPWSTR lpszInstance,
  80. DWORD dwCodePage);
  81. static PERF_INSTANCE_DEFINITION * GetInstanceByUniqueId (
  82. PERF_OBJECT_TYPE *pObjectDef,
  83. LONG InstanceUniqueId);
  84. static PERF_INSTANCE_DEFINITION * GetInstance(
  85. PERF_OBJECT_TYPE *pObjectDef,
  86. LONG InstanceNumber);
  87. static PERF_OBJECT_TYPE * GetObjectDefByName (
  88. PERF_DATA_BLOCK *pDataBlock,
  89. DWORD dwLastNameIndex,
  90. LPCWSTR *NameArray,
  91. LPCWSTR szObjectName);
  92. static PERF_OBJECT_TYPE * GetObjectDefByTitleIndex (
  93. PERF_DATA_BLOCK *pDataBlock,
  94. DWORD ObjectTypeTitleIndex);
  95. static BOOL PerfHelper::IsMatchingInstance (
  96. PERF_INSTANCE_DEFINITION *pInstanceDef,
  97. DWORD dwCodePage,
  98. LPWSTR szInstanceNameToMatch,
  99. DWORD dwInstanceNameLength);
  100. static void RefreshEnumeratorInstances (
  101. IN RefresherCacheEl *pThisCacheEl,
  102. IN PERF_DATA_BLOCK *PerfData,
  103. IN PERF_OBJECT_TYPE *PerfObj);
  104. public:
  105. static BOOL ParseInstanceName (
  106. LPCWSTR szInstanceString,
  107. LPWSTR szInstanceName,
  108. LPWSTR szParentName,
  109. LPDWORD lpIndex);
  110. static DWORD GetFullInstanceNameStr (
  111. PERF_DATA_BLOCK *pPerfData,
  112. PERF_OBJECT_TYPE *pObjectDef,
  113. PERF_INSTANCE_DEFINITION *pInstanceDef,
  114. LPWSTR szInstanceName);
  115. static BOOL QueryInstances(
  116. CPerfObjectAccess *pPerfObj,
  117. CClassMapInfo *pClassMap,
  118. IWbemObjectSink *pSink
  119. );
  120. static BOOL RefreshInstances(
  121. CNt5Refresher *pRef
  122. );
  123. static VOID UpdateTimers(
  124. CClassMapInfo *pClassMap,
  125. IWbemObjectAccess *pInst,
  126. PPERF_DATA_BLOCK PerfData,
  127. PPERF_OBJECT_TYPE PerfObj
  128. );
  129. };
  130. __inline
  131. LONG64
  132. Assign64(
  133. IN PLARGE_INTEGER Unaligned
  134. )
  135. {
  136. PLARGE_INTEGER pAligned;
  137. LONG64 llVal;
  138. pAligned = (PLARGE_INTEGER) &llVal;
  139. pAligned->LowPart = Unaligned->LowPart;
  140. pAligned->HighPart = Unaligned->HighPart;
  141. return llVal;
  142. }
  143. #endif