In the announcement for this Spooktacular, I quoted the famous H. P. Lovecraft passage where he describes the unspeakable horror felt by a group of programmers when they see the Event Tracing for Windows API for the first time. If you’ve been trying this Spooktacular Challenge in earnest, right about now, you probably feel as deranged and terrified as they did.
I don’t blame you. I’ve had several run-ins with the ETW API, and it has never been pretty. I’ve definitely rage quit more than once. And it’s highly, highly likely that I would never have even tried to figure out a way to do live, continuous PMC collection via ETW if I hadn’t first been sent a very valuable resource.
Of course, I didn’t want to give you this resource up front. Why? Because many of you have never experienced the horrors of trying to get ETW to work in the first place. I could never have told you how bad it was — you would not have believed me. To truly understand its depravity, you had to go into it empty-handed at least once, as I did the very first time I wrote ETW code.
However, now that we’re half way through the Spooktacular, it’s time to share the resource with you: it’s Mārtiņš Možeiko’s miniperf gist.
This gist shows you everything you need to do to sample PMCs at the beginning and end of the execution of a thread. Until seeing this gist, I didn’t even realize the ETW API had been extended to support real-time collection of PMCs! I had only seen examples of people doing traces of entire process runs using file-based logging and a hodge-podge of command line utilities. To the best of my knowledge, Mārtiņš is the only person who ever figured out how to do PMC collection directly via the real-time logging API.
So if you end up using any of the finished PMC collection code I show at the end of the challenge, you have Mārtiņš to thank. I would’ve never gone down this rabbit hole if he hadn’t posted miniperf first.
And that, of course, is today’s hint: if you’re stuck on something, and can’t get PMC collection working at all, read Mārtiņš Možeiko’s miniperf gist. It doesn’t contain everything you’ll need to complete the challenge, but it provides a complete working example of PMC collection that can help you figure out how all the relevant ETW APIs work. If you’ve been struggling with the challenge thus far, the miniperf source code should give you a huge boost!
That concludes today’s giant hint. Until tomorrow, good luck making progress on the Spooktacular Challenge!
I will post additional hints here every day until Halloween. If you’d like the rest of the Spooktacular Challenge to be delivered automatically to your inbox, you can select a subscription option here:
It's always Mārtinš isn't it 😄
I have purposefully not been reading these every day so I can dispense the hints at my own pace on weekends but a good bonus hint I could give to you all that I only realized yesterday is, Microsoft lets you download sections of msdn as .pdf! Including the entire ETW documentation. Letting you read or search through them at actually acceptable speeds. Good luck everyone!