mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-12 10:22:12 +02:00
MacOS cpu support
This commit is contained in:
@@ -374,4 +374,22 @@ void ffSettingsGetAppleProperty(const char* propName, FFstrbuf* result)
|
||||
|
||||
result->chars[result->length] = '\0';
|
||||
}
|
||||
|
||||
int ffSettingsGetAppleInt(const char* propName, int defaultValue)
|
||||
{
|
||||
int result;
|
||||
size_t neededLength = sizeof(result);
|
||||
if(sysctlbyname(propName, &result, &neededLength, NULL, 0) != 0)
|
||||
return defaultValue;
|
||||
return result;
|
||||
}
|
||||
|
||||
int64_t ffSettingsGetAppleInt64(const char* propName, int64_t defaultValue)
|
||||
{
|
||||
int64_t result;
|
||||
size_t neededLength = sizeof(result);
|
||||
if(sysctlbyname(propName, &result, &neededLength, NULL, 0) != 0)
|
||||
return defaultValue;
|
||||
return result;
|
||||
}
|
||||
#endif //__APPLE__
|
||||
|
||||
@@ -38,6 +38,8 @@ void ffSettingsGetAndroidProperty(const char* propName, FFstrbuf* result);
|
||||
|
||||
#ifdef __APPLE__
|
||||
void ffSettingsGetAppleProperty(const char* propName, FFstrbuf* result);
|
||||
int ffSettingsGetAppleInt(const char* propName, int defaultValue);
|
||||
int64_t ffSettingsGetAppleInt64(const char* propName, int64_t defaultValue);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,17 +1,42 @@
|
||||
#include "cpu.h"
|
||||
#include "common/settings.h"
|
||||
|
||||
static double getFrequency(const char* propName)
|
||||
{
|
||||
double herz = (double) ffSettingsGetAppleInt64(propName, 0);
|
||||
if(herz <= 0.0)
|
||||
return herz;
|
||||
|
||||
herz /= 1000.0; //to KHz
|
||||
herz /= 1000.0; //to MHz
|
||||
return herz / 1000.0; //to GHz
|
||||
}
|
||||
|
||||
void ffDetectCPUImpl(FFCPUResult* cpu)
|
||||
{
|
||||
ffStrbufInit(&cpu->name);
|
||||
ffSettingsGetAppleProperty("machdep.cpu.brand_string", &cpu->name);
|
||||
|
||||
ffStrbufInit(&cpu->vendor);
|
||||
ffSettingsGetAppleProperty("machdep.cpu.vendor", &cpu->vendor);
|
||||
|
||||
cpu->coresPhysical = 0;
|
||||
cpu->coresLogical = 0;
|
||||
cpu->coresOnline = 0;
|
||||
cpu->coresPhysical = (uint16_t) ffSettingsGetAppleInt("hw.physicalcpu_max", 1);
|
||||
if(cpu->coresPhysical == 1)
|
||||
cpu->coresPhysical = (uint16_t) ffSettingsGetAppleInt("hw.physicalcpu", 1);
|
||||
|
||||
cpu->frequencyCurrent = 0.0;
|
||||
cpu->frequencyMin = 0.0;
|
||||
cpu->frequencyMax = 0.0;
|
||||
cpu->coresLogical = (uint16_t) ffSettingsGetAppleInt("hw.logicalcpu_max", 1);
|
||||
if(cpu->coresLogical == 1)
|
||||
cpu->coresLogical = (uint16_t) ffSettingsGetAppleInt("hw.ncpu", 1);
|
||||
|
||||
cpu->temperature = FF_CPU_TEMP_UNKNOWN;
|
||||
cpu->coresOnline = (uint16_t) ffSettingsGetAppleInt("hw.logicalcpu", 1);
|
||||
if(cpu->coresOnline == 1)
|
||||
cpu->coresOnline = (uint16_t) ffSettingsGetAppleInt("hw.activecpu", 1);
|
||||
|
||||
cpu->frequencyMin = getFrequency("hw.cpufrequency_min");
|
||||
cpu->frequencyMax = getFrequency("hw.cpufrequency_max");
|
||||
if(cpu->frequencyMax == 0.0)
|
||||
cpu->frequencyMax = getFrequency("hw.cpufrequency");
|
||||
|
||||
//TODO find a way to detect this
|
||||
cpu->temperature = FF_CPU_TEMP_UNSET;
|
||||
}
|
||||
|
||||
+9
-16
@@ -247,22 +247,15 @@ static inline void printCommandHelp(const char* command)
|
||||
}
|
||||
else if(strcasecmp(command, "cpu-format") == 0)
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("cpu", "{2} ({7}) @ {15}GHz", 15,
|
||||
"CPU name",
|
||||
"Prettified CPU name",
|
||||
"CPU Vendor name (Vendor ID)",
|
||||
"CPU logical core count online",
|
||||
"CPU logical core count configured",
|
||||
"CPU physical core count",
|
||||
"Always set core count",
|
||||
"CPU package temperature",
|
||||
"frequency bios limit",
|
||||
"frequency scaling max",
|
||||
"frequency scaling min",
|
||||
"frequency info max",
|
||||
"frequency info min",
|
||||
"frequeny from /proc/cpuinfo",
|
||||
"most accurate frequeny"
|
||||
constructAndPrintCommandHelpFormat("cpu", "{1} ({5}) @ {7}GHz", 8,
|
||||
"Name",
|
||||
"Vendor",
|
||||
"Physical core count",
|
||||
"Logical core count",
|
||||
"Online core count",
|
||||
"Min frequency",
|
||||
"Max frequency",
|
||||
"Temperature"
|
||||
);
|
||||
}
|
||||
else if(strcasecmp(command, "cpu-usage-format") == 0)
|
||||
|
||||
Reference in New Issue
Block a user