summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Robbins <brianrob@microsoft.com>2017-05-10 15:11:28 -0700
committerGitHub <noreply@github.com>2017-05-10 15:11:28 -0700
commit377073385e4545d36e1a96429dd78548f87c597c (patch)
treef89141239ab55d650e7b516ea10a8514d5c81c44
parent0b625bfdbb97565b7d489d1d083cfaf4dbd47e0d (diff)
downloadcoreclr-377073385e4545d36e1a96429dd78548f87c597c.tar.gz
coreclr-377073385e4545d36e1a96429dd78548f87c597c.tar.bz2
coreclr-377073385e4545d36e1a96429dd78548f87c597c.zip
Re-Factor EventSource to Support Writing to EventPipe (#11435)
Re-Factor EventSource to Support Writing to EventPipe.
-rw-r--r--clr.coreclr.props9
-rw-r--r--clr.defines.targets1
-rw-r--r--clrdefinitions.cmake4
-rw-r--r--src/inc/CrstTypes.def2
-rw-r--r--src/inc/crsttypes.h3
-rw-r--r--src/mscorlib/System.Private.CoreLib.csproj1
-rw-r--r--src/mscorlib/shared/System.Private.CoreLib.Shared.projitems1
-rw-r--r--src/mscorlib/shared/System/Diagnostics/Tracing/EventProvider.cs74
-rw-r--r--src/mscorlib/shared/System/Diagnostics/Tracing/EventSource.cs8
-rw-r--r--src/mscorlib/shared/System/Diagnostics/Tracing/IEventProvider.cs38
-rw-r--r--src/mscorlib/src/System/Diagnostics/Eventing/EventPipeEventProvider.cs86
-rw-r--r--src/vm/ecalllist.h12
-rw-r--r--src/vm/eventpipe.cpp69
-rw-r--r--src/vm/eventpipe.h27
-rw-r--r--src/vm/eventpipeconfiguration.cpp1
-rw-r--r--src/vm/eventpipeprovider.cpp48
-rw-r--r--src/vm/eventpipeprovider.h8
-rw-r--r--src/vm/mscorlib.cpp1
18 files changed, 319 insertions, 74 deletions
diff --git a/clr.coreclr.props b/clr.coreclr.props
index 5251eab780..059fb3a597 100644
--- a/clr.coreclr.props
+++ b/clr.coreclr.props
@@ -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>
@@ -76,15 +76,20 @@
<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>
diff --git a/clr.defines.targets b/clr.defines.targets
index 1dd41f16d6..df6a409f97 100644
--- a/clr.defines.targets
+++ b/clr.defines.targets
@@ -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>
diff --git a/clrdefinitions.cmake b/clrdefinitions.cmake
index 92b63a30a5..6db2b24483 100644
--- a/clrdefinitions.cmake
+++ b/clrdefinitions.cmake
@@ -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)
diff --git a/src/inc/CrstTypes.def b/src/inc/CrstTypes.def
index 227f986a85..5bf4ec63db 100644
--- a/src/inc/CrstTypes.def
+++ b/src/inc/CrstTypes.def
@@ -781,5 +781,5 @@ Crst InlineTrackingMap
End
Crst EventPipe
- AcquiredBefore ThreadIdDispenser ThreadStore
+ AcquiredBefore ThreadIdDispenser ThreadStore DomainLocalBlock InstMethodHashTable
End
diff --git a/src/inc/crsttypes.h b/src/inc/crsttypes.h
index b4f6f49e64..55dc5bd4ab 100644
--- a/src/inc/crsttypes.h
+++ b/src/inc/crsttypes.h
@@ -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)
-
diff --git a/src/mscorlib/System.Private.CoreLib.csproj b/src/mscorlib/System.Private.CoreLib.csproj
index e519199640..ff4aa31eb7 100644
--- a/src/mscorlib/System.Private.CoreLib.csproj
+++ b/src/mscorlib/System.Private.CoreLib.csproj
@@ -566,6 +566,7 @@
<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" />
diff --git a/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems b/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems
index 3e00140cc7..921354bd4c 100644
--- a/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems
+++ b/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems
@@ -427,6 +427,7 @@
<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" />
diff --git a/src/mscorlib/shared/System/Diagnostics/Tracing/EventProvider.cs b/src/mscorlib/shared/System/Diagnostics/Tracing/EventProvider.cs
index e18574c1b4..e5316bc365 100644
--- a/src/mscorlib/shared/System/Diagnostics/Tracing/EventProvider.cs
+++ b/src/mscorlib/shared/System/Diagnostics/Tracing/EventProvider.cs
@@ -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
}
diff --git a/src/mscorlib/shared/System/Diagnostics/Tracing/EventSource.cs b/src/mscorlib/shared/System/Diagnostics/Tracing/EventSource.cs
index cf4901de6f..483b1f8e36 100644
--- a/src/mscorlib/shared/System/Diagnostics/Tracing/EventSource.cs
+++ b/src/mscorlib/shared/System/Diagnostics/Tracing/EventSource.cs
@@ -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
index 0000000000..0b51e52ec4
--- /dev/null
+++ b/src/mscorlib/shared/System/Diagnostics/Tracing/IEventProvider.cs
@@ -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
index 0000000000..5917ecc89c
--- /dev/null
+++ b/src/mscorlib/src/System/Diagnostics/Eventing/EventPipeEventProvider.cs
@@ -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);
+ }
+}
diff --git a/src/vm/ecalllist.h b/src/vm/ecalllist.h
index cc6966ed8e..ef82daab95 100644
--- a/src/vm/ecalllist.h
+++ b/src/vm/ecalllist.h
@@ -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)
diff --git a/src/vm/eventpipe.cpp b/src/vm/eventpipe.cpp
index 8ea3f0867e..bed4cfdbc4 100644
--- a/src/vm/eventpipe.cpp
+++ b/src/vm/eventpipe.cpp
@@ -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
diff --git a/src/vm/eventpipe.h b/src/vm/eventpipe.h
index c6d7f61152..d5b85f7e3a 100644
--- a/src/vm/eventpipe.h
+++ b/src/vm/eventpipe.h
@@ -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__
diff --git a/src/vm/eventpipeconfiguration.cpp b/src/vm/eventpipeconfiguration.cpp
index cfb96fc8d5..01286850a2 100644
--- a/src/vm/eventpipeconfiguration.cpp
+++ b/src/vm/eventpipeconfiguration.cpp
@@ -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;
}
diff --git a/src/vm/eventpipeprovider.cpp b/src/vm/eventpipeprovider.cpp
index da185334a9..362c37a50f 100644
--- a/src/vm/eventpipeprovider.cpp
+++ b/src/vm/eventpipeprovider.cpp
@@ -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,
diff --git a/src/vm/eventpipeprovider.h b/src/vm/eventpipeprovider.h
index 610d76d8bf..d1ce1584d7 100644
--- a/src/vm/eventpipeprovider.h
+++ b/src/vm/eventpipeprovider.h
@@ -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.
diff --git a/src/vm/mscorlib.cpp b/src/vm/mscorlib.cpp
index d1f48bd1f5..3e2d478bbf 100644
--- a/src/vm/mscorlib.cpp
+++ b/src/vm/mscorlib.cpp
@@ -93,6 +93,7 @@
#if defined(FEATURE_EVENTSOURCE_XPLAT)
#include "nativeeventsource.h"
+#include "eventpipe.h"
#endif //defined(FEATURE_EVENTSOURCE_XPLAT)
#endif // CROSSGEN_MSCORLIB