]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fixed problem with progress bar not persisting, added time elapsed
authorPaul Cruz <paulcruz74@fb.com>
Fri, 7 Jul 2017 03:30:20 +0000 (20:30 -0700)
committerPaul Cruz <paulcruz74@fb.com>
Fri, 7 Jul 2017 03:30:20 +0000 (20:30 -0700)
contrib/adaptive-compression/multi.c

index 4e33a0514c3d3cc9c616210989b7aa52301d3198..814018d68ec367dec5c61eaa1db052c9cb366553 100644 (file)
@@ -22,6 +22,7 @@ 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 g_startTime = 0;
 static clock_t const refreshRate = CLOCKS_PER_SEC / 60; /* 60 Hz */
 
 typedef struct {
@@ -239,13 +240,19 @@ static void* compressionThread(void* arg)
     return arg;
 }
 
-static void displayProgress(unsigned jobDoneID)
+static void displayProgress(unsigned jobDoneID, unsigned cLevel, unsigned last)
 {
     clock_t currTime = clock();
     unsigned const refresh = currTime - g_time > refreshRate ? 1 : 0;
+    double timeElapsed = (double)((currTime - g_startTime) * 1000 / CLOCKS_PER_SEC);
     if (refresh) {
-        fprintf(stdout, "\r%u jobs completed", jobDoneID+1);
-        fflush(stdout);
+        fprintf(stdout, "\r| %4u jobs completed | Current Compresion Level: %2u | Time Elapsed: %5.0fms |", jobDoneID, cLevel, timeElapsed);
+        if (last) {
+            fprintf(stdout, "\n");
+        }
+        else {
+            fflush(stdout);
+        }
     }
 }
 
@@ -282,8 +289,8 @@ static void* outputThread(void* arg)
             }
         }
         DEBUGLOG(2, "finished job write %u\n", currJob);
-        displayProgress(currJob);
         currJob++;
+        displayProgress(currJob, ctx->compressionLevel, currJob >= ctx->lastJobID);
         DEBUGLOG(2, "locking job write mutex\n");
         pthread_mutex_lock(&ctx->jobWrite_mutex);
         ctx->jobWriteID++;
@@ -364,6 +371,7 @@ static int compressFilename(const char* const srcFilename, const char* const dst
     int ret = 0;
     adaptCCtx* ctx = NULL;
     g_time = clock();
+    g_startTime = clock();
 
 
     /* checking for errors */