Skip to content

Feedback for converting eventsource metadata list to a dict #117092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jun 28, 2025
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -2327,9 +2327,9 @@ private void WriteStringToAllListeners(string eventName, string msg)
{
// if there's *any* enabled event on the dispatcher we'll write out the string
// otherwise we'll treat the listener as disabled and skip it
foreach (bool enabled in dispatcher.m_EventEnabled.Values)
foreach (KeyValuePair<int, bool> entry in dispatcher.m_EventEnabled)
{
if (enabled)
if (entry.Value)
{
dispatcherEnabled = true;
break;
Expand Down Expand Up @@ -2824,17 +2824,19 @@ internal bool EnableEventForDispatcher(EventDispatcher? dispatcher, EventProvide
if (dispatcher == null)
{
if (m_etwProvider != null && eventProviderType == EventProviderType.ETW)
{ eventMeta.EnabledForETW = value;}
eventMeta.EnabledForETW = value;

#if FEATURE_PERFTRACING
if (m_eventPipeProvider != null && eventProviderType == EventProviderType.EventPipe)
{eventMeta.EnabledForEventPipe = value;}
eventMeta.EnabledForEventPipe = value;
#endif
}
else
{
Debug.Assert(dispatcher.m_EventEnabled != null);
if (!dispatcher.m_EventEnabled.ContainsKey(eventId)) return false;

if (!dispatcher.m_EventEnabled.ContainsKey(eventId))
return false;

dispatcher.m_EventEnabled[eventId] = value;
if (value)
Expand Down Expand Up @@ -2891,13 +2893,10 @@ private void EnsureDescriptorsInitialized()
EventDispatcher? dispatcher = m_Dispatchers;
while (dispatcher != null)
{
Dictionary<int, bool> eventEnabled = new Dictionary<int, bool>(m_eventData?.Count ?? 0);
if (m_eventData != null)
Dictionary<int, bool> eventEnabled = new Dictionary<int, bool>(m_eventData.Count);
foreach (int eventId in m_eventData.Keys)
{
foreach (int eventId in m_eventData.Keys)
{
eventEnabled[eventId] = false;
}
eventEnabled[eventId] = false;
}
dispatcher.m_EventEnabled ??= eventEnabled;
dispatcher = dispatcher.m_Next;
Expand Down Expand Up @@ -3159,7 +3158,7 @@ private static bool AttributeTypeNamesMatch(Type attributeType, Type reflectedAt
Dictionary<string, string>? eventsByName = null;
if (source != null || (flags & EventManifestOptions.Strict) != 0)
{
eventData = new();
eventData = new Dictionary<int, EventMetadata>();
ref EventMetadata newEventMetadata = ref CollectionsMarshal.GetValueRefOrAddDefault(eventData, 0, out _);
newEventMetadata.Name = ""; // Event 0 is the 'write messages string' event, and has an empty name.
}
Expand Down Expand Up @@ -3331,7 +3330,6 @@ private static bool AttributeTypeNamesMatch(Type attributeType, Type reflectedAt
ref EventMetadata startEventMetadata = ref CollectionsMarshal.GetValueRefOrNullRef(eventData, startEventId);
if (!Unsafe.IsNullRef(ref startEventMetadata))
{
// Since we reserve id 0, we know that id-1 is <= 0
// If you remove the Stop and add a Start does that name match the Start Event's Name?
// Ideally we would throw an error
if (startEventMetadata.Descriptor.Opcode == (byte)EventOpcode.Start &&
Expand Down
Loading