From: Andrey Rys Date: Sun, 6 Oct 2019 12:14:50 +0000 (+0200) Subject: tfc_signal: add elapsed time counter. X-Git-Url: https://jxself.org/git/?p=tfcrypt.git;a=commitdiff_plain;h=0303cbcec2b262cc3dcf8d89951967d7ba9543c7 tfc_signal: add elapsed time counter. --- diff --git a/VERSION b/VERSION index bb95160..a787364 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -33 +34 diff --git a/tfc_misc.c b/tfc_misc.c index f55726a..06c1a65 100644 --- a/tfc_misc.c +++ b/tfc_misc.c @@ -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; diff --git a/tfc_signal.c b/tfc_signal.c index 550b6c4..a2120f0 100644 --- a/tfc_signal.c +++ b/tfc_signal.c @@ -65,6 +65,7 @@ void print_crypt_status(int signal) } _out: tfc_getcurtime(¤t_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(¤t_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"); diff --git a/tfc_vars.c b/tfc_vars.c index 44da6e0..4ca3785 100644 --- a/tfc_vars.c +++ b/tfc_vars.c @@ -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; diff --git a/tfcrypt.h b/tfcrypt.h index f10e467..a313b33 100644 --- 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);