Fastfetch: increase precision of --stat

This commit is contained in:
Carter Li
2024-08-12 11:03:52 +08:00
committed by 李通洲
parent 946eb0eacd
commit 0b85fc74eb
3 changed files with 9 additions and 9 deletions
+3 -3
View File
@@ -111,7 +111,7 @@ void ffPrintCommandOption(FFdata* data, yyjson_mut_doc* jsonDoc)
uint32_t colonIndex = ffStrbufNextIndexC(&data->structure, startIndex, ':');
data->structure.chars[colonIndex] = '\0';
uint64_t ms = 0;
double ms = 0;
if(instance.config.display.stat)
ms = ffTimeGetTick();
@@ -124,12 +124,12 @@ void ffPrintCommandOption(FFdata* data, yyjson_mut_doc* jsonDoc)
if (jsonDoc)
{
yyjson_mut_val* moduleJson = yyjson_mut_arr_get_last(jsonDoc->root);
yyjson_mut_obj_add_uint(jsonDoc, moduleJson, "stat", ms);
yyjson_mut_obj_add_real(jsonDoc, moduleJson, "stat", ms);
}
else
{
char str[32];
int len = snprintf(str, sizeof str, "%" PRIu64 "ms", ms);
int len = snprintf(str, sizeof str, "%.3fms", ms);
printf("\033[s\033[1A\033[9999999C\033[%dD%s\033[u", len, str); // Save; Up 1; Right 9999999; Left <len>; Print <str>; Load
}
}
+3 -3
View File
@@ -185,7 +185,7 @@ static const char* printJsonConfig(bool prepare, yyjson_mut_doc* jsonDoc)
size_t idx, max;
yyjson_arr_foreach(modules, idx, max, item)
{
uint64_t ms = 0;
double ms = 0;
if(!prepare && instance.config.display.stat)
ms = ffTimeGetTick();
@@ -214,12 +214,12 @@ static const char* printJsonConfig(bool prepare, yyjson_mut_doc* jsonDoc)
if (jsonDoc)
{
yyjson_mut_val* moduleJson = yyjson_mut_arr_get_last(jsonDoc->root);
yyjson_mut_obj_add_uint(jsonDoc, moduleJson, "stat", ms);
yyjson_mut_obj_add_real(jsonDoc, moduleJson, "stat", ms);
}
else
{
char str[32];
int len = snprintf(str, sizeof str, "%" PRIu64 "ms", ms);
int len = snprintf(str, sizeof str, "%.3fms", ms);
printf("\033[s\033[1A\033[9999999C\033[%dD%s\033[u", len, str); // Save; Up 1; Right 9999999; Left <len>; Print <str>; Load
}
}
+3 -3
View File
@@ -9,18 +9,18 @@
#include <sysinfoapi.h>
#endif
static inline uint64_t ffTimeGetTick() //In msec
static inline double ffTimeGetTick() //In msec
{
#ifdef _WIN32
LARGE_INTEGER frequency;
QueryPerformanceFrequency(&frequency);
LARGE_INTEGER start;
QueryPerformanceCounter(&start);
return (uint64_t)(start.QuadPart * 1000 / frequency.QuadPart);
return (double) start.QuadPart * 1000 / (double) frequency.QuadPart;
#else
struct timespec timeNow;
clock_gettime(CLOCK_MONOTONIC, &timeNow);
return (uint64_t)(((uint64_t) timeNow.tv_sec * 1000u) + ((uint64_t) timeNow.tv_nsec / 1000000u));
return (double) timeNow.tv_sec * 1000. + (double) timeNow.tv_nsec / 1000000.;
#endif
}