Improve stats output.

This commit is contained in:
Christian Deacon
2025-02-26 12:31:16 -05:00
parent e54fb3fe79
commit 073f656da1
4 changed files with 29 additions and 3 deletions

View File

@@ -19,6 +19,7 @@
#include <loader/utils/helpers.h>
int cont = 1;
int doing_stats = 0;
int main(int argc, char *argv[])
{
@@ -194,6 +195,12 @@ int main(int argc, char *argv[])
struct stat conf_stat;
// Check if we're doing stats.
if (!cfg.nostats)
{
doing_stats = 1;
}
while (cont)
{
// Get current time.
@@ -225,6 +232,12 @@ int main(int argc, char *argv[])
// Update timer
last_config_check = time(NULL);
// Make sure we set doing stats if needed.
if (!cfg.nostats && !doing_stats)
{
doing_stats = 1;
}
}
// Update last updated variable.

View File

@@ -42,7 +42,15 @@ static void LogMsgRaw(int req_lvl, int cur_lvl, int error, const char* log_path,
char full_msg[len + 6 + 1];
snprintf(full_msg, sizeof(full_msg), "[%d] %s", req_lvl, f_msg);
// If we're calculating stats, we need to prepend a new line.
if (doing_stats)
{
fprintf(pipe, "\n%s\n", full_msg);
}
else
{
fprintf(pipe, "%s\n", full_msg);
}
if (log_path != NULL)
{

View File

@@ -14,5 +14,7 @@
#define RB_TIMEOUT 100
extern int doing_stats;
void LogMsg(config__t* cfg, int req_lvl, int error, const char* msg, ...);
int HandleRbEvent(void* ctx, void* data, size_t sz);

View File

@@ -41,8 +41,11 @@ int CalculateStats(int stats_map, int cpus)
passed += stats[i].passed;
}
printf("\r\033[1;32mAllowed:\033[0m %llu | ", allowed);
printf("\033[1;31mDropped:\033[0m %llu | ", dropped);
printf("\033[1;34mPassed:\033[0m %llu", passed);
fflush(stdout);
fprintf(stdout, "\rAllowed: %llu | Dropped: %llu | Passed: %llu", allowed, dropped, passed);
return EXIT_SUCCESS;
}