From 32639280a3cd8d07aff2b9b28136f560282e4eff Mon Sep 17 00:00:00 2001 From: classabbyamp Date: Wed, 4 Sep 2024 10:17:49 -0400 Subject: [PATCH] runit-startuptime: new script parse the timing info from dmesg to give uses a rough accounting of time spent during boot. this may fail to be accurate if run a long time from boot (i.e. if the messages have left the kernel message ring buffer) --- Makefile | 1 + runit-startuptime | 66 +++++++++++++++++++++++++++++++++++++++++++++ runit-startuptime.1 | 40 +++++++++++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100755 runit-startuptime create mode 100644 runit-startuptime.1 diff --git a/Makefile b/Makefile index 0aa219a..267c8a9 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,7 @@ install: install -m755 modules-load ${DESTDIR}/${PREFIX}/sbin/modules-load install -m755 seedrng ${DESTDIR}/${PREFIX}/sbin/seedrng install -m755 zzz ${DESTDIR}/${PREFIX}/sbin + install -m755 runit-analyze ${DESTDIR}/${PREFIX}/sbin ln -sf zzz ${DESTDIR}/${PREFIX}/sbin/ZZZ ln -sf halt ${DESTDIR}/${PREFIX}/sbin/poweroff ln -sf halt ${DESTDIR}/${PREFIX}/sbin/reboot diff --git a/runit-startuptime b/runit-startuptime new file mode 100755 index 0000000..b6dec2f --- /dev/null +++ b/runit-startuptime @@ -0,0 +1,66 @@ +#!/bin/sh +# vim: set ts=4 sw=4 et ft=awk: + +if [ -n "$1" ]; then + printf "Usage: runit-startuptime\n\nPrint a rough accounting of where time is spent during boot\n" >&2 + exit 1 +fi + +dmesg -l debug | LANG=C.UTF-8 awk -F '[][ :]+' ' +BEGIN { + PROCINFO["sorted_in"] = "@ind_str_asc" + initramfs = 0 + coresvtotal = 0 + rclocal = 0 + total = 0 +} + +function svbasename(file) { + sub(".*/", "", file) + sub(".sh$", "", file) + return file +} + +$3 == "/init" { + initramfs = $2 + next +} + +$3 == "runit" { + if ($5 == "core") { + sv = svbasename($6) + if ($4 == "start") { + coresv[sv] = $2 + if (coresvtotal == 0) + coresvtotal = $2 + } else if ($4 == "finish") { + if ($6 != "") { + if (sv in coresv) + coresv[sv] = $2 - coresv[sv] + else + # /dev is not guaranteed until 00-pseudofs + # so the first start message may not exist + coresv[sv] = $2 - initramfs + } else + coresvtotal = $2 - coresvtotal + } + } else if ($5 == "rclocal") { + if ($4 == "start") + rclocal = $2 + else if ($4 == "finish") + rclocal = $2 - rclocal + } else if ($5 == "runsvdir") + total = $2 + next +} + +END { + if (NR > 2) { + printf "initramfs\t%0.3f s\n", initramfs + printf "core-services\t%0.3f s\n", coresvtotal + for (sv in coresv) + printf " %-20s\t%0.3f s\n", sv, coresv[sv] + printf "rc.local\t%0.3f s\n", rclocal + printf "total\t\t%0.3f s\n", total + } +}' diff --git a/runit-startuptime.1 b/runit-startuptime.1 new file mode 100644 index 0000000..ee44031 --- /dev/null +++ b/runit-startuptime.1 @@ -0,0 +1,40 @@ +.Dd September 4, 2024 +.Dt RUNIT-STARTUPTIME 1 +.Os +.Sh NAME +.Nm runit-startuptime +.Nd Print a rough accounting of where time is spent during boot +.Sh SYNOPSIS +.Nm runit-startuptime +.Sh DESCRIPTION +Void's runit init scripts print messages to the kernel message buffer at startup, +marking when some procedures start and finish. +.Nm +prints a rough accounting of where time is spent during boot using these messages. +.Nm +may require superuser privileges to read from dmesg. +.Sh EXAMPLES +.Bd -literal +# runit-startuptime +initramfs 0.646 s +core-services 4.002 s + 00-pseudofs 0.056 s + 01-static-devnodes 1.178 s + 02-kmods 0.027 s + 02-udev 2.413 s + 03-console-setup 0.096 s + 03-filesystems 0.202 s + 04-swap 0.004 s + 05-misc 0.015 s + 08-sysctl 0.008 s + 20-screen 0.001 s + 98-sbin-merge 0.000 s + 99-cleanup 0.001 s +rc.local 0.002 s +total 7.952 s +.Ed +.Sh SEE ALSO +.Xr runit-init 8 +.Sh AUTHOR +.An classabbyamp , +.Mt void@placeviolette.net .