Skip to content

Commit

Permalink
first activity plumbing
Browse files Browse the repository at this point in the history
  • Loading branch information
baronfel committed Jul 17, 2022
1 parent c19ebd5 commit 0dd5258
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
<SystemConsoleVersion>4.3.0</SystemConsoleVersion>
<SystemDataSqlClientPackageVersion>4.3.0</SystemDataSqlClientPackageVersion>
<SystemDesignVersion>4.0.0</SystemDesignVersion>
<SystemDiagnosticsDiagnosticSourceVersion>5.0.1</SystemDiagnosticsDiagnosticSourceVersion>
<SystemDiagnosticsProcessVersion>4.3.0</SystemDiagnosticsProcessVersion>
<SystemDiagnosticsTraceSourceVersion>4.3.0</SystemDiagnosticsTraceSourceVersion>
<MicrosoftDiaSymReaderPortablePdbVersion>1.6.0</MicrosoftDiaSymReaderPortablePdbVersion>
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Driver/fsc.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,7 @@ let CompileFromCommandLineArguments
with _ ->
()
}

use mainActivity = new Activity("fcs:main")
main1 (
ctok,
argv,
Expand Down
3 changes: 3 additions & 0 deletions src/fsc/fsc.targets
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@

<ItemGroup>
<PackageReference Include="System.Console" Version="$(SystemConsoleVersion)" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="$(SystemDiagnosticsDiagnosticSourceVersion)" />
<PackageReference Include="System.Linq.Expressions" Version="$(SystemLinqExpressionsVersion)" />
<PackageReference Include="System.Memory" Version="$(SystemMemoryVersion)" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="$(SystemRuntimeCompilerServicesUnsafeVersion)" />
<PackageReference Include="System.Reflection.Metadata" Version="$(SystemReflectionMetadataVersion)" />
<PackageReference Include="System.Runtime.Loader" Version="$(SystemRuntimeLoaderVersion)" />
<PackageReference Include="System.Security.Principal" Version="$(SystemSecurityPrincipalVersion)" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.1.0" />

</ItemGroup>

</Project>
20 changes: 20 additions & 0 deletions src/fsc/fscmain.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,31 @@ open FSharp.Compiler.Driver
open FSharp.Compiler.DiagnosticsLogger
open FSharp.Compiler.CodeAnalysis
open FSharp.Compiler.Text
open System.Diagnostics
open OpenTelemetry
open OpenTelemetry.Resources
open OpenTelemetry.Trace

[<Dependency("FSharp.Compiler.Service", LoadHint.Always)>]
do ()

[<EntryPoint>]
let main (argv) =

use tracerProvider =
Sdk.CreateTracerProviderBuilder()
.AddSource("fsc")
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(serviceName ="fsc", serviceVersion = "42.42.42.42"))
.AddConsoleExporter()
.Build();
use activitySource = new ActivitySource("fsc")
use mainActivity = activitySource.StartActivity("main")

let forceCleanup() =
mainActivity.Dispose()
activitySource.Dispose()
tracerProvider.Dispose()

let compilerName =
// the 64 bit desktop version of the compiler is name fscAnyCpu.exe, all others are fsc.exe
if
Expand Down Expand Up @@ -67,6 +85,7 @@ let main (argv) =
let stats = ILBinaryReader.GetStatistics()

AppDomain.CurrentDomain.ProcessExit.Add(fun _ ->
forceCleanup()
printfn
"STATS: #ByteArrayFile = %d, #MemoryMappedFileOpen = %d, #MemoryMappedFileClosed = %d, #RawMemoryFile = %d, #WeakByteArrayFile = %d"
stats.byteFileCount
Expand All @@ -81,6 +100,7 @@ let main (argv) =
let quitProcessExiter =
{ new Exiter with
member _.Exit(n) =
forceCleanup()
try
exit n
with _ ->
Expand Down

0 comments on commit 0dd5258

Please sign in to comment.