2021-02-18 22:25:36 +01:00
|
|
|
#include "fastfetch.h"
|
2022-07-25 13:15:01 +02:00
|
|
|
#include "common/printing.h"
|
2022-07-25 13:36:58 +02:00
|
|
|
#include "common/caching.h"
|
2022-09-04 22:20:12 +02:00
|
|
|
#include "detection/cpu/cpu.h"
|
2021-04-09 14:07:05 +02:00
|
|
|
|
2021-04-15 18:59:26 +02:00
|
|
|
#define FF_CPU_MODULE_NAME "CPU"
|
2022-09-04 22:20:12 +02:00
|
|
|
#define FF_CPU_NUM_FORMAT_ARGS 8
|
2022-06-17 20:41:11 +02:00
|
|
|
|
2021-02-27 18:30:05 +01:00
|
|
|
void ffPrintCPU(FFinstance* instance)
|
2021-02-18 22:25:36 +01:00
|
|
|
{
|
2022-06-17 18:15:36 +02:00
|
|
|
if(ffPrintFromCache(instance, FF_CPU_MODULE_NAME, &instance->config.cpu, FF_CPU_NUM_FORMAT_ARGS))
|
2021-02-22 16:52:51 +01:00
|
|
|
return;
|
|
|
|
|
|
2022-09-04 22:20:12 +02:00
|
|
|
const FFCPUResult* cpu = ffDetectCPU();
|
2021-06-16 11:28:33 +02:00
|
|
|
|
2022-09-04 22:20:12 +02:00
|
|
|
if(cpu->vendor.length == 0 && cpu->name.length == 0 && cpu->coresOnline == 0)
|
2021-02-19 16:23:41 +01:00
|
|
|
{
|
2022-09-04 22:20:12 +02:00
|
|
|
ffPrintError(instance, FF_CPU_MODULE_NAME, 0, &instance->config.cpu, "No CPU detected");
|
2021-04-03 21:51:50 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-04 22:20:12 +02:00
|
|
|
FFstrbuf output;
|
|
|
|
|
ffStrbufInitA(&output, 128);
|
2022-06-16 13:36:00 +02:00
|
|
|
|
2022-09-04 22:20:12 +02:00
|
|
|
if(cpu->name.length > 0)
|
|
|
|
|
ffStrbufAppend(&output, &cpu->name);
|
|
|
|
|
else if(cpu->vendor.length > 0)
|
2021-03-19 20:57:07 +01:00
|
|
|
{
|
2022-09-04 22:20:12 +02:00
|
|
|
ffStrbufAppend(&output, &cpu->vendor);
|
|
|
|
|
ffStrbufAppendS(&output, " CPU");
|
2021-03-19 20:57:07 +01:00
|
|
|
}
|
|
|
|
|
else
|
2022-09-04 22:20:12 +02:00
|
|
|
ffStrbufAppendS(&output, "CPU");
|
|
|
|
|
|
|
|
|
|
if(cpu->coresOnline > 1)
|
|
|
|
|
ffStrbufAppendF(&output, " (%u)", cpu->coresOnline);
|
|
|
|
|
|
|
|
|
|
if(cpu->frequencyMax > 0.0)
|
|
|
|
|
ffStrbufAppendF(&output, " @ %.9gGHz", cpu->frequencyMax);
|
|
|
|
|
|
|
|
|
|
ffPrintAndWriteToCache(instance, FF_CPU_MODULE_NAME, &instance->config.cpu, &output, FF_CPU_NUM_FORMAT_ARGS, (FFformatarg[]){
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_STRBUF, &cpu->name},
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_STRBUF, &cpu->vendor},
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_UINT16, &cpu->coresPhysical},
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_UINT16, &cpu->coresLogical},
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_UINT16, &cpu->coresOnline},
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_DOUBLE, &cpu->frequencyMin},
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_DOUBLE, &cpu->frequencyMax},
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_DOUBLE, &cpu->temperature}
|
2021-04-15 18:59:26 +02:00
|
|
|
});
|
2022-09-18 16:30:26 +02:00
|
|
|
|
|
|
|
|
ffStrbufDestroy(&output);
|
2021-03-27 18:14:19 +01:00
|
|
|
}
|