From 1c9d6b2c6b26f0c916218d5ecfad8a155273c403 Mon Sep 17 00:00:00 2001 From: Paul Cruz Date: Fri, 7 Jul 2017 15:42:20 -0700 Subject: [PATCH] rewrote time elapsed with UTIL --- contrib/adaptive-compression/Makefile | 1 + contrib/adaptive-compression/multi.c | 38 +++++++++++++-------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/contrib/adaptive-compression/Makefile b/contrib/adaptive-compression/Makefile index 2ebec9ba..2d3de33e 100644 --- a/contrib/adaptive-compression/Makefile +++ b/contrib/adaptive-compression/Makefile @@ -1,5 +1,6 @@ ZSTDDIR = ../../lib +PRGDIR = ../../programs ZSTDCOMMON_FILES := $(ZSTDDIR)/common/*.c ZSTDCOMP_FILES := $(ZSTDDIR)/compress/*.c ZSTDDECOMP_FILES := $(ZSTDDIR)/decompress/*.c diff --git a/contrib/adaptive-compression/multi.c b/contrib/adaptive-compression/multi.c index 943bd856..9f981f81 100644 --- a/contrib/adaptive-compression/multi.c +++ b/contrib/adaptive-compression/multi.c @@ -15,17 +15,16 @@ typedef unsigned char BYTE; #include /* malloc, free */ #include /* pthread functions */ #include /* memset */ -#include /* 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;