pdh

Getting current cpu usage in c++/windows for particular process

可紊 提交于 2019-11-28 09:57:04
问题 I want to calculate current cpu usage for particular application in my code. I looked up on internet and found pdh library for windows. When I tried it I am getting overall cpu usage not cpu usage for one process. PdhAddCounter(hquery, TEXT("\\Processor(_Total)\\% Processor Time"),0,&counter); So what I do with this line to get cpu usage for particular process? I tried replacing _Total with process name(explorer). At that time I am getting 0 cpu usage. But I checked in resource monitor that