-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprofile.sh
executable file
·65 lines (56 loc) · 2.19 KB
/
profile.sh
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
#!/usr/bin/env bash
WORKSPACE=$(cd `dirname $0`; pwd)
if [ $# -ne 1 ] ; then
echo "usage: $(basename $0) PROPS_FILE" >&2
exit 2
fi
if [ -f ${WORKSPACE}/report/.run ]; then
rm -rf ${WORKSPACE}/report/.run
fi
function profile() {
local props=$1
if [ -f ${props} ]; then
local addr=`cat ${props} | grep profAddr | awk -F '=' '{print $2}'`
if [ "${addr}"x == x ]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` The profile server addr is not configured, please check."
exit 0;
fi
local port=`cat ${props} | grep profPort | awk -F '=' '{print $2}'`
if [ "${port}"x == x ]; then
echo "`date +'%Y-%m-%d %H:%M:%S'` The profile server port is not configured, please check."
exit
fi
local think=`cat ${props} | grep profThink | awk -F '=' '{print $2}'`
if [ "${port}"x == x ]; then
think=60
fi
echo "`date +'%Y-%m-%d %H:%M:%S'` The profile server addr is ${addr}"
echo "`date +'%Y-%m-%d %H:%M:%S'` The profile server port is ${port}"
else
echo "`date +'%Y-%m-%d %H:%M:%S'` File ${props} does not exists.please check..... "
exit 0;
fi
echo "`date +'%Y-%m-%d %H:%M:%S'` Start to sleep for ${think} second, please wait...."
sleep ${think}
if [ -f ${WORKSPACE}/report/.run ]; then
local runid=`cat ${WORKSPACE}/report/.run`
echo "runid=${runid}"
OLD_IFS="$IFS"
IFS=","
addrs=(${addr})
IFS="$OLD_IFS"
for ad in ${addrs[@]}
do
echo "`date +'%Y-%m-%d %H:%M:%S'` Start to get profile from server ${ad}"
mkdir -p ${WORKSPACE}/${runid}/prof/${ad}
curl http://${ad}:${port}/debug/pprof/profile?seconds=30 > ${WORKSPACE}/${runid}/prof/${ad}/cpu
curl http://${ad}:${port}/debug/pprof/heap > ${WORKSPACE}/${runid}/prof/${ad}/heap
curl http://${ad}:${port}/debug/pprof/goroutine?debug=2 -o ${WORKSPACE}/${runid}/prof/${ad}/goroutine.log
#curl http://${ad}:${port}/debug/pprof/trace?seconds=10 -o ${WORKSPACE}/${runid}/prof/${ad}/trace.out
echo "`date +'%Y-%m-%d %H:%M:%S'` Finish to get profile from server ${ad}"
done
else
exit 0;
fi
}
profile $1