add README, and CLI options
This commit is contained in:
1 parent
b8bdb2d6cb
commit
f09ed5dbee
3 files changed
+178
-6
No files matched your search
@@ -0,0 +1,75 @@
|
|||||||
|
# pmc-cloud-tools
|
||||||
|
|
||||||
|
Linux tools for measuring PMCs (Performance Monitoring Counters) in the cloud.
|
||||||
|
|
||||||
|
## Architectural PMCs
|
||||||
|
|
||||||
|
These are seven PMCs that are enabled on some newer AWS EC2 types, eg, m4.16xl. See <a href="http://www.brendangregg.com/blog/2017-05-04/the-pmcs-of-ec2.html">The PMCs of EC2</a>.
|
||||||
|
|
||||||
|
### pmcarch
|
||||||
|
|
||||||
|
Summarizes the architectural PMCs. Eg:
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
# ./pmcarch
|
||||||
|
K_CYCLES K_INSTR IPC BR_RETIRED BR_MISPRED BMR% LLCREF LLCMISS LLC%
|
||||||
|
96163187 87166313 0.91 19730994925 679187299 3.44 656597454 174313799 73.45
|
||||||
|
93988372 87205023 0.93 19669256586 724072315 3.68 666041693 169603955 74.54
|
||||||
|
93863787 86981089 0.93 19548779510 669172769 3.42 649844207 176100680 72.90
|
||||||
|
93739565 86349653 0.92 19339320671 634063527 3.28 642506778 181385553 71.77
|
||||||
|
94495981 86815232 0.92 19482504710 648954409 3.33 628548666 180975066 71.21
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
# ./pmcarch -h
|
||||||
|
USAGE: pmcarch {-C CPU | -p PID | -c CMD} [interval [duration]]
|
||||||
|
-C CPU # measure this CPU only
|
||||||
|
-p PID # measure this PID only
|
||||||
|
-c 'CMD' # measure this command only (quote it)
|
||||||
|
interval # output interval in secs (default 1)
|
||||||
|
duration # total seconds (default infinityish)
|
||||||
|
eg,
|
||||||
|
pmcarch # show stats across all CPUs
|
||||||
|
pmcarch 5 # show stats every 5 seconds
|
||||||
|
pmcarch -C 0 # measure CPU 0 only
|
||||||
|
pmcarch -p 181 # measure PID 181 only
|
||||||
|
pmcarch -c 'cksum /boot/*' # measure run and measure this cmd
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
## All PMCs
|
||||||
|
|
||||||
|
These are available on some AWS Nitro hypervisor instance types. Eg, c5.9xl.
|
||||||
|
|
||||||
|
### tlbstat
|
||||||
|
|
||||||
|
Summarizes TLB (Translation Lookaside Buffer) statistics (an MMU cache). Eg:
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
# ./tlbstat
|
||||||
|
K_CYCLES K_INSTR IPC DTLB_WALKS ITLB_WALKS K_DTLBCYC K_ITLBCYC DTLB% ITLB%
|
||||||
|
93091508 86971957 0.93 135562325 45028565 3053416 1121015 3.28 1.20
|
||||||
|
94354781 88708445 0.94 136898873 49736338 3135383 1199061 3.32 1.27
|
||||||
|
94274360 88372901 0.94 138668282 48503863 3200281 1194388 3.39 1.27
|
||||||
|
92040379 86763153 0.94 133141376 44859310 3060742 1118921 3.33 1.22
|
||||||
|
92152495 87144845 0.95 135446984 50308740 3156780 1200598 3.43 1.30
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
# ./tlbstat -h
|
||||||
|
USAGE: tlbstat {-C CPU | -p PID | -c CMD} [interval [duration]]
|
||||||
|
-C CPU # measure this CPU only
|
||||||
|
-p PID # measure this PID only
|
||||||
|
-c 'CMD' # measure this command only (quote it)
|
||||||
|
interval # output interval in secs (default 1)
|
||||||
|
duration # total seconds (default infinityish)
|
||||||
|
eg,
|
||||||
|
tlbstat # show stats across all CPUs
|
||||||
|
tlbstat 5 # show stats every 5 seconds
|
||||||
|
tlbstat -C 0 # measure CPU 0 only
|
||||||
|
tlbstat -p 181 # measure PID 181 only
|
||||||
|
tlbstat -c 'cksum /boot/*' # measure run and measure this cmd
|
||||||
|
</pre>
|
||||||
@@ -2,9 +2,13 @@
|
|||||||
#
|
#
|
||||||
# pmcarch - measure and summarize architectural PMCs.
|
# pmcarch - measure and summarize architectural PMCs.
|
||||||
#
|
#
|
||||||
|
# USAGE: pmcarch {-C CPU | -p PID | -c CMD} [interval [duration]]
|
||||||
|
#
|
||||||
# PMCs are performance monitoring counters. This script uses the architectural
|
# PMCs are performance monitoring counters. This script uses the architectural
|
||||||
# set to report on:
|
# set to report on:
|
||||||
#
|
#
|
||||||
|
# - K_CYCLES: CPU Cycles x 1000
|
||||||
|
# - K_INSTR: CPU Instructions x 1000
|
||||||
# - IPC: instructions-per-cycle
|
# - IPC: instructions-per-cycle
|
||||||
# - BMR%: branch misprediction ration, as a percentage
|
# - BMR%: branch misprediction ration, as a percentage
|
||||||
# - LLC%: last level cache hit ratio, as a percentage
|
# - LLC%: last level cache hit ratio, as a percentage
|
||||||
@@ -14,16 +18,62 @@
|
|||||||
#
|
#
|
||||||
# 07-Apr-2017 Brendan Gregg Created this.
|
# 07-Apr-2017 Brendan Gregg Created this.
|
||||||
|
|
||||||
|
function usage {
|
||||||
|
cat <<-END >&2
|
||||||
|
USAGE: pmcarch {-C CPU | -p PID | -c CMD} [interval [duration]]
|
||||||
|
-C CPU # measure this CPU only
|
||||||
|
-p PID # measure this PID only
|
||||||
|
-c 'CMD' # measure this command only (quote it)
|
||||||
|
interval # output interval in secs (default 1)
|
||||||
|
duration # total seconds (default infinityish)
|
||||||
|
eg,
|
||||||
|
pmcarch # show stats across all CPUs
|
||||||
|
pmcarch 5 # show stats every 5 seconds
|
||||||
|
pmcarch -C 0 # measure CPU 0 only
|
||||||
|
pmcarch -p 181 # measure PID 181 only
|
||||||
|
pmcarch -c 'cksum /boot/*' # measure run and measure this cmd
|
||||||
|
END
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
opt_cpu=0; opt_pid=0; opt_cmd=0; cpu=""; pid=""; cmd=""
|
||||||
|
|
||||||
|
while getopts C:p:c:h opt
|
||||||
|
do
|
||||||
|
case $opt in
|
||||||
|
C) opt_cpu=1; cpu=$OPTARG ;;
|
||||||
|
p) opt_pid=1; pid=$OPTARG ;;
|
||||||
|
c) opt_cmd=1; cmd=$OPTARG ;;
|
||||||
|
h|?) usage ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
shift $(( $OPTIND - 1 ))
|
||||||
|
|
||||||
|
if (( opt_cpu + opt_pid + opt_cmd > 1 )); then
|
||||||
|
echo >&2 "ERROR: pick one of -C, -p, -c"
|
||||||
|
usage
|
||||||
|
fi
|
||||||
secs=${1-1} # default 1 second
|
secs=${1-1} # default 1 second
|
||||||
duration=${2-999999999} # default semi-infinite seconds
|
duration=${2-999999999} # default semi-infinite seconds
|
||||||
hlines=25 # lines to repeat header
|
hlines=25 # lines to repeat header
|
||||||
|
target=-a
|
||||||
|
(( opt_cpu )) && target="-C $cpu sleep $duration"
|
||||||
|
(( opt_pid )) && target="-p $pid sleep $duration"
|
||||||
|
(( opt_cmd )) && target="$cmd"
|
||||||
|
|
||||||
|
if (( opt_pid )); then
|
||||||
|
if [ ! -d /proc/$pid ]; then
|
||||||
|
echo >&2 "ERROR: Can't find PID $pid. Exiting."
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# order of PMCs attempts to workaround a 3.13 issue
|
# order of PMCs attempts to workaround a 3.13 issue
|
||||||
# note that instructions is last on purpose, it triggers output
|
# note that instructions is last on purpose, it triggers output
|
||||||
perf stat -e cycles \
|
perf stat -e cycles -e cycles \
|
||||||
-e r4f2e -e r412e \
|
-e r4f2e -e r412e \
|
||||||
-e r00c4 -e r00c5 -e instructions \
|
-e r00c4 -e r00c5 -e instructions \
|
||||||
-a -I $(( secs * 1000 )) sleep $duration 2>&1 | awk -v hlines=$hlines '
|
-I $(( secs * 1000 )) $target 2>&1 | awk -v hlines=$hlines '
|
||||||
BEGIN {
|
BEGIN {
|
||||||
htxt = sprintf("%-10s %-10s %5s %-12s %-10s %5s %-11s %-10s %5s",
|
htxt = sprintf("%-10s %-10s %5s %-12s %-10s %5s %-11s %-10s %5s",
|
||||||
"K_CYCLES", "K_INSTR", "IPC", "BR_RETIRED", "BR_MISPRED", "BMR%",
|
"K_CYCLES", "K_INSTR", "IPC", "BR_RETIRED", "BR_MISPRED", "BMR%",
|
||||||
@@ -51,6 +101,7 @@ perf stat -e cycles \
|
|||||||
}
|
}
|
||||||
ins = $2
|
ins = $2
|
||||||
if (llcref == 0) { llcref = 1; llcmiss = 0 }
|
if (llcref == 0) { llcref = 1; llcmiss = 0 }
|
||||||
|
if (cycles == 0) { cycles = 1 } # PMCs are broken, or no events
|
||||||
|
|
||||||
printf("%-10d %-10d %5.2f %-12d %-10d %5.2f %-11d %-10d %5.2f\n",
|
printf("%-10d %-10d %5.2f %-12d %-10d %5.2f %-11d %-10d %5.2f\n",
|
||||||
cycles / 1000, ins / 1000, ins / cycles, brretired, brmiss,
|
cycles / 1000, ins / 1000, ins / cycles, brretired, brmiss,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
# TLB: Translation Lookaside Buffer (the MMU page translation cache)
|
# TLB: Translation Lookaside Buffer (the MMU page translation cache)
|
||||||
# PMC: Performance Monitoring Counters
|
# PMC: Performance Monitoring Counters
|
||||||
#
|
#
|
||||||
# USAGE: tlbstat [interval [duration]]
|
# USAGE: tlbstat {-C CPU | -p PID | -c CMD} [interval [duration]]
|
||||||
#
|
#
|
||||||
# REQUIREMENTS: perf command, TLB PMCs (counters listed below)
|
# REQUIREMENTS: perf command, TLB PMCs (counters listed below)
|
||||||
#
|
#
|
||||||
@@ -26,12 +26,58 @@
|
|||||||
#
|
#
|
||||||
# 08-Jan-2018 Brendan Gregg Created this.
|
# 08-Jan-2018 Brendan Gregg Created this.
|
||||||
|
|
||||||
|
function usage {
|
||||||
|
cat <<-END >&2
|
||||||
|
USAGE: tlbstat {-C CPU | -p PID | -c CMD} [interval [duration]]
|
||||||
|
-C CPU # measure this CPU only
|
||||||
|
-p PID # measure this PID only
|
||||||
|
-c 'CMD' # measure this command only (quote it)
|
||||||
|
interval # output interval in secs (default 1)
|
||||||
|
duration # total seconds (default infinityish)
|
||||||
|
eg,
|
||||||
|
tlbstat # show stats across all CPUs
|
||||||
|
tlbstat 5 # show stats every 5 seconds
|
||||||
|
tlbstat -C 0 # measure CPU 0 only
|
||||||
|
tlbstat -p 181 # measure PID 181 only
|
||||||
|
tlbstat -c 'cksum /boot/*' # measure run and measure this cmd
|
||||||
|
END
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
opt_cpu=0; opt_pid=0; opt_cmd=0; cpu=""; pid=""; cmd=""
|
||||||
|
|
||||||
|
while getopts C:p:c:h opt
|
||||||
|
do
|
||||||
|
case $opt in
|
||||||
|
C) opt_cpu=1; cpu=$OPTARG ;;
|
||||||
|
p) opt_pid=1; pid=$OPTARG ;;
|
||||||
|
c) opt_cmd=1; cmd=$OPTARG ;;
|
||||||
|
h|?) usage ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
shift $(( $OPTIND - 1 ))
|
||||||
|
|
||||||
|
if (( opt_cpu + opt_pid + opt_cmd > 1 )); then
|
||||||
|
echo >&2 "ERROR: pick one of -C, -p, -c"
|
||||||
|
usage
|
||||||
|
fi
|
||||||
secs=${1-1} # default 1 second
|
secs=${1-1} # default 1 second
|
||||||
duration=${2-999999999} # default semi-infinite seconds
|
duration=${2-999999999} # default semi-infinite seconds
|
||||||
hlines=25 # lines to repeat header
|
hlines=25 # lines to repeat header
|
||||||
|
target=-a
|
||||||
|
(( opt_cpu )) && target="-C $cpu sleep $duration"
|
||||||
|
(( opt_pid )) && target="-p $pid sleep $duration"
|
||||||
|
(( opt_cmd )) && target="$cmd"
|
||||||
|
|
||||||
|
if (( opt_pid )); then
|
||||||
|
if [ ! -d /proc/$pid ]; then
|
||||||
|
echo >&2 "ERROR: Can't find PID $pid. Exiting."
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# note that instructions is last on purpose, it triggers output
|
# note that instructions is last on purpose, it triggers output
|
||||||
perf stat -e cycles \
|
perf stat -e cycles -e cycles \
|
||||||
-e dtlb_load_misses.miss_causes_a_walk \
|
-e dtlb_load_misses.miss_causes_a_walk \
|
||||||
-e dtlb_store_misses.miss_causes_a_walk \
|
-e dtlb_store_misses.miss_causes_a_walk \
|
||||||
-e itlb_misses.miss_causes_a_walk \
|
-e itlb_misses.miss_causes_a_walk \
|
||||||
@@ -39,7 +85,7 @@ perf stat -e cycles \
|
|||||||
-e dtlb_store_misses.walk_active \
|
-e dtlb_store_misses.walk_active \
|
||||||
-e itlb_misses.walk_active \
|
-e itlb_misses.walk_active \
|
||||||
-e instructions \
|
-e instructions \
|
||||||
-a -I $(( secs * 1000 )) sleep $duration 2>&1 | awk -v hlines=$hlines '
|
-I $(( secs * 1000 )) $target 2>&1 | awk -v hlines=$hlines '
|
||||||
BEGIN {
|
BEGIN {
|
||||||
htxt = sprintf("%-10s %-10s %5s %-10s %-10s %-10s %-10s %5s %5s",
|
htxt = sprintf("%-10s %-10s %5s %-10s %-10s %-10s %-10s %5s %5s",
|
||||||
"K_CYCLES", "K_INSTR", "IPC", "DTLB_WALKS", "ITLB_WALKS",
|
"K_CYCLES", "K_INSTR", "IPC", "DTLB_WALKS", "ITLB_WALKS",
|
||||||
@@ -63,7 +109,7 @@ perf stat -e cycles \
|
|||||||
header = hlines
|
header = hlines
|
||||||
}
|
}
|
||||||
ins = $2
|
ins = $2
|
||||||
if (cycles == 0) { cycles = 1 } # and PMCs are broken
|
if (cycles == 0) { cycles = 1 } # PMCs are broken, or no events
|
||||||
|
|
||||||
printf("%-10d %-10d %5.2f %-10d %-10d %-10d %-10d %5.2f %5.2f\n",
|
printf("%-10d %-10d %5.2f %-10d %-10d %-10d %-10d %5.2f %5.2f\n",
|
||||||
cycles / 1000, ins / 1000, ins / cycles,
|
cycles / 1000, ins / 1000, ins / cycles,
|
||||||
|
|||||||
Reference in new issue
Block a user