Re-Factor EventSource to Support Writing to EventPipe (#11435)
authorBrian Robbins <brianrob@microsoft.com>
Wed, 10 May 2017 22:11:28 +0000 (15:11 -0700)
committerGitHub <noreply@github.com>
Wed, 10 May 2017 22:11:28 +0000 (15:11 -0700)
Re-Factor EventSource to Support Writing to EventPipe.

18 files changed:
clr.coreclr.props
clr.defines.targets
clrdefinitions.cmake
src/inc/CrstTypes.def
src/inc/crsttypes.h
src/mscorlib/System.Private.CoreLib.csproj
src/mscorlib/shared/System.Private.CoreLib.Shared.projitems
src/mscorlib/shared/System/Diagnostics/Tracing/EventProvider.cs
src/mscorlib/shared/System/Diagnostics/Tracing/EventSource.cs
src/mscorlib/shared/System/Diagnostics/Tracing/IEventProvider.cs [new file with mode: 0644]
src/mscorlib/src/System/Diagnostics/Eventing/EventPipeEventProvider.cs [new file with mode: 0644]
src/vm/ecalllist.h
src/vm/eventpipe.cpp
src/vm/eventpipe.h
src/vm/eventpipeconfiguration.cpp
src/vm/eventpipeprovider.cpp
src/vm/eventpipeprovider.h
src/vm/mscorlib.cpp

index 5251eab..059fb3a 100644 (file)
@@ -47,7 +47,7 @@
     <FeatureRandomizedStringHashing>true</FeatureRandomizedStringHashing>
     <!-- The rejit feature is available only on supported architectures (x86 & x64) -->
     <FeatureReJIT Condition="('$(TargetArch)' == 'i386') or ('$(TargetArch)' == 'amd64')">true</FeatureReJIT>
-    <FeatureManagedEtw>true</FeatureManagedEtw>
+    <FeatureManagedEtw>false</FeatureManagedEtw>
     <FeatureManagedEtwChannels>true</FeatureManagedEtwChannels>
     <BinderDebugLog Condition="'$(_BuildType)'=='dbg'">true</BinderDebugLog>
     <FeatureAppX>true</FeatureAppX>
     <FeatureCominterop>false</FeatureCominterop>
     <FeatureCominteropUnmanagedActivation>false</FeatureCominteropUnmanagedActivation>
     <FeatureCominteropWinRTManagedActivation>false</FeatureCominteropWinRTManagedActivation>
-    <FeatureManagedEtw>false</FeatureManagedEtw>
 
     <FeatureCoreFxGlobalization>true</FeatureCoreFxGlobalization>
   </PropertyGroup>
 
   <PropertyGroup Condition="'$(TargetsWindows)' == 'true'">
     <FeatureArrayStubAsIL Condition="('$(TargetArch)' == 'arm') or ('$(TargetArch)' == 'amd64') or ('$(TargetArch)' == 'arm64')">true</FeatureArrayStubAsIL>
+    <FeatureManagedEtw>true</FeatureManagedEtw>
     <FeatureStubsAsIL Condition="'$(TargetArch)' == 'arm64'">true</FeatureStubsAsIL>
     <FeatureUseLcid>true</FeatureUseLcid>
     <FeatureImplicitLongPath>true</FeatureImplicitLongPath>
   </PropertyGroup>
+
+  <PropertyGroup Condition="'$(TargetsLinux)' == 'true'">
+    <FeatureManagedEtw>true</FeatureManagedEtw>
+    <FeaturePerfTracing>true</FeaturePerfTracing>
+  </PropertyGroup>
 </Project>
index 1dd41f1..df6a409 100644 (file)
@@ -20,6 +20,7 @@
         <DefineConstants Condition="'$(FeatureManagedEtwChannels)' == 'true'">$(DefineConstants);FEATURE_MANAGED_ETW_CHANNELS</DefineConstants>
         <DefineConstants Condition="'$(FeaturePal)' == 'true'">$(DefineConstants);FEATURE_PAL</DefineConstants>
         <DefineConstants Condition="'$(FeaturePathCompat)' == 'true'">$(DefineConstants);FEATURE_PATHCOMPAT</DefineConstants>
+        <DefineConstants Condition="'$(FeaturePerfTracing)' == 'true'">$(DefineConstants);FEATURE_PERFTRACING</DefineConstants>
         <DefineConstants Condition="'$(FeatureXplatEventSource)' == 'true'">$(DefineConstants);FEATURE_EVENTSOURCE_XPLAT</DefineConstants>
         <DefineConstants Condition="'$(FeatureRandomizedStringHashing)' == 'true'">$(DefineConstants);FEATURE_RANDOMIZED_STRING_HASHING</DefineConstants>
         <DefineConstants Condition="'$(FeatureSortTables)' == 'true'">$(DefineConstants);FEATURE_SORT_TABLES</DefineConstants>
index 92b63a3..6db2b24 100644 (file)
@@ -135,9 +135,9 @@ if(FEATURE_INTERPRETER)
 endif(FEATURE_INTERPRETER)
 add_definitions(-DFEATURE_ISYM_READER)
 add_definitions(-DFEATURE_LOADER_OPTIMIZATION)
-if (NOT CLR_CMAKE_PLATFORM_UNIX)
+if (CLR_CMAKE_PLATFORM_LINUX OR WIN32)
     add_definitions(-DFEATURE_MANAGED_ETW)
-endif(NOT CLR_CMAKE_PLATFORM_UNIX)
+endif(CLR_CMAKE_PLATFORM_LINUX OR WIN32)
 add_definitions(-DFEATURE_MANAGED_ETW_CHANNELS)
 
 if(FEATURE_MERGE_JIT_AND_ENGINE)
index 227f986..5bf4ec6 100644 (file)
@@ -781,5 +781,5 @@ Crst InlineTrackingMap
 End
 
 Crst EventPipe
-    AcquiredBefore ThreadIdDispenser ThreadStore
+    AcquiredBefore ThreadIdDispenser ThreadStore DomainLocalBlock InstMethodHashTable
 End
index b4f6f49..55dc5bd 100644 (file)
@@ -237,7 +237,7 @@ int g_rgCrstLevelMap[] =
     3,                 // CrstDynamicMT
     3,                 // CrstDynLinkZapItems
     7,                 // CrstEtwTypeLogHash
-    11,                        // CrstEventPipe
+    17,                        // CrstEventPipe
     0,                 // CrstEventStore
     0,                 // CrstException
     7,                 // CrstExecuteManLock
@@ -560,4 +560,3 @@ inline static LPCSTR GetCrstName(CrstType crstType)
 }
 
 #endif // defined(__IN_CRST_CPP) && defined(_DEBUG)
