Skip to content

Commit

Permalink
Optionally record activities in the service (#13835)
Browse files Browse the repository at this point in the history
Co-authored-by: Chet Husk <chusk3@gmail.com>
Co-authored-by: Tomas Grosup <tomasgrosup@microsoft.com>
  • Loading branch information
3 people authored Nov 21, 2022
1 parent c6350ce commit f0143ef
Show file tree
Hide file tree
Showing 19 changed files with 207 additions and 163 deletions.
1 change: 1 addition & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<SystemBuffersVersion>4.5.1</SystemBuffersVersion>
<SystemCollectionsImmutableVersion>6.0.0</SystemCollectionsImmutableVersion>
<MicrosoftDiaSymReaderPortablePdbVersion>1.6.0</MicrosoftDiaSymReaderPortablePdbVersion>
<SystemDiagnosticsDiagnosticSourceVersion>6.0.0</SystemDiagnosticsDiagnosticSourceVersion>
<SystemMemoryVersion>4.5.5</SystemMemoryVersion>
<SystemReflectionEmitVersion>4.7.0</SystemReflectionEmitVersion>
<SystemReflectionMetadataVersion>6.0.0</SystemReflectionMetadataVersion>
Expand Down
17 changes: 15 additions & 2 deletions src/Compiler/Checking/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module internal FSharp.Compiler.CheckDeclarations
open System
open System.Collections.Generic

open FSharp.Compiler.Diagnostics
open Internal.Utilities.Collections
open Internal.Utilities.Library
open Internal.Utilities.Library.Extras
Expand Down Expand Up @@ -5289,11 +5290,17 @@ let CheckOneImplFile
env,
rootSigOpt: ModuleOrNamespaceType option,
synImplFile) =

let (ParsedImplFileInput (_, isScript, qualNameOfFile, scopedPragmas, _, implFileFrags, isLastCompiland, _)) = synImplFile
let (ParsedImplFileInput (fileName, isScript, qualNameOfFile, scopedPragmas, _, implFileFrags, isLastCompiland, _)) = synImplFile
let infoReader = InfoReader(g, amap)

cancellable {
use _ =
Activity.start "CheckDeclarations.CheckOneImplFile"
[|
"fileName", fileName
"qualifiedNameOfFile", qualNameOfFile.Text
|]
let cenv =
cenv.Create (g, isScript, amap, thisCcu, false, Option.isSome rootSigOpt,
conditionalDefines, tcSink, (LightweightTcValForUsingInBuildMethodCall g), isInternalTestSpanStackReferring,
Expand Down Expand Up @@ -5421,6 +5428,12 @@ let CheckOneImplFile
/// Check an entire signature file
let CheckOneSigFile (g, amap, thisCcu, checkForErrors, conditionalDefines, tcSink, isInternalTestSpanStackReferring) tcEnv (sigFile: ParsedSigFileInput) =
cancellable {
use _ =
Activity.start "CheckDeclarations.CheckOneSigFile"
[|
"fileName", sigFile.FileName
"qualifiedNameOfFile", sigFile.QualifiedName.Text
|]
let cenv =
cenv.Create
(g, false, amap, thisCcu, true, false, conditionalDefines, tcSink,
Expand Down
11 changes: 6 additions & 5 deletions src/Compiler/Driver/CompilerOptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2331,13 +2331,14 @@ let PrintWholeAssemblyImplementation (tcConfig: TcConfig) outfile header expr =
//----------------------------------------------------------------------------

let mutable tPrev: (DateTime * DateTime * float * int[]) option = None
let mutable nPrev: string option = None
let mutable nPrev: (string * IDisposable) option = None

let ReportTime (tcConfig: TcConfig) descr =

match nPrev with
| None -> ()
| Some prevDescr ->
| Some (prevDescr, prevActivity) ->
use _ = prevActivity // Finish the previous diagnostics activity by .Dispose() at the end of this block

if tcConfig.pause then
dprintf "[done '%s', entering '%s'] press <enter> to continue... " prevDescr descr
Console.ReadLine() |> ignore
Expand Down Expand Up @@ -2376,7 +2377,7 @@ let ReportTime (tcConfig: TcConfig) descr =

let tStart =
match tPrev, nPrev with
| Some (tStart, tPrev, utPrev, gcPrev), Some prevDescr ->
| Some (tStart, tPrev, utPrev, gcPrev), Some (prevDescr, _) ->
let spanGC = [| for i in 0..maxGen -> GC.CollectionCount i - gcPrev[i] |]
let t = tNow - tStart
let tDelta = tNow - tPrev
Expand All @@ -2403,7 +2404,7 @@ let ReportTime (tcConfig: TcConfig) descr =

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

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

let ignoreFailureOnMono1_1_16 f =
try
Expand Down
6 changes: 4 additions & 2 deletions src/Compiler/Driver/ParseAndCheckInputs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
module internal FSharp.Compiler.ParseAndCheckInputs

open System
open System.Diagnostics
open System.IO
open System.Collections.Generic

Expand Down Expand Up @@ -1175,6 +1176,9 @@ let CheckOneInputAux

cancellable {
try
use _ =
Activity.start "ParseAndCheckInputs.CheckOneInput" [| "fileName", inp.FileName |]

CheckSimulateException tcConfig

let m = inp.Range
Expand Down Expand Up @@ -1365,10 +1369,8 @@ let CheckMultipleInputsFinish (results, tcState: TcState) =

let CheckOneInputAndFinish (checkForErrors, tcConfig: TcConfig, tcImports, tcGlobals, prefixPathOpt, tcSink, tcState, input) =
cancellable {
Logger.LogBlockStart LogCompilerFunctionId.CompileOps_TypeCheckOneInputAndFinishEventually
let! result, tcState = CheckOneInput(checkForErrors, tcConfig, tcImports, tcGlobals, prefixPathOpt, tcSink, tcState, input, false)
let finishedResult = CheckMultipleInputsFinish([ result ], tcState)
Logger.LogBlockStop LogCompilerFunctionId.CompileOps_TypeCheckOneInputAndFinishEventually
return finishedResult
}

Expand Down
5 changes: 0 additions & 5 deletions src/Compiler/Driver/fsc.fs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,6 @@ let main1

// Process command line, flags and collect filenames
let sourceFiles =

// The ParseCompilerOptions function calls imperative function to process "real" args
// Rather than start processing, just collect names, then process them.
try
Expand Down Expand Up @@ -710,7 +709,6 @@ let main2
exiter: Exiter,
ilSourceDocs))
=

if tcConfig.typeCheckOnly then
exiter.Exit 0

Expand Down Expand Up @@ -818,7 +816,6 @@ let main3
exiter: Exiter,
ilSourceDocs))
=

// Encode the signature data
ReportTime tcConfig "Encode Interface Data"
let exportRemapping = MakeExportRemapping generatedCcu generatedCcu.Contents
Expand Down Expand Up @@ -914,7 +911,6 @@ let main4
exiter: Exiter,
ilSourceDocs))
=

