EtwProfiler throws
When trying to profile the benchmark, I'm getting this exception. No special configuration was used, just the attribute.
.csproj:
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.14.0" />
Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'key')
at System.ArgumentNullException.Throw(String paramName)
at System.ArgumentNullException.ThrowIfNull(Object argument, String paramName)
at System.Collections.Generic.SortedDictionary`2.TryGetValue(TKey key, TValue& value)
at Microsoft.Diagnostics.Tracing.Session.TraceEventProviders.GetProviderGuidByName(String name)
at Microsoft.Diagnostics.Tracing.Session.TraceEventSession.EnableProvider(String providerName, TraceEventLevel providerLevel, UInt64 matchAnyKeywords, TraceEventProviderOptions options)
at BenchmarkDotNet.Diagnostics.Windows.UserSession.EnableProviders()
at BenchmarkDotNet.Diagnostics.Windows.EtwProfiler.Start(DiagnoserActionParameters parameters)
at BenchmarkDotNet.Diagnostics.Windows.EtwProfiler.Handle(HostSignal signal, DiagnoserActionParameters parameters)
at BenchmarkDotNet.Diagnosers.CompositeDiagnoser.Handle(HostSignal signal, DiagnoserActionParameters parameters)
at BenchmarkDotNet.Toolchains.DotNetCli.DotNetCliExecutor.Execute(BenchmarkCase benchmarkCase, BenchmarkId benchmarkId, ILogger logger, ArtifactsPaths artifactsPaths, IDiagnoser diagnoser, String executableName, IResolver resolver, Int32 launchIndex)
at BenchmarkDotNet.Toolchains.DotNetCli.DotNetCliExecutor.Execute(ExecuteParameters executeParameters)
at BenchmarkDotNet.Running.BenchmarkRunnerClean.RunExecute(ILogger logger, BenchmarkCase benchmarkCase, BenchmarkId benchmarkId, IToolchain toolchain, BuildResult buildResult, IResolver resolver, IDiagnoser diagnoser, Int32 launchIndex)
at BenchmarkDotNet.Running.BenchmarkRunnerClean.Execute(ILogger logger, BenchmarkCase benchmarkCase, BenchmarkId benchmarkId, IToolchain toolchain, BuildResult buildResult, IResolver resolver)
at BenchmarkDotNet.Running.BenchmarkRunnerClean.RunCore(BenchmarkCase benchmarkCase, BenchmarkId benchmarkId, ILogger logger, IResolver resolver, BuildResult buildResult)
at BenchmarkDotNet.Running.BenchmarkRunnerClean.Run(BenchmarkRunInfo benchmarkRunInfo, Dictionary`2 buildResults, IResolver resolver, ILogger logger, EventProcessor eventProcessor, List`1 artifactsToCleanup, String resultsFolderPath, String logFilePath, Int32 totalBenchmarkCount, StartedClock& runsChronometer, Int32& benchmarksToRunCount, TaskbarProgress taskbarProgress)
at BenchmarkDotNet.Running.BenchmarkRunnerClean.Run(BenchmarkRunInfo[] benchmarkRunInfos)
at BenchmarkDotNet.Running.BenchmarkRunner.RunWithDirtyAssemblyResolveHelper(Type type, IConfig config, String[] args)
at BenchmarkDotNet.Running.BenchmarkRunner.<>c__DisplayClass0_0`1.<Run>b__0()
at BenchmarkDotNet.Running.BenchmarkRunner.RunWithExceptionHandling(Func`1 run)
at BenchmarkDotNet.Running.BenchmarkRunner.Run[T](IConfig config, String[] args)
at <Program>F434C893D347D378BD1CFEE9E250135FD99E920ADDCBBE6AEE63D66CD410CFDAA__Runner.<>c__1`1.<Add>b__1_0() in C:\Users\domin\dev\DotProduct\Metis\Benchmarks\Program.cs:line 20
at <Program>F434C893D347D378BD1CFEE9E250135FD99E920ADDCBBE6AEE63D66CD410CFDAA__Runner.Run(ImmutableArray`1 selection) in C:\Users\domin\dev\DotProduct\Metis\Benchmarks\Program.cs:line 28
at Program.<Main>$(String[] args) in C:\Users\domin\dev\DotProduct\Metis\Benchmarks\Program.cs:line 11
Note: I've also tried creating an explicit configuration where I'd pass an empty list of providers, but it still fails. After checking the code of UserSession.EnableProviders(), it seems like the only culprit could be https://github.com/dotnet/BenchmarkDotNet/blob/cac4f6e7342eb28e73f59d21ca87f48cfce7b6ba/src/BenchmarkDotNet.Diagnostics.Windows/Sessions.cs#L46C46-L46C63
@brianrob do you have any idea why this could be failing? we have not touched this code for years, I expect it could be some ETW-related problem that occurred for PerfView users in the past.
There was an issue around this code a while back which resulted in this change: https://github.com/microsoft/perfview/commit/9d05617bba91a22807777a9a725353781ecb651b#diff-1f06bc7c79946634f1cf3b0eea5ef2e74db9cea1b22a251df4b9173f5c5136abR1643.
It looks like the behavior observed here is slightly different. From the stack, it looks like the call to TraceEventProviders.GetProviderGuidByName is being passed null for name, which results in this exception. I'd expect to get an exception in this case, as a null value is not a valid value for this parameter.
As a next step, I'd recommend debugging into this to see if the value being passed to TraceEventProviders.GetProviderGuidByName is in-fact null.