Logger.fs 3.1 KB
Newer Older
1 2
// Copyright (c) Microsoft Corporation.  All Rights Reserved.  See License.txt in the project root for license information.

D
Don Syme 已提交
3
namespace FSharp.Compiler.Diagnostics
4 5 6 7 8

open System.Diagnostics.Tracing
open System

type LogCompilerFunctionId =
9 10 11 12 13
    | Service_ParseAndCheckFileInProject = 1
    | Service_CheckOneFile = 2
    | Service_IncrementalBuildersCache_BuildingNewCache = 3
    | Service_IncrementalBuildersCache_GettingCache = 4
    | CompileOps_TypeCheckOneInputAndFinishEventually = 5
14 15
    | IncrementalBuild_CreateItemKeyStoreAndSemanticClassification = 6
    | IncrementalBuild_TypeCheck = 7
16

17
/// This is for ETW tracing across FSharp.Compiler.
18
[<Sealed; EventSource(Name = "FSharpCompiler")>]
19 20 21 22 23 24 25 26
type FSharpCompilerEventSource() =
    inherit EventSource()

    static let instance = new FSharpCompilerEventSource()
    static member Instance = instance

    [<Event(1)>]
    member this.Log(functionId: LogCompilerFunctionId) =
27
        if this.IsEnabled() then this.WriteEvent(1, int functionId)
28

29
    [<Event(2)>]
30
    member this.LogMessage(message: string, functionId: LogCompilerFunctionId) =
31
        if this.IsEnabled() then
32
            this.WriteEvent(2, message, int functionId)
33 34

    [<Event(3)>]
35
    member this.BlockStart(functionId: LogCompilerFunctionId) =
36
        if this.IsEnabled() then this.WriteEvent(3, int functionId)
37

38
    [<Event(4)>]
39
    member this.BlockStop(functionId: LogCompilerFunctionId) =
40
        if this.IsEnabled() then this.WriteEvent(4, int functionId)
41 42

    [<Event(5)>]
43
    member this.BlockMessageStart(message: string, functionId: LogCompilerFunctionId) =
44 45 46
        if this.IsEnabled() then
            this.WriteEvent(5, message, int functionId)

47 48 49 50 51
    [<Event(6)>]
    member this.BlockMessageStop(message: string, functionId: LogCompilerFunctionId) =
        if this.IsEnabled() then
            this.WriteEvent(6, message, int functionId)

52 53 54
[<RequireQualifiedAccess>]
module Logger =

55
    let Log functionId =
56 57
        FSharpCompilerEventSource.Instance.Log(functionId)

58
    let LogMessage message functionId =
59
        FSharpCompilerEventSource.Instance.LogMessage(message, functionId)
60

61
    let LogBlockStart functionId =
62 63
        FSharpCompilerEventSource.Instance.BlockStart(functionId)

64
    let LogBlockStop functionId =
65 66 67 68
        FSharpCompilerEventSource.Instance.BlockStop(functionId)

    let LogBlockMessageStart message functionId =
        FSharpCompilerEventSource.Instance.BlockMessageStart(message, functionId)
69

70 71
    let LogBlockMessageStop message functionId =
        FSharpCompilerEventSource.Instance.BlockMessageStop(message, functionId)
72

73
    let LogBlock functionId =
74
        FSharpCompilerEventSource.Instance.BlockStart(functionId)
75

76
        { new IDisposable with
D
Don Syme 已提交
77
            member _.Dispose() =
78 79
                FSharpCompilerEventSource.Instance.BlockStop(functionId)
        }
80 81 82

    let LogBlockMessage message functionId =
        FSharpCompilerEventSource.Instance.BlockMessageStart(message, functionId)
83

84
        { new IDisposable with
D
Don Syme 已提交
85
            member _.Dispose() =
86 87
                FSharpCompilerEventSource.Instance.BlockMessageStop(message, functionId)
        }