Skip to content
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

Modify AvTrace call chain to use params ReadOnlySpan<object> instead of an array #9468

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 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
44 changes: 4 additions & 40 deletions eng/WpfArcadeSdk/tools/CodeGen/AvTrace/AvTraceMessages.tt
Original file line number Diff line number Diff line change
Expand Up @@ -70,51 +70,15 @@ namespace MS.Internal
<# } #>

/// <summary> Send a single trace output </summary>
static public void Trace( TraceEventType type, AvTraceDetails traceDetails, params object[] parameters )
static public void Trace(TraceEventType type, AvTraceDetails traceDetails, params Span<object> parameters)
{
_avTrace.Trace( type, traceDetails.Id, traceDetails.Message, traceDetails.Labels, parameters );
}

/// <summary> These help delay allocation of object array </summary>
static public void Trace( TraceEventType type, AvTraceDetails traceDetails )
{
_avTrace.Trace( type, traceDetails.Id, traceDetails.Message, traceDetails.Labels, Array.Empty<object>() );
}
static public void Trace( TraceEventType type, AvTraceDetails traceDetails, object p1 )
{
_avTrace.Trace( type, traceDetails.Id, traceDetails.Message, traceDetails.Labels, new object[] { p1 } );
}
static public void Trace( TraceEventType type, AvTraceDetails traceDetails, object p1, object p2 )
{
_avTrace.Trace( type, traceDetails.Id, traceDetails.Message, traceDetails.Labels, new object[] { p1, p2 } );
}
static public void Trace( TraceEventType type, AvTraceDetails traceDetails, object p1, object p2, object p3 )
{
_avTrace.Trace( type, traceDetails.Id, traceDetails.Message, traceDetails.Labels, new object[] { p1, p2, p3 } );
_avTrace.Trace(type, traceDetails.Id, traceDetails.Message, traceDetails.Labels, parameters);
}

/// <summary> Send a singleton "activity" trace (really, this sends the same trace as both a Start and a Stop) </summary>
static public void TraceActivityItem( AvTraceDetails traceDetails, params Object[] parameters )
{
_avTrace.TraceStartStop( traceDetails.Id, traceDetails.Message, traceDetails.Labels, parameters );
}

/// <summary> These help delay allocation of object array </summary>
static public void TraceActivityItem( AvTraceDetails traceDetails )
{
_avTrace.TraceStartStop( traceDetails.Id, traceDetails.Message, traceDetails.Labels, Array.Empty<object>() );
}
static public void TraceActivityItem( AvTraceDetails traceDetails, object p1 )
{
_avTrace.TraceStartStop( traceDetails.Id, traceDetails.Message, traceDetails.Labels, new object[] { p1 } );
}
static public void TraceActivityItem( AvTraceDetails traceDetails, object p1, object p2 )
{
_avTrace.TraceStartStop( traceDetails.Id, traceDetails.Message, traceDetails.Labels, new object[] { p1, p2 } );
}
static public void TraceActivityItem( AvTraceDetails traceDetails, object p1, object p2, object p3 )
static public void TraceActivityItem(AvTraceDetails traceDetails, params Span<object> parameters)
{
_avTrace.TraceStartStop( traceDetails.Id, traceDetails.Message, traceDetails.Labels, new object[] { p1, p2, p3 } );
_avTrace.TraceStartStop(traceDetails.Id, traceDetails.Message, traceDetails.Labels, parameters);
}

static public bool IsEnabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,51 +74,15 @@ static public AvTraceDetails InvokeHandlers
}

/// <summary> Send a single trace output </summary>
static public void Trace( TraceEventType type, AvTraceDetails traceDetails, params object[] parameters )
static public void Trace(TraceEventType type, AvTraceDetails traceDetails, params Span<object> parameters)
{
_avTrace.Trace( type, traceDetails.Id, traceDetails.Message, traceDetails.Labels, parameters );
}

