From 5029ebce2f6dbf55071e4e99579839a89b0f0a85 Mon Sep 17 00:00:00 2001 From: Ephraim Park Date: Mon, 3 Jun 2019 14:38:40 -0700 Subject: [PATCH] zstdcli : exposing cpu load indicator for each file on -vv mode --- programs/fileio.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/programs/fileio.c b/programs/fileio.c index dc8479ab..390a3bbe 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -1236,6 +1236,9 @@ static int FIO_compressFilename_dstFile(FIO_prefs_t* const prefs, const char* srcFileName, int compressionLevel) { + UTIL_time_t const timeStart = UTIL_getTime(); + clock_t const cpuStart = clock(); + int closeDstFile = 0; int result; stat_t statbuf; @@ -1282,7 +1285,14 @@ static int FIO_compressFilename_dstFile(FIO_prefs_t* const prefs, UTIL_setFileStat(dstFileName, &statbuf); } } - + { clock_t const cpuEnd = clock(); + double const cpuLoad_s = (double)(cpuEnd - cpuStart) / CLOCKS_PER_SEC; + U64 const timeLength_ns = UTIL_clockSpanNano(timeStart); + double const timeLength_s = (double)timeLength_ns / 1000000000; + double const cpuLoad_pct = (cpuLoad_s / timeLength_s) * 100; + DISPLAYLEVEL(4, "%s: Completed in %.2f sec (cpu load : %.0f%%)\n", + srcFileName, timeLength_s, cpuLoad_pct); + } return result; } @@ -1339,15 +1349,12 @@ int FIO_compressFilename(FIO_prefs_t* const prefs, const char* dictFileName, int compressionLevel, ZSTD_compressionParameters comprParams) { - clock_t const start = clock(); U64 const fileSize = UTIL_getFileSize(srcFileName); U64 const srcSize = (fileSize == UTIL_FILESIZE_UNKNOWN) ? ZSTD_CONTENTSIZE_UNKNOWN : fileSize; cRess_t const ress = FIO_createCResources(prefs, dictFileName, compressionLevel, srcSize, comprParams); int const result = FIO_compressFilename_srcFile(prefs, ress, dstFileName, srcFileName, compressionLevel); - double const seconds = (double)(clock() - start) / CLOCKS_PER_SEC; - DISPLAYLEVEL(4, "Completed in %.2f sec \n", seconds); FIO_freeCResources(ress); return result;