Global: support --stat option for benchmark

This commit is contained in:
李通洲
2022-12-14 11:30:50 +08:00
parent c9bc1f8306
commit b09aa3240a
6 changed files with 28 additions and 0 deletions
+1
View File
@@ -174,6 +174,7 @@ __fastfetch_completion()
"--show-errors"
"--logo-print-remaining"
"--multithreading"
"--stat"
"--allow-slow-operations"
"--unbuffered"
"--disable-linewrap"
+1
View File
@@ -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);
+6
View File
@@ -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.
+1
View File
@@ -18,6 +18,7 @@ General options:
--nocache <?value>: don't use cached values, but also don't overwrite existing ones
--load-config <file>: load a config file or a preset (+)
--multithreading <?value>: use multiple threads to detect values
--stat <?value>: print time usage (in ms) for individual modules
--allow-slow-operations <?value>: allow operations that are usually very slow for more detailed output
--unbuffered <?value>: disable stdout application buffer
--escape-bedrock <?value>: on bedrock linux, sets if it should escape the bedrock jail or not
+18
View File
@@ -3,10 +3,12 @@
#include "common/printing.h"
#include "common/parsing.h"
#include "common/io.h"
#include "common/time.h"
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <inttypes.h>
#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 <len>; Print <str>; Load
}
startIndex = colonIndex + 1;
}
+1
View File
@@ -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;