获取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