/// <summary> These help delay allocation of object array </summary>
static public void Trace( TraceEventType type, AvTraceDetails traceDetails )
{
_avTrace.Trace( type, traceDetails.Id, traceDetails.Message, traceDetails.Labels, Array.Empty<object>() );
}
static public void Trace( TraceEventType type, AvTraceDetails traceDetails, object p1 )
{
_avTrace.Trace( type, traceDetails.Id, traceDetails.Message, traceDetails.Labels, new object[] { p1 } );
}
static public void Trace( TraceEventType type, AvTraceDetails traceDetails, object p1, object p2 )
{
_avTrace.Trace( type, traceDetails.Id, traceDetails.Message, traceDetails.Labels, new object[] { p1, p2 } );
}
static public void Trace( TraceEventType type, AvTraceDetails traceDetails, object p1, object p2, object p3 )
{
_avTrace.Trace( type, traceDetails.Id, traceDetails.Message, traceDetails.Labels, new object[] { p1, p2, p3 } );
_avTrace.Trace(type, traceDetails.Id, traceDetails.Message, traceDetails.Labels, parameters);
}

/// <summary> Send a singleton "activity" trace (really, this sends the same trace as both a Start and a Stop) </summary>
static public void TraceActivityItem( AvTraceDetails traceDetails, params Object[] parameters )
{
_avTrace.TraceStartStop( traceDetails.Id, traceDetails.Message, traceDetails.Labels, parameters );
}

/// <summary> These help delay allocation of object array </summary>
static public void TraceActivityItem( AvTraceDetails traceDetails )
{
_avTrace.TraceStartStop( traceDetails.Id, traceDetails.Message, traceDetails.Labels, Array.Empty<object>() );
}
static public void TraceActivityItem( AvTraceDetails traceDetails, object p1 )
{
_avTrace.TraceStartStop( traceDetails.Id, traceDetails.Message, traceDetails.Labels, new object[] { p1 } );
}
static public void TraceActivityItem( AvTraceDetails traceDetails, object p1, object p2 )
{
_avTrace.TraceStartStop( traceDetails.Id, traceDetails.Message, traceDetails.Labels, new object[] { p1, p2 } );
}
static public void TraceActivityItem( AvTraceDetails traceDetails, object p1, object p2, object p3 )
static public void TraceActivityItem(AvTraceDetails traceDetails, params Span<object> parameters)
{
_avTrace.TraceStartStop( traceDetails.Id, traceDetails.Message, traceDetails.Labels, new object[] { p1, p2, p3 } );
_avTrace.TraceStartStop(traceDetails.Id, traceDetails.Message, traceDetails.Labels, parameters);
}

static public bool IsEnabled
Expand Down Expand Up @@ -258,51 +222,15 @@ static public AvTraceDetails AnimateStorageValidationNoLongerFailing
}

/// <summary> Send a single trace output </summary>
static public void Trace( TraceEventType type, AvTraceDetails traceDetails, params object[] parameters )
static public void Trace(TraceEventType type, AvTraceDetails traceDetails, params Span<object> parameters)
{
_avTrace.Trace( type, traceDetails.Id, traceDetails.Message, traceDetails.Labels, parameters );
}

/// <summary> These help delay allocation of object array </summary>
static public void Trace( TraceEventType type, AvTraceDetails traceDetails )
{
_avTrace.Trace( type, traceDetails.Id, traceDetails.Message, traceDetails.Labels, Array.Empty<object>() );
}
static public void Trace( TraceEventType type, AvTraceDetails traceDetails, object p1 )
{
_avTrace.Trace( type, traceDetails.Id, traceDetails.Message, traceDetails.Labels, new object[] { p1 } );
}
static public void Trace( TraceEventType type, AvTraceDetails traceDetails, object p1, object p2 )
{
_avTrace.Trace( type, traceDetails.Id, traceDetails.Message, traceDetails.Labels, new object[] { p1, p2 } );
}
static public void Trace( TraceEventType type, AvTraceDetails traceDetails, object p1, object p2, object p3 )
{
_avTrace.Trace( type, traceDetails.Id, traceDetails.Message, traceDetails.Labels, new object[] { p1, p2, p3 } );
_avTrace.Trace(type, traceDetails.Id, traceDetails.Message, traceDetails.Labels, parameters);
}

/// <summary> Send a singleton "activity" trace (really, this sends the same trace as both a Start and a Stop) </summary>
static public void TraceActivityItem( AvTraceDetails traceDetails, params Object[] parameters )
{
_avTrace.TraceStartStop( traceDetails.Id, traceDetails.Message, traceDetails.Labels, parameters );
}

