]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
zstdcli : moving cpu load calculation from FIO_compressFilename_dstFile to FIO_compre...
authorEphraim Park <ephiepark@fb.com>
Tue, 4 Jun 2019 16:04:35 +0000 (09:04 -0700)
committerEphraim Park <ephiepark@fb.com>
Tue, 4 Jun 2019 16:04:35 +0000 (09:04 -0700)
programs/fileio.c

index d1b155c2d930632a9a860caefb6a0a676fe5030b..39d02a6537fa414445d2d167edf53a638ff01363 100644 (file)
@@ -1165,6 +1165,9 @@ FIO_compressFilename_internal(FIO_prefs_t* const prefs,
                               const char* dstFileName, const char* srcFileName,
                               int compressionLevel)
 {
+    UTIL_time_t const timeStart = UTIL_getTime();;
+    clock_t const cpuStart = clock();
+
     U64 readsize = 0;
     U64 compressedfilesize = 0;
     U64 const fileSize = UTIL_getFileSize(srcFileName);
@@ -1217,6 +1220,15 @@ FIO_compressFilename_internal(FIO_prefs_t* const prefs,
         (unsigned long long)readsize, (unsigned long long) compressedfilesize,
          dstFileName);
 
+    /* Elapsed Time and CPU Load */
+    {   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 0;
 }
 
@@ -1236,9 +1248,6 @@ static int FIO_compressFilename_dstFile(FIO_prefs_t* const prefs,
                                         const char* srcFileName,
                                         int compressionLevel)
 {
-    UTIL_time_t timeStart;
-    clock_t cpuStart;
-
     int closeDstFile = 0;
     int result;
     stat_t statbuf;
@@ -1262,9 +1271,6 @@ static int FIO_compressFilename_dstFile(FIO_prefs_t* const prefs,
             transfer_permissions = 1;
     }
 
-    timeStart = UTIL_getTime();
-    cpuStart = clock();
-
     result = FIO_compressFilename_internal(prefs, ress, dstFileName, srcFileName, compressionLevel);
 
     if (closeDstFile) {
@@ -1288,14 +1294,7 @@ 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;
 }