zstdcli : exposing cpu load indicator for each file on -vv mode

dev
Ephraim Park 2019-06-03 14:38:40 -07:00
parent b13a9207f9
commit 5029ebce2f
1 changed files with 11 additions and 4 deletions

View File

@ -1236,6 +1236,9 @@ static int FIO_compressFilename_dstFile(FIO_prefs_t* const prefs,
const char* srcFileName, const char* srcFileName,
int compressionLevel) int compressionLevel)
{ {
UTIL_time_t const timeStart = UTIL_getTime();
clock_t const cpuStart = clock();
int closeDstFile = 0; int closeDstFile = 0;
int result; int result;
stat_t statbuf; stat_t statbuf;
@ -1282,7 +1285,14 @@ static int FIO_compressFilename_dstFile(FIO_prefs_t* const prefs,
UTIL_setFileStat(dstFileName, &statbuf); 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; return result;
} }
@ -1339,15 +1349,12 @@ int FIO_compressFilename(FIO_prefs_t* const prefs,
const char* dictFileName, int compressionLevel, const char* dictFileName, int compressionLevel,
ZSTD_compressionParameters comprParams) ZSTD_compressionParameters comprParams)
{ {
clock_t const start = clock();
U64 const fileSize = UTIL_getFileSize(srcFileName); U64 const fileSize = UTIL_getFileSize(srcFileName);
U64 const srcSize = (fileSize == UTIL_FILESIZE_UNKNOWN) ? ZSTD_CONTENTSIZE_UNKNOWN : fileSize; U64 const srcSize = (fileSize == UTIL_FILESIZE_UNKNOWN) ? ZSTD_CONTENTSIZE_UNKNOWN : fileSize;
cRess_t const ress = FIO_createCResources(prefs, dictFileName, compressionLevel, srcSize, comprParams); cRess_t const ress = FIO_createCResources(prefs, dictFileName, compressionLevel, srcSize, comprParams);
int const result = FIO_compressFilename_srcFile(prefs, ress, dstFileName, srcFileName, compressionLevel); 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); FIO_freeCResources(ress);
return result; return result;