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

Add ETW events when ALCs are created or disposed #75550

Merged
merged 4 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions src/Compilers/Core/Portable/CodeAnalysisEventSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static class Tasks
public const EventTask SingleGeneratorRunTime = (EventTask)2;
public const EventTask BuildStateTable = (EventTask)3;
public const EventTask Compilation = (EventTask)4;
public const EventTask AnalyzerAssemblyLoader = (EventTask)5;
}

private CodeAnalysisEventSource() { }
Expand Down Expand Up @@ -102,6 +103,15 @@ internal unsafe void NodeTransform(int nodeHashCode, string name, string tableTy
[Event(8, Message = "Server compilation {0} completed", Keywords = Keywords.Performance, Level = EventLevel.Informational, Opcode = EventOpcode.Stop, Task = Tasks.Compilation)]
internal void StopServerCompilation(string name) => WriteEvent(8, name);

[Event(9, Message = "ALC for directory '{0}' created", Keywords = Keywords.Performance, Level = EventLevel.Informational, Opcode = EventOpcode.Start, Task = Tasks.AnalyzerAssemblyLoader)]
internal void CreateAssemblyLoadContext(string directory) => WriteEvent(9, directory);

[Event(10, Message = "ALC for directory '{0}' disposed", Keywords = Keywords.Performance, Level = EventLevel.Informational, Opcode = EventOpcode.Stop, Task = Tasks.AnalyzerAssemblyLoader)]
internal void DisposeAssemblyLoadContext(string directory) => WriteEvent(10, directory);

[Event(11, Message = "ALC for directory '{0}' disposal failed with exception '{1}'", Keywords = Keywords.Performance, Level = EventLevel.Error, Opcode = EventOpcode.Stop, Task = Tasks.AnalyzerAssemblyLoader)]
internal void DisposeAssemblyLoadContextException(string directory, string errorMessage) => WriteEvent(11, directory, errorMessage);

private static unsafe EventData GetEventDataForString(string value, char* ptr)
{
fixed (char* ptr2 = value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ private partial Assembly Load(AssemblyName assemblyName, string assemblyOriginal
{
if (!_loadContextByDirectory.TryGetValue(fullDirectoryPath, out loadContext))
{
CodeAnalysisEventSource.Log.CreateAssemblyLoadContext(fullDirectoryPath);
loadContext = new DirectoryLoadContext(fullDirectoryPath, this);
_loadContextByDirectory[fullDirectoryPath] = loadContext;
}
Expand Down Expand Up @@ -111,9 +112,11 @@ private partial void DisposeWorker()
try
{
context.Unload();
CodeAnalysisEventSource.Log.DisposeAssemblyLoadContext(context.Directory);
}
catch (Exception ex) when (FatalError.ReportAndCatch(ex, ErrorSeverity.Critical))
{
CodeAnalysisEventSource.Log.DisposeAssemblyLoadContextException(context.Directory, ex.ToString());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<Compile Include="..\..\..\Compilers\Core\Portable\DiagnosticAnalyzer\DefaultAnalyzerAssemblyLoader.cs" Link="Diagnostics\CompilerShared\DefaultAnalyzerAssemblyLoader.cs" />
<Compile Include="..\..\..\Compilers\Core\Portable\DiagnosticAnalyzer\ShadowCopyAnalyzerAssemblyLoader.cs" Link="Diagnostics\CompilerShared\ShadowCopyAnalyzerAssemblyLoader.cs" />
<Compile Include="..\..\..\Compilers\Core\Portable\DiagnosticAnalyzer\IAnalyzerAssemblyResolver.cs" Link="Diagnostics\CompilerShared\IAnalyzerAssemblyResolver.cs" />
<Compile Include="..\..\..\Compilers\Core\Portable\CodeAnalysisEventSource.cs" Link="Diagnostics\CompilerShared\CodeAnalysisEventSource.cs" />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect that this source-include of the CodeAnalysisEventSource is causing regression https://dev.azure.com/devdiv/DevDiv/_workitems/edit/2289777

<Compile Include="..\..\..\Compilers\Core\Portable\Text\SourceHashAlgorithms.cs" Link="Text\SourceHashAlgorithms.cs" />
<Compile Include="..\..\..\Compilers\Core\Portable\AssemblyUtilitiesCore.cs" Link="AssemblyUtilitiesCore.cs" />
</ItemGroup>
Expand Down
Loading