Skip to content

Commit 20e2f1e

Browse files
Detect CPU temp only if a custom format string is given
1 parent ad28b3a commit 20e2f1e

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

src/modules/cpu.c

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,32 @@ static double getGhz(const char* policyFile, const char* cpuFile)
2727
return herz / 1000.0; //to GHz
2828
}
2929

30+
static double detectCPUTemp(const FFinstance* instance)
31+
{
32+
const FFTempsResult *temps = ffDetectTemps(instance);
33+
34+
for(uint32_t i = 0; i < temps->values.length; i++)
35+
{
36+
FFTempValue* value = ffListGet(&temps->values, i);
37+
38+
if(
39+
ffStrbufFirstIndexS(&value->name, "cpu") == value->name.length &&
40+
ffStrbufCompS(&value->name, "k10temp") != 0 &&
41+
ffStrbufCompS(&value->name, "coretemp") != 0
42+
) continue;
43+
44+
double temp = ffStrbufToDouble(&value->value);
45+
46+
//NaN
47+
if(temp != temp)
48+
continue;
49+
50+
return temp / 1000.0; // millidegrees to degrees
51+
}
52+
53+
return 0.0 / 0.0; //NaN
54+
}
55+
3056
void ffPrintCPU(FFinstance* instance)
3157
{
3258
if(ffPrintFromCache(instance, FF_CPU_MODULE_NAME, &instance->config.cpu, FF_CPU_NUM_FORMAT_ARGS))
@@ -141,28 +167,11 @@ void ffPrintCPU(FFinstance* instance)
141167
ffStrbufSubstrBeforeFirstC(&namePretty, '@'); //Cut the speed output in the name as we append our own
142168
ffStrbufTrimRight(&namePretty, ' '); //If we removed the @ in previous step there was most likely a space before it
143169

144-
const FFTempsResult *temps = ffDetectTemps(instance);
145-
double cpuTemp = 0.0/0.0; //NaN
146-
147-
for(uint32_t i = 0; i < temps->values.length; i++)
148-
{
149-
FFTempValue* value = ffListGet(&temps->values, i);
150-
151-
if(
152-
ffStrbufFirstIndexS(&value->name, "cpu") == value->name.length &&
153-
ffStrbufCompS(&value->name, "k10temp") != 0 &&
154-
ffStrbufCompS(&value->name, "coretemp") != 0
155-
) continue;
156-
157-
double temp = ffStrbufToDouble(&value->value);
158-
159-
//NaN
160-
if(temp != temp)
161-
continue;
162-
163-
cpuTemp = temp / 1000.0;
164-
break;
165-
}
170+
double cpuTemp;
171+
if(instance->config.cpu.outputFormat.length > 0)
172+
cpuTemp = detectCPUTemp(instance);
173+
else
174+
cpuTemp = 0.0 / 0.0; //NaN
166175

167176
FFstrbuf cpu;
168177
ffStrbufInitA(&cpu, 128);

0 commit comments

Comments
 (0)