From b6cc0847162ff6eb7e7398f92736ecf4941b614c Mon Sep 17 00:00:00 2001 From: Paul Cruz Date: Thu, 6 Jul 2017 17:48:18 -0700 Subject: [PATCH] added really simple progress update in the corner --- contrib/adaptive-compression/multi.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/contrib/adaptive-compression/multi.c b/contrib/adaptive-compression/multi.c index 2b2aacab..324a570b 100644 --- a/contrib/adaptive-compression/multi.c +++ b/contrib/adaptive-compression/multi.c @@ -14,11 +14,14 @@ typedef unsigned char BYTE; #include /* malloc, free */ #include /* pthread functions */ #include /* memset */ +#include /* clock(), CLOCKS_PER_SEC */ #include "zstd.h" static int g_displayLevel = DEFAULT_DISPLAY_LEVEL; static unsigned g_compressionLevel = DEFAULT_COMPRESSION_LEVEL; static unsigned g_displayStats = 0; +static clock_t g_time = 0; +static clock_t const refreshRate = CLOCKS_PER_SEC / 60; /* 60 Hz */ typedef struct { void* start; @@ -235,6 +238,16 @@ static void* compressionThread(void* arg) return arg; } +static void displayProgress(unsigned jobDoneID) +{ + clock_t currTime = clock(); + unsigned const refresh = currTime - g_time > refreshRate ? 1 : 0; + if (refresh) { + fprintf(stdout, "%u jobs completed\r", jobDoneID+1); + fflush(stdout); + } +} + static void* outputThread(void* arg) { adaptCCtx* ctx = (adaptCCtx*)arg; @@ -268,6 +281,7 @@ static void* outputThread(void* arg) } } DEBUGLOG(2, "finished job write %u\n", currJob); + displayProgress(currJob); currJob++; DEBUGLOG(2, "locking job write mutex\n"); pthread_mutex_lock(&ctx->jobWrite_mutex); @@ -348,6 +362,7 @@ static int compressFilename(const char* const srcFilename, const char* const dst size_t const numJobs = MAX_NUM_JOBS; int ret = 0; adaptCCtx* ctx = NULL; + g_time = clock(); /* checking for errors */