commit:     94ca500baf225994b88f750262c0895553c70a8a
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 18 18:34:19 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Thu Jul 18 18:34:19 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=94ca500b

qlop: enhance running time indicator

Fix elapsed time mode (-t) when using -r displaying the elapsed time
also as the ETA.  When using -v, display what ETA is being used (average
or longest run).

Also, better document which flags can be combined with -r.

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 man/include/qlop.optdesc.yaml |  7 +++++--
 man/qlop.1                    |  7 +++++--
 qlop.c                        | 47 +++++++++++++++++++++++++------------------
 3 files changed, 37 insertions(+), 24 deletions(-)

diff --git a/man/include/qlop.optdesc.yaml b/man/include/qlop.optdesc.yaml
index 19f56db..463a19d 100644
--- a/man/include/qlop.optdesc.yaml
+++ b/man/include/qlop.optdesc.yaml
@@ -50,5 +50,8 @@ running: |
     Print operations currently in progress.  An ETA is calculated based
     on the average for the operation.  If the elapsed exceeds the
     average, the ETA is calculated against the longest time observed for
-    the operation.  If the elapsed time exceeds this too, or no previous
-    occurrences for the operation exist, \fIunknown\fR is printed.
+    the operation.  The \fB-v\fR flag will display which mode is
+    currently used.  If the elapsed time also exceeds the longest time
+    observed, or no previous occurrences for the operation exist,
+    \fIunknown\fR is printed.  When combined with \fB-t\fR the
+    elapsed time is also displayed.

diff --git a/man/qlop.1 b/man/qlop.1
index 10eaa27..909ebdc 100644
--- a/man/qlop.1
+++ b/man/qlop.1
@@ -72,8 +72,11 @@ Report time at which the operation finished (iso started).
 Print operations currently in progress.  An ETA is calculated based
 on the average for the operation.  If the elapsed exceeds the
 average, the ETA is calculated against the longest time observed for
-the operation.  If the elapsed time exceeds this too, or no previous
-occurrences for the operation exist, \fIunknown\fR is printed.
+the operation.  The \fB-v\fR flag will display which mode is
+currently used.  If the elapsed time also exceeds the longest time
+observed, or no previous occurrences for the operation exist,
+\fIunknown\fR is printed.  When combined with \fB-t\fR the
+elapsed time is also displayed.
 .TP
 \fB\-d\fR \fI<arg>\fR, \fB\-\-date\fR \fI<arg>\fR
 Limit the selection of packages to the date given, or to the range

diff --git a/qlop.c b/qlop.c
index e20c97b..fce0f69 100644
--- a/qlop.c
+++ b/qlop.c
@@ -773,14 +773,17 @@ static int do_emerge_log(
                array_for_each(merge_matches, i, pkgw) {
                        size_t j;
                        time_t maxtime = 0;
+                       bool isMax = false;
 
                        elapsed = tstart - pkgw->tbegin;
                        pkg = NULL;
                        array_for_each(merge_averages, j, pkg) {
                                if (atom_compare(pkg->atom, pkgw->atom) == 
EQUAL) {
                                        maxtime = pkg->time / pkg->cnt;
-                                       if (elapsed >= maxtime)
+                                       if (elapsed >= maxtime) {
                                                maxtime = elapsed >= 
pkg->tbegin ? 0 : pkg->tbegin;
+                                               isMax = true;
+                                       }
                                        break;
                                }
                                pkg = NULL;
@@ -797,52 +800,56 @@ static int do_emerge_log(
                        }
 
                        if (flags->do_time) {
-                               printf("%s >>> %s: %s...%s ETA: %s\n",
+                               printf("%s >>> %s: %s",
                                                fmt_date(flags, pkgw->tbegin, 
0),
                                                atom_format(flags->fmt, 
pkgw->atom),
-                                               fmt_elapsedtime(flags, elapsed),
-                                               p == NULL ? "" : p,
-                                               maxtime == 0 ? "unknown" :
-                                                       fmt_elapsedtime(flags, 
maxtime - elapsed));
+                                               fmt_elapsedtime(flags, 
elapsed));
                        } else {
-                               printf("%s >>> %s...%s ETA: %s\n",
+                               printf("%s >>> %s",
                                                fmt_date(flags, pkgw->tbegin, 
0),
-                                               atom_format(flags->fmt, 
pkgw->atom),
-                                               p == NULL ? "" : p,
-                                               maxtime == 0 ? "unknown" :
-                                                       fmt_elapsedtime(flags, 
maxtime - elapsed));
+                                               atom_format(flags->fmt, 
pkgw->atom));
                        }
+                       printf("...%s ETA: %s%s\n",
+                                       p == NULL ? "" : p,
+                                       maxtime == 0 ? "unknown" :
+                                               fmt_elapsedtime(flags, maxtime 
- elapsed),
+                                       maxtime > 0 && verbose ?
+                                               isMax ? " (longest run)" : " 
(average run)" : "");
                }
                array_for_each(unmerge_matches, i, pkgw) {
                        size_t j;
                        time_t maxtime = 0;
+                       bool isMax = false;
 
                        elapsed = tstart - pkgw->tbegin;
                        pkg = NULL;
                        array_for_each(unmerge_averages, j, pkg) {
                                if (atom_compare(pkg->atom, pkgw->atom) == 
EQUAL) {
                                        maxtime = pkg->time / pkg->cnt;
-                                       if (elapsed >= maxtime)
+                                       if (elapsed >= maxtime) {
                                                maxtime = elapsed >= 
pkg->tbegin ? 0 : pkg->tbegin;
+                                               isMax = true;
+                                       }
                                        break;
                                }
                                pkg = NULL;
                        }
 
                        if (flags->do_time) {
-                               printf("%s <<< %s: %s... ETA: %s\n",
+                               printf("%s <<< %s: %s",
                                                fmt_date(flags, pkgw->tbegin, 
0),
                                                atom_format(flags->fmt, 
pkgw->atom),
-                                               fmt_elapsedtime(flags, elapsed),
-                                               maxtime == 0 ? "unknown" :
-                                                       fmt_elapsedtime(flags, 
maxtime - elapsed));
+                                               fmt_elapsedtime(flags, 
elapsed));
                        } else {
-                               printf("%s <<< %s... ETA: %s\n",
+                               printf("%s <<< %s",
                                                fmt_date(flags, pkgw->tbegin, 
0),
-                                               atom_format(flags->fmt, 
pkgw->atom),
-                                               maxtime == 0 ? "unknown" :
-                                                       fmt_elapsedtime(flags, 
maxtime - elapsed));
+                                               atom_format(flags->fmt, 
pkgw->atom));
                        }
+                       printf("... ETA: %s%s\n",
+                                       maxtime == 0 ? "unknown" :
+                                       fmt_elapsedtime(flags, maxtime - 
elapsed),
+                                       maxtime > 0 && verbose ?
+                                               isMax ? " (longest run)" : " 
(average run)" : "");
                }
        } else if (flags->do_average) {
                size_t total_merges = 0;

Reply via email to