From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 764B0138334 for ; Thu, 28 Feb 2019 18:37:21 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id C2018E085E; Thu, 28 Feb 2019 18:37:20 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 8156EE085E for ; Thu, 28 Feb 2019 18:37:20 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 32215335CDB for ; Thu, 28 Feb 2019 18:37:19 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id A13F6546 for ; Thu, 28 Feb 2019 18:37:17 +0000 (UTC) From: "Fabian Groffen" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Fabian Groffen" Message-ID: <1551378953.9dcbcdfd0c90d76ddbb4b4dcdd41a981441f53e2.grobian@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: / X-VCS-Repository: proj/portage-utils X-VCS-Files: qlop.c X-VCS-Directories: / X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: 9dcbcdfd0c90d76ddbb4b4dcdd41a981441f53e2 X-VCS-Branch: master Date: Thu, 28 Feb 2019 18:37:17 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 6c8d4c15-338b-4735-929b-d35cbf902fc5 X-Archives-Hash: 9d4a464cd2e5bdcfd24c50c464cabc6e commit: 9dcbcdfd0c90d76ddbb4b4dcdd41a981441f53e2 Author: Fabian Groffen gentoo org> AuthorDate: Thu Feb 28 18:35:53 2019 +0000 Commit: Fabian Groffen gentoo org> CommitDate: Thu Feb 28 18:35:53 2019 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=9dcbcdfd qlop: introduce machine elapsed time and standard time Report elapsed time in short notation by default, use elaborate notation using -H, print just seconds (previous behaviour) using -M. Signed-off-by: Fabian Groffen gentoo.org> qlop.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 20 deletions(-) diff --git a/qlop.c b/qlop.c index 08ea479..d5c2548 100644 --- a/qlop.c +++ b/qlop.c @@ -11,12 +11,13 @@ #define QLOP_DEFAULT_LOGFILE "emerge.log" -#define QLOP_FLAGS "ctaHmuUserd:f:w:" COMMON_FLAGS +#define QLOP_FLAGS "ctaHMmuUserd:f:w:" COMMON_FLAGS static struct option const qlop_long_opts[] = { {"summary", no_argument, NULL, 'c'}, {"time", no_argument, NULL, 't'}, {"average", no_argument, NULL, 'a'}, {"human", no_argument, NULL, 'H'}, + {"machine", no_argument, NULL, 'M'}, {"merge", no_argument, NULL, 'm'}, {"unmerge", no_argument, NULL, 'u'}, {"autoclean", no_argument, NULL, 'U'}, @@ -33,6 +34,7 @@ static const char * const qlop_opts_help[] = { "Print time taken to complete action", "Print average time taken to complete action", "Print elapsed time in human readable format (use with -t or -a)", + "Print elapsed time as seconds with no formatting", "Show merge history", "Show unmerge history", "Show autoclean unmerge history", @@ -63,6 +65,7 @@ struct qlop_mode { char do_average:1; char do_summary:1; char do_human:1; + char do_machine:1; char do_endtime:1; }; @@ -181,21 +184,28 @@ static char *fmt_date(struct qlop_mode *flags, time_t ts, time_t te) static char _elapsed_buf[256]; static char *fmt_elapsedtime(struct qlop_mode *flags, time_t e) { - if (flags->do_human) { - time_t dd; - time_t hh; - time_t mm; - time_t ss; - size_t bufpos = 0; - - ss = e % 60; - e /= 60; - mm = e % 60; - e /= 60; - hh = e % 24; - e /= 24; - dd = e; + time_t dd; + time_t hh; + time_t mm; + time_t ss; + size_t bufpos = 0; + + if (flags->do_machine) { + snprintf(_elapsed_buf, sizeof(_elapsed_buf), + "%s%zd%s", + GREEN, (size_t)e, NORM); + return _elapsed_buf; + } + ss = e % 60; + e /= 60; + mm = e % 60; + e /= 60; + hh = e % 24; + e /= 24; + dd = e; + + if (flags->do_human) { if (dd > 0) bufpos += snprintf(_elapsed_buf + bufpos, sizeof(_elapsed_buf) - bufpos, @@ -220,8 +230,23 @@ static char *fmt_elapsedtime(struct qlop_mode *flags, time_t e) bufpos == 0 ? "" : ", ", GREEN, (size_t)ss, NORM, ss == 1 ? "" : "s"); } else { - snprintf(_elapsed_buf, sizeof(_elapsed_buf), "%s%zd%s seconds", - GREEN, (size_t)e, NORM); + hh += 24 * dd; + if (hh > 0) { + snprintf(_elapsed_buf, sizeof(_elapsed_buf), + "%s%zd%s:%s%02zd%s:%s%02zd%s", + GREEN, (size_t)hh, NORM, + GREEN, (size_t)mm, NORM, + GREEN, (size_t)ss, NORM); + } else if (mm > 0) { + snprintf(_elapsed_buf, sizeof(_elapsed_buf), + "%s%zd%s′%s%02zd%s″", + GREEN, (size_t)mm, NORM, + GREEN, (size_t)ss, NORM); + } else { + snprintf(_elapsed_buf, sizeof(_elapsed_buf), + "%s%zd%ss", + GREEN, (size_t)ss, NORM); + } } return _elapsed_buf; @@ -461,7 +486,8 @@ static int do_emerge_log( if (flags->do_time) { printf("%s *** %s%s%s: %s\n", fmt_date(flags, sync_start, tstart), - GREEN, p, NORM, fmt_elapsedtime(flags, elapsed)); + GREEN, p, NORM, + fmt_elapsedtime(flags, elapsed)); } else { printf("%s *** %s%s%s\n", fmt_date(flags, sync_start, tstart), @@ -846,6 +872,7 @@ int qlop_main(int argc, char **argv) m.do_average = 0; m.do_summary = 0; m.do_human = 0; + m.do_machine = 0; m.do_endtime = 0; while ((ret = GETOPT_LONG(QLOP, qlop, "")) != -1) { @@ -861,6 +888,7 @@ int qlop_main(int argc, char **argv) case 'a': m.do_average = 1; break; case 'c': m.do_summary = 1; break; case 'H': m.do_human = 1; break; + case 'M': m.do_machine = 1; break; case 'e': m.do_endtime = 1; break; case 'd': if (start_time == 0) { @@ -924,8 +952,7 @@ int qlop_main(int argc, char **argv) m.do_sync == 0 && m.do_running == 0 && m.do_average == 0 && - m.do_summary == 0 && - m.do_human == 0 + m.do_summary == 0 ) { m.do_merge = 1; @@ -951,6 +978,13 @@ int qlop_main(int argc, char **argv) m.do_average = 0; } + /* handle -H / -M conflict */ + if (m.do_human && m.do_machine) { + warn("-H and -M cannot be used together, dropping -M: " + "only humans make mistakes"); + m.do_machine = 0; + } + if (m.do_sync && array_cnt(atoms) > 0) { warn("-s cannot be used when specifying atoms, dropping -s"); m.do_sync = 0;