Skip to content

Commit 1eff343

Browse files
Finish exposing temperatur to cpu format
1 parent acdbf69 commit 1eff343

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

presets/verbose

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
--cursor-format "Theme: {}; Size: {}"
1818
--terminal-format "Process: {}; Path: {}; Exe: {}"
1919
--terminal-font-format "Raw: {}; Name: {}; Size: {}; Styles: {}; Pretty: {}"
20-
--cpu-format "Name: {}; Pretty: {}; Vendor: {}; Logical online: {}; Logical configured: {}; Physical: {}; Cores: {}; bios: {}; scaling max: {}; scaling min: {}; info max: {}; info min: {}; cpuinfo: {}; frequency: {}"
20+
--cpu-format "Name: {}; Pretty: {}; Vendor: {}; Logical online: {}; Logical configured: {}; Physical: {}; Cores: {}; bios: {}; temperatur: {}; scaling max: {}; scaling min: {}; info max: {}; info min: {}; cpuinfo: {}; frequency: {}"
2121
--cpu-usage-format "Percentage: {}"
2222
--gpu-format "Vendor: {}; Vendor pretty: {}; Name: {}; Name pretty: {}; Driver: {}"
2323
--memory-format "Used: {}; Total: {}; Percentage: {}"

src/modules/cpu.c

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@
66
#define FF_CPU_MODULE_NAME "CPU"
77
#define FF_CPU_NUM_FORMAT_ARGS 15
88

9-
109
static long parseLong(const FFstrbuf* content)
1110
{
1211
long value;
1312
if(sscanf(content->chars, "%li", &value) != 1)
1413
return -1;
15-
return value;
1614

15+
return value;
1716
}
1817

19-
static double parseHz(const FFstrbuf* content)
18+
static double parseDouble(const FFstrbuf* content)
2019
{
2120
double herz;
2221
if(sscanf(content->chars, "%lf", &herz) != 1)
@@ -34,7 +33,7 @@ static double getGhz(const char* policyFile, const char* cpuFile)
3433
if(content.length == 0)
3534
ffGetFileContent(cpuFile, &content);
3635

37-
double herz = parseHz(&content);
36+
double herz = parseDouble(&content);
3837

3938
ffStrbufDestroy(&content);
4039

@@ -89,7 +88,7 @@ void ffPrintCPU(FFinstance* instance)
8988

9089
fclose(cpuinfo);
9190

92-
double procGhz = parseHz(&procGhzString) / 1000.0; //to GHz
91+
double procGhz = parseDouble(&procGhzString) / 1000.0; //to GHz
9392
ffStrbufDestroy(&procGhzString);
9493

9594
double biosLimit = getGhz("/sys/devices/system/cpu/cpufreq/policy0/bios_limit", "/sys/devices/system/cpu/cpu0/cpufreq/bios_limit");
@@ -112,19 +111,6 @@ void ffPrintCPU(FFinstance* instance)
112111
if(numProcs <= 1)
113112
numProcs = physicalCores;
114113

115-
116-
const FFTempsResult *temps = ffDetectTemps(&instance);
117-
double cpuTemp = 0.0/0.0;
118-
for(uint32_t i = 0; i< temps->values.length; i++)
119-
{
120-
FFTempValue *v = ffListGet(&temps->values, i);
121-
if(ffStrbufFirstIndexS(&v->name, "cpu") == v->name.length
122-
&& ffStrbufCompS(&v->name, "k10temp") != 0
123-
&& ffStrbufCompS(&v->name, "coretemp") != 0)
124-
break;
125-
cpuTemp = (double) parseLong(&v->value) / 1000.0f;
126-
}
127-
128114
double ghz = biosLimit;
129115
if(ghz == 0)
130116
ghz = scalingMaxFreq;
@@ -164,6 +150,21 @@ void ffPrintCPU(FFinstance* instance)
164150
ffStrbufSubstrBeforeFirstC(&namePretty, '@'); //Cut the speed output in the name as we append our own
165151
ffStrbufTrimRight(&namePretty, ' '); //If we removed the @ in previous step there was most likely a space before it
166152

153+
const FFTempsResult *temps = ffDetectTemps(&instance);
154+
double cpuTemp = 0.0/0.0; //NaN
155+
156+
for(uint32_t i = 0; i< temps->values.length; i++)
157+
{
158+
FFTempValue *v = ffListGet(&temps->values, i);
159+
if(
160+
ffStrbufFirstIndexS(&v->name, "cpu") == v->name.length &&
161+
ffStrbufCompS(&v->name, "k10temp") != 0 &&
162+
ffStrbufCompS(&v->name, "coretemp") != 0
163+
) break;
164+
165+
cpuTemp = (double) parseLong(&v->value) / 1000.0;
166+
}
167+
167168
FFstrbuf cpu;
168169
ffStrbufInitA(&cpu, 128);
169170

0 commit comments

Comments
 (0)