Add more ICorProfiler API versions
authorGleb Balykov <g.balykov@samsung.com>
Wed, 31 May 2023 16:46:58 +0000 (19:46 +0300)
committerGleb Balykov/Advanced System SW Lab /SRR/Staff Engineer/Samsung Electronics <g.balykov@samsung.com>
Wed, 21 Jun 2023 12:38:33 +0000 (15:38 +0300)
src/profilerinfo.cpp
src/profilerinfo.h

index b3e2442df2825ee51e1bbbe6a68da6eb3a8a399b..65ad1bb59ba4d6a50ddaa1e71352e26a961dce56 100644 (file)
@@ -24,6 +24,9 @@ ProfilerInfo::ProfilerInfo() noexcept
     , m_pProfilerInfo5(nullptr)
     , m_pProfilerInfo6(nullptr)
     , m_pProfilerInfo7(nullptr)
+    , m_pProfilerInfo8(nullptr)
+    , m_pProfilerInfo9(nullptr)
+    , m_pProfilerInfo10(nullptr)
     , m_version(0)
 {
 }
@@ -40,6 +43,90 @@ HRESULT ProfilerInfo::Initialize(IUnknown *pICorProfilerInfoUnk) noexcept
 
     HRESULT hr = S_OK;  // for case when Initialize() called twice
 
+    if (m_pProfilerInfo10 == nullptr)
+    {
+        hr = pICorProfilerInfoUnk->QueryInterface(
+            IID_ICorProfilerInfo10,
+            (void**)&m_pProfilerInfo10);
+        if (SUCCEEDED(hr)) {
+            _ASSERTE(m_version == 0);
+            m_version = 10;
+
+            m_pProfilerInfo9 = static_cast<ICorProfilerInfo9*>(
+                m_pProfilerInfo10);
+            m_pProfilerInfo8 = static_cast<ICorProfilerInfo8*>(
+                m_pProfilerInfo10);
+            m_pProfilerInfo7 = static_cast<ICorProfilerInfo7*>(
+                m_pProfilerInfo10);
+            m_pProfilerInfo6 = static_cast<ICorProfilerInfo6*>(
+                m_pProfilerInfo10);
+            m_pProfilerInfo5 = static_cast<ICorProfilerInfo5*>(
+                m_pProfilerInfo10);
+            m_pProfilerInfo4 = static_cast<ICorProfilerInfo4*>(
+                m_pProfilerInfo10);
+            m_pProfilerInfo3 = static_cast<ICorProfilerInfo3*>(
+                m_pProfilerInfo10);
+            m_pProfilerInfo2 = static_cast<ICorProfilerInfo2*>(
+                m_pProfilerInfo10);
+            m_pProfilerInfo  = static_cast<ICorProfilerInfo* >(
+                m_pProfilerInfo10);
+        }
+    }
+
+    if (m_pProfilerInfo9 == nullptr)
+    {
+        hr = pICorProfilerInfoUnk->QueryInterface(
+            IID_ICorProfilerInfo9,
+            (void**)&m_pProfilerInfo9);
+        if (SUCCEEDED(hr)) {
+            _ASSERTE(m_version == 0);
+            m_version = 9;
+
+            m_pProfilerInfo8 = static_cast<ICorProfilerInfo8*>(
+                m_pProfilerInfo9);
+            m_pProfilerInfo7 = static_cast<ICorProfilerInfo7*>(
+                m_pProfilerInfo9);
+            m_pProfilerInfo6 = static_cast<ICorProfilerInfo6*>(
+                m_pProfilerInfo9);
+            m_pProfilerInfo5 = static_cast<ICorProfilerInfo5*>(
+                m_pProfilerInfo9);
+            m_pProfilerInfo4 = static_cast<ICorProfilerInfo4*>(
+                m_pProfilerInfo9);
+            m_pProfilerInfo3 = static_cast<ICorProfilerInfo3*>(
+                m_pProfilerInfo9);
+            m_pProfilerInfo2 = static_cast<ICorProfilerInfo2*>(
+                m_pProfilerInfo9);
+            m_pProfilerInfo  = static_cast<ICorProfilerInfo* >(
+                m_pProfilerInfo9);
+        }
+    }
+
+    if (m_pProfilerInfo8 == nullptr)
+    {
+        hr = pICorProfilerInfoUnk->QueryInterface(
+            IID_ICorProfilerInfo8,
+            (void**)&m_pProfilerInfo8);
+        if (SUCCEEDED(hr)) {
+            _ASSERTE(m_version == 0);
+            m_version = 8;
+
+            m_pProfilerInfo7 = static_cast<ICorProfilerInfo7*>(
+                m_pProfilerInfo8);
+            m_pProfilerInfo6 = static_cast<ICorProfilerInfo6*>(
+                m_pProfilerInfo8);
+            m_pProfilerInfo5 = static_cast<ICorProfilerInfo5*>(
+                m_pProfilerInfo8);
+            m_pProfilerInfo4 = static_cast<ICorProfilerInfo4*>(
+                m_pProfilerInfo8);
+            m_pProfilerInfo3 = static_cast<ICorProfilerInfo3*>(
+                m_pProfilerInfo8);
+            m_pProfilerInfo2 = static_cast<ICorProfilerInfo2*>(
+                m_pProfilerInfo8);
+            m_pProfilerInfo  = static_cast<ICorProfilerInfo* >(
+                m_pProfilerInfo8);
+        }
+    }
+
     if (m_pProfilerInfo7 == nullptr)
     {
         hr = pICorProfilerInfoUnk->QueryInterface(
@@ -165,6 +252,9 @@ HRESULT ProfilerInfo::Initialize(IUnknown *pICorProfilerInfoUnk) noexcept
         }
     }
 
