An easy way to use XPerf and Event Tracing for Windows (ETW)

With Wolfgang Kroneder

Me and Wolfgang Kroneder

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 :).

  1. 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")
  2. 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

    Create Provider

    Create Provider

  3. Then added a test event (SomethingJustHappened)

    Create Event

    Create Event

  4. I created a TestProvider.cs file with the TestEtw namespace to use from my application as follows:
    mc -css TestEtw .\TestProvider.man
  5. 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.

  6. Now you can check whether it is installed exists (still in powershell):
    xperf -providers | Select-String "TestProvider"
  7. I added a call to the following method into a button click event handler:
    TestProvider.EventWriteSomethingJustHappened();
  8. 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
    
  9. Check your usersession.etl with the Windows Performance Analyser
    xperfview usersession.etl

    Windows Performance Analyser

    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.

Advertisements

About Tamas Nemeth

Husband and proud father of two daughters in Nürnberg. I'm working as a Senior Software Developer and an enthusiastic Clean-Coder. I spend most of my free time with my family (playing, hiking, etc...). I also play table-tennis and badminton sometimes...
This entry was posted in Technical Interest and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s