Skip to content

Commit

Permalink
runit-startuptime: new script
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
classabbyamp committed Sep 6, 2024
1 parent 7f44b79 commit 8a322cd
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
69 changes: 69 additions & 0 deletions runit-startuptime
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/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
if (coresvtotal == 0)
coresvtotal = $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
}
}'
40 changes: 40 additions & 0 deletions runit-startuptime.1
Original file line number Diff line number Diff line change
@@ -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 [email protected] .

0 comments on commit 8a322cd

Please sign in to comment.