Skip to content

Commit

Permalink
Only emit event in native code
Browse files Browse the repository at this point in the history
  • Loading branch information
verdie-g committed Nov 30, 2023
1 parent c0afd7d commit 49c270a
Show file tree
Hide file tree
Showing 27 changed files with 13 additions and 332 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,5 @@ private static partial void LogThreadPoolIOPack(
IntPtr NativeOverlapped,
IntPtr Overlapped,
ushort ClrInstanceID);

[NonEvent]
[LibraryImport(RuntimeHelpers.QCall)]
private static partial void LogWaitHandleWaitStart(
WaitHandleWaitSourceMap WaitSource,
IntPtr AssociatedObjectID,
ushort ClrInstanceID);

[NonEvent]
[LibraryImport(RuntimeHelpers.QCall)]
private static partial void LogWaitHandleWaitStop(ushort ClrInstanceID);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,4 @@ EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogExceptionThrown(
{
}

EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogWaitHandleWaitStart(uint8_t WaitSource, intptr_t AssociatedObjectID, uint16_t ClrInstanceID)
{
}

EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogWaitHandleWaitStop(uint16_t ClrInstanceID)
{
}

#endif // FEATURE_PERFTRACING
10 changes: 0 additions & 10 deletions src/coreclr/nativeaot/Runtime/runtimeeventinternal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,4 @@ EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogExceptionThrown(
GetClrInstanceId());
}

EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogWaitHandleWaitStart(uint8_t WaitSource, intptr_t AssociatedObjectID, uint16_t ClrInstanceID)
{
FireEtwWaitHandleWaitStart(WaitSource, reinterpret_cast<const void*>(AssociatedObjectID), ClrInstanceID);
}

EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogWaitHandleWaitStop(uint16_t ClrInstanceID)
{
FireEtwWaitHandleWaitStop(ClrInstanceID);
}

#endif // FEATURE_PERFTRACING
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public static partial class Keywords
public const EventKeywords ContentionKeyword = (EventKeywords)0x4000;
public const EventKeywords ThreadingKeyword = (EventKeywords)0x10000;
public const EventKeywords ThreadTransferKeyword = (EventKeywords)0x80000000;
public const EventKeywords WaitHandleKeyword = (EventKeywords)0x40000000000;
}

[NonEvent]
Expand Down Expand Up @@ -133,20 +132,5 @@ internal static void LogThreadPoolIOPack(
{
RuntimeImports.NativeRuntimeEventSource_LogThreadPoolIOPack(NativeOverlapped, Overlapped, ClrInstanceID);
}

[NonEvent]
internal static void LogWaitHandleWaitStart(
WaitHandleWaitSourceMap WaitSource,
IntPtr AssociatedObjectID,
ushort ClrInstanceID)
{
RuntimeImports.NativeRuntimeEventSource_LogWaitHandleWaitStart((byte)WaitSource, AssociatedObjectID, ClrInstanceID);
}

[NonEvent]
internal static void LogWaitHandleWaitStop(ushort ClrInstanceID)
{
RuntimeImports.NativeRuntimeEventSource_LogWaitHandleWaitStop(ClrInstanceID);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -826,17 +826,6 @@ internal static partial void NativeRuntimeEventSource_LogThreadPoolIOPack(
[LibraryImport(RuntimeLibrary)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
internal static unsafe partial void NativeRuntimeEventSource_LogExceptionThrown(char* exceptionTypeName, char* exceptionMessage, IntPtr faultingIP, long hresult);

[LibraryImport(RuntimeLibrary)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
internal static partial void NativeRuntimeEventSource_LogWaitHandleWaitStart(
byte WaitSource,
IntPtr AssociatedObjectID,
ushort ClrInstanceID);

[LibraryImport(RuntimeLibrary)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
internal static partial void NativeRuntimeEventSource_LogWaitHandleWaitStop(ushort ClrInstanceID);
#endif // FEATURE_PERFTRACING

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

#pragma warning disable 0420 //passing volatile fields by ref


using System.Diagnostics;
using System.Diagnostics.Tracing;
using System.Runtime.CompilerServices;

namespace System.Threading
{
Expand Down Expand Up @@ -98,7 +97,7 @@ public Condition(Lock @lock)

public bool Wait(TimeSpan timeout) => Wait(WaitHandle.ToTimeoutMilliseconds(timeout));

public unsafe bool Wait(int millisecondsTimeout, object? associatedObject = null)
public unsafe bool Wait(int millisecondsTimeout)
{
ArgumentOutOfRangeException.ThrowIfLessThan(millisecondsTimeout, -1);

Expand All @@ -108,17 +107,6 @@ public unsafe bool Wait(int millisecondsTimeout, object? associatedObject = null
Waiter waiter = GetWaiterForCurrentThread();
AddWaiter(waiter);

bool isWaitHandleKeywordEnabled = NativeRuntimeEventSource.Log.IsEnabled(
EventLevel.Verbose,
NativeRuntimeEventSource.Keywords.WaitHandleKeyword);
if (isWaitHandleKeywordEnabled)
{
associatedObject ??= this;
NativeRuntimeEventSource.Log.WaitHandleWaitStart(
NativeRuntimeEventSource.WaitHandleWaitSourceMap.MonitorWait,
*(nint*)Unsafe.AsPointer(ref associatedObject));
}

uint recursionCount = _lock.ExitAll();
bool success = false;
try
Expand All @@ -144,11 +132,6 @@ public unsafe bool Wait(int millisecondsTimeout, object? associatedObject = null
waiter.ev.Reset();
}

if (isWaitHandleKeywordEnabled)
{
NativeRuntimeEventSource.Log.WaitHandleWaitStop();
}

AssertIsNotInList(waiter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public static bool IsEntered(object obj)
[UnsupportedOSPlatform("browser")]
public static bool Wait(object obj, int millisecondsTimeout)
{
return GetCondition(obj).Wait(millisecondsTimeout, obj);
return GetCondition(obj).Wait(millisecondsTimeout);
}

public static void Pulse(object obj)
Expand Down
6 changes: 4 additions & 2 deletions src/coreclr/scripts/genRuntimeEventSources.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ def getManifestsToGenerate(runtimeFlavor):

def generateEvent(eventNode, providerNode, outputFile, stringTable):

# ThreadPool, Contention and WaitHandle events are defined manually in NativeRuntimeEventSource.Threading.cs
# ThreadPool and Contention events are defined manually in NativeRuntimeEventSource.Threading.cs
symbol = eventNode.getAttribute("symbol")
if any(s in symbol for s in ["ThreadPool", "Contention", "WaitHandle"]):
if "ThreadPool" in symbol:
return
if "Contention" in symbol:
return

evtLevel = eventNode.getAttribute("level")[4:]
Expand Down
20 changes: 0 additions & 20 deletions src/coreclr/vm/nativeeventsource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,24 +189,4 @@ extern "C" void QCALLTYPE LogContentionStop(uint8_t ContentionFlags, uint16_t Cl
END_QCALL;
}

extern "C" void QCALLTYPE LogWaitHandleWaitStart(uint8_t WaitSource, void* AssociatedObjectID, uint16_t ClrInstanceID)
{
QCALL_CONTRACT;
BEGIN_QCALL;

FireEtwWaitHandleWaitStart(WaitSource, AssociatedObjectID, ClrInstanceID);

END_QCALL;
}

extern "C" void QCALLTYPE LogWaitHandleWaitStop(uint16_t ClrInstanceID)
{
QCALL_CONTRACT;
BEGIN_QCALL;

FireEtwWaitHandleWaitStop(ClrInstanceID);

END_QCALL;
}

#endif // FEATURE_PERFTRACING
2 changes: 0 additions & 2 deletions src/coreclr/vm/nativeeventsource.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ extern "C" void QCALLTYPE LogThreadPoolIOPack(_In_z_ void* nativeOverlapped, _In
extern "C" void QCALLTYPE LogContentionLockCreated(void* LockID, void* AssociatedObjectID, uint16_t ClrInstanceID);
extern "C" void QCALLTYPE LogContentionStart(uint8_t ContentionFlags, uint16_t ClrInstanceID, void* LockID, void* AssociatedObjectID, uint64_t LockOwnerThreadID);
extern "C" void QCALLTYPE LogContentionStop(uint8_t ContentionFlags, uint16_t ClrInstanceID, double DurationNs);
extern "C" void QCALLTYPE LogWaitHandleWaitStart(uint8_t WaitSource, void* AssociatedObjectID, uint16_t ClrInstanceID);
extern "C" void QCALLTYPE LogWaitHandleWaitStop(uint16_t ClrInstanceID);
#endif // defined(FEATURE_PERFTRACING)

#endif //_NATIVEEVENTSOURCE_H_
2 changes: 0 additions & 2 deletions src/coreclr/vm/qcallentrypoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,6 @@ static const Entry s_QCall[] =
DllImportEntry(LogContentionLockCreated)
DllImportEntry(LogContentionStart)
DllImportEntry(LogContentionStop)
DllImportEntry(LogWaitHandleWaitStart)
DllImportEntry(LogWaitHandleWaitStop)
DllImportEntry(EventPipeInternal_Enable)
DllImportEntry(EventPipeInternal_Disable)
DllImportEntry(EventPipeInternal_GetSessionInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ public void Test_GenerateManifest_InvalidEventSources()

e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.EventIdReusedEventSource), string.Empty, strictOptions));
AssertExceptionStringsEqual(() => string.Join(Environment.NewLine,
GetResourceString("EventSource_EventIdReused", "WriteInteger2", 1, "WriteInteger1"),
GetResourceString("EventSource_EventIdReused", "WriteInteger2", 1),
GetResourceString("EventSource_TaskOpcodePairReused", "WriteInteger2", 1, "WriteInteger1", 1)),
e);


e = AssertExtensions.Throws<ArgumentException>(null, () => EventSource.GenerateManifest(typeof(Sdt.EventIdReusedEventSource), string.Empty, strictOptions));
AssertExceptionStringsEqual(() => string.Join(Environment.NewLine,
GetResourceString("EventSource_EventIdReused", "WriteInteger2", 1, "WriteInteger1"),
GetResourceString("EventSource_EventIdReused", "WriteInteger2", 1),
GetResourceString("EventSource_TaskOpcodePairReused", "WriteInteger2", 1, "WriteInteger1", 1)),
e);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2091,7 +2091,7 @@
<value>Channel {0} has a value of {1} which is outside the legal range (16-254).</value>
</data>
<data name="EventSource_EventIdReused" xml:space="preserve">
<value>Event {0} has ID {1} which is already in use by event {2}.</value>
<value>Event {0} has ID {1} which is already in use.</value>
</data>
<data name="EventSource_EventMustHaveTaskIfNonDefaultOpcode" xml:space="preserve">
<value>Event {0} (with ID {1}) has a non-default opcode but not a task.</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3530,13 +3530,9 @@ private static void DebugCheckEvent(ref Dictionary<string, string>? eventsByName
manifest.ManifestError(SR.Format(SR.EventSource_MismatchIdToWriteEvent, evtName, evtId, eventArg), true);
}

if (evtId < eventData.Length)
if (evtId < eventData.Length && eventData[evtId].Descriptor.EventId != 0)
{
var existingEventMetadata = eventData[evtId];
if (existingEventMetadata.Descriptor.EventId != 0)
{
manifest.ManifestError(SR.Format(SR.EventSource_EventIdReused, evtName, evtId, existingEventMetadata.Name), true);
}
manifest.ManifestError(SR.Format(SR.EventSource_EventIdReused, evtName, evtId), true);
}

// We give a task to things if they don't have one.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ private static partial class Messages
public const string IOEnqueue = "NativeOverlapped={0};\nOverlapped={1};\nMultiDequeues={2};\nClrInstanceID={3}";
public const string IO = "NativeOverlapped={0};\nOverlapped={1};\nClrInstanceID={2}";
public const string WorkingThreadCount = "Count={0};\nClrInstanceID={1}";
public const string WaitHandleWaitStart = "WaitSource={0};\nAssociatedObjectID={1};\nClrInstanceID={2}";
public const string WaitHandleWaitStop = "ClrInstanceID={0}";
}

// The task definitions for the ETW manifest
Expand All @@ -45,7 +43,6 @@ private static partial class Messages
public const EventTask ThreadPool = (EventTask)23;
public const EventTask ThreadPoolWorkingThreadCount = (EventTask)22;
public const EventTask ThreadPoolMinMaxThreads = (EventTask)38;
public const EventTask WaitHandleWait = (EventTask)39;
}

public static partial class Opcodes // this name and visibility is important for EventSource
Expand Down Expand Up @@ -79,12 +76,6 @@ public enum ThreadAdjustmentReasonMap : uint
CooperativeBlocking,
}

public enum WaitHandleWaitSourceMap : byte
{
Unknown,
MonitorWait,
}

[Event(90, Level = EventLevel.Informational, Message = Messages.ContentionLockCreated, Task = Tasks.Contention, Opcode = EventOpcode.Info, Version = 0, Keywords = Keywords.ContentionKeyword)]
private void ContentionLockCreated(nint LockID, nint AssociatedObjectID, ushort ClrInstanceID = DefaultClrInstanceId)
{
Expand Down Expand Up @@ -329,22 +320,5 @@ public unsafe void ThreadPoolMinMaxThreads(
LogThreadPoolMinMaxThreads(MinWorkerThreads, MaxWorkerThreads, MinIOCompletionThreads, MaxIOCompletionThreads, ClrInstanceID);
}
}

[Event(301, Level = EventLevel.Verbose, Message = Messages.WaitHandleWaitStart, Task = Tasks.WaitHandleWait, Opcode = EventOpcode.Start, Version = 0, Keywords = Keywords.WaitHandleKeyword)]
public void WaitHandleWaitStart(
WaitHandleWaitSourceMap WaitSource,
nint AssociatedObjectID,
ushort ClrInstanceID = DefaultClrInstanceId)
{
Debug.Assert(IsEnabled(EventLevel.Verbose, Keywords.WaitHandleKeyword));
LogWaitHandleWaitStart(WaitSource, AssociatedObjectID, ClrInstanceID);
}

[Event(302, Level = EventLevel.Verbose, Message = Messages.WaitHandleWaitStop, Task = Tasks.WaitHandleWait, Opcode = EventOpcode.Stop, Version = 0, Keywords = Keywords.WaitHandleKeyword)]
public void WaitHandleWaitStop(ushort ClrInstanceID = DefaultClrInstanceId)
{
Debug.Assert(IsEnabled(EventLevel.Verbose, Keywords.WaitHandleKeyword));
LogWaitHandleWaitStop(ClrInstanceID);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public static partial class Keywords
public const EventKeywords ContentionKeyword = (EventKeywords)0x4000;
public const EventKeywords ThreadingKeyword = (EventKeywords)0x10000;
public const EventKeywords ThreadTransferKeyword = (EventKeywords)0x80000000;
public const EventKeywords WaitHandleKeyword = (EventKeywords)0x40000000000;
}

private static partial class Messages
Expand All @@ -33,8 +32,6 @@ private static partial class Messages
public const string IOEnqueue = "NativeOverlapped={0};\nOverlapped={1};\nMultiDequeues={2};\nClrInstanceID={3}";
public const string IO = "NativeOverlapped={0};\nOverlapped={1};\nClrInstanceID={2}";
public const string WorkingThreadCount = "Count={0};\nClrInstanceID={1}";
public const string WaitHandleWaitStart = "WaitSource={0};\nAssociatedObjectID={1};\nClrInstanceID={2}";
public const string WaitHandleWaitStop = "ClrInstanceID={0}";
}

// The task definitions for the ETW manifest
Expand All @@ -46,7 +43,6 @@ private static partial class Messages
public const EventTask ThreadPool = (EventTask)23;
public const EventTask ThreadPoolWorkingThreadCount = (EventTask)22;
public const EventTask ThreadPoolMinMaxThreads = (EventTask)38;
public const EventTask WaitHandleWait = (EventTask)39;
}

public static partial class Opcodes // this name and visibility is important for EventSource
Expand Down Expand Up @@ -80,12 +76,6 @@ public enum ThreadAdjustmentReasonMap : uint
CooperativeBlocking,
}

public enum WaitHandleWaitSourceMap : byte
{
Unknown,
MonitorWait,
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = "Parameters to this method are primitive and are trimmer safe")]
[Event(90, Level = EventLevel.Informational, Message = Messages.ContentionLockCreated, Task = Tasks.Contention, Opcode = EventOpcode.Info, Version = 0, Keywords = Keywords.ContentionKeyword)]
private unsafe void ContentionLockCreated(nint LockID, nint AssociatedObjectID, ushort ClrInstanceID = DefaultClrInstanceId)
Expand Down Expand Up @@ -514,40 +504,5 @@ public unsafe void ThreadPoolMinMaxThreads(
data[4].Reserved = 0;
WriteEventCore(59, 5, data);
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = "Parameters to this method are primitive and are trimmer safe")]
[Event(301, Level = EventLevel.Verbose, Message = Messages.WaitHandleWaitStart, Task = Tasks.WaitHandleWait, Opcode = EventOpcode.Start, Version = 0, Keywords = Keywords.WaitHandleKeyword)]
public unsafe void WaitHandleWaitStart(
WaitHandleWaitSourceMap WaitSource,
nint AssociatedObjectID,
ushort ClrInstanceID = DefaultClrInstanceId)
{
Debug.Assert(IsEnabled(EventLevel.Verbose, Keywords.WaitHandleKeyword));

EventData* data = stackalloc EventData[3];
data[0].DataPointer = (nint)(&WaitSource);
data[0].Size = sizeof(WaitHandleWaitSourceMap);
data[0].Reserved = 0;
data[1].DataPointer = (nint)(&AssociatedObjectID);
data[1].Size = nint.Size;
data[1].Reserved = 0;
data[2].DataPointer = (nint)(&ClrInstanceID);
data[2].Size = sizeof(ushort);
data[2].Reserved = 0;
WriteEventCore(301, 3, data);
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = "Parameters to this method are primitive and are trimmer safe")]
[Event(302, Level = EventLevel.Verbose, Message = Messages.WaitHandleWaitStop, Task = Tasks.WaitHandleWait, Opcode = EventOpcode.Stop, Version = 0, Keywords = Keywords.WaitHandleKeyword)]
public unsafe void WaitHandleWaitStop(ushort ClrInstanceID = DefaultClrInstanceId)
{
Debug.Assert(IsEnabled(EventLevel.Verbose, Keywords.WaitHandleKeyword));

EventData* data = stackalloc EventData[1];
data[0].DataPointer = (nint)(&ClrInstanceID);
data[0].Size = sizeof(ushort);
data[0].Reserved = 0;
WriteEventCore(302, 1, data);
}
}
}
Loading

0 comments on commit 49c270a

Please sign in to comment.