misc: Add two scripts to help debug things

This adds two new helper scripts that are good for debugging mgmt. Just
build and add `sigtee` to your ~/bin/ along with filter-golang-stack.py
and mgmt_debug.sh and use the later to call mgmt as you would normally.

For example, I might do:

$ mgmt_debug.sh ./mgmt run --tmp-prefix lang examples/lang/hello0.mcl

And if I kill it with ^\ then I'll get a filtered trace at the end in my
$PAGER (which is assumed to be `less`) and this should make my life
easier.

As a cool bonus, this means we use bash, python, and golang all
together!
This commit is contained in:
James Shubin
2020-01-13 00:59:27 -05:00
parent fec94aa53a
commit b65a9abf8e
2 changed files with 94 additions and 0 deletions

31
misc/mgmt_debug.sh Executable file
View File

@@ -0,0 +1,31 @@
#!/bin/bash
# This is a helper script to run mgmt and capture and filter stack traces. Any
# time mgmt crashes with a trace, it will first be filtered, and then displayed
# with `less`.
f1=`mktemp /tmp/tmp.X'X'X`
f2=`mktemp /tmp/tmp.X'X'X`
# run the program until it ends
# XXX: we need an --ignore-exit signal blocker too so we can ^\
#$@ 2>&1 | tee --ignore-interrupts --ignore-exit "$f1"
$@ 2>&1 | sigtee "$f1"
# clean up when we're done
function cleanup {
filter-golang-stack.py "$f1" > "$f2"
if [ $? -eq 0 ]; then
less "$f2"
fi
if [ "$1" = "--preserve" ]; then
echo "logged:"
echo "$f1"
echo "$f2"
else
rm "$f2"
rm "$f1"
fi
}
trap cleanup EXIT