Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8eb48d0

Browse files
authored
Added basic ETW logging for editor and compiler (dotnet#4820)
1 parent8c1c159 commit8eb48d0

File tree

11 files changed

+171
-3
lines changed

11 files changed

+171
-3
lines changed

‎fcs/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<ProjectSdk="Microsoft.NET.Sdk">
1+
<ProjectSdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<FSharpSourcesRoot>$(MSBuildProjectDirectory)\..\..\src</FSharpSourcesRoot>
44
</PropertyGroup>
@@ -63,6 +63,12 @@
6363
<OtherFlags>--module Microsoft.FSharp.Compiler.Parser --open Microsoft.FSharp.Compiler --internal --lexlib Internal.Utilities.Text.Lexing --parslib Internal.Utilities.Text.Parsing</OtherFlags>
6464
<Link>pars.fsy</Link>
6565
</FsYacc>
66+
<CompileInclude="$(FSharpSourcesRoot)/fsharp/Logger.fsi">
67+
<Link>Logger.fsi</Link>
68+
</Compile>
69+
<CompileInclude="$(FSharpSourcesRoot)/fsharp/Logger.fs">
70+
<Link>Logger.fs</Link>
71+
</Compile>
6672
<CompileInclude="$(FSharpSourcesRoot)/utils/reshapedreflection.fs">
6773
<Link>Reshaped/reshapedreflection.fs</Link>
6874
</Compile>
@@ -650,5 +656,5 @@
650656
</ItemGroup>
651657
<ImportProject="$(FSharpSourcesRoot)\scripts\fssrgen.targets"Condition="'$(TargetFramework)' != ''" />
652658
<ImportProject="$(FSharpSourcesRoot)\..\packages\FsLexYacc.7.0.6\build\FsLexYacc.targets"Condition="'$(TargetFramework)' != '' AND Exists('$(FSharpSourcesRoot)\..\packages\FsLexYacc.7.0.6\build\FsLexYacc.targets')" />
653-
<TargetName="GenerateCode"AfterTargets="Restore"BeforeTargets="BeforeBuild"DependsOnTargets="CallFsLex;CallFsYacc;ProcessFsSrGen"Condition="'$(TargetFramework)' != ''"></Target>
659+
<TargetName="GenerateCode"AfterTargets="Restore"BeforeTargets="BeforeBuild"DependsOnTargets="CallFsLex;CallFsYacc;ProcessFsSrGen"Condition="'$(TargetFramework)' != ''"></Target>
654660
</Project>

‎src/buildfromsource/FSharp.Compiler.Private/FSharp.Compiler.Private.fsproj‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
</EmbeddedResource>
2525
<CompileInclude="FSComp.fs" />
2626
<CompileInclude="FSIstrings.fs" />
27+
<CompileInclude="..\..\fsharp\Logger.fsi">
28+
<Link>Logger.fsi</Link>
29+
</Compile>
30+
<CompileInclude="..\..\fsharp\Logger.fs">
31+
<Link>Logger.fs</Link>
32+
</Compile>
2733
<CompileInclude="..\..\utils\reshapedreflection.fs">
2834
<Link>Reflection\reshapedreflection.fs</Link>
2935
</Compile>

‎src/fsharp/FSharp.Compiler.Private/FSharp.Compiler.Private.fsproj‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@
6464
<EmbeddedResourceInclude="..\FSStrings.resx">
6565
<Link>FSStrings.resx</Link>
6666
</EmbeddedResource>
67+
<CompileInclude="..\Logger.fsi">
68+
<Link>Logger.fsi</Link>
69+
</Compile>
70+
<CompileInclude="..\Logger.fs">
71+
<Link>Logger.fs</Link>
72+
</Compile>
6773
<CompileInclude="..\..\utils\reshapedreflection.fs">
6874
<Link>Reflection\reshapedreflection.fs</Link>
6975
</Compile>

‎src/fsharp/Logger.fs‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
namespaceMicrosoft.FSharp.Compiler
4+
5+
openSystem.Diagnostics.Tracing
6+
openSystem
7+
8+
typeLogCompilerFunctionId=
9+
| ParseAndCheckFileInProject=1
10+
11+
/// This is for ETW tracing across FSharp.Compiler.
12+
[<Sealed;EventSource(Name="FSharpCompiler")>]
13+
typeFSharpCompilerEventSource()=
14+
inherit EventSource()
15+
16+
static letinstance=new FSharpCompilerEventSource()
17+
static memberInstance= instance
18+
19+
[<Event(1)>]
20+
memberthis.Log(functionId:LogCompilerFunctionId)=
21+
if this.IsEnabled()then
22+
this.WriteEvent(1, int functionId)
23+
24+
[<Event(2)>]
25+
memberthis.BlockStart(functionId:LogCompilerFunctionId)=
26+
if this.IsEnabled()then
27+
this.WriteEvent(2, int functionId)
28+
29+
[<Event(3)>]
30+
memberthis.BlockStop(functionId:LogCompilerFunctionId)=
31+
if this.IsEnabled()then
32+
this.WriteEvent(3, int functionId)
33+
34+
[<RequireQualifiedAccess>]
35+
moduleLogger=
36+
37+
letLog(functionId)= FSharpCompilerEventSource.Instance.Log(functionId)
38+
39+
letLogBlockStart(functionId)= FSharpCompilerEventSource.Instance.BlockStart(functionId)
40+
41+
letLogBlockStop(functionId)= FSharpCompilerEventSource.Instance.BlockStop(functionId)
42+
43+
letLogBlock(functionId)=
44+
FSharpCompilerEventSource.Instance.BlockStart(functionId)
45+
{new IDisposablewith
46+
member__.Dispose()=
47+
FSharpCompilerEventSource.Instance.BlockStop(functionId)}

‎src/fsharp/Logger.fsi‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
namespaceMicrosoft.FSharp.Compiler
4+
5+
openSystem
6+
7+
// FIXME: We cannot make this internal yet until F# gets a compiler switch to make cases public when the type itself is internal.
8+
// https://github.com/Microsoft/visualfsharp/issues/4821
9+
type(* internal*)LogCompilerFunctionId=
10+
| ParseAndCheckFileInProject=1
11+
12+
[<RequireQualifiedAccess>]
13+
moduleinternalLogger=
14+
15+
valLog:LogCompilerFunctionId->unit
16+
17+
valLogBlockStart:LogCompilerFunctionId->unit
18+
19+
valLogBlockStop:LogCompilerFunctionId->unit
20+
21+
valLogBlock:LogCompilerFunctionId->IDisposable

‎src/fsharp/service/service.fs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2656,6 +2656,8 @@ type BackgroundCompiler(legacyReferenceResolver, projectCacheSize, keepAssemblyC
26562656
letexecWithReactorAsync action= reactor.EnqueueAndAwaitOpAsync(userOpName,"ParseAndCheckFileInProject", filename, action)
26572657
async{
26582658
try
2659+
use _logBlock= Logger.LogBlock(LogCompilerFunctionId.ParseAndCheckFileInProject)
2660+
26592661
if implicitlyStartBackgroundWorkthen
26602662
reactor.CancelBackgroundOp()// cancel the background work, since we will start new work after we're done
26612663
let!builderOpt,creationErrors,decrement= execWithReactorAsync(fun ctok-> getOrCreateBuilderAndKeepAlive(ctok, options, userOpName))

‎vsintegration/src/FSharp.Editor/Classification/ClassificationService.fs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,17 @@ type internal FSharpClassificationService
3434

3535
member__.AddSyntacticClassificationsAsync(document:Document,textSpan:TextSpan,result:List<ClassifiedSpan>,cancellationToken:CancellationToken)=
3636
async{
37+
use _logBlock= Logger.LogBlock(LogEditorFunctionId.SyntacticClassification)
38+
3739
letdefines= projectInfoManager.GetCompilationDefinesForEditingDocument(document)
3840
let!sourceText= document.GetTextAsync(cancellationToken)|> Async.AwaitTask
3941
result.AddRange(Tokenizer.getClassifiedSpans(document.Id, sourceText, textSpan, Some(document.FilePath), defines, cancellationToken))
4042
}|> RoslynHelpers.StartAsyncUnitAsTask cancellationToken
4143

4244
member__.AddSemanticClassificationsAsync(document:Document,textSpan:TextSpan,result:List<ClassifiedSpan>,cancellationToken:CancellationToken)=
4345
asyncMaybe{
44-
do Trace.TraceInformation("{0:n3} (start) SemanticColorization", DateTime.Now.TimeOfDay.TotalSeconds)
46+
use _logBlock= Logger.LogBlock(LogEditorFunctionId.SemanticClassification)
47+
4548
do! Async.Sleep DefaultTuning.SemanticClassificationInitialDelay|> liftAsync// be less intrusive, give other work priority most of the time
4649
let!_,_,projectOptions= projectInfoManager.TryGetOptionsForDocumentOrProject(document)
4750
let!sourceText= document.GetTextAsync(cancellationToken)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
namespaceMicrosoft.VisualStudio.FSharp.Editor
4+
5+
openSystem
6+
openSystem.Diagnostics.Tracing
7+
8+
typeLogEditorFunctionId=
9+
| SemanticClassification=1
10+
| SyntacticClassification=2
11+
| HandleCommandLineArgs=3
12+
13+
/// This is for ETW tracing across FSharp.Editor.
14+
[<Sealed;EventSource(Name="FSharpEditor")>]
15+
typeFSharpEditorEventSource()=
16+
inherit EventSource()
17+
18+
static letinstance=new FSharpEditorEventSource()
19+
static memberInstance= instance
20+
21+
[<Event(1)>]
22+
memberthis.Log(functionId:LogEditorFunctionId)=
23+
if this.IsEnabled()then
24+
this.WriteEvent(1, int functionId)
25+
26+
[<Event(2)>]
27+
memberthis.BlockStart(functionId:LogEditorFunctionId)=
28+
if this.IsEnabled()then
29+
this.WriteEvent(2, int functionId)
30+
31+
[<Event(3)>]
32+
memberthis.BlockStop(functionId:LogEditorFunctionId)=
33+
if this.IsEnabled()then
34+
this.WriteEvent(3, int functionId)
35+
36+
[<RequireQualifiedAccess>]
37+
moduleLogger=
38+
39+
letLog(functionId)= FSharpEditorEventSource.Instance.Log(functionId)
40+
41+
letLogBlockStart(functionId)= FSharpEditorEventSource.Instance.BlockStart(functionId)
42+
43+
letLogBlockStop(functionId)= FSharpEditorEventSource.Instance.BlockStop(functionId)
44+
45+
letLogBlock(functionId)=
46+
FSharpEditorEventSource.Instance.BlockStart(functionId)
47+
{new IDisposablewith
48+
member__.Dispose()=
49+
FSharpEditorEventSource.Instance.BlockStop(functionId)}
50+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
namespaceMicrosoft.VisualStudio.FSharp.Editor
4+
5+
openSystem
6+
7+
// FIXME: We cannot make this internal yet until F# gets a compiler switch to make cases public when the type itself is internal.
8+
// https://github.com/Microsoft/visualfsharp/issues/4821
9+
type(* internal*)LogEditorFunctionId=
10+
| SemanticClassification=1
11+
| SyntacticClassification=2
12+
| HandleCommandLineArgs=3
13+
14+
[<RequireQualifiedAccess>]
15+
moduleinternalLogger=
16+
17+
valLog:LogEditorFunctionId->unit
18+
19+
valLogBlockStart:LogEditorFunctionId->unit
20+
21+
valLogBlockStop:LogEditorFunctionId->unit
22+
23+
valLogBlock:LogEditorFunctionId->IDisposable

‎vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
<GeneratedModuleName>Microsoft.VisualStudio.FSharp.Editor.SR</GeneratedModuleName>
2727
</EmbeddedResource>
2828
<CompileInclude="Common\AssemblyInfo.fs" />
29+
<CompileInclude="Common\Logger.fsi" />
30+
<CompileInclude="Common\Logger.fs" />
2931
<CompileInclude="Common\Pervasive.fs" />
3032
<CompileInclude="Common\Extensions.fs" />
3133
<CompileInclude="Common\Constants.fs" />

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp