Skip to content

Don't require the users to do manual installation of TraceEvent when using Diagnostics package #962

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

Merged
merged 2 commits into from
Nov 16, 2018

Conversation

WojciechNagorski
Copy link
Contributor

Currently, when you create application that use BenchmarkDotNet.Diagnostics.Window you should add reference to Microsoft.Diagnostics.Tracing.TraceEvent directly in your csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="BenchmarkDotNet" Version="0.11.2-develop" />
    <PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.11.2-develop" />
    
    <!-- Add reference to Microsoft.Diagnostics.Tracing.TraceEvent -->
    <PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="2.0.26" />
  </ItemGroup>

</Project>

If you don't do this, you get error message:

Please install the latest Microsoft.Diagnostics.Tracing.TraceEvent package in the project with benchmarks so MSBuild can copy the native dependencies of TraceEvent to the output folder.

Unhandled Exception: System.ComponentModel.Win32Exception: The specified module could not be found
   at Microsoft.Diagnostics.Tracing.Extensions.ETWKernelControl.LoadKernelTraceControl()
   at Microsoft.Diagnostics.Tracing.Extensions.ETWKernelControl.StartKernelSession(UInt64& TraceHandle, Void* propertyBuff, Int32 propertyBuffLength, STACK_TRACING_EVENT_ID* stackTracingEventIds, Int32 cStackTracingEventIds)
   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.Extensions.CommonExtensions.ForEach[T](IList`1 source, Action`1 command)
   at BenchmarkDotNet.Toolchains.DotNetCli.DotNetCliExecutor.Execute(BenchmarkCase benchmarkCase, BenchmarkId benchmarkId, ILogger logger, ArtifactsPaths artifactsPaths, IDiagnoser diagnoser, String executableName, IConfig config, IResolver resolver)
   at BenchmarkDotNet.Toolchains.DotNetCli.DotNetCliExecutor.Execute(ExecuteParameters executeParameters)
   at BenchmarkDotNet.Running.BenchmarkRunner.Execute(ILogger logger, BenchmarkCase benchmarkCase, BenchmarkId benchmarkId, IToolchain toolchain, BuildResult buildResult, IConfig config, IResolver resolver)
   at BenchmarkDotNet.Running.BenchmarkRunner.RunCore(BenchmarkCase benchmarkCase, BenchmarkId benchmarkId, ILogger logger, ReadOnlyConfig config, IResolver resolver, BuildResult buildResult)
   at BenchmarkDotNet.Running.BenchmarkRunner.Run(BenchmarkRunInfo benchmarkRunInfo, Dictionary`2 buildResults, IResolver resolver, ILogger logger, List`1 artifactsToCleanup, String rootArtifactsFolderPath, StartedClock& runChronometer)
   at BenchmarkDotNet.Running.BenchmarkRunner.Run(BenchmarkRunInfo[] benchmarkRunInfos, IConfig commonSettingsConfig)
   at BenchmarkDotNet.Running.BenchmarkSwitcher.Run(String[] args, IConfig config)
   at Test_955.Program.Main(String[] args) in c:\Work\Test_955\Program.cs:line 13

I start application by command:

dotnet run -c Release -- --filter * --profiler ETW

In this PR I push changes that set PrivateAssets="contentfiles;analyzers" on nuget reference to Microsoft.Diagnostics.Tracing.TraceEvent. Default value is contentfiles;analyzers;build. There is documentation for this feature https://docs.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files.

After that you don't need reference to Microsoft.Diagnostics.Tracing.TraceEvent in csproj. You just need:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="BenchmarkDotNet" Version="0.11.2-develop" />
    <PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.11.2-develop" />
  </ItemGroup>

</Project>

But of course you can add a reference to the newer version.
I tested these changes using local feed.

@adamsitnik
Copy link
Member

@wojtpl2 excellent! big thanks for identifying the issue and getting rid of it! it was super annoying, now we are going to have much better first user experience for EtwProfiler!

@adamsitnik adamsitnik merged commit 4e65311 into dotnet:master Nov 16, 2018
@WojciechNagorski WojciechNagorski deleted the Improve_diagnostics_dll branch November 16, 2018 10:58
@AndreyAkinshin AndreyAkinshin added this to the v0.11.3 milestone Nov 16, 2018
@adamsitnik adamsitnik changed the title Improve diagnostics dll Don't require the users to do manual installation of TraceEvent when using Diagnostics package Nov 16, 2018
@AndyAyersMS
Copy link
Member

AndyAyersMS commented Jun 29, 2022

I am running into this error again on windows arm64. I think it might be fixed if we update the dependency on BenchmarkDotNet.Diagnostics.Windows to a newer version like 3.0.1, but am not 100% sure yet.

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

Successfully merging this pull request may close these issues.

4 participants