diff options
author | Brian Robbins <brianrob@microsoft.com> | 2018-08-01 21:38:39 +0300 |
---|---|---|
committer | Brian Robbins <brianrob@microsoft.com> | 2018-08-01 22:30:37 +0300 |
commit | baf3dabd49ac3adc0595ee984253b505190a86f0 (patch) | |
tree | e884fbd062e1f1807ada8203c192b733b23b9ac9 /src | |
parent | 697c70b9942f5b5c104f196b399e12dfb8a323bf (diff) |
Expose OSThreadId and TimeStamp on EventWrittenEventArgs (#19002)
* Add EventWrittenEventArgs public properties OSThreadId and TimeStamp and plumb through OSThreadId.
* Plumb ActivityId and RelatedActivityId to EventListener.
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs | 63 |
1 files changed, 58 insertions, 5 deletions
diff --git a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs index 55b19058d..ce43ed093 100644 --- a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs +++ b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs @@ -1913,13 +1913,25 @@ namespace System.Diagnostics.Tracing // Maintain old behavior - object identity is preserved if (AppContextSwitches.PreserveEventListnerObjectIdentity) { - WriteToAllListeners(eventId, pActivityId, childActivityID, args); + WriteToAllListeners( + eventId: eventId, + osThreadId: null, + timeStamp: null, + activityID: pActivityId, + childActivityID: childActivityID, + args: args); } else #endif // !ES_BUILD_STANDALONE { object[] serializedArgs = SerializeEventArgs(eventId, args); - WriteToAllListeners(eventId, pActivityId, childActivityID, serializedArgs); + WriteToAllListeners( + eventId: eventId, + osThreadId: null, + timeStamp: null, + activityID: pActivityId, + childActivityID: childActivityID, + args: serializedArgs); } } } @@ -2021,14 +2033,24 @@ namespace System.Diagnostics.Tracing EventSource.EventData* dataPtr = data; for (int i = 0; i < paramCount; i++) args[i] = DecodeObject(eventId, i, ref dataPtr); - WriteToAllListeners(eventId, activityID, childActivityID, args); + WriteToAllListeners( + eventId: eventId, + osThreadId: null, + timeStamp: null, + activityID: activityID, + childActivityID: childActivityID, + args: args); } // helper for writing to all EventListeners attached the current eventSource. - internal unsafe void WriteToAllListeners(int eventId, Guid* activityID, Guid* childActivityID, params object[] args) + internal unsafe void WriteToAllListeners(int eventId, uint* osThreadId, DateTime* timeStamp, Guid* activityID, Guid* childActivityID, params object[] args) { EventWrittenEventArgs eventCallbackArgs = new EventWrittenEventArgs(this); eventCallbackArgs.EventId = eventId; + if (osThreadId != null) + eventCallbackArgs.OSThreadId = (int)*osThreadId; + if (timeStamp != null) + eventCallbackArgs.TimeStamp = *timeStamp; if (activityID != null) eventCallbackArgs.ActivityId = *activityID; if (childActivityID != null) @@ -4609,16 +4631,47 @@ namespace System.Diagnostics.Tracing } } -#region private + /// <summary> + /// Gets the identifier for the OS thread that wrote the event. + /// </summary> + public long OSThreadId + { + get + { + if (!m_osThreadId.HasValue) + { + m_osThreadId = (long)RuntimeThread.CurrentOSThreadId; + } + + return m_osThreadId.Value; + } + internal set + { + m_osThreadId = value; + } + } + + /// <summary> + /// Gets a UTC DateTime that specifies when the event was written. + /// </summary> + public DateTime TimeStamp + { + get; + internal set; + } + + #region private internal EventWrittenEventArgs(EventSource eventSource) { m_eventSource = eventSource; + TimeStamp = DateTime.UtcNow; } private string m_message; private string m_eventName; private EventSource m_eventSource; private ReadOnlyCollection<string> m_payloadNames; private Guid m_activityId; + private long? m_osThreadId; internal EventTags m_tags; internal EventOpcode m_opcode; internal EventLevel m_level; |