tfc_signal: add elapsed time counter.
authorAndrey Rys <rys@lynxlynx.ru>
Sun, 6 Oct 2019 12:14:50 +0000 (14:14 +0200)
committerAndrey Rys <rys@lynxlynx.ru>
Sun, 6 Oct 2019 12:14:50 +0000 (14:14 +0200)
VERSION
tfc_misc.c
tfc_signal.c
tfc_vars.c
tfcrypt.h

diff --git a/VERSION b/VERSION
index bb95160cb6e07358f54a28a208ae41e69889c97b..a7873645902455c63d166fdcaa4b2fe565f6de7d 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-33
+34
index f55726ac897974471b33f9ad4422bc4463ddccfe..06c1a653e7d6a3ac23047288f6e7224e15b83789 100644 (file)
@@ -94,6 +94,28 @@ void tfc_getcurtime(tfc_useconds *tx)
        memset(&t, 0, sizeof(t));
 }
 
+char *tfc_format_time(tfc_useconds t)
+{
+       tfc_useconds secs, dsecs;
+       unsigned days, hours, minutes, seconds;
+       static char r[128];
+
+       secs = (tfc_useconds)TFC_UTODSECS(t);
+       dsecs = (tfc_useconds)(t - (secs * 1000000));
+
+       days = secs / 86400;
+       hours = (secs / 3600) % 24;
+       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));
+
+       return r;
+}
+
 tfc_fsize tfc_fdsize(int fd)
 {
        off_t l, cur;
index 550b6c4d0ae1f5c74213495cb7030f593907cb88..a2120f0d1712512b9bb2126d203427aeb88a156e 100644 (file)
@@ -65,6 +65,7 @@ void print_crypt_status(int signal)
        }
 
 _out:  tfc_getcurtime(&current_time);
+       total_time += (current_time - delta_time);
        seconds = TFC_UTODSECS(current_time - delta_time);
        wr_speed = delta_processed / seconds;
        tfc_describescale(total_processed_src, &human_totalproc_src, &src_scale_idx);
@@ -90,29 +91,29 @@ _out:       tfc_getcurtime(&current_time);
        if (do_less_stats == YES) {
                tfc_nfsay(stderr, "%s%s:"
                        " %s %.2f%s,"
-                       " %.2f%s B/s",
+                       " %.2f%s B/s @%s",
                        inplace, progname,
                        oper_mode,
                        human_totalproc_dst, tfc_getscale(dst_scale_idx),
-                       human_wr_speed, tfc_getscale(wr_speed_scale));
+                       human_wr_speed, tfc_getscale(wr_speed_scale), tfc_format_time(total_time));
        }
        else {
                if (ctr_mode <= TFC_MODE_PLAIN) tfc_nfsay(stderr, "%s%s: read: %llu (%.2f%s),"
                        " %s %llu (%.2f%s) bytes,"
-                       " (%llu (%.2f%s) B/s)",
+                       " (%llu (%.2f%s) B/s), time %s",
                        inplace, progname,
                        total_processed_src, human_totalproc_src, tfc_getscale(src_scale_idx),
                        oper_mode,
                        total_processed_dst, human_totalproc_dst, tfc_getscale(dst_scale_idx),
-                       wr_speed, human_wr_speed, tfc_getscale(wr_speed_scale));
+                       wr_speed, human_wr_speed, tfc_getscale(wr_speed_scale), tfc_format_time(total_time));
                else tfc_nfsay(stderr, "%s%s: read: %llu (%.2f%s),"
                        " %s %s %llu (%.2f%s) bytes,"
-                       " (%llu (%.2f%s) B/s)",
+                       " (%llu (%.2f%s) B/s), time %s",
                        inplace, progname,
                        total_processed_src, human_totalproc_src, tfc_getscale(src_scale_idx),
                        tfc_modename(ctr_mode), oper_mode,
                        total_processed_dst, human_totalproc_dst, tfc_getscale(dst_scale_idx),
-                       wr_speed, human_wr_speed, tfc_getscale(wr_speed_scale));
+                       wr_speed, human_wr_speed, tfc_getscale(wr_speed_scale), tfc_format_time(total_time));
        }
 
        if ((do_statline_dynamic == NO || last == YES || signal == -1) && was_sigint == NO) tfc_esay("\n");
index 44da6e07ac024ba2e3533c2d50feccb5390dbec4..4ca378554eaf522a5df4c90437abfbc80a03caa4 100644 (file)
@@ -69,6 +69,6 @@ char *srcfname = TFC_STDIN_NAME, *dstfname = TFC_STDOUT_NAME, *do_mac_file, *cou
 char *saltf, *genkeyf, *mackeyf, *tweakf;
 char *pw_prompt, *mac_pw_prompt;
 tfc_useconds status_timer, bench_timer;
-tfc_useconds current_time, delta_time;
+tfc_useconds total_time, current_time, delta_time;
 
 struct getpasswd_state getps;
index f10e46768ba7a2d8348489140fb7e3c7f3ff03d9..a313b33d142fe8b5629f669aa4161acc0d0b2110 100644 (file)
--- a/tfcrypt.h
+++ b/tfcrypt.h
@@ -162,7 +162,7 @@ extern char *srcfname, *dstfname, *do_mac_file, *counter_file, *sksum_hashlist_f
 extern char *saltf, *genkeyf, *mackeyf, *tweakf;
 extern char *pw_prompt, *mac_pw_prompt;
 extern tfc_useconds status_timer, bench_timer;
-extern tfc_useconds current_time, delta_time;
+extern tfc_useconds total_time, current_time, delta_time;
 extern struct getpasswd_state getps;
 
 size_t xread(int fd, void *data, size_t szdata);
@@ -188,6 +188,7 @@ tfc_yesno str_empty(const char *str);
 void xclose(int fd);
 const char *tfc_modename(int mode);
 void tfc_getcurtime(tfc_useconds *tx);
+char *tfc_format_time(tfc_useconds t);
 tfc_fsize tfc_fdsize(int fd);
 tfc_fsize tfc_fdgetpos(int fd);
 tfc_fsize tfc_fnamesize(char *fname, tfc_yesno noexit);