Skip to content

Commit

Permalink
initrdscripts: add bootchart hook w/ OS_DEVELOPMENT=1
Browse files Browse the repository at this point in the history
Run systemd-bootchart in an initramfs hook early in the boot process to
collect information on CPU and disk load, and output to a chart in
/run/log.

This hook is disabled by default, and can be enabled using the
`bootchart` bootparam.

Change-type: patch
Signed-off-by: Joseph Kogut <[email protected]>
  • Loading branch information
jakogut committed Dec 5, 2024
1 parent f7006b8 commit 29ac5ae
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ PACKAGE_INSTALL:append = " initramfs-module-console-null-workaround"
PACKAGE_INSTALL:append = "${@oe.utils.conditional('SIGN_API','','',' initramfs-module-cryptsetup initramfs-module-kexec',d)}"
PACKAGE_INSTALL:append = "${@oe.utils.conditional('PARTITION_TABLE_TYPE','gpt',' gptfdisk ','',d)}"

PACKAGE_INSTALL:append = "${@bb.utils.contains('DISTRO_FEATURES', 'osdev-image', ' initramfs-module-bootchart', '', d)}"

# Do not pollute the initrd image with rootfs features
IMAGE_FEATURES = ""

Expand Down
19 changes: 19 additions & 0 deletions meta-balena-common/recipes-core/initrdscripts/files/bootchart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

bootchart_enabled() {
# shellcheck disable=SC2154
[ "${bootparam_bootchart}" = "true" ] && return 0 || return 1
}

bootchart_run() {
# bootchart runs backgrounded through switch_root, after the real root
# is mounted and init is run, until it's collected enough samples, at
# which point it exits
#
# argv[0][0] is replaced with '@' in main() to indicate that the
# process remains from the initramfs, and to prevent init from killing
# it
#
# https://freedesktop.org/wiki/Software/systemd/RootStorageDaemons/
( exec /lib/systemd/systemd-bootchart ) &
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
SRC_URI:append = " \
file://console_null_workaround \
file://prepare \
file://bootchart \
file://fsck \
file://fsuuidsinit \
file://machineid \
Expand All @@ -22,6 +23,7 @@ SRC_URI:append = " \
do_install:append() {
install -m 0755 ${WORKDIR}/console_null_workaround ${D}/init.d/000-console_null_workaround
install -m 0755 ${WORKDIR}/prepare ${D}/init.d/00-prepare
install -m 0755 ${WORKDIR}/bootchart ${D}/init.d/000-bootchart
install -m 0755 ${WORKDIR}/fsuuidsinit ${D}/init.d/75-fsuuidsinit
install -m 0755 ${WORKDIR}/fsck ${D}/init.d/87-fsck
install -m 0755 ${WORKDIR}/rootfs ${D}/init.d/90-rootfs
Expand All @@ -48,6 +50,7 @@ do_install:append() {

PACKAGES:append = " \
initramfs-module-console-null-workaround \
initramfs-module-bootchart \
initramfs-module-fsck \
initramfs-module-machineid \
initramfs-module-resindataexpander \
Expand All @@ -68,6 +71,10 @@ SUMMARY:initramfs-module-console-null-workaround = "Workaround needed for when c
RDEPENDS:initramfs-module-console-null-workaround = "${PN}-base"
FILES:initramfs-module-console-null-workaround = "/init.d/000-console_null_workaround"

SUMMARY:initramfs-module-bootchart = "Boot profiling"
RDEPENDS:initramfs-module-bootchart = "${PN}-base systemd-bootchart"
FILES:initramfs-module-bootchart = "/init.d/000-bootchart"

SUMMARY:initramfs-module-fsck = "Filesystem check for partitions"
RDEPENDS:initramfs-module-fsck = "${PN}-base e2fsprogs-e2fsck dosfstools-fsck"
FILES:initramfs-module-fsck = "/init.d/87-fsck"
Expand Down

0 comments on commit 29ac5ae

Please sign in to comment.