Wrap PerfEventSource usage in IsEnabled checks (dotnet/coreclr#27177)
authorMichal Strehovský <MichalStrehovsky@users.noreply.github.com>
Mon, 14 Oct 2019 20:08:06 +0000 (22:08 +0200)
committerGitHub <noreply@github.com>
Mon, 14 Oct 2019 20:08:06 +0000 (22:08 +0200)
After the recent start/stop event refactoring, this is the only use of PerfEventSource that is not wrapped in a IsEnabled call.

Tools like IL Linker are able to strip EventSource usage to make the app smaller and the way they do it is by replacing IsEnabled to always return false and making Write methods always throw. If we don't wrap EventSource usage in IsEnabled checks, this results in a broken app.

Commit migrated from https://github.com/dotnet/coreclr/commit/2d636cdcb90b0e880b45126b4f65cb815f3872f4

src/coreclr/src/tools/crossgen2/ILCompiler.DependencyAnalysisFramework/DependencyAnalyzer.cs

index 18187a1..e734a31 100644 (file)
@@ -287,7 +287,8 @@ namespace ILCompiler.DependencyAnalysisFramework
         {
             if (_marker.MarkNode(node, reason1, reason2, reason))
             {
-                PerfEventSource.Log.AddedNodeToMarkStack();
+                if (PerfEventSource.Log.IsEnabled())
+                    PerfEventSource.Log.AddedNodeToMarkStack();
 
                 // Pop the top node of the mark stack
                 if (_stackPopRandomizer == null)