From bf78455d4964ea12399464b383d140a992f5ad84 Mon Sep 17 00:00:00 2001 From: allanjude Date: Sat, 13 Oct 2018 02:21:23 +0000 Subject: [PATCH] Make `mfiutil show progress` print out the elapsed time estimate in a more humanized way PR: 225993 Submitted by: Enji Cooper Reviewed by: jhb (previous version) Approved by: re (rgrimes) --- usr.sbin/mfiutil/mfi_cmd.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/usr.sbin/mfiutil/mfi_cmd.c b/usr.sbin/mfiutil/mfi_cmd.c index 33bd01dc6e8..094c9017348 100644 --- a/usr.sbin/mfiutil/mfi_cmd.c +++ b/usr.sbin/mfiutil/mfi_cmd.c @@ -31,17 +31,18 @@ * $FreeBSD$ */ -#include -#include #include +#include #include #include #include +#include #include #include #include #include +#include #include #include "mfiutil.h" @@ -311,24 +312,34 @@ mfi_open(int unit, int acs) return (open(path, acs)); } +static void +print_time_humanized(uint seconds) +{ + + if (seconds > 3600) { + printf("%u:", seconds / 3600); + } + if (seconds > 60) { + seconds %= 3600; + printf("%02u:%02u", seconds / 60, seconds % 60); + } else { + printf("%us", seconds); + } +} + void mfi_display_progress(const char *label, struct mfi_progress *prog) { uint seconds; - printf("%s: %.2f%% complete, after %ds", label, - (float)prog->progress * 100 / 0xffff, prog->elapsed_seconds); + printf("%s: %.2f%% complete after ", label, + (float)prog->progress * 100 / 0xffff); + print_time_humanized(prog->elapsed_seconds); if (prog->progress != 0 && prog->elapsed_seconds > 10) { printf(" finished in "); seconds = (0x10000 * (uint32_t)prog->elapsed_seconds) / prog->progress - prog->elapsed_seconds; - if (seconds > 3600) - printf("%u:", seconds / 3600); - if (seconds > 60) { - seconds %= 3600; - printf("%02u:%02u", seconds / 60, seconds % 60); - } else - printf("%us", seconds); + print_time_humanized(seconds); } printf("\n"); } -- 2.45.0