Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Expose OSThreadId and TimeStamp on EventWrittenEventArgs (#19002)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
brianrob committed Aug 1, 2018
1 parent 724ffde commit 4f12959
Showing 1 changed file with 58 additions and 5 deletions.
63 changes: 58 additions & 5 deletions src/Common/src/CoreLib/System/Diagnostics/Tracing/EventSource.cs
Expand Up @@ -1913,13 +1913,25 @@ private unsafe void WriteEventVarargs(int eventId, Guid* childActivityID, object
// 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);
}
}
}
Expand Down Expand Up @@ -2021,14 +2033,24 @@ private unsafe void WriteToAllListeners(int eventId, Guid* activityID, Guid* chi
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)
Expand Down Expand Up @@ -4609,16 +4631,47 @@ public EventLevel Level
}
}

#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;
Expand Down

0 comments on commit 4f12959

Please sign in to comment.