Search code examples
windowswinapivisual-c++performancecounter

Register performance counter without lodctr


I am looking for an approach to register to XML-based performance counters without using lodctr executable.

While this question and this question has given some insight to the problem, none gives a proper resolution.

The function LoadPerfCounterTextStrings seems to do the trick, but doesn't seem to take XML as input (i.e. /M argument for lodctr command). The function would anyway call the lodctr command but will save the programmer from calling lodctr.exe programmatically.

Is there an approach to call this function (or any other) that would behave as if:

lodctr.exe /M:xmlfile.xml

?

Just an additional information that LoadPerfCounterTextStrings is available in Windows XP, however, the new API (perflib 2) is available only after Vista. I am using V2.


Solution

  • I don't think it is possible, at least with a documented way. If you'd find and use some undocumented way, it may break with some OS/service pack or with future versions of Windows.

    Best bet is you call LODCTR and UNLODCTR for installation/registration of performance counters within your process. Since these are command line tools, they would probably show up with a command (black) console window. You may hide with input/output redirection with pipes, so that console window doesn't appear.

    Note that these tools don't take up much of time or resources, so calling these EXEs from your process won't take up much time (user won't notice, and even won't be able to easily figure out with some process monitoring tool).

    Note that registering/unregistering PC is a rare activity - hence Microsoft won't bother to provide you a nice callable Windows API.