diff --git a/src/Compiler/Utilities/Activity.fs b/src/Compiler/Utilities/Activity.fs index 66c22f43c1..e3b29dd6fd 100644 --- a/src/Compiler/Utilities/Activity.fs +++ b/src/Compiler/Utilities/Activity.fs @@ -7,11 +7,18 @@ open System.Diagnostics open System.IO open System.Text +module ActivityNames = + [] + let FscSourceName = "fsc" + + [] + let ProfiledSourceName = "fsc_with_env_stats" + + let AllRelevantNames = [| FscSourceName; ProfiledSourceName |] + [] module internal Activity = - let FscSourceName = "fsc" - module Tags = let fileName = "fileName" let project = "project" @@ -47,9 +54,6 @@ module internal Activity = module Events = let cacheHit = "cacheHit" - let private activitySourceName = FscSourceName - let private profiledSourceName = "fsc_with_env_stats" - type System.Diagnostics.Activity with member this.RootId = @@ -67,18 +71,18 @@ module internal Activity = depth this 0 - let private activitySource = new ActivitySource(activitySourceName) + let private activitySource = new ActivitySource(ActivityNames.FscSourceName) let start (name: string) (tags: (string * string) seq) : IDisposable = - let activity = activitySource.StartActivity(name) + let activity = activitySource.CreateActivity(name, ActivityKind.Internal) match activity with - | null -> () + | null -> activity | activity -> for key, value in tags do activity.AddTag(key, value) |> ignore - activity + activity.Start() let startNoTags (name: string) : IDisposable = activitySource.StartActivity(name) @@ -98,7 +102,7 @@ module internal Activity = let profilingTags = [| workingSetMB; gc0; gc1; gc2; handles; threads |] - let private profiledSource = new ActivitySource(profiledSourceName) + let private profiledSource = new ActivitySource(ActivityNames.ProfiledSourceName) let startAndMeasureEnvironmentStats (name: string) : IDisposable = profiledSource.StartActivity(name) @@ -112,7 +116,7 @@ module internal Activity = let l = new ActivityListener( - ShouldListenTo = (fun a -> a.Name = profiledSourceName), + ShouldListenTo = (fun a -> a.Name = ActivityNames.ProfiledSourceName), Sample = (fun _ -> ActivitySamplingResult.AllData), ActivityStarted = (fun a -> a.AddTag(gcStatsInnerTag, collectGCStats ()) |> ignore), ActivityStopped = @@ -145,7 +149,7 @@ module internal Activity = let consoleWriterListener = new ActivityListener( - ShouldListenTo = (fun a -> a.Name = profiledSourceName), + ShouldListenTo = (fun a -> a.Name = ActivityNames.ProfiledSourceName), Sample = (fun _ -> ActivitySamplingResult.AllData), ActivityStopped = (fun a -> @@ -237,7 +241,7 @@ module internal Activity = let l = new ActivityListener( - ShouldListenTo = (fun a -> a.Name = activitySourceName || a.Name = profiledSourceName), + ShouldListenTo = (fun a -> ActivityNames.AllRelevantNames |> Array.contains a.Name), Sample = (fun _ -> ActivitySamplingResult.AllData), ActivityStopped = (fun a -> msgQueue.Post(createCsvRow a)) ) diff --git a/src/Compiler/Utilities/Activity.fsi b/src/Compiler/Utilities/Activity.fsi index ca52ef2847..94784c97f0 100644 --- a/src/Compiler/Utilities/Activity.fsi +++ b/src/Compiler/Utilities/Activity.fsi @@ -7,9 +7,19 @@ open System /// For activities following the dotnet distributed tracing concept /// https://learn.microsoft.com/dotnet/core/diagnostics/distributed-tracing-concepts?source=recommendations [] -module internal Activity = +module ActivityNames = + [] + val FscSourceName: string = "fsc" + + [] + val ProfiledSourceName: string = "fsc_with_env_stats" - val FscSourceName: string + val AllRelevantNames: string[] + +/// For activities following the dotnet distributed tracing concept +/// https://learn.microsoft.com/dotnet/core/diagnostics/distributed-tracing-concepts?source=recommendations +[] +module internal Activity = module Tags = val fileName: string diff --git a/tests/FSharp.Compiler.ComponentTests/FSharpChecker/CommonWorkflows.fs b/tests/FSharp.Compiler.ComponentTests/FSharpChecker/CommonWorkflows.fs index 7b91fde601..56f0716b8b 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharpChecker/CommonWorkflows.fs +++ b/tests/FSharp.Compiler.ComponentTests/FSharpChecker/CommonWorkflows.fs @@ -11,12 +11,13 @@ open FSharp.Compiler.Text open FSharp.Compiler.CodeAnalysis module FcsDiagnostics = FSharp.Compiler.Diagnostics.Activity +module FscActivityNames = FSharp.Compiler.Diagnostics.ActivityNames let expectCacheHits n = let events = ResizeArray() let listener = new ActivityListener( - ShouldListenTo = (fun s -> s.Name = FcsDiagnostics.FscSourceName), + ShouldListenTo = (fun s -> s.Name = FscActivityNames.FscSourceName), Sample = (fun _ -> ActivitySamplingResult.AllData), ActivityStopped = (fun a -> events.AddRange a.Events) ) diff --git a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl index a55725f241..cbda528c23 100644 --- a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl +++ b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl @@ -2326,6 +2326,10 @@ FSharp.Compiler.DependencyManager.ResolvingErrorReport: System.IAsyncResult Begi FSharp.Compiler.DependencyManager.ResolvingErrorReport: Void .ctor(System.Object, IntPtr) FSharp.Compiler.DependencyManager.ResolvingErrorReport: Void EndInvoke(System.IAsyncResult) FSharp.Compiler.DependencyManager.ResolvingErrorReport: Void Invoke(FSharp.Compiler.DependencyManager.ErrorReportType, Int32, System.String) +FSharp.Compiler.Diagnostics.ActivityNames: System.String FscSourceName +FSharp.Compiler.Diagnostics.ActivityNames: System.String ProfiledSourceName +FSharp.Compiler.Diagnostics.ActivityNames: System.String[] AllRelevantNames +FSharp.Compiler.Diagnostics.ActivityNames: System.String[] get_AllRelevantNames() FSharp.Compiler.Diagnostics.CompilerDiagnostics: System.Collections.Generic.IEnumerable`1[System.String] GetSuggestedNames(Microsoft.FSharp.Core.FSharpFunc`2[Microsoft.FSharp.Core.FSharpFunc`2[System.String,Microsoft.FSharp.Core.Unit],Microsoft.FSharp.Core.Unit], System.String) FSharp.Compiler.Diagnostics.CompilerDiagnostics: System.String GetErrorMessage(FSharp.Compiler.Diagnostics.FSharpDiagnosticKind) FSharp.Compiler.Diagnostics.FSharpDiagnostic: FSharp.Compiler.Diagnostics.FSharpDiagnostic Create(FSharp.Compiler.Diagnostics.FSharpDiagnosticSeverity, System.String, Int32, FSharp.Compiler.Text.Range, Microsoft.FSharp.Core.FSharpOption`1[System.String], Microsoft.FSharp.Core.FSharpOption`1[System.String]) diff --git a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl index a55725f241..cbda528c23 100644 --- a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl +++ b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl @@ -2326,6 +2326,10 @@ FSharp.Compiler.DependencyManager.ResolvingErrorReport: System.IAsyncResult Begi FSharp.Compiler.DependencyManager.ResolvingErrorReport: Void .ctor(System.Object, IntPtr) FSharp.Compiler.DependencyManager.ResolvingErrorReport: Void EndInvoke(System.IAsyncResult) FSharp.Compiler.DependencyManager.ResolvingErrorReport: Void Invoke(FSharp.Compiler.DependencyManager.ErrorReportType, Int32, System.String) +FSharp.Compiler.Diagnostics.ActivityNames: System.String FscSourceName +FSharp.Compiler.Diagnostics.ActivityNames: System.String ProfiledSourceName +FSharp.Compiler.Diagnostics.ActivityNames: System.String[] AllRelevantNames +FSharp.Compiler.Diagnostics.ActivityNames: System.String[] get_AllRelevantNames() FSharp.Compiler.Diagnostics.CompilerDiagnostics: System.Collections.Generic.IEnumerable`1[System.String] GetSuggestedNames(Microsoft.FSharp.Core.FSharpFunc`2[Microsoft.FSharp.Core.FSharpFunc`2[System.String,Microsoft.FSharp.Core.Unit],Microsoft.FSharp.Core.Unit], System.String) FSharp.Compiler.Diagnostics.CompilerDiagnostics: System.String GetErrorMessage(FSharp.Compiler.Diagnostics.FSharpDiagnosticKind) FSharp.Compiler.Diagnostics.FSharpDiagnostic: FSharp.Compiler.Diagnostics.FSharpDiagnostic Create(FSharp.Compiler.Diagnostics.FSharpDiagnosticSeverity, System.String, Int32, FSharp.Compiler.Text.Range, Microsoft.FSharp.Core.FSharpOption`1[System.String], Microsoft.FSharp.Core.FSharpOption`1[System.String])