From 7bde242bc4d99505955f023b4a71aa08b3a762fd Mon Sep 17 00:00:00 2001
From: Harald Pfeiffer <coding@lirion.de>
Date: Sat, 16 Nov 2019 10:19:04 +0100
Subject: adding display of makecache and upgrade durations to console output,
 easier debug of lame bandwidths :)

---
 bin/dnfu | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/bin/dnfu b/bin/dnfu
index 963bdbd..966285e 100755
--- a/bin/dnfu
+++ b/bin/dnfu
@@ -97,20 +97,27 @@ function supgrade {
 	#	100) $LCMD "Updates found.";;
 	#	*) $LECMD "check-upgrade went wrong!";RETVAL=1;return 1;;
 	#esac
+	USTART="$(date +%s)"
 	rbeg "Upgrading system packages"
 	sudo "${UCMD}" -y upgrade 2>&1|sed "s/^/$(date --rfc-3339=seconds) /">>"$DLOG"
 	case "${PIPESTATUS[0]}" in
-		0) $LCMD "Upgrade OK.";rok;;
+		0)
+
+			UFIN="$(date +%s)"
+			$LCMD "Upgrade OK.";rok "Update took $((UFIN-USTART)) seconds."
+		;;
 		1)
+			UFIN="$(date +%s)"
 			$LWCMD "Error on upgrade, but handled by dnf."
-			rwrn "error occurred but was handled by dnf"
+			rwrn "error occurred but handled by dnf (duration: $((UFIN-USTART)) seconds)"
 			case "RETVAL" in
 				0) RETVAL=255;;
 			esac
 		;;
 		255)
+			UFIN="$(date +%s)"
 			$LWCMD "Upgrade finished, pending updates remaining."
-			rwrn "Upgrade done but updates remaining"
+			rwrn "Upgrade done but updates remaining (duration: $((UFIN-USTART)) seconds)"
 			case "$RETVAL" in
 				0) RETVAL=255;;
 			esac
@@ -121,6 +128,7 @@ function supgrade {
 			RETVAL=1;return 1
 		;;
 	esac
+	unset UFIN USTART
 	printf "Checking for outdated running services or necessity to reboot...:\n"
 	sudo "${UCMD}" needs-restarting -C --color true 2>&1|tee -a "$DLOG"
 	sudo "$UCMD" needs-restarting -r >/dev/null 2>&1 ||$LWCMD "Reboot required."||:
@@ -134,13 +142,21 @@ function snrefresh {
 	esac
 }
 
+CSTART="$(date +%s)"
 rbeg "Updating dnf cache"
 sudo "${UCMD}" makecache 2>&1|sed "s/^/$(date --rfc-3339=seconds) /" >> "$DLOG"
 case "${PIPESTATUS[0]}" in
-	0) $LCMD "DNF cache update OK.";rok;;
-	100) $LWCMD "RC 100 on makecache.";rwrn;;
+	0)
+		CFIN="$(date +%s)"
+		$LCMD "DNF cache update OK.";rok "duration: $((CFIN-CSTART)) seconds"
+	;;
+	100)
+		CFIN="$(date +%s)"
+		$LWCMD "RC 100 on makecache.";rwrn "duration: $((CFIN-CSTART)) seconds"
+	;;
 	*) $LECMD "DNF cache update failed!";rerr;exit 1;;
 esac
+unset CFIN CSTART
 rbeg "Checking for upgrades"
 sudo "${UCMD}" -C check-upgrade 2>&1|sed "s/^/$(date --rfc-3339=seconds) /">>"$DLOG"
 case "${PIPESTATUS[0]}" in
-- 
cgit v1.2.3