-
index e519199..ff4aa31 100644 (file)
     <Compile Include="$(BclSourcesRoot)\System\Diagnostics\Eventing\EventSource_CoreCLR.cs" />
     <Compile Condition="'$(FeatureXplatEventSource)' == 'true'" Include="$(BclSourcesRoot)\System\Diagnostics\Eventing\XplatEventLogger.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Diagnostics\Eventing\FrameworkEventSource.cs" />
+    <Compile Condition="'$(FeaturePerfTracing)' == 'true'" Include="$(BclSourcesRoot)\System\Diagnostics\Eventing\EventPipeEventProvider.cs" />
   </ItemGroup>
   <ItemGroup>
     <Compile Include="$(BclSourcesRoot)\System\Diagnostics\Contracts\Contracts.cs" />
index 3e00140..921354b 100644 (file)
     <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\EventProvider.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\EventSource.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\EventSourceException.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\IEventProvider.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\StubEnvironment.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\Winmeta.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\Tracing\TraceLogging\ArrayTypeInfo.cs" />
index e18574c..e5316bc 100644 (file)
@@ -78,6 +78,7 @@ namespace System.Diagnostics.Tracing
 
         private static bool m_setInformationMissing;
 
+        private IEventProvider m_eventProvider;          // The interface that implements the specific logging mechanism functions.
         UnsafeNativeMethods.ManifestEtw.EtwEnableCallback m_etwCallback;     // Trace Callback function
         private long m_regHandle;                        // Trace Registration Handle
         private byte m_level;                            // Tracing Level
@@ -119,6 +120,11 @@ namespace System.Diagnostics.Tracing
         // EventSource has special logic to do this, no one else should be calling EventProvider.  
         internal EventProvider()
         {
+#if PLATFORM_WINDOWS
+            m_eventProvider = new EtwEventProvider();
+#elif FEATURE_PERFTRACING
+            m_eventProvider = new EventPipeEventProvider();
+#endif
         }
 
         /// <summary>
