public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Fabian Groffen" <grobian@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage-utils:master commit in: tests/qlop/, /
Date: Fri, 27 Dec 2019 20:42:34 +0000 (UTC)	[thread overview]
Message-ID: <1577479124.1e5b2c8d3fb58335990e411af98498f249b54980.grobian@gentoo> (raw)

commit:     1e5b2c8d3fb58335990e411af98498f249b54980
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Fri Dec 27 20:38:44 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Fri Dec 27 20:38:44 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=1e5b2c8d

qlop: some changes to -r (running) mode

- warn when qlop needs to defer to log heuristics (#701968)
- print running packages most recent first
- suppress identical running packages (#701392)
- ignore batches in emerge.log that appear to be backwards in time

Bug: https://bugs.gentoo.org/701968
Bug: https://bugs.gentoo.org/701392
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 qlop.c                 | 50 +++++++++++++++++++++++++++++++++++++++++++-------
 tests/qlop/list01.good |  2 +-
 tests/qlop/list10.good |  4 ++--
 tests/qlop/sync.log    | 12 ++++++------
 4 files changed, 52 insertions(+), 16 deletions(-)

diff --git a/qlop.c b/qlop.c
index 7cc8f44..634431a 100644
--- a/qlop.c
+++ b/qlop.c
@@ -371,6 +371,7 @@ static int do_emerge_log(
 	char *p;
 	char *q;
 	time_t tstart = LONG_MAX;
+	time_t tlast = tbegin;
 	time_t tstart_emerge = 0;
 	time_t last_merge = 0;
 	time_t sync_start = 0;
@@ -531,6 +532,9 @@ static int do_emerge_log(
 		}
 
 		tstart = atol(buf);
+		if (tstart < tlast)
+			continue;
+		tlast = tstart;
 		if (tstart < tbegin || tstart > tend)
 			continue;
 
@@ -845,6 +849,7 @@ static int do_emerge_log(
 	fclose(fp);
 	if (flags->do_running) {
 		time_t cutofftime;
+		set *pkgs_seen = create_set();
 
 		tstart = time(NULL);
 
@@ -856,7 +861,8 @@ static int do_emerge_log(
 
 		/* can't report endtime for non-finished operations */
 		flags->do_endtime = 0;
-		sync_time /= sync_cnt;
+		if (sync_time > 0)
+			sync_time /= sync_cnt;
 		if (sync_start >= cutofftime) {
 			elapsed = tstart - sync_start;
 			if (elapsed >= sync_time)
@@ -876,9 +882,10 @@ static int do_emerge_log(
 							fmt_elapsedtime(flags, sync_time - elapsed));
 			}
 		}
-		array_for_each(merge_matches, i, pkgw) {
+		array_for_each_rev(merge_matches, i, pkgw) {
 			time_t maxtime = 0;
 			bool isMax = false;
+			bool notseen;
 
 			if (pkgw->tbegin < cutofftime)
 				continue;
@@ -886,6 +893,11 @@ static int do_emerge_log(
 			snprintf(afmt, sizeof(afmt), "%s/%s",
 					pkgw->atom->CATEGORY, pkgw->atom->PN);
 
+			/* eliminate dups, bug #701392 */
+			add_set_unique(afmt, pkgs_seen, &notseen);
+			if (!notseen)
+				continue;
+
 			elapsed = tstart - pkgw->tbegin;
 			pkg = get_set(afmt, merge_averages);
 			if (pkg != NULL) {
@@ -923,9 +935,11 @@ static int do_emerge_log(
 					maxtime > 0 && verbose ?
 						isMax ? " (longest run)" : " (average run)" : "");
 		}
+		clear_set(pkgs_seen);
 		array_for_each(unmerge_matches, i, pkgw) {
 			time_t maxtime = 0;
 			bool isMax = false;
+			bool notseen;
 
 			if (pkgw->tbegin < cutofftime)
 				continue;
@@ -933,6 +947,11 @@ static int do_emerge_log(
 			snprintf(afmt, sizeof(afmt), "%s/%s",
 					pkgw->atom->CATEGORY, pkgw->atom->PN);
 
+			/* eliminate dups, bug #701392 */
+			add_set_unique(afmt, pkgs_seen, &notseen);
+			if (!notseen)
+				continue;
+
 			elapsed = tstart - pkgw->tbegin;
 			pkg = get_set(afmt, unmerge_averages);
 			if (pkg != NULL) {
@@ -959,6 +978,7 @@ static int do_emerge_log(
 					maxtime > 0 && verbose ?
 						isMax ? " (longest run)" : " (average run)" : "");
 		}
+		free_set(pkgs_seen);
 	} else if (flags->do_average) {
 		size_t total_merges = 0;
 		size_t total_unmerges = 0;
@@ -1135,9 +1155,22 @@ static array_t *probe_proc(array_t *atoms)
 		scandir_free(procs, procslen);
 	} else {
 		/* flag /proc doesn't exist */
+		warn("/proc doesn't exist, running merges are based on heuristics");
 		return NULL;
 	}
 
+	if (array_cnt(ret_atoms) == 0) {
+		/* if we didn't find anything, this is either because nothing is
+		 * running, or because we didn't have appropriate permissions --
+		 * try to figure out which of the two is it (there is no good
+		 * way) */
+		if (geteuid() != 0) {
+			warn("insufficient privileges for full /proc access, "
+					"running merges are based on heuristics");
+			return NULL;
+		}
+	}
+
 	if (array_cnt(atoms) > 0) {
 		size_t j;
 		depend_atom *atomr;
@@ -1351,12 +1384,15 @@ int qlop_main(int argc, char **argv)
 	}
 
 	if (m.do_running) {
-		array_t *new_atoms = probe_proc(atoms);
+		array_t *new_atoms = NULL;
+
+		if (runningmode > 1) {
+			warn("running without /proc scanning, heuristics only");
+		} else {
+			new_atoms = probe_proc(atoms);
+		}
 
-		if (runningmode > 1 || new_atoms == NULL) {
-			warn("/proc not available, deducing running "
-					"merges from emerge.log");
-		} else if (array_cnt(new_atoms) == 0) {
+		if (new_atoms != NULL && array_cnt(new_atoms) == 0) {
 			/* proc supported, found nothing running */
 			start_time = LONG_MAX;
 		}

diff --git a/tests/qlop/list01.good b/tests/qlop/list01.good
index 2689952..c923b2f 100644
--- a/tests/qlop/list01.good
+++ b/tests/qlop/list01.good
@@ -1,2 +1,2 @@
-2005-01-27T05:35:03 *** rsync://192.168.0.5/gentoo-portage
+2005-05-22T23:21:43 *** rsync://192.168.0.5/gentoo-portage
 2015-05-16T08:20:02 *** gentoo

diff --git a/tests/qlop/list10.good b/tests/qlop/list10.good
index 348992a..52b4fd3 100644
--- a/tests/qlop/list10.good
+++ b/tests/qlop/list10.good
@@ -1,3 +1,3 @@
-1568982460 >>> dev-qt/qtmultimedia... (96 of 129) ETA: unknown
-1568996270 >>> kde-frameworks/kxmlgui... (98 of 129) ETA: unknown
 1568996308 >>> net-analyzer/wireshark... (99 of 129) ETA: unknown
+1568996270 >>> kde-frameworks/kxmlgui... (98 of 129) ETA: unknown
+1568982460 >>> dev-qt/qtmultimedia... (96 of 129) ETA: unknown

diff --git a/tests/qlop/sync.log b/tests/qlop/sync.log
index 8979b23..24e1074 100644
--- a/tests/qlop/sync.log
+++ b/tests/qlop/sync.log
@@ -44,12 +44,12 @@
 1106806630:  *** exiting successfully.
 1106806630:  *** terminating.
 
-1106804103: Started emerge on: Jan 27, 2005 05:35:03
-1106804103:  *** emerge  sync
-1106804103:  === sync
-1106804103: >>> starting rsync with rsync://192.168.0.5/gentoo-portage
-1106804537: === Sync completed with rsync://192.168.0.5/gentoo-portage
-1106804538:  *** terminating.
+1116804103: Started emerge on: Jan 27, 2005 05:35:03
+1116804103:  *** emerge  sync
+1116804103:  === sync
+1116804103: >>> starting rsync with rsync://192.168.0.5/gentoo-portage
+1116804537: === Sync completed with rsync://192.168.0.5/gentoo-portage
+1116804538:  *** terminating.
 1431764402: Started emerge on: May 16, 2015 04:20:01
 1431764402:  *** emerge --quiet --keep-going --verbose --nospinner --oneshot --quiet-build=n --sync
 1431764402:  === sync


             reply	other threads:[~2019-12-27 20:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-27 20:42 Fabian Groffen [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-03-31 18:31 [gentoo-commits] proj/portage-utils:master commit in: tests/qlop/, / Fabian Groffen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1577479124.1e5b2c8d3fb58335990e411af98498f249b54980.grobian@gentoo \
    --to=grobian@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox