Skip to content

COMException when using hardware counters and in-process toolchain #394

@mlessmann

Description

@mlessmann

A COMException gets thrown when using the new in-process toolchain and hardware counters (any) on a class containing at least two benchmark methods.

Minimal repro (run as admin):

class Program
{
    static void Main(string[] args)
    {
        var config = DefaultConfig.Instance
            .With(Job.Default
                .With(InProcessToolchain.Instance)
                .WithHardwareCounters(HardwareCounter.TotalCycles));
        BenchmarkRunner.Run<Bench>(config);
    }
}

public class Bench
{
    [Benchmark]
    public void M1() { }

    [Benchmark]
    public void M2() { }
}

The following exception gets thrown during AfterSetup of the second method:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException: The WMI data block or event notification has already been enabled. (Exception from HRESULT: 0x8007106E)
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at Microsoft.Diagnostics.Tracing.Session.TraceEventProfileSources.Set(Int32[] profileSourceIDs, Int32[] profileSourceIntervals)
   at BenchmarkDotNet.Diagnostics.Windows.PmcDiagnoser.GetInitializedStats(Benchmark benchmark)
   at BenchmarkDotNet.Diagnostics.Windows.EtwDiagnoser`1.Start(Process process, Benchmark benchmark)
   at BenchmarkDotNet.Diagnostics.Windows.PmcDiagnoser.BeforeMainRun(Process process, Benchmark benchmark)
   at BenchmarkDotNet.Diagnosers.CompositeDiagnoser.<>c__DisplayClass5_0.<BeforeMainRun>b__0(IDiagnoser diagnoser)
   at BenchmarkDotNet.Extensions.CommonExtensions.ForEach[T](IList`1 source, Action`1 command)
   at BenchmarkDotNet.Diagnosers.CompositeDiagnoser.BeforeMainRun(Process process, Benchmark benchmark)
   at BenchmarkDotNet.Toolchains.InProcess.InProcessHost.SendSignal(HostSignal hostSignal)
   at BenchmarkDotNet.Engines.Engine.Run()
   at BenchmarkDotNet.Toolchains.InProcess.InProcessRunner.Runnable.RunCore(IHost host, Benchmark benchmark, BenchmarkActionCodegen codegenMode)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at BenchmarkDotNet.Toolchains.InProcess.InProcessRunner.Run(IHost host, Benchmark benchmark, BenchmarkActionCodegen codegenMode)

I'm using the current nightly build 0.10.3.39 running on .NET 4.6 in VS2015 on Windows 10.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions