Temps (macOS): code refactors

This commit is contained in:
李通洲
2023-08-07 10:15:08 +08:00
parent f1d4611a7d
commit 74233ac0cb
6 changed files with 100 additions and 164 deletions
+8 -20
View File
@@ -15,28 +15,19 @@ static double getFrequency(const char* propName)
static double detectCpuTemp(const FFstrbuf* cpuName)
{
FF_LIST_AUTO_DESTROY temps = ffListCreate(sizeof(FFTempValue));
double result = 0;
const char* error = NULL;
if(ffStrbufStartsWithS(cpuName, "Apple M1"))
ffDetectCoreTemps(FF_TEMP_CPU_M1X, &temps);
error = ffDetectCoreTemps(FF_TEMP_CPU_M1X, &result);
else if(ffStrbufStartsWithS(cpuName, "Apple M2"))
ffDetectCoreTemps(FF_TEMP_CPU_M2X, &temps);
else //TODO: PPC?
ffDetectCoreTemps(FF_TEMP_CPU_X64, &temps);
error = ffDetectCoreTemps(FF_TEMP_CPU_M2X, &result);
else // PPC?
error = ffDetectCoreTemps(FF_TEMP_CPU_X64, &result);
if(temps.length == 0)
if(error)
return FF_CPU_TEMP_UNSET;
double result = 0;
for(uint32_t i = 0; i < temps.length; ++i)
{
FFTempValue* tempValue = (FFTempValue*)ffListGet(&temps, i);
result += tempValue->value;
//TODO: do we really need this?
ffStrbufDestroy(&tempValue->name);
ffStrbufDestroy(&tempValue->deviceClass);
}
result /= temps.length;
return result;
}
@@ -63,10 +54,7 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
if(cpu->frequencyMax == 0.0)
cpu->frequencyMax = getFrequency("hw.cpufrequency");
if (options->temp)
cpu->temperature = detectCpuTemp(&cpu->name);
else
cpu->temperature = FF_CPU_TEMP_UNSET;
cpu->temperature = options->temp ? detectCpuTemp(&cpu->name) : FF_CPU_TEMP_UNSET;
return NULL;
}