match tcImportsCapture with
| None -> ()
| Some f -> f tcImports
Expand Down Expand Up @@ -1049,7 +1045,6 @@ let main6
exiter: Exiter,
ilSourceDocs))
=

ReportTime tcConfig "Write .NET Binary"

use _ = UseBuildPhase BuildPhase.Output
Expand Down
8 changes: 5 additions & 3 deletions src/Compiler/FSharp.Compiler.Service.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

<!-- The FSharp.Compiler.Service dll provides a referencable public interface for tool builders -->
<PropertyGroup Condition="'$(Configuration)' != 'Proto'">
<CompressMetadata Condition="'$(CompressAllMetadata)' != 'true'">false</CompressMetadata>
<CompressMetadata Condition="'$(CompressAllMetadata)' != 'true'">false</CompressMetadata>
</PropertyGroup>

<PropertyGroup>
Expand Down Expand Up @@ -57,6 +57,7 @@
<NuspecProperty Include="SystemBuffersPackageVersion=$(SystemBuffersVersion)" />
<NuspecProperty Include="SystemCollectionsImmutablePackageVersion=$(SystemCollectionsImmutableVersion)" />
<NuspecProperty Include="SystemMemoryPackageVersion=$(SystemMemoryVersion)" />
<NuspecProperty Include="SystemDiagnosticsDiagnosticSourcePackageVersion=$(SystemDiagnosticsDiagnosticSourceVersion)" />
<NuspecProperty Include="SystemReflectionEmitPackageVersion=$(SystemReflectionEmitVersion)" />
<NuspecProperty Include="SystemReflectionMetadataPackageVersion=$(SystemReflectionMetadataVersion)" />
<NuspecProperty Include="SystemRuntimeCompilerServicesUnsafePackageVersion=$(SystemRuntimeCompilerServicesUnsafeVersion)" />
Expand Down Expand Up @@ -91,6 +92,8 @@
<Link>FSStrings.resx</Link>
<LogicalName>FSStrings.resources</LogicalName>
</EmbeddedResource>
<Compile Include="Utilities\Activity.fsi" />
<Compile Include="Utilities\Activity.fs" />
<Compile Include="Utilities\sformat.fsi" />
<Compile Include="Utilities\sformat.fs" />
<Compile Include="Utilities\sr.fsi" />
Expand Down Expand Up @@ -131,8 +134,6 @@
<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\LanguageFeatures.fsi" />
<Compile Include="Facilities\LanguageFeatures.fs" />
<Compile Include="Facilities\DiagnosticOptions.fsi" />
Expand Down Expand Up @@ -488,6 +489,7 @@
<PackageReference Include="System.Reflection.Emit" Version="$(SystemReflectionEmitVersion)" />
<PackageReference Include="System.Reflection.Metadata" Version="$(SystemReflectionMetadataVersion)" />
<PackageReference Include="System.Buffers" Version="$(SystemBuffersVersion)" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="$(SystemDiagnosticsDiagnosticSourceVersion)" />
<PackageReference Include="System.Memory" Version="$(SystemMemoryVersion)" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="$(SystemRuntimeCompilerServicesUnsafeVersion)" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Compiler/FSharp.Compiler.Service.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<dependency id="FSharp.Core" version="$FSharpCorePackageVersion$" exclude="Build,Analyzers" />
<dependency id="System.Buffers" version="$SystemBuffersPackageVersion$" exclude="Build,Analyzers" />
<dependency id="System.Collections.Immutable" version="$SystemCollectionsImmutablePackageVersion$" exclude="Build,Analyzers" />
<dependency id="System.Diagnostics.DiagnosticSource" version="$SystemDiagnosticsDiagnosticSourcePackageVersion$" exclude="Build,Analyzers" />
<dependency id="System.Memory" version="$SystemMemoryPackageVersion$" exclude="Build,Analyzers" />
<dependency id="System.Reflection.Emit" version="$SystemReflectionEmitPackageVersion$" exclude="Build,Analyzers" />
<dependency id="System.Reflection.Metadata" version="$SystemReflectionMetadataPackageVersion$" exclude="Build,Analyzers" />
Expand Down
10 changes: 10 additions & 0 deletions src/Compiler/Facilities/BuildGraph.fs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ type NodeCodeBuilder() =
(value :> IDisposable).Dispose()
}
)

