-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable profiling framework in core ZFSBootMenu tools
Create /lib/profiling-lib.sh, which can be sourced by any Bash script. Once sourced, a debug trap is installed that dumps the stack (but not the command being executed) to a serial port, which collects the data on the host side into a log file. After the VM exits, the performance data is converted into a format expected by flamegraph.pl (https://github.com/brendangregg/FlameGraph) and then both a flamegraph and a flamechart are created. If profiling isn't enabled, a no-op /lib/profiling-lib.sh is created. The profiling library must always exist, and must always be sourceable. Optimizations/performance changes include: - setting the loglevel as from the KCL as early as possible, to preserve all log messages > zwarn - validating that the loglevel is an integer, otherwise defaulting to 4 - validating that zbm.timeout/timeout is an integer, otherwise defaulting to 10 - adding re-import guards to libraries - removing the zlog() function and doing the logging work in the zerror/zwarn/... function instead. This means that everything but zdebug can be as lean as possible. - gating a couple serial zdebug calls behind a single zdebug check - added a fast-fail to timed_prompt to return 0 if delay isn't greater than 0. Any default values for delay/prompt are assigned after this test. - add a short-circuit to get_zbm_arg that uses bashre to check if the kcl option string is present at all in the KCL. If it's not, the next option passed to get_zbm_arg is evaluated. - Avoid pre-computing a return value until it's actually needed - cut i18n out of testing builds unless a graphical interface is requested - cut crypt-ssh and network-legacy out of testing builds unless SSH access is requested - cut out 'nvdimm fs-lib rootfs-block dm dmraid lunmask' from testing builds. These can likely be cut from release builds as well. Closes #245
- Loading branch information
Showing
16 changed files
with
282 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,86 @@ | ||
#!/bin/bash | ||
# vim: softtabstop=2 shiftwidth=2 expandtab | ||
|
||
if [ -n "${_ZFSBOOTMENU_KMSG_LOG_LIB}" ]; then | ||
[ -z "${FORCE_RELOAD}" ] && return | ||
else | ||
readonly _ZFSBOOTMENU_KMSG_LOG_LIB=1 | ||
fi | ||
|
||
: "${loglevel:=4}" | ||
|
||
# arg1: log level | ||
# arg2: log line | ||
# arg1..argN: log line | ||
# prints: nothing | ||
# returns: nothing | ||
# returns: 1 if loglevel isn't high enough | ||
|
||
zlog() { | ||
zdebug() { | ||
[ ${loglevel:-4} -ge 7 ] || return 1 | ||
local prefix trace last lines line lc i | ||
[ -z "${1}" ] && return | ||
[ -z "${2}" ] && return | ||
|
||
# Remove everything but new lines from the string, count the length | ||
lines="${2//[!$'\n']/}" | ||
lines="${1//[!$'\n']/}" | ||
lines="${#lines}" | ||
lc=0 | ||
|
||
while IFS=$'\n' read -r line ; do | ||
# Only add script/function tracing to debug messages | ||
if [ "${1}" -eq 7 ] && [ "${lc}" -eq "${lines}" ] ; then | ||
if [ "${lc:=0}" -eq "${lines}" ] ; then | ||
trace= | ||
last=${#BASH_SOURCE[@]} | ||
for (( i=2 ; i<last ; i++ )) ; do | ||
for (( i=1 ; i<last ; i++ )) ; do | ||
trace="${FUNCNAME[$i]},${BASH_SOURCE[$i]},${BASH_LINENO[$i-1]}${trace:+;}${trace}" | ||
done | ||
prefix="<${1}>ZBM:[$$]|${trace}|" | ||
elif [ "${1}" -eq 7 ] ; then | ||
prefix="<${1}>ZBM:[$$]||" | ||
prefix="<7>ZBM:[$$]|${trace}|" | ||
else | ||
prefix="<${1}>ZFSBootMenu: " | ||
prefix="<7>ZBM:[$$]||" | ||
fi | ||
lc=$(( lc + 1 )) | ||
echo -e "${prefix}${line}" > /dev/kmsg | ||
done <<<"${2}" | ||
echo "${prefix}${line}" > /dev/kmsg | ||
done <<<"${1}" | ||
} | ||
|
||
if [ ${loglevel:-4} -ge 7 ] ; then | ||
# Trap errors and send them to the debug handler | ||
traperror() { | ||
zdebug "trapped error from: '${BASH_COMMAND}'" | ||
} | ||
|
||
trap traperror ERR | ||
set -o errtrace | ||
fi | ||
|
||
# arg1: log line | ||
# prints: nothing | ||
# returns: 1 if loglevel isn't high enough | ||
|
||
zdebug() { | ||
[ "${loglevel:-4}" -ge 7 ] || return 1 | ||
zlog 7 "$@" | ||
} | ||
|
||
zinfo() { | ||
[ "${loglevel:-4}" -ge 6 ] || return 1 | ||
zlog 6 "$@" | ||
echo "<6>ZFSBootMenu: $1" > /dev/kmsg | ||
} | ||
|
||
# arg1: log line | ||
# prints: nothing | ||
# returns: 1 if loglevel isn't high enough | ||
|
||
znotice() { | ||
[ "${loglevel:-4}" -ge 5 ] || return 1 | ||
zlog 5 "$@" | ||
echo "<5>ZFSBootMenu: $1" > /dev/kmsg | ||
} | ||
|
||
# arg1: log line | ||
# prints: nothing | ||
# returns: 1 if loglevel isn't high enough | ||
|
||
zwarn() { | ||
[ "${loglevel:-4}" -ge 4 ] || return 1 | ||
: > "${BASE}/have_warnings" | ||
zlog 4 "$@" | ||
echo "<4>ZFSBootMenu: $1" > /dev/kmsg | ||
} | ||
|
||
# arg1: log line | ||
# prints: nothing | ||
# returns: 1 if loglevel isn't high enough | ||
|
||
zerror() { | ||
[ "${loglevel:-4}" -ge 3 ] || return 1 | ||
: > "${BASE}/have_errors" | ||
zlog 3 "$@" | ||
} | ||
|
||
traperror() { | ||
zdebug "trapped error from: '${BASH_COMMAND}'" | ||
echo "<3>ZFSBootMenu: $1" > /dev/kmsg | ||
} | ||
|
||
if [ "${loglevel:-4}" -eq 7 ] ; then | ||
set -o errtrace | ||
set -o functrace | ||
trap traperror ERR | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.