moving to clock_gettime and add correction of time spent in freezed state.
authorAndrey Rys <rys@lynxlynx.ru>
Sun, 28 Nov 2021 13:07:23 +0000 (14:07 +0100)
committerAndrey Rys <rys@lynxlynx.ru>
Sun, 28 Nov 2021 13:07:23 +0000 (14:07 +0100)
VERSION
tfc_misc.c
tfc_signal.c
tfcrypt.h

diff --git a/VERSION b/VERSION
index c739b42c4d2ce23786c5350641d0adbf5fa7d6b2..ea90ee31980757b2e469741512bcb39e73494e78 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-44
+45
index 3bfd214c1914163bf0019a4241e52eb11a035a8c..a39f4591831ddf988f8cbcb74ab323658c74b76a 100644 (file)
@@ -85,11 +85,11 @@ const char *tfc_modename(int mode)
 
 void tfc_getcurtime(tfc_useconds *tx)
 {
-       struct timeval t;
+       struct timespec t;
        memset(&t, 0, sizeof(t));
 
-       gettimeofday(&t, NULL);
-       *tx = (tfc_useconds)t.tv_sec * 1000000 + t.tv_usec;
+       clock_gettime(CLOCK_MONOTONIC, &t);
+       *tx = (tfc_useconds)t.tv_sec * 1000000 + (t.tv_nsec / 1000);
 
        memset(&t, 0, sizeof(t));
 }
@@ -108,10 +108,10 @@ char *tfc_format_time(tfc_useconds t)
        minutes = (secs / 60) % 60;
        seconds = secs % 60;
 
-       if (days > 0) sprintf(r, "%ud,%02u:%02u:%02u.%03u", days, hours, minutes, seconds, (unsigned)(dsecs / 1000));
-       else if (hours > 0) sprintf(r, "%02u:%02u:%02u.%03u", hours, minutes, seconds, (unsigned)(dsecs / 1000));
-       else if (minutes > 0) sprintf(r, "%02u:%02u.%03u", minutes, seconds, (unsigned)(dsecs / 1000));
-       else sprintf(r, "%02u.%03u", seconds, (unsigned)(dsecs / 1000));
+       if (days > 0) sprintf(r, "%ud,%02u:%02u:%02u.%04u", days, hours, minutes, seconds, (unsigned)(dsecs / 100));
+       else if (hours > 0) sprintf(r, "%02u:%02u:%02u.%04u", hours, minutes, seconds, (unsigned)(dsecs / 100));
+       else if (minutes > 0) sprintf(r, "%02u:%02u.%04u", minutes, seconds, (unsigned)(dsecs / 100));
+       else sprintf(r, "%02u.%04u", seconds, (unsigned)(dsecs / 100));
 
        return r;
 }
index b2862eedcdaa53fab7f6c71b13b691dd3ff6563a..4c918193f9f44ebfc1493e80a6a3e7ee7d31292e 100644 (file)
@@ -35,7 +35,14 @@ void exit_sigterm(int signal)
 
 void handle_sigtstp(int signal)
 {
-       if (signal == SIGTSTP) kill(getpid(), SIGSTOP);
+       if (signal == SIGTSTP) {
+               tfc_useconds freeze_start, freeze_end;
+
+               tfc_getcurtime(&freeze_start);
+               kill(getpid(), SIGSTOP);
+               tfc_getcurtime(&freeze_end);
+               total_time -= (freeze_end - freeze_start);
+       }
 }
 
 void print_crypt_status(int signal)
@@ -79,8 +86,7 @@ void print_crypt_status(int signal)
                        "avg. speed %llu (%.2f%s) B/s, time %.4fs.",
                        oper_mode,
                        total_processed_src, human_totalproc_src, tfc_getscale(src_scale_idx),
-                       wr_speed, human_wr_speed, tfc_getscale(wr_speed_scale),
-                       TFC_UTODSECS(current_time - delta_time));
+                       wr_speed, human_wr_speed, tfc_getscale(wr_speed_scale), seconds);
                tfc_esay("\n");
                xexit(0);
        }
index e9aedd61ccb3de5e4dc2f2e547d881c35e7f3764..67b4956cf83d8952289afdb3a4682d1161559d93 100644 (file)
--- a/tfcrypt.h
+++ b/tfcrypt.h
@@ -61,6 +61,7 @@
 #include <limits.h>
 #include <fcntl.h>
 #include <signal.h>
+#include <time.h>
 #include <sys/time.h>
 #include <stdint.h>