@@ -429,7 +435,7 @@ namespace System.Diagnostics.Tracing
 
             // However the framework version of EventSource DOES have ES_SESSION_INFO defined and thus
             // does not have this issue.  
-#if ES_SESSION_INFO || !ES_BUILD_STANDALONE  
+#if (PLATFORM_WINDOWS && (ES_SESSION_INFO || !ES_BUILD_STANDALONE))
             int buffSize = 256;     // An initial guess that probably works most of the time.  
             byte* buffer;
             for (; ; )
@@ -1056,7 +1062,7 @@ namespace System.Diagnostics.Tracing
                                 userDataPtr[refObjPosition[7]].Ptr = (ulong)v7;
                             }
 
-                            status = UnsafeNativeMethods.ManifestEtw.EventWriteTransferWrapper(m_regHandle, ref eventDescriptor, activityID, childActivityID, argCount, userData);
+                            status = m_eventProvider.EventWriteTransferWrapper(m_regHandle, ref eventDescriptor, activityID, childActivityID, argCount, userData);
                         }
                     }
                     else
@@ -1082,7 +1088,7 @@ namespace System.Diagnostics.Tracing
                             }
                         }
 
-                        status = UnsafeNativeMethods.ManifestEtw.EventWriteTransferWrapper(m_regHandle, ref eventDescriptor, activityID, childActivityID, argCount, userData);
+                        status = m_eventProvider.EventWriteTransferWrapper(m_regHandle, ref eventDescriptor, activityID, childActivityID, argCount, userData);
 
                         for (int i = 0; i < refObjIndex; ++i)
                         {
@@ -1135,7 +1141,7 @@ namespace System.Diagnostics.Tracing
                                 (EventOpcode)eventDescriptor.Opcode == EventOpcode.Stop);
             }
 
-            int status = UnsafeNativeMethods.ManifestEtw.EventWriteTransferWrapper(m_regHandle, ref eventDescriptor, activityID, childActivityID, dataCount, (EventData*)data);
+            int status = m_eventProvider.EventWriteTransferWrapper(m_regHandle, ref eventDescriptor, activityID, childActivityID, dataCount, (EventData*)data);
 
             if (status != 0)
             {
@@ -1155,7 +1161,7 @@ namespace System.Diagnostics.Tracing
         {
             int status;
 
-            status = UnsafeNativeMethods.ManifestEtw.EventWriteTransferWrapper(
+            status = m_eventProvider.EventWriteTransferWrapper(
                 m_regHandle,
                 ref eventDescriptor,
                 activityID,
@@ -1178,12 +1184,12 @@ namespace System.Diagnostics.Tracing
         {
             m_providerId = providerId;
             m_etwCallback = enableCallback;
-            return UnsafeNativeMethods.ManifestEtw.EventRegister(ref providerId, enableCallback, null, ref m_regHandle);
+            return m_eventProvider.EventRegister(ref providerId, enableCallback, null, ref m_regHandle);
         }
 
         private uint EventUnregister(long registrationHandle)
         {
-            return UnsafeNativeMethods.ManifestEtw.EventUnregister(registrationHandle);
+            return m_eventProvider.EventUnregister(registrationHandle);
         }
 
         static int[] nibblebits = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 };
@@ -1203,5 +1209,59 @@ namespace System.Diagnostics.Tracing
             return idx;
         }
     }
+
+#if PLATFORM_WINDOWS
+
+    // A wrapper around the ETW-specific API calls.
+    internal sealed class EtwEventProvider : IEventProvider
+    {
+        // Register an event provider.
+        unsafe uint IEventProvider.EventRegister(
+            ref Guid providerId,
+            UnsafeNativeMethods.ManifestEtw.EtwEnableCallback enableCallback,
+            void* callbackContext,
+            ref long registrationHandle)
+        {
+            return UnsafeNativeMethods.ManifestEtw.EventRegister(
+                ref providerId,
+                enableCallback,
+                callbackContext,
+                ref registrationHandle);
+        }
+
+        // Unregister an event provider.
+        uint IEventProvider.EventUnregister(long registrationHandle)
+        {
+            return UnsafeNativeMethods.ManifestEtw.EventUnregister(registrationHandle);
+        }
+
+        // Write an event.
+        unsafe int IEventProvider.EventWriteTransferWrapper(
+            long registrationHandle,
+            ref EventDescriptor eventDescriptor,
+            Guid* activityId,
+            Guid* relatedActivityId,
+            int userDataCount,
+            EventProvider.EventData* userData)
+        {
+            return UnsafeNativeMethods.ManifestEtw.EventWriteTransferWrapper(
+                registrationHandle,
+                ref eventDescriptor,
+                activityId,
+                relatedActivityId,
+                userDataCount,
+                userData);
+        }
+
+        // Get or set the per-thread activity ID.
+        int IEventProvider.EventActivityIdControl(UnsafeNativeMethods.ManifestEtw.ActivityControl ControlCode, ref Guid ActivityId)
+        {
+            return UnsafeNativeMethods.ManifestEtw.EventActivityIdControl(
+                ControlCode,
+                ref ActivityId);
+        }
+    }
+
+#endif
 }
 
