From 6223c18480bfd050bec3f535c945e97d67b2b7b2 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Wed, 22 Mar 2023 15:11:22 +0100 Subject: [PATCH 1/2] Activity - exposing name, starting after tags are added --- src/Compiler/Utilities/Activity.fs | 30 +++++++++++-------- src/Compiler/Utilities/Activity.fsi | 14 +++++++-- .../FSharpChecker/CommonWorkflows.fs | 3 +- 3 files changed, 31 insertions(+), 16 deletions(-) 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 ce7820ddf4..63b4022194 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharpChecker/CommonWorkflows.fs +++ b/tests/FSharp.Compiler.ComponentTests/FSharpChecker/CommonWorkflows.fs @@ -12,12 +12,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) ) From 31330e3c6fc5be66f3ca0d9daddc6ba84877f2cd Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Wed, 22 Mar 2023 15:22:43 +0100 Subject: [PATCH 2/2] surface area updated --- ...piler.Service.SurfaceArea.netstandard20.debug.bsl | 12 ++++++++---- ...ler.Service.SurfaceArea.netstandard20.release.bsl | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) 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 92cb8e737b..e8933c6dd5 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 @@ -2325,6 +2325,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]) @@ -3173,9 +3177,9 @@ FSharp.Compiler.EditorServices.NavigableContainer: Int32 GetHashCode() FSharp.Compiler.EditorServices.NavigableContainer: Int32 GetHashCode(System.Collections.IEqualityComparer) FSharp.Compiler.EditorServices.NavigableContainer: System.String FullName FSharp.Compiler.EditorServices.NavigableContainer: System.String Name +FSharp.Compiler.EditorServices.NavigableContainer: System.String ToString() FSharp.Compiler.EditorServices.NavigableContainer: System.String get_FullName() FSharp.Compiler.EditorServices.NavigableContainer: System.String get_Name() -FSharp.Compiler.EditorServices.NavigableContainer: System.String ToString() FSharp.Compiler.EditorServices.NavigableContainerType+Tags: Int32 Exception FSharp.Compiler.EditorServices.NavigableContainerType+Tags: Int32 File FSharp.Compiler.EditorServices.NavigableContainerType+Tags: Int32 Module @@ -3217,7 +3221,9 @@ FSharp.Compiler.EditorServices.NavigableItem: Boolean Equals(FSharp.Compiler.Edi FSharp.Compiler.EditorServices.NavigableItem: Boolean Equals(System.Object) FSharp.Compiler.EditorServices.NavigableItem: Boolean Equals(System.Object, System.Collections.IEqualityComparer) FSharp.Compiler.EditorServices.NavigableItem: Boolean IsSignature +FSharp.Compiler.EditorServices.NavigableItem: Boolean NeedsBackticks FSharp.Compiler.EditorServices.NavigableItem: Boolean get_IsSignature() +FSharp.Compiler.EditorServices.NavigableItem: Boolean get_NeedsBackticks() FSharp.Compiler.EditorServices.NavigableItem: FSharp.Compiler.EditorServices.NavigableContainer Container FSharp.Compiler.EditorServices.NavigableItem: FSharp.Compiler.EditorServices.NavigableContainer get_Container() FSharp.Compiler.EditorServices.NavigableItem: FSharp.Compiler.EditorServices.NavigableItemKind Kind @@ -3226,10 +3232,8 @@ FSharp.Compiler.EditorServices.NavigableItem: FSharp.Compiler.Text.Range Range FSharp.Compiler.EditorServices.NavigableItem: FSharp.Compiler.Text.Range get_Range() FSharp.Compiler.EditorServices.NavigableItem: Int32 GetHashCode() FSharp.Compiler.EditorServices.NavigableItem: Int32 GetHashCode(System.Collections.IEqualityComparer) -FSharp.Compiler.EditorServices.NavigableItem: System.String ToString() -FSharp.Compiler.EditorServices.NavigableItem: Boolean NeedsBackticks -FSharp.Compiler.EditorServices.NavigableItem: Boolean get_NeedsBackticks() FSharp.Compiler.EditorServices.NavigableItem: System.String Name +FSharp.Compiler.EditorServices.NavigableItem: System.String ToString() FSharp.Compiler.EditorServices.NavigableItem: System.String get_Name() FSharp.Compiler.EditorServices.NavigableItem: Void .ctor(System.String, Boolean, FSharp.Compiler.Text.Range, Boolean, FSharp.Compiler.EditorServices.NavigableItemKind, FSharp.Compiler.EditorServices.NavigableContainer) FSharp.Compiler.EditorServices.NavigableItemKind+Tags: Int32 Constructor 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 92cb8e737b..e8933c6dd5 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 @@ -2325,6 +2325,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]) @@ -3173,9 +3177,9 @@ FSharp.Compiler.EditorServices.NavigableContainer: Int32 GetHashCode() FSharp.Compiler.EditorServices.NavigableContainer: Int32 GetHashCode(System.Collections.IEqualityComparer) FSharp.Compiler.EditorServices.NavigableContainer: System.String FullName FSharp.Compiler.EditorServices.NavigableContainer: System.String Name +FSharp.Compiler.EditorServices.NavigableContainer: System.String ToString() FSharp.Compiler.EditorServices.NavigableContainer: System.String get_FullName() FSharp.Compiler.EditorServices.NavigableContainer: System.String get_Name() -FSharp.Compiler.EditorServices.NavigableContainer: System.String ToString() FSharp.Compiler.EditorServices.NavigableContainerType+Tags: Int32 Exception FSharp.Compiler.EditorServices.NavigableContainerType+Tags: Int32 File FSharp.Compiler.EditorServices.NavigableContainerType+Tags: Int32 Module @@ -3217,7 +3221,9 @@ FSharp.Compiler.EditorServices.NavigableItem: Boolean Equals(FSharp.Compiler.Edi FSharp.Compiler.EditorServices.NavigableItem: Boolean Equals(System.Object) FSharp.Compiler.EditorServices.NavigableItem: Boolean Equals(System.Object, System.Collections.IEqualityComparer) FSharp.Compiler.EditorServices.NavigableItem: Boolean IsSignature +FSharp.Compiler.EditorServices.NavigableItem: Boolean NeedsBackticks FSharp.Compiler.EditorServices.NavigableItem: Boolean get_IsSignature() +FSharp.Compiler.EditorServices.NavigableItem: Boolean get_NeedsBackticks() FSharp.Compiler.EditorServices.NavigableItem: FSharp.Compiler.EditorServices.NavigableContainer Container FSharp.Compiler.EditorServices.NavigableItem: FSharp.Compiler.EditorServices.NavigableContainer get_Container() FSharp.Compiler.EditorServices.NavigableItem: FSharp.Compiler.EditorServices.NavigableItemKind Kind @@ -3226,10 +3232,8 @@ FSharp.Compiler.EditorServices.NavigableItem: FSharp.Compiler.Text.Range Range FSharp.Compiler.EditorServices.NavigableItem: FSharp.Compiler.Text.Range get_Range() FSharp.Compiler.EditorServices.NavigableItem: Int32 GetHashCode() FSharp.Compiler.EditorServices.NavigableItem: Int32 GetHashCode(System.Collections.IEqualityComparer) -FSharp.Compiler.EditorServices.NavigableItem: System.String ToString() -FSharp.Compiler.EditorServices.NavigableItem: Boolean NeedsBackticks -FSharp.Compiler.EditorServices.NavigableItem: Boolean get_NeedsBackticks() FSharp.Compiler.EditorServices.NavigableItem: System.String Name +FSharp.Compiler.EditorServices.NavigableItem: System.String ToString() FSharp.Compiler.EditorServices.NavigableItem: System.String get_Name() FSharp.Compiler.EditorServices.NavigableItem: Void .ctor(System.String, Boolean, FSharp.Compiler.Text.Range, Boolean, FSharp.Compiler.EditorServices.NavigableItemKind, FSharp.Compiler.EditorServices.NavigableContainer) FSharp.Compiler.EditorServices.NavigableItemKind+Tags: Int32 Constructor