PerfCtrv2Mgr v1.03 A collection of
C++ classes to encapsulate the Performance Counters v2 infrastructure
Welcome to PerfCtrv2Mgr, which is a collection of freeware C++ classes to encapsulate
the Performance Counters v2 infrastructure available in Windows Vista or later.
- To use the classes in your code, just include "PerfCtrlv2Mgr.h"
in which ever module requires it in your project.
- As of v1.03, the classes are designed for VC 2017 or later. They will not compile on
earlier releases of VC.
- The sample app included in the download is a VC 2017 console app which demonstrates
- The code is UNICODE enabled and build configurations are provided for in
the sample app.
- To generate a collection of counters you start with a xml manifest file
which defines the counters you want. In the sample this is "PerfCountersv2.man".
- You then need to compile this manifest file using the SDK tool ctrpp.exe
using for example the command line: ctrpp -o perfcountersv2.h -rc perfcountersv2.rc
perfcountersv2.man. Ideally you should create a simple resource only DLL project
which just includes the perfcountersv2.rc (or your equivalent) file. This file
will be loaded by Windows when it needs the strings for a specific set of counters.
For the included sample project the rc file is simply included in the main exe
project for convenience.
- You should then register the xml manifest file from an elevated command
prompt: lodctr "/M:c:\....\PerfCountersv2.man" Info: Successfully
installed performance counters in c:\....\PerfCountersv2.man. Lodctr is a standard
Windows executable for registering performance counters. At this point if you
bring up Windows Performance Monitor (aka PerfMon) to show the counters it will
fail to show the counters and instead you will get two guids which are the guids
of the sample counter sets. This is because the PerfCountersv2.exe has not been
- Add the "PerfCtrv2Mg.h" header file to your project
- Initialize and create whatever counters you need along the lines of the
code in the "perfcountersv2.cpp" file. This sample code registers
the two counter sets and then randomly changes each counter up or down every
second for a total of thirty seconds before the app exits.
- Build your project and ensure that the DLL or exe which includes the rc
strings from the earlier step is in the same directory as where you registered
the man file from. In the included sample app this would entail coping the PerfCountersv2.exe
up one level.
- If you now bring up Perfmon, you should see two new counters called "PerfCountersv2
(CounterSet1)" and "PerfCounterv2 (CounterSet2)".
- If you now run the sample exe, and add the two counters in Perfmon you should
now see the two counters change randomly up or down every second.
- Hopefully the tutorial above should provide a quick start for you to add
a simple performance counters infrastructure to your apps. Happing coding!
The enclosed zip file contains the source
code and a simple VC 2017 console based application which exercises the classes.
- You are allowed to include the source code in any product (commercial, shareware,
freeware or otherwise) when your product is released in binary form.
- You are allowed to modify the source code in any way you want except you
cannot modify the copyright details at the top of each module.
- If you want to distribute source code with your application, then you are
only allowed to distribute versions released by the author. This is to maintain
a single distribution point for the source code.
28 September 2018
V1.03 (19 September 2018)
- Updated copyright details.
- Fixed a number of C++ core guidelines compiler warnings. These changes
mean that the code will now only compile on VC 2017 or later.
- Removed all code which uses LoadLibrary \ GetProcAddress.
3 September 2018
6 July 2017
29 May 2017
V1.02 (10 February 2016)
- Updated the code to use LoadLibrary rather than relying on client applications
already having a implicit dependency on ADVAPI32.dll. This bug / issue was spotted
when you compile the sample app in release mode which ships with the wrapper
V1.01 (2 January 2016)
- Updated copyright details
- Added SAL annotations to all the code
- Removed unnecessary CStringW instance from CPerfProvider::QueryInstance
- CPerfCounterSet::CreateInstance now uses a PCWSTR parameter instead of a
LPCTSTR parameter. This avoids the need for the use of a CStringW local variable
- Updated the parameter values names for the classes to be consistent with
the Windows 10 SDK perflib.h header.
- Updated the code to compile without taking a dependency on MFC.
22 October 2014
V1.0 (11 October 2012)