Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ internal static void Enable(EventPipeConfiguration configuration)
configuration.OutputFile,
configuration.Format,
configuration.CircularBufferSizeInMB,
providers,
(uint)providers.Length);
providers);
}

internal static void Disable()
Expand All @@ -210,17 +209,81 @@ internal static void Disable()

internal static class EventPipeInternal
{
private unsafe struct EventPipeProviderConfigurationNative
{
private char* m_pProviderName;
private ulong m_keywords;
private uint m_loggingLevel;
private char* m_pFilterData;

internal static void MarshalToNative(EventPipeProviderConfiguration managed, ref EventPipeProviderConfigurationNative native)
{
native.m_pProviderName = (char*)Marshal.StringToCoTaskMemUni(managed.ProviderName);
native.m_keywords = managed.Keywords;
native.m_loggingLevel = managed.LoggingLevel;
native.m_pFilterData = (char*)Marshal.StringToCoTaskMemUni(managed.FilterData);
}

internal void Release()
{
if (m_pProviderName != null)
{
Marshal.FreeCoTaskMem((IntPtr)m_pProviderName);
}
if (m_pFilterData != null)
{
Marshal.FreeCoTaskMem((IntPtr)m_pFilterData);
}
}
}

//
// These PInvokes are used by the configuration APIs to interact with EventPipe.
//
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
internal static extern ulong Enable(
string? outputFile,
private static unsafe extern ulong Enable(
char* outputFile,
EventPipeSerializationFormat format,
uint circularBufferSizeInMB,
EventPipeProviderConfiguration[] providers,
EventPipeProviderConfigurationNative* providers,
uint numProviders);

internal static unsafe ulong Enable(
string? outputFile,
EventPipeSerializationFormat format,
uint circularBufferSizeInMB,
EventPipeProviderConfiguration[] providers)
{
Span<EventPipeProviderConfigurationNative> providersNative = new Span<EventPipeProviderConfigurationNative>((void*)Marshal.AllocCoTaskMem(sizeof(EventPipeProviderConfigurationNative) * providers.Length), providers.Length);
providersNative.Clear();

try
{
for (int i = 0; i < providers.Length; i++)
{
EventPipeProviderConfigurationNative.MarshalToNative(providers[i], ref providersNative[i]);
}

fixed (char* outputFilePath = outputFile)
fixed (EventPipeProviderConfigurationNative* providersNativePointer = providersNative)
{
return Enable(outputFilePath, format, circularBufferSizeInMB, providersNativePointer, (uint)providersNative.Length);
}
}
finally
{
for (int i = 0; i < providers.Length; i++)
{
providersNative[i].Release();
}

fixed (EventPipeProviderConfigurationNative* providersNativePointer = providersNative)
{
Marshal.FreeCoTaskMem((IntPtr)providersNativePointer);
}
}
}

[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
internal static extern void Disable(ulong sessionID);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private void CommitDispatchConfiguration()
new EventPipeProviderConfiguration(NativeRuntimeEventSource.EventSourceName, (ulong)aggregatedKeywords, (uint)highestLevel, null)
};

m_sessionID = EventPipeInternal.Enable(null, EventPipeSerializationFormat.NetTrace, DefaultEventListenerCircularMBSize, providerConfiguration, 1);
m_sessionID = EventPipeInternal.Enable(null, EventPipeSerializationFormat.NetTrace, DefaultEventListenerCircularMBSize, providerConfiguration);
Debug.Assert(m_sessionID != 0);

// Get the session information that is required to properly dispatch events.
Expand Down