Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mlessmann opened this issue Mar 20, 2017 · 1 comment
Closed
Assignees

Comments

@mlessmann
Copy link

mlessmann commented Mar 20, 2017

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.

@adamsitnik
Copy link
Member

Hello @mlessmann

I am glad that you try our new features. I am afraid that it's impossible to combine these two features. When we run in process we do some extra work, that can spoil the results of the Hardware Counters. That's why for the non-in process toolchain we perform separate run for the diagnosers only. I will find some free time and provide the docs and nice warning about this limitation

@adamsitnik adamsitnik self-assigned this Mar 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants