Performance Counters in c++ without lodctr

纵饮孤独 提交于 2019-12-12 18:42:12

问题


I'm kind of used to the way how C# applications are able to create performance counters - just instantiating new PerformanceCounter object, and using it.

I'm now forced to use unmanaged C (C++?), and I'm really unhappy with ease of use of the API and samples provided. My main pain is the need to use lodctr for loading manifest, as is told in MSDN. I wasn't able to find any solution for this. Is there any way how can I use Performance counters without having explicitly loading the manifest, as I can do in C#?


回答1:


You want to use the PDH (Performance Data handler) library. The basic flow goes like this

// During startup call
h = PdhOpenQuery()
for each counter
   PdhAddCounter( h ... )

// When you want the data values call
PdhCollectQueryData( h )
for each counter
   PdhGetFormattedCounterValue()


来源:https://stackoverflow.com/questions/17880592/performance-counters-in-c-without-lodctr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!