2021-02-18 22:25:36 +01:00
|
|
|
#include "fastfetch.h"
|
|
|
|
|
|
|
|
|
|
#include <float.h>
|
|
|
|
|
|
|
|
|
|
void ffPrintCPU(FFstate* state)
|
|
|
|
|
{
|
|
|
|
|
char name[256];
|
|
|
|
|
ffParsePropFile("/proc/cpuinfo", "model name%*s %[^\n]", name);
|
2021-02-19 16:23:41 +01:00
|
|
|
if(name[0] == '\0')
|
|
|
|
|
{
|
|
|
|
|
if(state->showErrors)
|
|
|
|
|
ffPrintError(state, "CPU", "\"model name%*s %[^\\n]\" not found in \"/proc/cpuinfo\"");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-02-18 22:25:36 +01:00
|
|
|
|
2021-02-19 16:23:41 +01:00
|
|
|
FILE* frequencyFile = fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq", "r");
|
|
|
|
|
if(frequencyFile == NULL)
|
|
|
|
|
{
|
|
|
|
|
if(state->showErrors)
|
|
|
|
|
ffPrintError(state, "CPU", "fopen(\"/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq\", \"r\") == NULL");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
uint32_t frequency;
|
|
|
|
|
int scanned = fscanf(frequencyFile, "%u", &frequency);
|
|
|
|
|
if(scanned != 1)
|
|
|
|
|
{
|
|
|
|
|
if(state->showErrors)
|
|
|
|
|
ffPrintError(state, "CPU", "fscanf(frequencyFile, \"%s\", frequency) != 1");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
fclose(frequencyFile);
|
2021-02-18 22:25:36 +01:00
|
|
|
|
2021-02-19 16:23:41 +01:00
|
|
|
frequency /= 1000; //to MHz
|
|
|
|
|
double ghz = (double) frequency / 1000.0; //to GHz
|
2021-02-18 22:25:36 +01:00
|
|
|
|
|
|
|
|
ffPrintLogoAndKey(state, "CPU");
|
|
|
|
|
printf("%s (%i) @ %.9gGHz\n", name, get_nprocs(), ghz);
|
|
|
|
|
}
|