index cf4901d..483b1f8 100644 (file)
@@ -4,16 +4,10 @@
 
 // This program uses code hyperlinks available as part of the HyperAddin Visual Studio plug-in.
 // It is available from http://www.codeplex.com/hyperAddin 
-#if PLATFORM_WINDOWS
-
-#define FEATURE_MANAGED_ETW
-
 #if !ES_BUILD_STANDALONE && !CORECLR && !ES_BUILD_PN
 #define FEATURE_ACTIVITYSAMPLING
 #endif // !ES_BUILD_STANDALONE
 
-#endif // PLATFORM_WINDOWS
-
 #if ES_BUILD_STANDALONE
 #define FEATURE_MANAGED_ETW_CHANNELS
 // #define FEATURE_ADVANCED_MANAGED_ETW_CHANNELS
@@ -1474,7 +1468,7 @@ namespace System.Diagnostics.Tracing
                 // Set m_provider, which allows this.  
                 m_provider = provider;
 
-#if (!ES_BUILD_STANDALONE && !ES_BUILD_PN)
+#if (!ES_BUILD_STANDALONE && !ES_BUILD_PN && !PLATFORM_UNIX)
                 // API available on OS >= Win 8 and patched Win 7.
                 // Disable only for FrameworkEventSource to avoid recursion inside exception handling.
                 if (this.Name != "System.Diagnostics.Eventing.FrameworkEventSource" || Environment.IsWindows8OrAbove)
