Skip to content

Commit

Permalink
Add event source tracing (dotnet/linker#3043)
Browse files Browse the repository at this point in the history
Adds EventSource events for the start and end of Main() and for the start and end of each call to IStep.Process().

The dotnet/performance scenarios can use ETW events to give a more detailed breakdown of where time is spent. This PR creates a few simple events to be able to track the time the linker takes from process start to end more precisely without any noise from MSBuild. If we want to track more fine-grained details, it will be easy to add them in the future.

LinkerStart is emitted right at the start of Main().
LinkerStop is emitted right before returning from Main().
LinkerStepStart is emitted right before calling IStep.Process.
LinkerStrpStop is emitted right after IStep.Process returns.

Commit migrated from dotnet/linker@65c17f7
  • Loading branch information
jtschuster authored Sep 21, 2022
1 parent 79f0444 commit 79e31e7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/tools/illink/src/linker/Linker/Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,17 @@ public partial class Driver : IDisposable

public static int Main (string[] args)
{
LinkerEventSource.Log.LinkerStart (string.Join ("; ", args));
if (args.Length == 0) {
Console.Error.WriteLine ("No parameters specified");
LinkerEventSource.Log.LinkerStop ();
return 1;
}

if (!ProcessResponseFile (args, out var arguments))
if (!ProcessResponseFile (args, out var arguments)) {
LinkerEventSource.Log.LinkerStop ();
return 1;
}

try {
using (Driver driver = new Driver (arguments)) {
Expand All @@ -66,6 +70,8 @@ public static int Main (string[] args)
} catch {
Console.Error.WriteLine ("Fatal error in {0}", _linker);
throw;
} finally {
LinkerEventSource.Log.LinkerStop ();
}
}

Expand Down
30 changes: 30 additions & 0 deletions src/tools/illink/src/linker/Linker/LinkerEventSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Diagnostics.Tracing;

namespace Mono.Linker
{
[EventSource (Name = "Microsoft-DotNET-Linker")]
sealed class LinkerEventSource : EventSource
{
public static LinkerEventSource Log { get; } = new LinkerEventSource ();

[Event (1)]
public void LinkerStart (string args) => WriteEvent (1, args);

[Event (2)]
public void LinkerStop () => WriteEvent (2);

[Event (3, Keywords = Keywords.Step)]
public void LinkerStepStart (string stepName) => WriteEvent (3, stepName);

[Event (4, Keywords = Keywords.Step)]
public void LinkerStepStop (string stepName) => WriteEvent (4, stepName);

public static class Keywords
{
public const EventKeywords Step = (EventKeywords) (1 << 1);
}
}
}
9 changes: 9 additions & 0 deletions src/tools/illink/src/linker/Linker/Pipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,16 @@ public void Process (LinkContext context)
{
while (_steps.Count > 0) {
IStep step = _steps[0];
string? stepName = null;
if (LinkerEventSource.Log.IsEnabled ()) {
stepName = step.GetType ().Name;
LinkerEventSource.Log.LinkerStepStart (stepName);
}
ProcessStep (context, step);
if (LinkerEventSource.Log.IsEnabled ()) {
stepName ??= step.GetType ().Name;
LinkerEventSource.Log.LinkerStepStop (stepName);
}
_steps.Remove (step);
}
}
Expand Down

0 comments on commit 79e31e7

Please sign in to comment.