diff --git a/presets/verbose b/presets/verbose index 7839bd1a7..9d470737a 100644 --- a/presets/verbose +++ b/presets/verbose @@ -17,7 +17,7 @@ --terminal-font-format Raw: {}; Name: {}; Size: {}; Styles: {}; Pretty: {} --cpu-format Name: {}, Vendor: {}, CoresPhysical: {}, CoresLogical: {}, CoresOnline: {}, FrequencyMin: {}, FrequencyMax: {}, Temperature: {} --cpu-usage-format Percentage: {} ---gpu-format Vendor: {}; Name: {}; Driver: {}; Temperature: {} +--gpu-format Vendor: {}; Name: {}; Driver: {}; Temperature: {}; CoreCount: {} --memory-format Used: {}; Total: {}; Percentage: {} --disk-format Used: {}; Total: {}; Files: {}; Percentage: {} --battery-format Manufactor: {}; Model: {}; Technology: {}; Capacity: {}; Status: {} diff --git a/src/detection/gpu/gpu.h b/src/detection/gpu/gpu.h index 0b750b4e5..08b90d3be 100644 --- a/src/detection/gpu/gpu.h +++ b/src/detection/gpu/gpu.h @@ -6,6 +6,7 @@ #include "fastfetch.h" #define FF_GPU_TEMP_UNSET (0/0.0) +#define FF_GPU_CORE_COUNT_UNSET -1 typedef struct FFGPUResult { @@ -13,6 +14,7 @@ typedef struct FFGPUResult FFstrbuf name; FFstrbuf driver; double temperature; + int coreCount; } FFGPUResult; const FFlist* ffDetectGPU(const FFinstance* instance); diff --git a/src/detection/gpu/gpu_android.c b/src/detection/gpu/gpu_android.c index 9b07669a2..6e0afe389 100644 --- a/src/detection/gpu/gpu_android.c +++ b/src/detection/gpu/gpu_android.c @@ -1,6 +1,7 @@ #include "gpu.h" -void ffDetectGPUImpl(FFlist* gpus, const FFinstance* instance) +const char* ffDetectGPUImpl(FFlist* gpus, const FFinstance* instance) { FF_UNUSED(gpus, instance); + return "Unimplemented"; } diff --git a/src/detection/gpu/gpu_apple.c b/src/detection/gpu/gpu_apple.c index 6f22e4721..b8a2b34e6 100644 --- a/src/detection/gpu/gpu_apple.c +++ b/src/detection/gpu/gpu_apple.c @@ -1,33 +1,18 @@ #include "gpu.h" #include "common/library.h" #include "detection/cpu/cpu.h" +#include "util/apple/cfdict_helpers.h" -#include #include -void ffDetectGPUImpl(FFlist* gpus, const FFinstance* instance) +const char* ffDetectGPUImpl(FFlist* gpus, const FFinstance* instance) { FF_UNUSED(instance); - const FFCPUResult* cpu = ffDetectCPU(); - if(ffStrbufStartsWithIgnCaseS(&cpu->name, "Apple M")) - { - FFGPUResult* gpu = ffListAdd(gpus); - - ffStrbufInit(&gpu->vendor); - ffStrbufAppendS(&gpu->vendor, "Apple"); - - ffStrbufInit(&gpu->name); - ffStrbufAppendS(&gpu->name, cpu->name.chars + 6); //Cut "Apple " - - ffStrbufInitA(&gpu->driver, 0); - gpu->temperature = FF_GPU_TEMP_UNSET; - } - - CFMutableDictionaryRef matchDict = IOServiceMatching("IOPCIDevice"); + CFMutableDictionaryRef matchDict = IOServiceMatching(kIOAcceleratorClassName); io_iterator_t iterator; if(IOServiceGetMatchingServices(0, matchDict, &iterator) != kIOReturnSuccess) - return; + return "IOServiceGetMatchingServices() failed"; io_registry_entry_t registryEntry; while((registryEntry = IOIteratorNext(iterator)) != 0) @@ -39,25 +24,19 @@ void ffDetectGPUImpl(FFlist* gpus, const FFinstance* instance) continue; } - CFStringRef key = CFStringCreateWithCStringNoCopy(NULL, "model", kCFStringEncodingASCII, kCFAllocatorNull); - CFStringRef model = CFDictionaryGetValue(properties, key); - if(model == NULL || CFGetTypeID(model) != CFDataGetTypeID()) - { - CFRelease(properties); - IOObjectRelease(registryEntry); - continue; - } - FFGPUResult* gpu = ffListAdd(gpus); - uint32_t modelLength = (uint32_t) CFStringGetLength(model); - ffStrbufInitA(&gpu->name, modelLength + 1); - CFStringGetCString(model, gpu->name.chars, modelLength + 1, kCFStringEncodingASCII); - gpu->name.length = modelLength; - gpu->name.chars[gpu->name.length] = '\0'; + ffStrbufInit(&gpu->name); + ffCfDictGetString(properties, "model", &gpu->name); + + if (!ffCfDictGetInt(properties, "gpu-core-count", &gpu->coreCount)) + gpu->coreCount = FF_GPU_CORE_COUNT_UNSET; ffStrbufInitA(&gpu->vendor, 0); - ffStrbufInitA(&gpu->driver, 0); + + ffStrbufInit(&gpu->driver); + ffCfDictGetString(properties, "CFBundleIdentifier", &gpu->driver); + gpu->temperature = FF_GPU_TEMP_UNSET; CFRelease(properties); @@ -65,4 +44,5 @@ void ffDetectGPUImpl(FFlist* gpus, const FFinstance* instance) } IOObjectRelease(iterator); + return NULL; } diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index ebab29a8c..1aa33f6d9 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -168,24 +168,26 @@ static void pciHandleDevice(FFlist* results, PCIData* pci, struct pci_dev* devic ffStrbufInit(&gpu->driver); pciDetectDriverName(gpu, pci, device); + gpu->coreCount = FF_GPU_CORE_COUNT_UNSET; + gpu->temperature = FF_GPU_TEMP_UNSET; pciDetectTemperatur(gpu, device); } -static void pciDetectGPUs(const FFinstance* instance, FFlist* gpus) +static const char* pciDetectGPUs(const FFinstance* instance, FFlist* gpus) { PCIData pci; - FF_LIBRARY_LOAD(libpci, instance->config.libPCI, , "libpci.so", 4) - FF_LIBRARY_LOAD_SYMBOL(libpci, pci_alloc, ) - FF_LIBRARY_LOAD_SYMBOL(libpci, pci_init, ) - FF_LIBRARY_LOAD_SYMBOL(libpci, pci_scan_bus, ) - FF_LIBRARY_LOAD_SYMBOL(libpci, pci_cleanup, ) + FF_LIBRARY_LOAD(libpci, instance->config.libPCI, "dlopen libpci.so failed", "libpci.so", 4) + FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libpci, pci_alloc) + FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libpci, pci_init) + FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libpci, pci_scan_bus) + FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libpci, pci_cleanup) - FF_LIBRARY_LOAD_SYMBOL_VAR(libpci, pci, pci_read_byte, ) - FF_LIBRARY_LOAD_SYMBOL_VAR(libpci, pci, pci_read_word, ) - FF_LIBRARY_LOAD_SYMBOL_VAR(libpci, pci, pci_lookup_name, ) - FF_LIBRARY_LOAD_SYMBOL_VAR(libpci, pci, pci_get_param, ) + FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libpci, pci, pci_read_byte) + FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libpci, pci, pci_read_word) + FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libpci, pci, pci_lookup_name) + FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libpci, pci, pci_get_param) pci.access = ffpci_alloc(); ffpci_init(pci.access); @@ -200,13 +202,14 @@ static void pciDetectGPUs(const FFinstance* instance, FFlist* gpus) ffpci_cleanup(pci.access); dlclose(libpci); + return NULL; } #endif -void ffDetectGPUImpl(FFlist* gpus, const FFinstance* instance) +const char* ffDetectGPUImpl(FFlist* gpus, const FFinstance* instance) { #ifdef FF_HAVE_LIBPCI - pciDetectGPUs(instance, gpus); + return pciDetectGPUs(instance, gpus); #endif } diff --git a/src/fastfetch.c b/src/fastfetch.c index 6b674f321..17f5cab30 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -274,11 +274,12 @@ static inline void printCommandHelp(const char* command) } else if(strcasecmp(command, "gpu-format") == 0) { - constructAndPrintCommandHelpFormat("gpu", "{} {}", 4, + constructAndPrintCommandHelpFormat("gpu", "{} {}", 5, "GPU vendor", "GPU name", "GPU driver", - "GPU temperature" + "GPU temperature", + "GPU core count" ); } else if(strcasecmp(command, "memory-format") == 0) diff --git a/src/modules/gpu.c b/src/modules/gpu.c index 599843e00..93aaa6940 100644 --- a/src/modules/gpu.c +++ b/src/modules/gpu.c @@ -7,7 +7,7 @@ #include #define FF_GPU_MODULE_NAME "GPU" -#define FF_GPU_NUM_FORMAT_ARGS 4 +#define FF_GPU_NUM_FORMAT_ARGS 5 static void printGPUResult(FFinstance* instance, uint8_t index, FFcache* cache, FFGPUResult* gpu) { @@ -22,11 +22,15 @@ static void printGPUResult(FFinstance* instance, uint8_t index, FFcache* cache, ffStrbufAppend(&output, &gpu->name); + if(gpu->coreCount != FF_GPU_CORE_COUNT_UNSET) + ffStrbufAppendF(&output, " (%d)", gpu->coreCount); + ffPrintAndAppendToCache(instance, FF_GPU_MODULE_NAME, index, &instance->config.gpu, cache, &output, FF_GPU_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &gpu->vendor}, {FF_FORMAT_ARG_TYPE_STRBUF, &gpu->name}, {FF_FORMAT_ARG_TYPE_STRBUF, &gpu->driver}, - {FF_FORMAT_ARG_TYPE_DOUBLE, &gpu->temperature} + {FF_FORMAT_ARG_TYPE_DOUBLE, &gpu->temperature}, + {FF_FORMAT_ARG_TYPE_INT, &gpu->coreCount}, }); ffStrbufDestroy(&output);