Does anybody know of a method for creating custom Performance Counters using ordinary unmanaged Visual C++?
I know that it can be done easily using managed C++, but I need to do it using an unmanaged Windows service.
I also know that you can retrieve performance counter data, but I need to create some custom counters and increment them during the applications runtime.
The support for adding C++ performance counters changed in Vista and beyond. The Performance DLL approach suggested in another answer still works, but the new technique described here is easier to use.
In this approach you write a manifest that describes your counters, run CTRPP, a tool that generates code from your manifest. Compile and link this code with your application, and add a call to initialize the process (it starts a background thread), and add code to update the counters as necessary. The details of publishing the counters are handled by the background thread running the generated code.
You also need to run lodctr /m:[manifest file] to register your counters before they can be used. This must be run as an admin.
BTW: Another program, unlodctr reverse the effect of lodctr and must be used if you make any changes to your counters because there is no "replace" operation, only delete the old, then install the new.
<RANT>Documentation for all the above is just plain awful. For example lodctr was completely reworked for Vista, but the doc in MSDN is all for the XP version and no longer applies. If you visit MSDN please use the "This documentation is not helpful" button liberally and maybe Microsoft will get the message.</RANT>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With