Skip to content

Commit d67a497

Browse files
Updated CPU telemetry code to better handle failed PDH queries.
Fixes #223
1 parent d204ead commit d67a497

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

IntelPresentMon/ControlLib/WmiCpu.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#include <format>
44
#include "WmiCpu.h"
55

6+
#define GLOG_NO_ABBREVIATED_SEVERITIES
7+
#include <glog/logging.h>
8+
69
namespace pwr::cpu::wmi {
710

811
std::wstring kProcessorFrequency =
@@ -24,32 +27,23 @@ WmiCpu::WmiCpu() {
2427
PdhAddEnglishCounterW(query_.get(), kProcessorFrequency.c_str(), 0,
2528
&processor_frequency_counter_);
2629
result != ERROR_SUCCESS) {
27-
throw std::runtime_error{
28-
std::format("PdhAddEnglishCounter failed when adding processor frequency "
29-
"counter. Result: {}",
30-
result)
31-
.c_str()};
30+
LOG(INFO) << "PdhAddEnglishCounter failed when adding processor frequency counter. Result:"
31+
<< result << std::endl;
3232
}
3333

3434
if (const auto result =
3535
PdhAddEnglishCounterW(query_.get(), kProcessorPerformance.c_str(),
3636
0, &processor_performance_counter_);
3737
result != ERROR_SUCCESS) {
38-
throw std::runtime_error{
39-
std::format("PdhAddEnglishCounter failed when adding processor performance "
40-
"counter. Result: {}",
41-
result)
42-
.c_str()};
38+
LOG(INFO) << "PdhAddEnglishCounter failed when adding processor performance counter. Result:"
39+
<< result << std::endl;
4340
}
4441

4542
if (const auto result = PdhAddEnglishCounterW(query_.get(), kProcessorIdleTime.c_str(), 0,
4643
&processor_idle_time_counter_);
4744
result != ERROR_SUCCESS) {
48-
throw std::runtime_error{
49-
std::format("PdhAddEnglishCounter failed when adding "
50-
"processor time counter. Result: {}",
51-
result)
52-
.c_str()};
45+
LOG(INFO) << "PdhAddEnglishCounter failed when adding processor time counter. Result:"
46+
<< result << std::endl;
5347
}
5448

5549
// Most counters require two sample values to display a formatted value.

IntelPresentMon/PresentMonService/PMMainThread.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,11 @@ void PresentMonMainThread(Service* const pSvc)
338338
}();
339339
// register cpu
340340
pComms->RegisterCpuDevice(vendor, cpu->GetCpuName(), cpu->GetCpuTelemetryCapBits());
341+
} else {
342+
// We were unable to determine the cpu.
343+
std::bitset<static_cast<size_t>(CpuTelemetryCapBits::cpu_telemetry_count)>
344+
cpuTelemetryCapBits_{};
345+
pComms->RegisterCpuDevice(PM_DEVICE_VENDOR_UNKNOWN, "UNKNOWN_CPU", cpuTelemetryCapBits_);
341346
}
342347

343348
while (WaitForSingleObjectEx(pSvc->GetServiceStopHandle(), INFINITE, (bool)opt.timedStop) != WAIT_OBJECT_0) {

0 commit comments

Comments
 (0)