Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/linker.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJackson Schuster <36744439+jtschuster@users.noreply.github.com>2022-09-21 19:54:52 +0300
committerGitHub <noreply@github.com>2022-09-21 19:54:52 +0300
commit65c17f71e4863117b3ff0e083b630e605c841dd6 (patch)
tree3380151182299d2aa93f4cd4fdd49eecdae04e8b
parent3443678a7cc9654bbbe5102821301450ba9f05ea (diff)
Add event source tracing (#3043)
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.
-rw-r--r--src/linker/Linker/Driver.cs8
-rw-r--r--src/linker/Linker/LinkerEventSource.cs30
-rw-r--r--src/linker/Linker/Pipeline.cs9
3 files changed, 46 insertions, 1 deletions
diff --git a/src/linker/Linker/Driver.cs b/src/linker/Linker/Driver.cs
index b1fcf1b90..f92457544 100644
--- a/src/linker/Linker/Driver.cs
+++ b/src/linker/Linker/Driver.cs
@@ -51,13 +51,17 @@ namespace Mono.Linker
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)) {
@@ -66,6 +70,8 @@ namespace Mono.Linker
} catch {
Console.Error.WriteLine ("Fatal error in {0}", _linker);
throw;
+ } finally {
+ LinkerEventSource.Log.LinkerStop ();
}
}
diff --git a/src/linker/Linker/LinkerEventSource.cs b/src/linker/Linker/LinkerEventSource.cs
new file mode 100644
index 000000000..b939f9bfd
--- /dev/null
+++ b/src/linker/Linker/LinkerEventSource.cs
@@ -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);
+ }
+ }
+}
diff --git a/src/linker/Linker/Pipeline.cs b/src/linker/Linker/Pipeline.cs
index f5e3e47ec..d0307b342 100644
--- a/src/linker/Linker/Pipeline.cs
+++ b/src/linker/Linker/Pipeline.cs
@@ -159,7 +159,16 @@ namespace Mono.Linker
{
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);
}
}