BenchmarkDotNet icon indicating copy to clipboard operation
BenchmarkDotNet copied to clipboard

COMException when generating ETW Log for benchmark

Open rbanks54 opened this issue 3 years ago • 7 comments

Just posting this here for visibility as it's the same problem as microsoft/perfview#1723.

I'm seeing COMExceptions when trying to generate an ETW trace for a benchmark.

The exception is

Unhandled exception. System.Runtime.InteropServices.COMException (0x800700AA): The requested resource is in use. (0x800700AA)
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
   at Microsoft.Diagnostics.Tracing.Session.TraceEventSession.EnableKernelProvider(Keywords flags, Keywords stackCapture)
   at BenchmarkDotNet.Diagnostics.Windows.KernelSession.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)

rbanks54 avatar Oct 06 '22 12:10 rbanks54

Hi @rbanks54

In such case we need to wait until https://github.com/microsoft/perfview/issues/1723 gets fixed. In the meantime, you can downgrade to previous version which used older TraceEvent.

adamsitnik avatar Oct 06 '22 12:10 adamsitnik

And thank you for digging in and reporting the issue in PerfView repo!

adamsitnik avatar Oct 06 '22 12:10 adamsitnik

It seems the linked https://github.com/microsoft/perfview/issues/1723 issue is resolved. Shall we bump Microsoft.Diagnostics.Tracing.TraceEvent dependency once a new release is available from that nuget package?

I have tried downgrading to version 0.12.1, where I get the same error with the previous provider, after BeforeActualRun:

// BeforeActualRun
Unhandled exception. System.Runtime.InteropServices.COMException (0x800700AA): The requested resource is in use. (0x800700AA)
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
   at Microsoft.Diagnostics.Tracing.Session.TraceEventSession.EnableKernelProvider(Keywords flags, Keywords stackCapture)
   at BenchmarkDotNet.Diagnostics.Windows.PmcDiagnoser.EnableProvider()
   at BenchmarkDotNet.Diagnostics.Windows.EtwDiagnoser`1.Start(DiagnoserActionParameters parameters)
   at BenchmarkDotNet.Diagnostics.Windows.PmcDiagnoser.Handle(HostSignal signal, DiagnoserActionParameters parameters)
   at BenchmarkDotNet.Diagnosers.CompositeDiagnoser.Handle(HostSignal signal, DiagnoserActionParameters parameters)
   at BenchmarkDotNet.Loggers.SynchronousProcessOutputLoggerWithDiagnoser.ProcessInput()
   at BenchmarkDotNet.Toolchains.DotNetCli.DotNetCliExecutor.Execute(BenchmarkCase benchmarkCase, BenchmarkId benchmarkId, ILogger logger, ArtifactsPaths artifactsPaths, IDiagnoser diagnoser, String executableName, IResolver resolver)
   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, Boolean& success)
   at BenchmarkDotNet.Running.BenchmarkRunnerClean.Execute(ILogger logger, BenchmarkCase benchmarkCase, BenchmarkId benchmarkId, IToolchain toolchain, BuildResult buildResult, IResolver resolver)
...

And then going further back (v 0.11.5) I get Unhandled exception. System.NotSupportedException: Unknown .NET Framework with .NET 7 RC1. I suppose really need wait for the fixed dependency.

ladeak avatar Oct 09 '22 14:10 ladeak

It seems the linked https://github.com/microsoft/perfview/issues/1723 issue is resolved.

It turned out to be Windows OS bug and has not been solved yet, only the PerfView issue got closed: https://github.com/microsoft/perfview/issues/1723#issuecomment-1272029634

adamsitnik avatar Oct 10 '22 07:10 adamsitnik

@ladeak I mentioned in the perfview issue that I could workaround the problem by disabling realtime virus protection. It's (very) obviously not an ideal approach, but it unblocks me. It might be something that works for you as well.

rbanks54 avatar Oct 11 '22 05:10 rbanks54

Thank you for the suggestion, I will give it a try.

EDIT: disabling the viros protection does seem to work as a workaround.

ladeak avatar Oct 11 '22 06:10 ladeak

@adamsitnik There's some extra details in this thread https://github.com/microsoft/perfview/issues/1726 you might be interested in :)

rbanks54 avatar Oct 13 '22 10:10 rbanks54