I’ve been lately given the opportunity to visit the Optimization of Code Performance in .NET workshop at the Microsoft in Unterschleißheim. I’ve been learning a lot from Wolfgang Kroneder. If you would like to try the example below, you have to have the Win 7 or Win 8 SDK (containing the Windows Performance Toolkit) installed. For running the commands and the tools I’m using powershell ISE, so that I also learn something about that :).
- Just after installing the SDK I’ve been adding them to the path with the following command:
[System.Environment]::SetEnvironmentVariable("PATH", $Env:Path + ";C:\Program Files (x86)\Windows Kits\8.0\bin\x64;C:\Program Files (x86)\Windows Kits\8.0\Windows Performance Toolkit", "Machine")
- Then we need to define an Event which we will monitor. I’ve created a manifest with the ecmangen.exe. I’ve created here a TestProvider
- Then added a test event (SomethingJustHappened)
- I created a TestProvider.cs file with the TestEtw namespace to use from my application as follows:
mc -css TestEtw .\TestProvider.man
- I installed the manifest with the Windows Events Command Line Utility:
<em>C:\Windows\System32\wevtutil.exe <strong>im</strong> C:\temp\TestEtw\TestProvider.man
You can uninstall with the um option.
- Now you can check whether it is installed exists (still in powershell):
xperf -providers | Select-String "TestProvider"
- I added a call to the following method into a button click event handler:
- Now I can start monitoring it with the following:
xperf -start usersession -on "TestProvider" -f usersession.etl #Start your app and click your button few times! xperf -stop usersession
- Check your usersession.etl with the Windows Performance Analyser
I hope you enjoyed as much as I did. You can find more detailed information about the Event Tracing for Windows (ETW). Naveen’s Blog helped me also a lot. And for the full picture you could also try to Create your own ETW provider and log it by xperf.