-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflamesync
More file actions
executable file
·148 lines (117 loc) · 4.5 KB
/
Copy pathflamesync
File metadata and controls
executable file
·148 lines (117 loc) · 4.5 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
# Manage Symbols, Collect Flame Data
# Scans the squid binary and retrieves a list of packages that are supplying its shared libraries
# krb5 is included manually because it looks like a package error prevents it from being resolved automatically
# glibc and openssl included manually because they're critical and seeing them hard coded makes me feel better
#BINARY=/usr/local/squid/sbin/squid
BINARY=/usr/local/sbin/unbound
ID=$(wget -q -O - http://169.254.169.254/latest/meta-data/instance-id)
if [ ! -z "$2" ]; then
if [ -x "$2" ]; then
BINARY="$2"
else
echo Could not find executable at $2
exit
fi
fi
echo Scanning $BINARY
BIN_PKG="$(rpm --qf "%{NAME}\n" -qf $BINARY)"
if [ ! $? -eq 0 ]; then
echo Binary not from a system package
BIN_PKG=""
fi
PACKAGES="kernel glibc openssl krb5 krb5-debuginfo $BIN_PKG $(rpm --qf '%{NAME}\n' -qf $(ldd $BINARY | awk '{print($3)}' | grep "/") | grep -v "not owned by" | sort -u | tr '\n' ' ')"
echo "Identified Packages: $PACKAGES"
install_debuginfo () {
# debuginfo-install is part of the underlying linux distro, it's job is to fetch symbols
echo Searching for debugging symbols...
debuginfo-install -y $PACKAGES | tee /tmp/flame.tmp
# Check the symbolization for errors
ERROR="$(cat /tmp/flame.tmp | grep -i "yum lock")"
if [ ! -z "$ERROR" ]; then
echo -e "\033[1;31mFAIL\033[m" - Something else has the yum lock? Try again.
exit
fi
# Check the symbolization for errors
ERROR="$(cat /tmp/flame.tmp | grep -i "could not find")"
if [ ! -z "$ERROR" ]; then
echo -e "\033[1;31mFAIL\033[m" - Some debug symbols could not be installed - probably need to try --symbolize
return
fi
echo -e "\033[1;32mSUCCESS\033[m" - Debug Symbols Good
}
install_tools() {
# Install the Linux Perf analysis engine
yum -y -q install perf.x86_64
# Install Flame Graph Scripts
if [ ! -x /home/ec2-user/FlameGraph ]; then
git clone https://github.com/brendangregg/FlameGraph /home/ec2-user/FlameGraph
fi
}
if [ "$1" == "--apache-mods" ]; then
# Scan the apache modules
PACKAGES="$(rpm --qf '%{NAME}\n' -qf $(ls -ad1 /etc/httpd/modules/* | grep "/") | grep -v "not owned by" | sort -u | tr '\n' ' ')"
echo "Apache Module Packages: $PACKAGES"
yum -y -q install $PACKAGES
install_debuginfo
exit
fi
if [ "$1" == "--symbolize" ]; then
install_tools
# Update all the packages because debug symbols for non-current packages are frequently not available
# This is why squid has to be restarted, the running squid won't be relinked with the new libraries.
echo Upgrading involved packages...
yum -y -q install $PACKAGES
# Get all the debug symbols associated with these packages
install_debuginfo
echo -e "\n\033[1;4;31mIf anything updated, you need to restart squid for it to take affect\033[m"
exit
fi
#if [ "$1" == "--full-symbolize" ]; then
# install_tools
#
# yum -y update
#
# debuginfo-install -y '*'
#
# echo -e "\n\033[1;4;31mIf anything updated, you need to restart squid for it to take affect\033[m"
#
# exit
#fi
if [ "$1" != "--collect" ]; then
echo Tool to help install debug symbols
echo
echo Collect flame data:
echo "./flame --collect [/path/to/binary]"
echo
echo If you get a symbol installation failure, you probably need to try --symbolize
echo and restart squid. This can be avoided by baking good symbols into the ec2
echo image.
echo "./flame --symbolize [/path/to/binary]"
echo
exit
fi
install_tools
install_debuginfo
while true; do
echo Collecting data...
# Dwarf Collect
nice -n -1 perf record -F 99 -ag --call-graph=dwarf,16384 --proc-map-timeout=1000 -- sleep 30
# Frame Pointer Collect
#nice -n -1 perf record -F 99 -ag --proc-map-timeout=1000 -- sleep 30
echo Graphing data...
# Flame graph stack collapse
perf script | /home/ec2-user/FlameGraph/stackcollapse-perf.pl > out.perf-folded
# Modifed linux stack collapse to provide info on bad traces
#perf script -s securly_stackcollapse.py > out.perf-folded
# Linux stack collapse
#perf script report stackcollapse > out.perf-folded
# Some Brendon Gregg hack, Seems to give us cleaner data, but I think it might just be discarding stuff it doesn't understand - Needs study
#perf report --stdio --no-children -n -g folded,0,caller,count -s comm | awk '/^ / { comm = $3 } /^[0-9]/ { print comm ";" $2, $1 }' > out.perf-folded
# convert the collapsed stack to a flame graph
cat out.perf-folded | /home/ec2-user/FlameGraph/flamegraph.pl > flame.$(date +"%FT%T").svg
# Temporary file
rm out.perf-folded perf.data
# Sync to bucket
aws s3 sync --delete . s3://david-hinkle/flamesync/$ID
done