PerfCounter.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. #ifdef PERF_COUNTERS
  7. // Forward declaration from perflib.h
  8. struct _PERF_COUNTERSET_INSTANCE;
  9. typedef struct _PERF_COUNTERSET_INSTANCE *PPERF_COUNTERSET_INSTANCE;
  10. enum PageAllocatorType;
  11. #define MAX_OBJECT_NAME_PREFIX 1024
  12. namespace PerfCounter
  13. {
  14. class Provider;
  15. class InstanceBase
  16. {
  17. protected:
  18. InstanceBase(Provider& provider, GUID const& guid);
  19. ~InstanceBase();
  20. bool IsProviderInitialized() const;
  21. bool Initialize(char16 const * wszInstanceName, DWORD id);
  22. DWORD * InitializeSharedMemory(DWORD numCounter, HANDLE& handle);
  23. DWORD * OpenSharedMemory(__in_ecount(MAX_OBJECT_NAME_PREFIX) char16 const wszObjectNamePrefix[MAX_OBJECT_NAME_PREFIX], DWORD pid, DWORD numCounter, HANDLE& handle);
  24. void UninitializeSharedMemory(DWORD * data, HANDLE handle);
  25. bool IsEnabled() const;
  26. private:
  27. Provider& GetProvider() { return provider; }
  28. PPERF_COUNTERSET_INSTANCE GetData() { return instanceData; }
  29. Provider& provider;
  30. GUID const& guid;
  31. PPERF_COUNTERSET_INSTANCE instanceData;
  32. friend class Counter;
  33. };
  34. class Counter
  35. {
  36. public:
  37. Counter() : count(NULL) {};
  38. void Initialize(InstanceBase& instance, DWORD id, DWORD * count);
  39. void Uninitialize(InstanceBase& instance, DWORD id);
  40. Counter& operator+=(size_t value);
  41. Counter& operator-=(size_t value);
  42. Counter& operator++();
  43. Counter& operator--();
  44. DWORD GetValue() { return *count; }
  45. private:
  46. /* TODO: 64-bit */
  47. DWORD * count;
  48. };
  49. class PageAllocatorCounterSetDefinition
  50. {
  51. public:
  52. static DWORD const MaxCounter = 24;
  53. static GUID const& GetGuid();
  54. static Provider& GetProvider();
  55. static uint GetReservedCounterId(PageAllocatorType type);
  56. static uint GetCommittedCounterId(PageAllocatorType type);
  57. static uint GetUsedCounterId(PageAllocatorType type);
  58. };
  59. class BasicCounterSetDefinition
  60. {
  61. public:
  62. static DWORD const MaxCounter = 4;
  63. static GUID const& GetGuid();
  64. static Provider& GetProvider();
  65. };
  66. class CodeCounterSetDefinition
  67. {
  68. public:
  69. static DWORD const MaxCounter = 17;
  70. static GUID const& GetGuid();
  71. static Provider& GetProvider();
  72. };
  73. #ifdef HEAP_PERF_COUNTERS
  74. class HeapCounterSetDefinition
  75. {
  76. public:
  77. static DWORD const MaxCounter = 2;
  78. static GUID const& GetGuid();
  79. static Provider& GetProvider();
  80. };
  81. #endif
  82. #ifdef RECYCLER_PERF_COUNTERS
  83. class RecyclerCounterSetDefinition
  84. {
  85. public:
  86. static DWORD const MaxCounter = 14;
  87. static GUID const& GetGuid();
  88. static Provider& GetProvider();
  89. };
  90. #endif
  91. #ifdef PROFILE_RECYCLER_ALLOC
  92. #define RECYCLER_TRACKER_PERF_COUNTER_TYPE(MACRO) \
  93. MACRO(JavascriptNumber); \
  94. MACRO(ConcatString); \
  95. MACRO(LiteralString); \
  96. MACRO(SubString); \
  97. MACRO(PropertyString); \
  98. MACRO(PropertyRecord); \
  99. MACRO(DynamicObject); \
  100. MACRO(CustomExternalObject); \
  101. MACRO(DynamicType); \
  102. MACRO(JavascriptFunction); \
  103. MACRO(JavascriptArray); \
  104. MACRO(SingleCharString); \
  105. MACRO(FrameDisplay); \
  106. MACRO(CompoundString); \
  107. MACRO(RecyclerWeakReferenceBase); \
  108. MACRO(ProjectionObjectInstance); \
  109. #define RECYCLER_TRACKER_ARRAY_PERF_COUNTER_TYPE(MACRO) \
  110. MACRO(Var); \
  111. MACRO(char16); \
  112. #define RECYCLER_TRACKER_WEAKREF_PERF_COUNTER_TYPE(MACRO) \
  113. MACRO(PropertyRecord); \
  114. MACRO(DynamicType); \
  115. MACRO(PropertyString); \
  116. MACRO(DynamicObject); \
  117. MACRO(Type); \
  118. #define DECLARE_RECYCLER_TRACKER_PERF_COUNTER_INDEX(type) \
  119. static uint const type##CounterIndex; \
  120. static uint const type##SizeCounterIndex;
  121. #define DECLARE_RECYCLER_TRACKER_ARRAY_PERF_COUNTER_INDEX(type) \
  122. static uint const type##ArrayCounterIndex; \
  123. static uint const type##ArraySizeCounterIndex;
  124. #define DECLARE_RECYCLER_TRACKER_WEAKREF_PERF_COUNTER_INDEX(type) \
  125. static uint const type##WeakRefCounterIndex;
  126. class RecyclerTrackerCounterSetDefinition
  127. {
  128. public:
  129. static DWORD const MaxCounter = 46;
  130. static GUID const& GetGuid();
  131. static Provider& GetProvider();
  132. RECYCLER_TRACKER_PERF_COUNTER_TYPE(DECLARE_RECYCLER_TRACKER_PERF_COUNTER_INDEX);
  133. RECYCLER_TRACKER_ARRAY_PERF_COUNTER_TYPE(DECLARE_RECYCLER_TRACKER_ARRAY_PERF_COUNTER_INDEX);
  134. RECYCLER_TRACKER_WEAKREF_PERF_COUNTER_TYPE(DECLARE_RECYCLER_TRACKER_WEAKREF_PERF_COUNTER_INDEX);
  135. };
  136. #undef DECLARE_RECYCLER_TRACKER_PERF_COUNTER_INDEX
  137. #undef DECLARE_RECYCLER_TRACKER_ARRAY_PERF_COUNTER_INDEX
  138. #undef DECLARE_RECYCLER_TRACKER_WEAKREF_PERF_COUNTER_INDEX
  139. #endif
  140. };
  141. #endif