PdhAddEnglishCounter/PdhAddCounter 添加cpu计数器返回-1073738824 C000 0BB8

获取cpu负载时 使用pdhaddenglishcounter 返回-1073738824  C000 0BB8  

PDH_CSTATUS_NO_OBJECT 

 

auto state = PdhOpenQuery(NULL, NULL, &cpuQuery);
            if (state != ERROR_SUCCESS) {
                DLOG(ERROR) << "PdhOpenQuery Failed:" << state << std::endl;
                return 0;
            }
            state = PdhAddCounter(cpuQuery, "\\Processor(_Total)\\% Processor Time", NULL, &cpuTotal);
            if (state != ERROR_SUCCESS)
            {
                DLOG(ERROR) << "PdhAddEnglishCounter Failed" << PdhAddEnglishCounter(cpuQuery, "\\Processor(_Total)\\% Processor Time", NULL, &cpuTotal) << std::endl;
                return 0;
            }

解决方法:

重置性能计数

Lodctr /r

 

参考:

https://helgeklein.com/blog/how-to-easily-monitor-system-performance-with-the-new-diskled-1-1/

也可能是:

计算机\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\PerfProc\Performance\Disable Performance Counters  设置成了 1

 

posted @ 2021-07-08 13:50  wolbo  阅读(467)  评论(0编辑  收藏  举报