[<DebuggerHidden; DebuggerStepThrough>]
member _.Using(value: IDisposable, binder: IDisposable -> NodeCode<'U>) =
Node(
async {
use _ = value
return! binder value |> Async.AwaitNodeCode
}
)


let node = NodeCodeBuilder()

Expand Down
7 changes: 5 additions & 2 deletions src/Compiler/Facilities/BuildGraph.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module internal FSharp.Compiler.BuildGraph

open System
open System.Diagnostics
open System.Threading
open System.Threading.Tasks
open FSharp.Compiler.DiagnosticsLogger
Expand Down Expand Up @@ -43,10 +44,12 @@ type NodeCodeBuilder =

member Combine: x1: NodeCode<unit> * x2: NodeCode<'T> -> NodeCode<'T>

/// A limited form 'use' for establishing the compilation globals. (Note
/// that a proper generic 'use' could be implemented but has not currently been necessary)
/// A limited form 'use' for establishing the compilation globals.
member Using: CompilationGlobalsScope * (CompilationGlobalsScope -> NodeCode<'T>) -> NodeCode<'T>

/// A generic 'use' that disposes of the IDisposable at the end of the computation.
member Using: IDisposable * (IDisposable -> NodeCode<'T>) -> NodeCode<'T>

/// Specifies code that can be run as part of the build graph.
val node: NodeCodeBuilder

Expand Down
87 changes: 0 additions & 87 deletions src/Compiler/Facilities/Logger.fs

This file was deleted.

33 changes: 0 additions & 33 deletions src/Compiler/Facilities/Logger.fsi

This file was deleted.

4 changes: 3 additions & 1 deletion src/Compiler/Service/FSharpCheckerResults.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,7 @@ module internal ParseAndCheckFile =

let parseFile (sourceText: ISourceText, fileName, options: FSharpParsingOptions, userOpName: string, suggestNamesForErrors: bool) =
Trace.TraceInformation("FCS: {0}.{1} ({2})", userOpName, "parseFile", fileName)
use act = Activity.start "ParseAndCheckFile.parseFile" [| "fileName", fileName |]

let errHandler =
DiagnosticsHandler(true, fileName, options.DiagnosticOptions, sourceText, suggestNamesForErrors)
Expand Down Expand Up @@ -2502,7 +2503,8 @@ module internal ParseAndCheckFile =
) =

cancellable {
use _logBlock = Logger.LogBlock LogCompilerFunctionId.Service_CheckOneFile
use _ =
Activity.start "ParseAndCheckFile.CheckOneFile" [| "fileName", mainInputFileName; "length", sourceText.Length.ToString() |]

let parsedMainInput = parseResults.ParseTree

Expand Down
Loading

0 comments on commit f0143ef

Please sign in to comment.