Skip to content
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
30 changes: 17 additions & 13 deletions src/Compiler/Utilities/Activity.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@ open System.Diagnostics
open System.IO
open System.Text

module ActivityNames =
[<Literal>]
let FscSourceName = "fsc"

[<Literal>]
let ProfiledSourceName = "fsc_with_env_stats"

let AllRelevantNames = [| FscSourceName; ProfiledSourceName |]

[<RequireQualifiedAccess>]
module internal Activity =

let FscSourceName = "fsc"

module Tags =
let fileName = "fileName"
let project = "project"
Expand Down Expand Up @@ -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 =
Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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 =
Expand Down Expand Up @@ -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 ->
Expand Down Expand Up @@ -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))
)
Expand Down
14 changes: 12 additions & 2 deletions src/Compiler/Utilities/Activity.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -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
[<RequireQualifiedAccess>]
module internal Activity =
module ActivityNames =
[<Literal>]
val FscSourceName: string = "fsc"

[<Literal>]
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
[<RequireQualifiedAccess>]
module internal Activity =

module Tags =
val fileName: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down