Skip to content

Commit 55a1340

Browse files
17314642flightlessmango
authored andcommitted
gpu_fdinfo: check if hwmon exists
1 parent 816b4de commit 55a1340

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/gpu_fdinfo.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ void GPU_fdinfo::find_intel_hwmon() {
113113
device += pci_dev;
114114
device += "/hwmon";
115115

116+
if (!fs::exists(device)) {
117+
SPDLOG_DEBUG("Intel hwmon directory {} doesn't exist.", device);
118+
return;
119+
}
120+
116121
auto dir_iterator = fs::directory_iterator(device);
117122
auto hwmon = dir_iterator->path().string();
118123

@@ -123,7 +128,13 @@ void GPU_fdinfo::find_intel_hwmon() {
123128

124129
hwmon += "/energy1_input";
125130

131+
if (!fs::exists(hwmon)) {
132+
SPDLOG_DEBUG("Intel hwmon: file {} doesn't exist.", hwmon);
133+
return;
134+
}
135+
126136
SPDLOG_DEBUG("Intel hwmon found: hwmon = {}", hwmon);
137+
127138
energy_stream.open(hwmon);
128139

129140
if (!energy_stream.good())
@@ -138,7 +149,12 @@ float GPU_fdinfo::get_power_usage() {
138149
uint64_t energy_input;
139150

140151
energy_stream.seekg(0);
152+
141153
std::getline(energy_stream, energy_input_str);
154+
155+
if (energy_input_str.empty())
156+
return 0.f;
157+
142158
energy_input = std::stoull(energy_input_str);
143159

144160
return energy_input / 1'000'000;

0 commit comments

Comments
 (0)