/// <summary> These help delay allocation of object array </summary>
static public void TraceActivityItem( AvTraceDetails traceDetails )
{
_avTrace.TraceStartStop( traceDetails.Id, traceDetails.Message, traceDetails.Labels, Array.Empty<object>() );
}
static public void TraceActivityItem( AvTraceDetails traceDetails, object p1 )
{
_avTrace.TraceStartStop( traceDetails.Id, traceDetails.Message, traceDetails.Labels, new object[] { p1 } );
}
static public void TraceActivityItem( AvTraceDetails traceDetails, object p1, object p2 )
{
_avTrace.TraceStartStop( traceDetails.Id, traceDetails.Message, traceDetails.Labels, new object[] { p1, p2 } );
}
static public void TraceActivityItem( AvTraceDetails traceDetails, object p1, object p2, object p3 )
static public void TraceActivityItem(AvTraceDetails traceDetails, params Span<object> parameters)
{
_avTrace.TraceStartStop( traceDetails.Id, traceDetails.Message, traceDetails.Labels, new object[] { p1, p2, p3 } );
_avTrace.TraceStartStop(traceDetails.Id, traceDetails.Message, traceDetails.Labels, parameters);
}

static public bool IsEnabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,28 +178,23 @@ private void InvokeHandlersImpl(object source, RoutedEventArgs args, bool reRais

// Invoke listeners

var traceRoutedEventIsEnabled = TraceRoutedEvent.IsEnabled;
if ( traceRoutedEventIsEnabled )
bool traceRoutedEventIsEnabled = TraceRoutedEvent.IsEnabled;
if (traceRoutedEventIsEnabled)
{
_traceArguments ??= new object[3];
_traceArguments[0] = _routeItemList[i].Target;
_traceArguments[1] = args;
_traceArguments[2] = BooleanBoxes.Box(args.Handled);
TraceRoutedEvent.Trace(
TraceEventType.Start,
TraceRoutedEvent.InvokeHandlers,
_traceArguments);
_routeItemList[i].Target, args, BooleanBoxes.Box(args.Handled));
}

_routeItemList[i].InvokeHandler(args);

if( traceRoutedEventIsEnabled )
if(traceRoutedEventIsEnabled)
{
_traceArguments[2] = BooleanBoxes.Box(args.Handled);
TraceRoutedEvent.Trace(
TraceEventType.Stop,
TraceRoutedEvent.InvokeHandlers,
_traceArguments);
_routeItemList[i].Target, args, BooleanBoxes.Box(args.Handled));
}


Expand Down Expand Up @@ -250,29 +245,24 @@ private void InvokeHandlersImpl(object source, RoutedEventArgs args, bool reRais
}


var traceRoutedEventIsEnabled = TraceRoutedEvent.IsEnabled;
if ( traceRoutedEventIsEnabled )
bool traceRoutedEventIsEnabled = TraceRoutedEvent.IsEnabled;
if (traceRoutedEventIsEnabled)
{
_traceArguments ??= new object[3];
_traceArguments[0] = _routeItemList[i].Target;
_traceArguments[1] = args;
_traceArguments[2] = BooleanBoxes.Box(args.Handled);
TraceRoutedEvent.Trace(
TraceEventType.Start,
TraceRoutedEvent.InvokeHandlers,
_traceArguments);
_routeItemList[i].Target, args, BooleanBoxes.Box(args.Handled));
}

// Invoke listeners
_routeItemList[i].InvokeHandler(args);

if (traceRoutedEventIsEnabled)
{
_traceArguments[2] = BooleanBoxes.Box(args.Handled);
TraceRoutedEvent.Trace(
TraceEventType.Stop,
TraceRoutedEvent.InvokeHandlers,
_traceArguments);
_routeItemList[i].Target, args, BooleanBoxes.Box(args.Handled));
}

}
Expand Down Expand Up @@ -540,9 +530,6 @@ internal void Clear()
// Stores Source Items for separated trees
private FrugalStructList<SourceItem> _sourceItemList;

// Stores arguments that are passed to TraceRoutedEvent.Trace (to reduce allocations)
private object[] _traceArguments;

#endregion Data
}
}
Expand Down
Loading
Loading