rewrote time elapsed with UTIL

dev
Paul Cruz 2017-07-07 15:42:20 -07:00
parent c0c236a28b
commit 1c9d6b2c6b
2 changed files with 19 additions and 20 deletions

View File

@ -1,5 +1,6 @@
ZSTDDIR = ../../lib ZSTDDIR = ../../lib
PRGDIR = ../../programs
ZSTDCOMMON_FILES := $(ZSTDDIR)/common/*.c ZSTDCOMMON_FILES := $(ZSTDDIR)/common/*.c
ZSTDCOMP_FILES := $(ZSTDDIR)/compress/*.c ZSTDCOMP_FILES := $(ZSTDDIR)/compress/*.c
ZSTDDECOMP_FILES := $(ZSTDDIR)/decompress/*.c ZSTDDECOMP_FILES := $(ZSTDDIR)/decompress/*.c

View File

@ -15,17 +15,16 @@ typedef unsigned char BYTE;
#include <stdlib.h> /* malloc, free */ #include <stdlib.h> /* malloc, free */
#include <pthread.h> /* pthread functions */ #include <pthread.h> /* pthread functions */
#include <string.h> /* memset */ #include <string.h> /* memset */
#include <time.h> /* clock(), CLOCKS_PER_SEC */
#include "zstd.h" #include "zstd.h"
#include "util.h"
static int g_displayLevel = DEFAULT_DISPLAY_LEVEL; static int g_displayLevel = DEFAULT_DISPLAY_LEVEL;
static unsigned g_compressionLevel = DEFAULT_COMPRESSION_LEVEL; static unsigned g_compressionLevel = DEFAULT_COMPRESSION_LEVEL;
static unsigned g_displayStats = 0; static unsigned g_displayStats = 0;
static clock_t g_time = 0; static UTIL_time_t g_startTime;
static clock_t g_startTime = 0;
static clock_t const refreshRate = CLOCKS_PER_SEC / 60; /* 60 Hz */
static size_t g_streamedSize = 0; static size_t g_streamedSize = 0;
static unsigned g_useProgressBar = 0; static unsigned g_useProgressBar = 0;
static UTIL_freq_t g_ticksPerSecond;
typedef struct { typedef struct {
void* start; void* start;
@ -39,7 +38,7 @@ typedef struct {
unsigned readyCounter; unsigned readyCounter;
unsigned compressedCounter; unsigned compressedCounter;
unsigned writeCounter; unsigned writeCounter;
} stat_t; } cStat_t;
typedef struct { typedef struct {
buffer_t src; buffer_t src;
@ -69,7 +68,7 @@ typedef struct {
pthread_cond_t allJobsCompleted_cond; pthread_cond_t allJobsCompleted_cond;
pthread_mutex_t jobWrite_mutex; pthread_mutex_t jobWrite_mutex;
pthread_cond_t jobWrite_cond; pthread_cond_t jobWrite_cond;
stat_t stats; cStat_t stats;
jobDescription* jobs; jobDescription* jobs;
FILE* dstFile; FILE* dstFile;
ZSTD_CCtx* cctx; ZSTD_CCtx* cctx;
@ -249,12 +248,11 @@ static void* compressionThread(void* arg)
static void displayProgress(unsigned jobDoneID, unsigned cLevel, unsigned last) static void displayProgress(unsigned jobDoneID, unsigned cLevel, unsigned last)
{ {
if (!g_useProgressBar) return; if (!g_useProgressBar) return;
clock_t currTime = clock(); UTIL_time_t currTime;
unsigned const refresh = currTime - g_time > refreshRate ? 1 : 0; UTIL_getTime(&currTime);
double const timeElapsed = (double)((currTime - g_startTime) * 1000 / CLOCKS_PER_SEC); double const timeElapsed = (double)(UTIL_getSpanTimeMicro(g_ticksPerSecond, g_startTime, currTime) / 1000.0);
double const sizeMB = (double)g_streamedSize / (1 << 20); double const sizeMB = (double)g_streamedSize / (1 << 20);
double const avgCompRate = sizeMB * 1000 / timeElapsed; 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); 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) { if (last) {
fprintf(stdout, "\n"); fprintf(stdout, "\n");
@ -262,7 +260,6 @@ static void displayProgress(unsigned jobDoneID, unsigned cLevel, unsigned last)
else { else {
fflush(stdout); fflush(stdout);
} }
}
} }
static void* outputThread(void* arg) static void* outputThread(void* arg)
@ -362,7 +359,7 @@ static int createCompressionJob(adaptCCtx* ctx, BYTE* data, size_t srcSize)
return 0; return 0;
} }
static void printStats(stat_t stats) static void printStats(cStat_t stats)
{ {
DISPLAY("========STATISTICS========\n"); DISPLAY("========STATISTICS========\n");
DISPLAY("# times waited on job ready: %u\n", stats.waitReady); 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; size_t const numJobs = MAX_NUM_JOBS;
int ret = 0; int ret = 0;
adaptCCtx* ctx = NULL; adaptCCtx* ctx = NULL;
g_time = clock(); UTIL_getTime(&g_startTime);
g_startTime = clock();
g_streamedSize = 0; g_streamedSize = 0;
@ -517,6 +513,8 @@ int main(int argCount, const char* argv[])
int ret = 0; int ret = 0;
int argNum; int argNum;
UTIL_initTimer(&g_ticksPerSecond);
if (filenameTable == NULL) { if (filenameTable == NULL) {
DISPLAY("Error: could not allocate sapce for filename table.\n"); DISPLAY("Error: could not allocate sapce for filename table.\n");
return 1; return 1;