diff --git a/CHANGELOG.md b/CHANGELOG.md index a698d4b20..4a46f2408 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Features: * Support GNOME Console terminal version and font detection (Terminal, Linux) * Add `--cpu-freq-ndigits` to set number of digits for CPU frequency (CPU) * New module to detect physical disk I/O usage (DiskIO) +* Add `--cpuusage-separate` to display CPU usage per CPU logical core Bugfixes: * Fix possible crashes on Windows 7 (Disk, Windows) diff --git a/doc/json_schema.json b/doc/json_schema.json index d3e36fed8..3c4b031e7 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -631,10 +631,6 @@ "const": "chassis", "description": "Print chassis type (desktop, laptop, etc)" }, - { - "const": "cpuusage", - "description": "Print CPU usage. Costs some time to collect data" - }, { "const": "cursor", "description": "Print cursor style name" @@ -876,6 +872,20 @@ }, "additionalProperties": false }, + { + "title": "CPU Usage", + "properties": { + "type": { + "const": "cpuusage", + "description": "Print CPU usage. Costs some time to collect data" + }, + "separate": { + "type": "boolean", + "description": "Display CPU usage per CPU logical core, instead of an average result", + "default": false + } + } + }, { "title": "Colors", "properties": { diff --git a/src/data/help.txt b/src/data/help.txt index 154dd7a0e..a9ea8aab6 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -141,6 +141,7 @@ Module specific options: --battery-dir : The directory where the battery folders are. Standard: /sys/class/power_supply/ --cpu-temp : Detect and display CPU temperature if supported. Default is false --cpu-freq-ndigits : Set the number of digits to keep after the decimal point when printing CPU frequency. Default is 2 + --cpuusage-separate : Display CPU usage per CPU logical core, instead of an average result. Default is false --gpu-temp : Detect and display GPU temperature if supported. Default is false --gpu-force-vulkan : Force using vulkan to detect GPUs, which support video memory usage detection with `--allow-slow-operations`. Default is false --gpu-hide-type : Specify the type of GPUs should not be printed. Must be `integrated`, `discrete` or `none`. Default is none diff --git a/src/modules/cpuusage/cpuusage.c b/src/modules/cpuusage/cpuusage.c index 26b24e8ec..c5cd12345 100644 --- a/src/modules/cpuusage/cpuusage.c +++ b/src/modules/cpuusage/cpuusage.c @@ -45,7 +45,7 @@ void ffPrintCPUUsage(FFCPUUsageOptions* options) ffPrintLogoAndKey(FF_CPUUSAGE_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate(); - if (options->displayType == FF_CPUUSAGE_DISPLAY_TYPE_DEFAULT) + if (!options->separate) { if(instance.config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) ffAppendPercentBar(&str, avgValue, 0, 50, 80); @@ -98,13 +98,9 @@ bool ffParseCPUUsageCommandOptions(FFCPUUsageOptions* options, const char* key, if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs)) return true; - if (ffStrEqualsIgnCase(subKey, "display-type")) + if (ffStrEqualsIgnCase(subKey, "separate")) { - options->displayType = (FFCPUUsageDisplayType) ffOptionParseEnum(key, value, (FFKeyValuePair[]) { - { "default", FF_CPUUSAGE_DISPLAY_TYPE_DEFAULT }, - { "separate", FF_CPUUSAGE_DISPLAY_TYPE_SEPARATE }, - {}, - }); + options->separate = ffOptionParseBoolean(value); return true; } @@ -129,18 +125,9 @@ void ffParseCPUUsageJsonObject(FFCPUUsageOptions* options, yyjson_val* module) if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs)) continue; - if (ffStrEqualsIgnCase(key, "display-type")) + if (ffStrEqualsIgnCase(key, "separate")) { - int value; - const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) { - { "default", FF_CPUUSAGE_DISPLAY_TYPE_DEFAULT }, - { "separate", FF_CPUUSAGE_DISPLAY_TYPE_SEPARATE }, - {}, - }); - if (error) - ffPrintErrorString(FF_CPUUSAGE_MODULE_NAME, 0, NULL, FF_PRINT_TYPE_NO_CUSTOM_KEY, "Invalid %s value: %s", key, error); - else - options->displayType = (FFCPUUsageDisplayType) value; + options->separate = yyjson_get_bool(val); continue; } diff --git a/src/modules/cpuusage/option.h b/src/modules/cpuusage/option.h index 3a7069bce..d7fea247d 100644 --- a/src/modules/cpuusage/option.h +++ b/src/modules/cpuusage/option.h @@ -4,15 +4,10 @@ #include "common/option.h" -typedef enum FFCPUUsageDisplayType { - FF_CPUUSAGE_DISPLAY_TYPE_DEFAULT, - FF_CPUUSAGE_DISPLAY_TYPE_SEPARATE, -} FFCPUUsageDisplayType; - typedef struct FFCPUUsageOptions { FFModuleBaseInfo moduleInfo; FFModuleArgs moduleArgs; - FFCPUUsageDisplayType displayType; + bool separate; } FFCPUUsageOptions;