-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperf.sh
More file actions
executable file
·44 lines (33 loc) · 1.07 KB
/
Copy pathperf.sh
File metadata and controls
executable file
·44 lines (33 loc) · 1.07 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
#!/usr/bin/env bash
set -e
function usage() {
echo "Usage:"
echo " $(basename $0) [-F req] [-p pid]"
echo " $(basename $0) [-F req] [binary]"
echo "注意: -F 默认是 /proc/sys/kernel/perf_event_max_sample_rate 的值"
}
FlameGraph_home="${HOME}/go/src/github.com/brendangregg/FlameGraph"
if [ -z "$1" ]; then
usage
exit 1
fi
if [ ! -d "$FlameGraph_home" ]; then
mkdir -p "$(dirname "$FlameGraph_home")"
git clone --depth 1 https://github.com/brendangregg/FlameGraph.git "$FlameGraph_home"
fi
output_file=$(date '+%Y%m%d%H%M%S')
process_output_perf="output/${output_file}.data"
process_output_svg="output/${output_file}.svg"
function parse_perf() {
echo "proccess done...."
perf script -i "$process_output_perf" | "$FlameGraph_home"/stackcollapse-perf.pl | "$FlameGraph_home"/flamegraph.pl >"${process_output_svg}"
echo "open ${process_output_svg}"
}
# 移除文件
rm -rf "$process_output_perf"
rm -rf "$process_output_svg"
mkdir -p output
# 结束的时候
trap parse_perf EXIT
set -x
perf record -o "$process_output_perf" -g "$@"