Skip to content

Commit

Permalink
Rename activity file, fix NRE, rename start methods
Browse files Browse the repository at this point in the history
  • Loading branch information
safesparrow committed Oct 10, 2022
1 parent 1122aa6 commit b857487
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/Compiler/Driver/CompilerOptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2386,7 +2386,7 @@ let ReportTime (tcConfig: TcConfig) descr =

tPrev <- Some(tStart, tNow, utNow, gcNow)

nPrev <- Some(descr, Activity.StartNoTags descr)
nPrev <- Some(descr, Activity.startNoTags descr)

let ignoreFailureOnMono1_1_16 f =
try
Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/FSharp.Compiler.Service.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@
<Compile Include="Utilities\range.fsi" />
<Compile Include="Utilities\range.fs" />
<EmbeddedText Include="Facilities\UtilsStrings.txt" />
<Compile Include="Facilities\Logger.fsi" />
<Compile Include="Facilities\Logger.fs" />
<Compile Include="Facilities\Activity.fsi" />
<Compile Include="Facilities\Activity.fs" />
<Compile Include="Facilities\LanguageFeatures.fsi" />
<Compile Include="Facilities\LanguageFeatures.fs" />
<Compile Include="Facilities\DiagnosticOptions.fsi" />
Expand Down
29 changes: 29 additions & 0 deletions src/Compiler/Facilities/Activity.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace FSharp.Compiler.Diagnostics

open System
open System.Diagnostics

[<RequireQualifiedAccess>]
module Activity =

let private dummyDisposable =
{
new IDisposable with
member this.Dispose() = ()
}

let private activitySourceName = "fsc"
let private activitySource = new ActivitySource(activitySourceName)

let start name (tags : (string * string) seq) : IDisposable =
match activitySource.StartActivity(name) |> Option.ofObj with
| Some activity ->
for key, value in tags do
activity.AddTag(key, value) |> ignore
activity :> IDisposable
| None ->
dummyDisposable

let startNoTags name: IDisposable = activitySource.StartActivity(name)
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
namespace FSharp.Compiler.Diagnostics

open System
open System.Diagnostics

/// For activities following the dotnet distributed tracing concept
/// https://learn.microsoft.com/en-us/dotnet/core/diagnostics/distributed-tracing-concepts?source=recommendations
[<RequireQualifiedAccess>]
module internal Activity =

val StartNoTags: name: string -> IDisposable
val startNoTags: name: string -> IDisposable

val Start: name: string -> tags: (string * string) seq -> IDisposable
val start: name: string -> tags: (string * string) seq -> IDisposable
20 changes: 0 additions & 20 deletions src/Compiler/Facilities/Logger.fs

This file was deleted.

8 changes: 4 additions & 4 deletions src/Compiler/Service/service.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ type BackgroundCompiler
member _.ProjectChecked = projectChecked.Publish

member _.ClearCaches() =
use _ = Activity.StartNoTags "BackgroundCompiler.ClearCaches"
use _ = Activity.startNoTags "BackgroundCompiler.ClearCaches"

lock gate (fun () ->
parseCacheLock.AcquireLock(fun ltok ->
Expand All @@ -1149,7 +1149,7 @@ type BackgroundCompiler
scriptClosureCache.Clear AnyCallerThread)

member _.DownsizeCaches() =
use _ = Activity.StartNoTags "BackgroundCompiler.DownsizeCaches"
use _ = Activity.startNoTags "BackgroundCompiler.DownsizeCaches"

lock gate (fun () ->
parseCacheLock.AcquireLock(fun ltok ->
Expand Down Expand Up @@ -1241,7 +1241,7 @@ type FSharpChecker
?parallelReferenceResolution
) =

use _ = Activity.StartNoTags "FSharpChecker.Create"
use _ = Activity.startNoTags "FSharpChecker.Create"

let legacyReferenceResolver =
match legacyReferenceResolver with
Expand Down Expand Up @@ -1356,7 +1356,7 @@ type FSharpChecker
// This is for unit testing only
member ic.ClearLanguageServiceRootCachesAndCollectAndFinalizeAllTransients() =
use _ =
Activity.StartNoTags "FsharpChecker.ClearLanguageServiceRootCachesAndCollectAndFinalizeAllTransients"
Activity.startNoTags "FsharpChecker.ClearLanguageServiceRootCachesAndCollectAndFinalizeAllTransients"

ic.ClearCaches()
GC.Collect()
Expand Down

0 comments on commit b857487

Please sign in to comment.