Skip to contentSkip to conversation

build initramfs: logging is slow

DISCUSSION John Reiser 1 participant 1 message Sep 6, 2011

lore
Share & tools
lore
#0 lore raw

Commenting out this line from inst_simple:
ddebug "Installing $_src"
saves me about 10% real time (not counting final gzip) in build initramfs.

The low-level culprit is the extra _process_ [fork or clone] for $(_lvl2char ...) in:
----- dracut-logger

_do_dlog() {
    [ -z "$maxloglvl" ] && return 0
    local lvl="$1"; shift
    local lvlc=$(_lvl2char "$lvl") || return 0    ### SLOW!

    [ $lvl -le $maxloglvl ] || return 0

-----

Instead, the level translation should be done using an indexed array (after an arithmetic check for index-out-of-range.)

Even better, the level comparison should be hoisted into the definition of ddebug and dtrace, such as:
-----

ddebug() {
    [ 5 -le $maxloglvl ] || return 0
    set +x
    dlog 5 "$@"
}

-----

If bash could conditionally re-define a function, then dlog_init might:

    [ 5 -le $maxloglvl ]  ||  eval "function ddebug() {}"

but that did not work for me.