9
9
echo " $@ " >&2
10
10
exit 1
11
11
}
12
+
12
13
if [ " $( id -u) " != " 0" ]; then
13
14
die " Need to be root for runnig pmcstat"
14
15
fi
@@ -31,22 +32,23 @@ case "${cpu}" in
31
32
die " Unknow CPU (${cpu} )"
32
33
esac
33
34
34
- # Load Hardware Performance Monitoring Counter module
35
- kldstat -q -m hwpmc || kldload hwpmc
35
+ echo " ${cpu} detected, using ${counter} PMC counter"
36
+
37
+ if ! kldstat -q -m hwpmc; then
38
+ echo " Loading Hardware Peformance Monitoring Counter (hwpmc) kernel module..."
39
+ kldload hwpmc
40
+ fi
36
41
37
- # Delete existing log files
38
- for f in /tmp/pmc.* .log /tmp/flamegraph.svg; do
39
- rm -rf " ${f} "
40
- done
42
+ tmpdir=$( mktemp -d -t flame)
41
43
42
- # Collect system stats
43
- pmcstat -z ${graphdepth} -l ${seconds} -S ${counter} -O /tmp /pmc.raw.log
44
- # Generate system-wide profile with callgraphs
45
- pmcstat -z ${graphdepth} -R /tmp/ pmc.raw.log -G /tmp /pmc.callgraph.log
44
+ echo " Collecting hwpmc for ${seconds} seconds... "
45
+ pmcstat -z ${graphdepth} -l ${seconds} -S ${counter} -O ${tmpdir} /pmc.raw.log
46
+ echo " Generate system-wide profile with callgraphs... "
47
+ pmcstat -z ${graphdepth} -R ${tmpdir} / pmc.raw.log -G /${tmpdir} /pmc.callgraph.log
46
48
47
- whereis -q stackcollapse-pmc.pl || die " Missing flamegraph package"
48
- # fold stack samples into single lines.
49
- stackcollapse-pmc.pl /tmp/ pmc.callgraph.log > /tmp /pmc.folded.log
50
- # Generate flamegraph
51
- flamegraph.pl --title " counter: ${counter} " /tmp/ pmc.folded.log > flamegraph.svg
52
- echo " Done: flamegraph generated as /tmp /flamegraph.svg"
49
+ whereis -q stackcollapse-pmc.pl || die " Missing benchmarks/ flamegraph package"
50
+ echo " Fold stack samples into single lines... "
51
+ stackcollapse-pmc.pl ${tmpdir} / pmc.callgraph.log > ${tmpdir} /pmc.folded.log
52
+ echo " Generating flamegraph svg... "
53
+ flamegraph.pl --title " counter: ${counter} " ${tmpdir} / pmc.folded.log > ${tmpdir} / flamegraph.svg
54
+ echo " Done: flamegraph generated as ${tmpdir} /flamegraph.svg"
0 commit comments