]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
rewrote time elapsed with UTIL
authorPaul Cruz <paulcruz74@fb.com>
Fri, 7 Jul 2017 22:42:20 +0000 (15:42 -0700)
committerPaul Cruz <paulcruz74@fb.com>
Fri, 7 Jul 2017 22:42:20 +0000 (15:42 -0700)
contrib/adaptive-compression/Makefile
contrib/adaptive-compression/multi.c

index 2ebec9ba9055b3042ecd602e0e750516e357bdbc..2d3de33eaa4cb89f1a999ed6377b8c6c4e98abe8 100644 (file)
@@ -1,5 +1,6 @@
 
 ZSTDDIR = ../../lib
+PRGDIR  = ../../programs
 ZSTDCOMMON_FILES := $(ZSTDDIR)/common/*.c
 ZSTDCOMP_FILES   := $(ZSTDDIR)/compress/*.c
 ZSTDDECOMP_FILES := $(ZSTDDIR)/decompress/*.c
index 943bd8564ac2c87cb61c32a0a2040d05303271a4..9f981f8125d6bd9f6b331611cb2871a2011d33e7 100644 (file)
@@ -15,17 +15,16 @@ typedef unsigned char BYTE;
 #include <stdlib.h>     /* malloc, free */
 #include <pthread.h>    /* pthread functions */
 #include <string.h>     /* memset */
-#include <time.h>       /* clock(), CLOCKS_PER_SEC */
 #include "zstd.h"
+#include "util.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 g_startTime = 0;
-static clock_t const refreshRate = CLOCKS_PER_SEC / 60; /* 60 Hz */
+static UTIL_time_t g_startTime;
 static size_t g_streamedSize = 0;
 static unsigned g_useProgressBar = 0;
+static UTIL_freq_t g_ticksPerSecond;
 
 typedef struct {
     void* start;
@@ -39,7 +38,7 @@ typedef struct {
     unsigned readyCounter;
     unsigned compressedCounter;
     unsigned writeCounter;
-} stat_t;
+} cStat_t;
 
 typedef struct {
     buffer_t src;
@@ -69,7 +68,7 @@ typedef struct {
     pthread_cond_t allJobsCompleted_cond;
     pthread_mutex_t jobWrite_mutex;
     pthread_cond_t jobWrite_cond;
-    stat_t stats;
+    cStat_t stats;
     jobDescription* jobs;
     FILE* dstFile;
     ZSTD_CCtx* cctx;
@@ -249,19 +248,17 @@ static void* compressionThread(void* arg)
 static void displayProgress(unsigned jobDoneID, unsigned cLevel, unsigned last)
 {
     if (!g_useProgressBar) return;
-    clock_t currTime = clock();
-    unsigned const refresh = currTime - g_time > refreshRate ? 1 : 0;
-    double const timeElapsed = (double)((currTime - g_startTime) * 1000 / CLOCKS_PER_SEC);
+    UTIL_time_t currTime;
+    UTIL_getTime(&currTime);
+    double const timeElapsed = (double)(UTIL_getSpanTimeMicro(g_ticksPerSecond, g_startTime, currTime) / 1000.0);
     double const sizeMB = (double)g_streamedSize / (1 << 20);
     double const avgCompRate = sizeMB * 1000 / timeElapsed;
-    if (refresh) {
-        fprintf(stdout, "\r| %4u jobs completed | Current Compresion Level: %2u | Time Elapsed: %5.0f ms | Data Size: %7.1f MB | Avg Compression Rate: %6.2f MB/s |", jobDoneID, cLevel, timeElapsed, sizeMB, avgCompRate);
-        if (last) {
-            fprintf(stdout, "\n");
-        }
-        else {
-            fflush(stdout);
-        }
+    fprintf(stdout, "\r| %4u jobs completed | Current Compresion Level: %2u | Time Elapsed: %5.0f ms | Data Size: %7.1f MB | Avg Compression Rate: %6.2f MB/s |", jobDoneID, cLevel, timeElapsed, sizeMB, avgCompRate);
+    if (last) {
+        fprintf(stdout, "\n");
+    }
+    else {
+        fflush(stdout);
     }
 }
 
@@ -362,7 +359,7 @@ static int createCompressionJob(adaptCCtx* ctx, BYTE* data, size_t srcSize)
     return 0;
 }
 
-static void printStats(stat_t stats)
+static void printStats(cStat_t stats)
 {
     DISPLAY("========STATISTICS========\n");
     DISPLAY("# times waited on job ready: %u\n", stats.waitReady);
@@ -379,8 +376,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();
-    g_startTime = clock();
+    UTIL_getTime(&g_startTime);
     g_streamedSize = 0;
 
 
@@ -517,6 +513,8 @@ int main(int argCount, const char* argv[])
     int ret = 0;
     int argNum;
 
+    UTIL_initTimer(&g_ticksPerSecond);
+
     if (filenameTable == NULL) {
         DISPLAY("Error: could not allocate sapce for filename table.\n");
         return 1;