summaryrefslogtreecommitdiff
path: root/src/inc/perfcounters.h
diff options
context:
space:
mode:
authorJiyoung Yun <jy910.yun@samsung.com>2016-11-23 10:09:09 (GMT)
committerJiyoung Yun <jy910.yun@samsung.com>2016-11-23 10:09:09 (GMT)
commit4b4aad7217d3292650e77eec2cf4c198ea9c3b4b (patch)
tree98110734c91668dfdbb126fcc0e15ddbd93738ca /src/inc/perfcounters.h
parentfa45f57ed55137c75ac870356a1b8f76c84b229c (diff)
downloadcoreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.zip
coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.tar.gz
coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.tar.bz2
Imported Upstream version 1.1.0upstream/1.1.0
Diffstat (limited to 'src/inc/perfcounters.h')
-rw-r--r--src/inc/perfcounters.h124
1 files changed, 124 insertions, 0 deletions
diff --git a/src/inc/perfcounters.h b/src/inc/perfcounters.h
new file mode 100644
index 0000000..a27b58d
--- /dev/null
+++ b/src/inc/perfcounters.h
@@ -0,0 +1,124 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//-----------------------------------------------------------------------------
+// PerfCounters.h
+//
+// Internal Interface for CLR to use Performance counters
+//-----------------------------------------------------------------------------
+
+
+#ifndef _PerfCounters_h_
+#define _PerfCounters_h_
+
+#include "perfcounterdefs.h"
+
+#ifdef ENABLE_PERF_COUNTERS
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+// This code section active iff we're using Perf Counters
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+// PerfCounter class serves as namespace with data protection.
+// Enforce this by making constructor private
+//-----------------------------------------------------------------------------
+class PerfCounters
+{
+private:
+ PerfCounters();
+
+public:
+ static HRESULT Init();
+ static void Terminate();
+
+ static PerfCounterIPCControlBlock * GetPrivatePerfCounterPtr();
+
+private:
+ static HANDLE m_hPrivateMapPerf;
+
+ static PerfCounterIPCControlBlock * m_pPrivatePerf;
+
+ static BOOL m_fInit;
+
+// Set pointers to garbage so they're never null.
+ static PerfCounterIPCControlBlock m_garbage;
+
+ friend PerfCounterIPCControlBlock & GetPerfCounters();
+};
+
+//-----------------------------------------------------------------------------
+// Utility functions
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+// Get the perf counters specific to our process
+//-----------------------------------------------------------------------------
+inline PerfCounterIPCControlBlock & GetPerfCounters()
+{
+ LIMITED_METHOD_CONTRACT;
+
+ return *PerfCounters::m_pPrivatePerf;
+}
+
+inline PerfCounterIPCControlBlock *PerfCounters::GetPrivatePerfCounterPtr()
+{
+ LIMITED_METHOD_CONTRACT;
+
+ return m_pPrivatePerf;
+};
+
+extern "C" Perf_Contexts * STDMETHODCALLTYPE GetPrivateContextsPerfCounters();
+
+#define COUNTER_ONLY(x) x
+
+#define PERF_COUNTER_NUM_OF_ITERATIONS 10
+
+#if defined(_X86_) && defined(_MSC_VER)
+
+inline UINT64 GetCycleCount_UINT64()
+{
+ LIMITED_METHOD_CONTRACT;
+ return __rdtsc();
+}
+
+#else // defined(_X86_) && defined(_MSC_VER)
+inline UINT64 GetCycleCount_UINT64()
+{
+ LIMITED_METHOD_CONTRACT;
+
+ LARGE_INTEGER qwTmp;
+ QueryPerformanceCounter(&qwTmp);
+ return qwTmp.QuadPart;
+}
+#endif // defined(_X86_) && defined(_MSC_VER)
+
+#define PERF_COUNTER_TIMER_PRECISION UINT64
+#define GET_CYCLE_COUNT GetCycleCount_UINT64
+
+#define PERF_COUNTER_TIMER_START() \
+PERF_COUNTER_TIMER_PRECISION _startPerfCounterTimer = GET_CYCLE_COUNT();
+
+#define PERF_COUNTER_TIMER_STOP(global) \
+global = (GET_CYCLE_COUNT() - _startPerfCounterTimer);
+
+
+
+
+#else // ENABLE_PERF_COUNTERS
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+// This code section active iff we're NOT using Perf Counters
+// Note, not even a class definition, so all usages of PerfCounters in client
+// should be in #ifdef or COUNTER_ONLY().
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+
+#define COUNTER_ONLY(x)
+
+
+#endif // ENABLE_PERF_COUNTERS
+
+
+#endif // _PerfCounters_h_