diff --git a/src/mscorlib/shared/System/Diagnostics/Tracing/IEventProvider.cs b/src/mscorlib/shared/System/Diagnostics/Tracing/IEventProvider.cs
new file mode 100644 (file)
index 0000000..0b51e52
--- /dev/null
@@ -0,0 +1,38 @@
+// 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.
+
+using Microsoft.Win32;
+
+#if ES_BUILD_STANDALONE
+namespace Microsoft.Diagnostics.Tracing
+#else
+namespace System.Diagnostics.Tracing
+#endif
+{
+    // Represents the interface between EventProvider and an external logging mechanism.
+    internal interface IEventProvider
+    {
+        // Register an event provider.
+        unsafe uint EventRegister(
+            ref Guid providerId,
+            UnsafeNativeMethods.ManifestEtw.EtwEnableCallback enableCallback,
+            void* callbackContext,
+            ref long registrationHandle);
+
+        // Unregister an event provider.
+        uint EventUnregister(long registrationHandle);
+
+        // Write an event.
+        unsafe int EventWriteTransferWrapper(
+            long registrationHandle,
+            ref EventDescriptor eventDescriptor,
+            Guid* activityId,
+            Guid* relatedActivityId,
+            int userDataCount,
+            EventProvider.EventData* userData);
+
+        // Get or set the per-thread activity ID.
+        int EventActivityIdControl(UnsafeNativeMethods.ManifestEtw.ActivityControl ControlCode, ref Guid ActivityId);
+    }
+}
diff --git a/src/mscorlib/src/System/Diagnostics/Eventing/EventPipeEventProvider.cs b/src/mscorlib/src/System/Diagnostics/Eventing/EventPipeEventProvider.cs
new file mode 100644 (file)
index 0000000..5917ecc
--- /dev/null
@@ -0,0 +1,86 @@
+// 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.
+using System.Collections.Concurrent;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Security;
+using Microsoft.Win32;
+
+namespace System.Diagnostics.Tracing
+{
+    internal sealed class EventPipeEventProvider : IEventProvider
+    {
+        // The EventPipeProvider handle.
+        private IntPtr m_provHandle = IntPtr.Zero;
+
+        // Register an event provider.
+        unsafe uint IEventProvider.EventRegister(
+            ref Guid providerId,
+            UnsafeNativeMethods.ManifestEtw.EtwEnableCallback enableCallback,
+            void* callbackContext,
+            ref long registrationHandle)
+        {
+            uint returnStatus = 0;
+            m_provHandle = EventPipeInternal.CreateProvider(providerId, enableCallback);
+            if(m_provHandle != IntPtr.Zero)
+            {
+                // Fixed registration handle because a new EventPipeEventProvider
+                // will be created for each new EventSource.
+                registrationHandle = 1;
+            }
+            else
+            {
+                // Unable to create the provider.
+                returnStatus = 1;
+            }
+
+            return returnStatus;
+        }
+
+        // Unregister an event provider.
+        uint IEventProvider.EventUnregister(long registrationHandle)
+        {
+            EventPipeInternal.DeleteProvider(m_provHandle);
+            return 0;
+        }
+
+        // Write an event.
+        unsafe int IEventProvider.EventWriteTransferWrapper(
+            long registrationHandle,
+            ref EventDescriptor eventDescriptor,
+            Guid* activityId,
+            Guid* relatedActivityId,
+            int userDataCount,
+            EventProvider.EventData* userData)
+        {
+            return 0;
+        }
+
+        // Get or set the per-thread activity ID.
+        int IEventProvider.EventActivityIdControl(UnsafeNativeMethods.ManifestEtw.ActivityControl ControlCode, ref Guid ActivityId)
+        {
+            return 0;
+        }
+    }
+
+    // PInvokes into the runtime used to interact with the EventPipe.
+    internal static class EventPipeInternal
+    {
+        [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
+        [SuppressUnmanagedCodeSecurity]
+        internal static extern IntPtr CreateProvider(Guid providerID, UnsafeNativeMethods.ManifestEtw.EtwEnableCallback callbackFunc);
+
+        [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
+        [SuppressUnmanagedCodeSecurity]
+        internal static extern IntPtr AddEvent(IntPtr provHandle, Int64 keywords, uint eventID, uint eventVersion, uint level, bool needStack);
+
+        [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
+        [SuppressUnmanagedCodeSecurity]
+        internal static extern void DeleteProvider(IntPtr provHandle);
+
+        [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
+        [SuppressUnmanagedCodeSecurity]
+        internal static extern unsafe void WriteEvent(IntPtr eventHandle, void* data, uint length);
+    }
+}
index cc6966e..ef82daa 100644 (file)
@@ -1271,6 +1271,15 @@ FCFuncStart(gEventLogger)
 FCFuncEnd()
 #endif // defined(FEATURE_EVENTSOURCE_XPLAT)
 
+#ifdef FEATURE_PERFTRACING
+FCFuncStart(gEventPipeInternalFuncs)
+    QCFuncElement("CreateProvider", EventPipeInternal::CreateProvider)
+    QCFuncElement("AddEvent", EventPipeInternal::AddEvent)
+    QCFuncElement("DeleteProvider", EventPipeInternal::DeleteProvider)
+    QCFuncElement("WriteEvent", EventPipeInternal::WriteEvent)
+FCFuncEnd()
+#endif // FEATURE_PERFTRACING
+
 #ifdef FEATURE_COMINTEROP
 FCFuncStart(gRuntimeClassFuncs)
     FCFuncElement("GetRedirectedGetHashCodeMD", ComObject::GetRedirectedGetHashCodeMD)
@@ -1374,6 +1383,9 @@ FCClassElement("Environment", "System", gEnvironmentFuncs)
 #ifdef FEATURE_COMINTEROP
 FCClassElement("EventArgsMarshaler", "System.StubHelpers", gEventArgsMarshalerFuncs)
 #endif // FEATURE_COMINTEROP
+#if defined(FEATURE_PERFTRACING)
+FCClassElement("EventPipeInternal", "System.Diagnostics.Tracing", gEventPipeInternalFuncs)
+#endif // FEATURE_PERFTRACING
 FCClassElement("Exception", "System", gExceptionFuncs)
 FCClassElement("FileLoadException", "System.IO", gFileLoadExceptionFuncs)
 FCClassElement("FormatterServices", "System.Runtime.Serialization", gSerializationFuncs)
index 8ea3f08..bed4cfd 100644 (file)
@@ -184,8 +184,10 @@ void EventPipe::WriteEvent(EventPipeEvent &event, BYTE *pData, unsigned int leng
         length);
 
     // Write to the EventPipeFile.
-    _ASSERTE(s_pFile != NULL);
-    s_pFile->WriteEvent(instance);
+    if(s_pFile != NULL)
+    {
+        s_pFile->WriteEvent(instance);
+    }
 
     // Write to the EventPipeJsonFile if it exists.
     if(s_pJsonFile != NULL)
@@ -306,4 +308,67 @@ CrstStatic* EventPipe::GetLock()
     return &s_configCrst;
 }
 
+INT_PTR QCALLTYPE EventPipeInternal::CreateProvider(
+    GUID providerID,
+    EventPipeCallback pCallbackFunc)
+{
+    QCALL_CONTRACT;
+
+    EventPipeProvider *pProvider = NULL;
+
+    BEGIN_QCALL;
+
+    pProvider = new EventPipeProvider(providerID, pCallbackFunc, NULL);
+
+    END_QCALL;
+
+    return reinterpret_cast<INT_PTR>(pProvider);
+}
+
+INT_PTR QCALLTYPE EventPipeInternal::AddEvent(
+    INT_PTR provHandle,
+    __int64 keywords,
+    unsigned int eventID,
+    unsigned int eventVersion,
+    unsigned int level,
+    bool needStack)
+{
+    QCALL_CONTRACT;
+    BEGIN_QCALL;
+
+    // TODO
+
+    END_QCALL;
+
+    return 0;
+}
+
+void QCALLTYPE EventPipeInternal::DeleteProvider(
+    INT_PTR provHandle)
+{
+    QCALL_CONTRACT;
+    BEGIN_QCALL;
+
+    if(provHandle != NULL)
+    {
+        EventPipeProvider *pProvider = reinterpret_cast<EventPipeProvider*>(provHandle);
+        delete pProvider;
+    }
+
+    END_QCALL;
+}
+
+void QCALLTYPE EventPipeInternal::WriteEvent(
+    INT_PTR eventHandle,
+    void *pData,
+    unsigned int length)
+{
+    QCALL_CONTRACT;
+    BEGIN_QCALL;
+
+    // TODO
+
+    END_QCALL;
+}
+
 #endif // FEATURE_PERFTRACING
index c6d7f61..d5b85f7 100644 (file)
@@ -8,6 +8,7 @@
 #ifdef FEATURE_PERFTRACING
 
 #include "crst.h"
+#include "eventpipeprovider.h"
 #include "stackwalk.h"
 
 class EventPipeConfiguration;
@@ -174,6 +175,32 @@ class EventPipe
         static EventPipeJsonFile *s_pJsonFile;
 };
 
+class EventPipeInternal
+{
+
+public:
+
+    static INT_PTR QCALLTYPE CreateProvider(
+        GUID providerID,
+        EventPipeCallback pCallbackFunc);
+
+    static INT_PTR QCALLTYPE AddEvent(
+        INT_PTR provHandle,
+        __int64 keywords,
+        unsigned int eventID,
+        unsigned int eventVersion,
+        unsigned int level,
+        bool needStack);
+
+    static void QCALLTYPE DeleteProvider(
+        INT_PTR provHandle);
+
+    static void QCALLTYPE WriteEvent(
+        INT_PTR eventHandle,
+        void *pData,
+        unsigned int length);
+};
+
 #endif // FEATURE_PERFTRACING
 
 #endif // __EVENTPIPE_H__
index cfb96fc..0128685 100644 (file)
@@ -85,6 +85,7 @@ bool EventPipeConfiguration::RegisterProvider(EventPipeProvider &provider)
 
     // TODO: Set the provider configuration and enable it if we know
     // anything about the provider before it is registered.
+    provider.SetConfiguration(true /* providerEnabled */, 0xFFFFFFFFFFFFFFFF /* keywords */, EventPipeEventLevel::Verbose /* level */);
 
     return true;
 }
index da18533..362c37a 100644 (file)
@@ -10,7 +10,7 @@
 
 #ifdef FEATURE_PERFTRACING
 
-EventPipeProvider::EventPipeProvider(const GUID &providerID)
+EventPipeProvider::EventPipeProvider(const GUID &providerID, EventPipeCallback pCallbackFunction, void *pCallbackData)
 {
     CONTRACTL
     {
@@ -25,8 +25,8 @@ EventPipeProvider::EventPipeProvider(const GUID &providerID)
     m_keywords = 0;
     m_providerLevel = EventPipeEventLevel::Critical;
     m_pEventList = new SList<SListElem<EventPipeEvent*>>();
-    m_pCallbackFunction = NULL;
-    m_pCallbackData = NULL;
+    m_pCallbackFunction = pCallbackFunction;
+    m_pCallbackData = pCallbackData;
 
     // Register the provider.
     EventPipeConfiguration* pConfig = EventPipe::GetConfiguration();
@@ -165,46 +165,6 @@ void EventPipeProvider::AddEvent(EventPipeEvent &event)
     m_pEventList->InsertTail(new SListElem<EventPipeEvent*>(&event));
 }
 
-void EventPipeProvider::RegisterCallback(EventPipeCallback pCallbackFunction, void *pData)
-{
-    CONTRACTL
-    {
-        THROWS;
-        GC_NOTRIGGER;
-        MODE_ANY;
-    }
-    CONTRACTL_END;
-
-    // Take the config lock before setting the callback.
-    CrstHolder _crst(EventPipe::GetLock());
-
-    if(m_pCallbackFunction == NULL)
-    {
-        m_pCallbackFunction = pCallbackFunction;
-        m_pCallbackData = pData;
-    }
-}
-
-void EventPipeProvider::UnregisterCallback(EventPipeCallback pCallbackFunction)
-{
-    CONTRACTL
-    {
-        THROWS;
-        GC_NOTRIGGER;
-        MODE_ANY;
-    }
-    CONTRACTL_END;
-
-    // Take the config lock before setting the callback.
-    CrstHolder _crst(EventPipe::GetLock());
-
-    if(m_pCallbackFunction == pCallbackFunction)
-    {
-        m_pCallbackFunction = NULL;
-        m_pCallbackData = NULL;
-    }
-}
-
 void EventPipeProvider::InvokeCallback()
 {
     CONTRACTL
@@ -216,7 +176,7 @@ void EventPipeProvider::InvokeCallback()
     }
     CONTRACTL_END;
 
-    if(m_pCallbackFunction != NULL)
+    if(m_pCallbackFunction != NULL && !g_fEEShutDown)
     {
         (*m_pCallbackFunction)(
             &m_providerID,
index 610d76d..d1ce158 100644 (file)
@@ -61,7 +61,7 @@ private:
 
 public:
 
-    EventPipeProvider(const GUID &providerID);
+    EventPipeProvider(const GUID &providerID, EventPipeCallback pCallbackFunction = NULL, void *pCallbackData = NULL);
     ~EventPipeProvider();
 
     // Get the provider ID.
@@ -79,12 +79,6 @@ public:
     // Create a new event.
     EventPipeEvent* AddEvent(INT64 keywords, unsigned int eventID, unsigned int eventVersion, EventPipeEventLevel level, bool needStack);
 
-    // Register a callback with the provider to be called on state change.
-    void RegisterCallback(EventPipeCallback pCallbackFunction, void *pData);
-
-    // Unregister a callback.
-    void UnregisterCallback(EventPipeCallback pCallbackFunction);
-
 private:
 
     // Add an event to the provider.
index d1f48bd..3e2d478 100644 (file)
@@ -93,6 +93,7 @@
 
 #if defined(FEATURE_EVENTSOURCE_XPLAT)
 #include "nativeeventsource.h"
+#include "eventpipe.h"
 #endif //defined(FEATURE_EVENTSOURCE_XPLAT)
 
 #endif // CROSSGEN_MSCORLIB