-
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.
Create a global debug/trace log viewer
Using fzf in zlogtail allowed for easy searching of debug log lines, but it discarded the context when searching for a term. `ztrace` has been created to provide further structure to debug log messages and to subsequently keep it while viewing / searching the messages. Debug log messages now take the following form: ZBM:[pid]|<function,file,line;..>|<log message> The function stack is automatically calculated and inserted into the debug message. A fully generated message from inside a second function would look like this: ZBM:[556]|main,/bin/zfsbootmenu,124;draw_be,/lib/zfsbootmenu-lib.sh,493|selected: mod-r,ztest/ROOT/void The PID of the program that generated the message is 556. The main function, in /bin/zfsbootmenu at line 124 made the first call The draw_be function, in /lib/zfsbootmenu-lib.sh at line 493 made the zdebug call with the text 'selected: mod-r,ztest/ROOT/void' . This format allows for semi-readable raw messages in `dmesg` with out any color escape sequences, wrapped lines, etc. ztrace unpacks the log message and rewrites it to the following form: [ time stamp ] ZBM[pid]: debug message [ time stamp ] trace: first function [ time stamp ] trace: second function [ time stamp ] trace: ... The output is piped into `less`, which can decode the color escape sequences inserted by ztrace. It allows for searching and highlighting a term via `/term`. Lastly, MOD+T has been globally added to all ZBM screens to bring up ztrace viewing the up-to-date debug log buffer. Unlike `zlogtail`, `ztrace` does not follow logs. It shows the current log buffer and then waits for you to search or quit. Quit ztrace via `q` and then bring it up again to view new messages. Closes #198
- Loading branch information
Showing
6 changed files
with
56 additions
and
36 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
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash | ||
#shellcheck disable=SC2086 | ||
|
||
r="\033[0;31m" | ||
g="\033[0;32m" | ||
o="\033[0;33m" | ||
n="\033[0m" | ||
|
||
while read -r line ; do | ||
time="${line:0:13}" | ||
suffix="${line:14:${#line}}" | ||
|
||
if [ "${suffix:0:3}" != "ZBM" ]; then | ||
continue | ||
fi | ||
|
||
IFS='|' read -r prefix trace log <<<"${suffix}" | ||
IFS=';' read -ra tokens <<<"${trace}" | ||
|
||
ppref="$( printf "%*s" 11 "${prefix}:" )" | ||
tpref="$( printf "%*s" 11 "trace:" )" | ||
|
||
pad=' ' | ||
c="${g}" | ||
|
||
echo -e "${time} ${ppref} ${log}" | ||
for token in "${tokens[@]}" ; do | ||
IFS=',' read -r func file line <<<"${token}" | ||
echo -e "${time} ${tpref}${pad}${r}${func}@${c}${file}${n}#${line}" | ||
pad="${pad} " | ||
c="${o}" | ||
done | ||
|
||
done < <( dmesg -T --time-format reltime -f user -l 7 ) | less -R -S +G |