+    _ASSERTE(m_version < 10 || m_pProfilerInfo10 != nullptr);
+    _ASSERTE(m_version < 9 || m_pProfilerInfo9 != nullptr);
+    _ASSERTE(m_version < 8 || m_pProfilerInfo8 != nullptr);
     _ASSERTE(m_version < 7 || m_pProfilerInfo7 != nullptr);
     _ASSERTE(m_version < 6 || m_pProfilerInfo6 != nullptr);
     _ASSERTE(m_version < 5 || m_pProfilerInfo5 != nullptr);
@@ -190,6 +280,9 @@ void ProfilerInfo::Reset() noexcept
         m_pProfilerInfo5 = nullptr;
         m_pProfilerInfo6 = nullptr;
         m_pProfilerInfo7 = nullptr;
+        m_pProfilerInfo8 = nullptr;
+        m_pProfilerInfo9 = nullptr;
+        m_pProfilerInfo10 = nullptr;
         m_version = 0;
     }
 }
index c330790345f3f431e99cff52993829585c2e67a0..d0e4fd7262bf7de41dceae307faa88495b6b5378 100644 (file)
@@ -88,6 +88,24 @@ public:
         return m_pProfilerInfo7;
     }
 
+    ICorProfilerInfo8 *v8() const noexcept
+    {
+        _ASSERTE(m_version >= 8);
+        return m_pProfilerInfo8;
+    }
+
+    ICorProfilerInfo9 *v9() const noexcept
+    {
+        _ASSERTE(m_version >= 9);
+        return m_pProfilerInfo9;
+    }
+
+    ICorProfilerInfo10 *v10() const noexcept
+    {
+        _ASSERTE(m_version >= 10);
+        return m_pProfilerInfo10;
+    }
+
 private:
     // Pointers to the implementation of the ProfilerInfo interface(s).
     ICorProfilerInfo  *m_pProfilerInfo;
@@ -97,6 +115,9 @@ private:
     ICorProfilerInfo5 *m_pProfilerInfo5;
     ICorProfilerInfo6 *m_pProfilerInfo6;
     ICorProfilerInfo7 *m_pProfilerInfo7;
+    ICorProfilerInfo8 *m_pProfilerInfo8;
+    ICorProfilerInfo9 *m_pProfilerInfo9;
+    ICorProfilerInfo10 *m_pProfilerInfo10;
 
     // Version of the Profiler Info API.
     unsigned int m_version;