-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver
executable file
·116 lines (99 loc) · 2.96 KB
/
driver
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/sh
trap exit TERM INT QUIT
trap "kill 0" EXIT
logging_commence() {
mkfifo "$prefix.tmp"
tee "$CATBENCH_LOGFILE" <"$prefix.tmp" &
set -v
exec >"$prefix.tmp" 2>&1 3>&1 4>&2
}
logging_cleanup() {
set +v
exec >&3 2>&4
rm "$prefix.tmp"
}
shell_needs_protection() {
local thing_that_might_need_protection="$1"
[ "`eval printf '"%s\n"' "$thing_that_might_need_protection"`" != "$thing_that_might_need_protection" ]
}
shell_quoted_arguments() {
for arg in "$@"
do
local delim=""
if [ -z "$arg" ] || shell_needs_protection "$arg"
then
delim="'"
fi
printf %s " $delim$arg$delim" | sed "s/'\([^=]*=\)/\1'/g"
done | cut -d" " -f2-
}
if [ $# -lt 1 ]
then
cat <<-tac
USAGE: $0 <command token>...
Prepend $0 to the full command-line invokation of another script
or program to log its environment, invocation, and interactions.
If shell actions are provided (in escaped form so your own shell
doesn't eat them, of course), they will be interpreted. To add
files to the archive, place them in the \\\$dir directory.
tac
exit 127
fi
if [ -n "$CATBENCH_JAGFILE" ]
then
cat >&2 <<-tac
$0: called recursively! No mere script should call the great $0!
tac
exit 127
fi
for word in "$@"
do
if printf %s "$word" | grep -v = >/dev/null
then
cmd="$word"
break
fi
done
if ! mount | grep "$PWD/ramdisk" >/dev/null
then
mkdir -p ramdisk
sudo mount -ttmpfs none ramdisk
fi
prefix="catbench-`basename $cmd`_`date +%F_%H-%M-%S_%z`"
export CATBENCH_JAGFILE="$prefix.json"
export CATBENCH_LOGFILE="ramdisk/$prefix.log"
if [ -e "$CATBENCH_JAGFILE" ]
then
echo "ERROR: Output JSON file already exists; aborting!" >&2
exit 127
fi
logging_commence
cp jaguar/template.json "$CATBENCH_JAGFILE"
args="`shell_quoted_arguments "$@"`"
jaguar/jaguar set "$CATBENCH_JAGFILE" meta.command "$args"
jaguar/jaguar set "$CATBENCH_JAGFILE" meta.commit "`git log --oneline --abbrev-commit --no-decorate -1`"
jaguar/jaguar set "$CATBENCH_JAGFILE" meta.date "`date "+%F %T %z"`"
jaguar/jaguar set "$CATBENCH_JAGFILE" meta.message "`git log --no-abbrev-commit --decorate -1`"
git diff --ignore-submodules HEAD | base64 | jaguar/jaguar set "$CATBENCH_JAGFILE" meta.patch -
jaguar/jaguar set "$CATBENCH_JAGFILE" meta.perf "`perf -v`"
jaguar/jaguar set "$CATBENCH_JAGFILE" meta.status "`git status -uno`"
jaguar/jaguar set "$CATBENCH_JAGFILE" meta.submodule "`git submodule status`"
jaguar/jaguar set "$CATBENCH_JAGFILE" meta.uname "`uname -a`"
printf "%s\n" "$ $args"
eval "$args"
status="$?"
echo "Command exited with status: $status"
jaguar/jaguar set "$CATBENCH_JAGFILE" meta.exit "$status"
sleep 10
logging_cleanup
pack="base64 -w0 '$CATBENCH_LOGFILE'"
unpack="base64 -d"
if [ "`du -b "$CATBENCH_LOGFILE" | cut -f1`" -gt "$((2 * 1024 * 1024 * 1024))" ] # 2 GiB
then
pack="gzip -c '$CATBENCH_LOGFILE' | base64 -w0"
unpack="$unpack | zcat"
fi
eval "$pack" | jaguar/jaguar set "$CATBENCH_JAGFILE" meta.log -
jaguar/jaguar set "$CATBENCH_JAGFILE" meta.unpack "$unpack"
rm "$CATBENCH_LOGFILE"
exit "$status"