-
Notifications
You must be signed in to change notification settings - Fork 0
/
jagoff
executable file
·81 lines (67 loc) · 1.88 KB
/
jagoff
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
#!/bin/sh
rewritebinpaths() {
local modfile="$1"
local binfiles="$2"
set -e
local binfile
printf "%s\n" "$binfiles" | while read binfile
do
extractfile "meta.${binfile}_binary" "$binfile"
local pathoffsets="`strings -td "$modfile" | sed -n "s: *\(.*/.*$binfile\)$:\1:p" | cut -d" " -f1`"
local pathoffset
printf "%s\n" "$pathoffsets" | while read pathoffset
do
printf "%s\0" "$binfile" | dd of="$modfile" seek="$pathoffset" bs=1 conv=notrunc 2>/dev/null
done
done
}
extractfile() {
local whichkey="$1"
local filename="$2"
shift 2
set -e
local temporary="$filename.tmp"
jaguar/jaguar get "$jagfile" "$whichkey" | base64 -d >"$temporary"
if [ $# -gt 0 ]
then
local postproccmd="$1"
shift
"$postproccmd" "$temporary" "$@"
fi
if [ -e "$filename" ]
then
if diff "$filename" "$temporary" >/dev/null
then
local exitcode="0"
else
printf "%s\n" "ERROR: $filename: already exists!" >&2
local exitcode="3"
fi
rm "$temporary"
return "$exitcode"
fi
mv "$temporary" "$filename"
}
set -e
if [ $# -lt 2 ]
then
cat <<-tac
USAGE: $0 <Jaguar file> <perf.data key> [Perf argument]..."
Extracts a Perf recording and the binaries it profiles from an experiment datafile,
fixes paths so that symbols can be resolved regardless of whether it's being run on
the same machine that ran the experiment and without modifying the experimental
infrastructure, and launches perf report, optionally with command-line arguments.
<Jaguar file> probably ends in '.json'.
<perf.data key> probably ends in '.perf_data'.
[Perf argument]s are for 'perf report'.
tac
exit 2
fi
jagfile="$1"
perfkey="$2"
shift 2
perffile="perf.$perfkey.data"
binaries="`cut -d'"' -f2 "$jagfile" | sed -n 's/\(.*\)_binary$/\1/p' | sort | uniq`"
extractfile "$perfkey" "$perffile" rewritebinpaths "$binaries"
perf report -i"$perffile" "$@"
fuser "$perffile" >/dev/null 2>&1 || rm "$perffile"