diff --git a/completions/bash b/completions/bash index 7de2b3edf..31f2f7a3c 100644 --- a/completions/bash +++ b/completions/bash @@ -174,6 +174,7 @@ __fastfetch_completion() "--show-errors" "--logo-print-remaining" "--multithreading" + "--stat" "--allow-slow-operations" "--unbuffered" "--disable-linewrap" diff --git a/src/common/init.c b/src/common/init.c index c86285b70..51de9e18a 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -177,6 +177,7 @@ static void defaultConfig(FFinstance* instance) instance->config.glType = FF_GL_TYPE_AUTO; instance->config.pipe = false; instance->config.multithreading = true; + instance->config.stat = false; initModuleArg(&instance->config.os); initModuleArg(&instance->config.host); diff --git a/src/data/config_user.txt b/src/data/config_user.txt index 7a3fb1f9c..f7a1be09d 100644 --- a/src/data/config_user.txt +++ b/src/data/config_user.txt @@ -33,6 +33,12 @@ # Default is true. #--multithreading true +# Print stat option: +# Sets if fastfetch should print time usage (in ms) for individual modules. +# Must be true or false. +# Default is false. +#--stat true + # Disable stdout buffer option: # Sets if fastfetch should disable application buffer of stdout. Mainly for debugging purpose. # Must be true or false. diff --git a/src/data/help.txt b/src/data/help.txt index cd0c36168..40d9fd8d4 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -18,6 +18,7 @@ General options: --nocache : don't use cached values, but also don't overwrite existing ones --load-config : load a config file or a preset (+) --multithreading : use multiple threads to detect values + --stat : print time usage (in ms) for individual modules --allow-slow-operations : allow operations that are usually very slow for more detailed output --unbuffered : disable stdout application buffer --escape-bedrock : on bedrock linux, sets if it should escape the bedrock jail or not diff --git a/src/fastfetch.c b/src/fastfetch.c index 3f7f9f829..aa3401d9e 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -3,10 +3,12 @@ #include "common/printing.h" #include "common/parsing.h" #include "common/io.h" +#include "common/time.h" #include #include #include +#include #ifdef WIN32 #include "util/windows/getline.h" @@ -907,6 +909,8 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con optionParseConfigFile(instance, data, key, value); else if(strcasecmp(key, "--thread") == 0 || strcasecmp(key, "--multithreading") == 0) instance->config.multithreading = optionParseBoolean(value); + else if(strcasecmp(key, "--stat") == 0) + instance->config.stat = optionParseBoolean(value); else if(strcasecmp(key, "--allow-slow-operations") == 0) instance->config.allowSlowOperations = optionParseBoolean(value); else if(strcasecmp(key, "--unbuffered") == 0) @@ -1412,8 +1416,22 @@ int main(int argc, const char** argv) uint32_t colonIndex = ffStrbufNextIndexC(&data.structure, startIndex, ':'); data.structure.chars[colonIndex] = '\0'; + uint64_t ms = 0; + if(__builtin_expect(instance.config.stat, false)) + ms = ffTimeGetTick(); + parseStructureCommand(&instance, &data, data.structure.chars + startIndex); + if(__builtin_expect(instance.config.stat, false)) + { + char str[32]; + int len = snprintf(str, sizeof str, "%" PRIu64 "ms", ffTimeGetTick() - ms); + if(instance.config.pipe) + puts(str); + else + printf("\033[s\033[1A\033[9999999C\033[%dD%s\033[u", len, str); // Save; Up 1; Right 9999999; Left ; Print ; Load + } + startIndex = colonIndex + 1; } diff --git a/src/fastfetch.h b/src/fastfetch.h index 36bb4131a..bbd19122c 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -94,6 +94,7 @@ typedef struct FFconfig FFGLType glType; bool pipe; //disables logo and all escape sequences bool multithreading; + bool stat; FFModuleArgs os; FFModuleArgs host;