paleofetch

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 3dbc153b6db187d567abeac218fb5db66ad26b8b
parent ffad8c4df856f4e7a681f40b9086d4ad683b300e
Author: dwzg <dennis@wtzg.de>
Date:   Thu, 23 Apr 2020 17:25:37 +0200

Add detection of CPU max. frequency

Diffstat:
Mpaleofetch.c | 36++++++++++++++++++++++++++++--------
1 file changed, 28 insertions(+), 8 deletions(-)

diff --git a/paleofetch.c b/paleofetch.c @@ -334,6 +334,7 @@ char *get_cpu() { char *line = NULL; size_t len; /* unused */ int num_cores = 0; + double freq; /* read the model name into cpu_model, and increment num_cores every time model name is found */ while(getline(&line, &len, cpuinfo) != -1) { @@ -342,16 +343,35 @@ char *get_cpu() { free(line); fclose(cpuinfo); - char *cpu = malloc(BUF_SIZE); - snprintf(cpu, BUF_SIZE, "%s(%d)", cpu_model, num_cores); - free(cpu_model); + FILE *cpufreq = fopen("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq", "r"); + + if (cpufreq == NULL) { + status = -1; + halt_and_catch_fire("Unable to open cpufreq"); + } + + line = NULL; + + if (getline(&line, &len, cpufreq) != -1) { + sscanf(line, "%lf", &freq); + freq /= 1e6; // convert kHz to GHz + } else { + freq = 0.0; // cpuinfo_max_freq not available? + } + + free(line); + fclose(cpufreq); /* remove unneeded information */ - remove_substring(cpu, "(R)", 3); - remove_substring(cpu, "(TM)", 4); - remove_substring(cpu, "Core", 4); - remove_substring(cpu, "CPU", 3); - truncate_spaces(cpu); + remove_substring(cpu_model, "(R)", 3); + remove_substring(cpu_model, "(TM)", 4); + remove_substring(cpu_model, "Core", 4); + remove_substring(cpu_model, "CPU", 3); + truncate_spaces(cpu_model); + + char *cpu = malloc(BUF_SIZE); + snprintf(cpu, BUF_SIZE, "%s (%d) @ %.3fGHz", cpu_model, num_cores, freq); + free(cpu_model); return cpu; }