From 1eff343733be14205ff53319d2e9c2f4ca8efa19 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Thu, 16 Jun 2022 13:36:00 +0200 Subject: [PATCH] Finish exposing temperatur to cpu format --- presets/verbose | 2 +- src/modules/cpu.c | 37 +++++++++++++++++++------------------ 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/presets/verbose b/presets/verbose index 9694e4f6b..a6f4b307d 100644 --- a/presets/verbose +++ b/presets/verbose @@ -17,7 +17,7 @@ --cursor-format "Theme: {}; Size: {}" --terminal-format "Process: {}; Path: {}; Exe: {}" --terminal-font-format "Raw: {}; Name: {}; Size: {}; Styles: {}; Pretty: {}" ---cpu-format "Name: {}; Pretty: {}; Vendor: {}; Logical online: {}; Logical configured: {}; Physical: {}; Cores: {}; bios: {}; scaling max: {}; scaling min: {}; info max: {}; info min: {}; cpuinfo: {}; frequency: {}" +--cpu-format "Name: {}; Pretty: {}; Vendor: {}; Logical online: {}; Logical configured: {}; Physical: {}; Cores: {}; bios: {}; temperatur: {}; scaling max: {}; scaling min: {}; info max: {}; info min: {}; cpuinfo: {}; frequency: {}" --cpu-usage-format "Percentage: {}" --gpu-format "Vendor: {}; Vendor pretty: {}; Name: {}; Name pretty: {}; Driver: {}" --memory-format "Used: {}; Total: {}; Percentage: {}" diff --git a/src/modules/cpu.c b/src/modules/cpu.c index b24d54b07..1d66d6b0d 100644 --- a/src/modules/cpu.c +++ b/src/modules/cpu.c @@ -6,17 +6,16 @@ #define FF_CPU_MODULE_NAME "CPU" #define FF_CPU_NUM_FORMAT_ARGS 15 - static long parseLong(const FFstrbuf* content) { long value; if(sscanf(content->chars, "%li", &value) != 1) return -1; - return value; + return value; } -static double parseHz(const FFstrbuf* content) +static double parseDouble(const FFstrbuf* content) { double herz; if(sscanf(content->chars, "%lf", &herz) != 1) @@ -34,7 +33,7 @@ static double getGhz(const char* policyFile, const char* cpuFile) if(content.length == 0) ffGetFileContent(cpuFile, &content); - double herz = parseHz(&content); + double herz = parseDouble(&content); ffStrbufDestroy(&content); @@ -89,7 +88,7 @@ void ffPrintCPU(FFinstance* instance) fclose(cpuinfo); - double procGhz = parseHz(&procGhzString) / 1000.0; //to GHz + double procGhz = parseDouble(&procGhzString) / 1000.0; //to GHz ffStrbufDestroy(&procGhzString); 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) if(numProcs <= 1) numProcs = physicalCores; - - const FFTempsResult *temps = ffDetectTemps(&instance); - double cpuTemp = 0.0/0.0; - for(uint32_t i = 0; i< temps->values.length; i++) - { - FFTempValue *v = ffListGet(&temps->values, i); - if(ffStrbufFirstIndexS(&v->name, "cpu") == v->name.length - && ffStrbufCompS(&v->name, "k10temp") != 0 - && ffStrbufCompS(&v->name, "coretemp") != 0) - break; - cpuTemp = (double) parseLong(&v->value) / 1000.0f; - } - double ghz = biosLimit; if(ghz == 0) ghz = scalingMaxFreq; @@ -164,6 +150,21 @@ void ffPrintCPU(FFinstance* instance) ffStrbufSubstrBeforeFirstC(&namePretty, '@'); //Cut the speed output in the name as we append our own ffStrbufTrimRight(&namePretty, ' '); //If we removed the @ in previous step there was most likely a space before it + const FFTempsResult *temps = ffDetectTemps(&instance); + double cpuTemp = 0.0/0.0; //NaN + + for(uint32_t i = 0; i< temps->values.length; i++) + { + FFTempValue *v = ffListGet(&temps->values, i); + if( + ffStrbufFirstIndexS(&v->name, "cpu") == v->name.length && + ffStrbufCompS(&v->name, "k10temp") != 0 && + ffStrbufCompS(&v->name, "coretemp") != 0 + ) break; + + cpuTemp = (double) parseLong(&v->value) / 1000.0; + } + FFstrbuf cpu; ffStrbufInitA(&cpu, 128);