From owner-svn-src-head@freebsd.org Sat Oct 13 02:21:24 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 901AE10D50CD; Sat, 13 Oct 2018 02:21:24 +0000 (UTC) (envelope-from allanjude@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46B2F828F1; Sat, 13 Oct 2018 02:21:24 +0000 (UTC) (envelope-from allanjude@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 41B853FB; Sat, 13 Oct 2018 02:21:24 +0000 (UTC) (envelope-from allanjude@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w9D2LOVk032207; Sat, 13 Oct 2018 02:21:24 GMT (envelope-from allanjude@FreeBSD.org) Received: (from allanjude@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w9D2LOEh032206; Sat, 13 Oct 2018 02:21:24 GMT (envelope-from allanjude@FreeBSD.org) Message-Id: <201810130221.w9D2LOEh032206@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: allanjude set sender to allanjude@FreeBSD.org using -f From: Allan Jude Date: Sat, 13 Oct 2018 02:21:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r339344 - head/usr.sbin/mfiutil X-SVN-Group: head X-SVN-Commit-Author: allanjude X-SVN-Commit-Paths: head/usr.sbin/mfiutil X-SVN-Commit-Revision: 339344 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 13 Oct 2018 02:21:24 -0000 Author: allanjude Date: Sat Oct 13 02:21:23 2018 New Revision: 339344 URL: https://svnweb.freebsd.org/changeset/base/339344 Log: 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) Modified: head/usr.sbin/mfiutil/mfi_cmd.c Modified: head/usr.sbin/mfiutil/mfi_cmd.c ============================================================================== --- head/usr.sbin/mfiutil/mfi_cmd.c Sat Oct 13 02:20:16 2018 (r339343) +++ head/usr.sbin/mfiutil/mfi_cmd.c Sat Oct 13 02:21:23 2018 (r339344) @@ -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"); }