diff --git a/tools/perf-ampere.sh b/tools/perf-ampere.sh new file mode 100644 index 00000000000..05114116849 --- /dev/null +++ b/tools/perf-ampere.sh @@ -0,0 +1,144 @@ +#!/bin/env bash + +set -euo pipefail + +set -x + +# Function to print help information +print_help() { + cat <&2 echo "Unknown parameter $1. Pass --help for valid options." + exit 1 + ;; + esac +done + +set +u + +if [[ -z "$OUTFILE" ]]; then + OUTFILE=flamegraph.html +fi +if [[ -z "$DATAFILE" ]]; then + DATAFILE=perf.data +fi +if [[ -z "$SPACETIME_PID" ]]; then + # -f allows us to get the args + # -e lets us see all users + SPACETIMES="$(ps -a -e -f | grep '\.*\' | grep -v '\')" + LINES="$(echo "$SPACETIMES" | wc -l)" + if [[ $LINES < 1 ]] ; then + >&2 echo "spacetime PID not found, is it running?" + exit 1 + elif [[ $LINES > 1 ]] ; then + >&2 echo "Multiple spacetime PIDs. Specify one with -z" + >&2 echo "$SPACETIMES" + exit 1 + fi + + SPACETIME_PID=$(echo "$SPACETIMES" | awk '{print $2}') +fi +if ! [[ $SPACETIME_PID =~ ^[0-9]+$ ]]; then + >&2 echo "Refusing to instrument suspicious-looking PID: $SPACETIME_PID" + exit 1 +fi +if [[ -z "$SLEEP_TIME" ]]; then + SLEEP_TIME=10 +fi + +echo "Instrumenting PID $SPACETIME_PID for $SLEEP_TIME seconds." +echo "Writing data to $DATAFILE and flamegraph to $OUTFILE." + +# Download the required FlameGraph scripts +if ! [ -d /home/ubuntu/FlameGraph ] ; then + git clone https://github.com/brendangregg/FlameGraph.git /home/ubuntu/FlameGraph + chown -R ubuntu:ubuntu /home/ubuntu/FlameGraph +fi + +# /home/ubuntu/bin/perf record -m 8192 --call-graph lbr --pid $SPACETIME_PID -o $DATAFILE sleep $SLEEP_TIME +# /home/ubuntu/bin/perf record --call-graph dwarf,4096 -m 8192 -e task-clock -F 999 \ + # --pid $SPACETIME_PID -o perf.data sleep 10 + +"$PERF_PATH" record -m 8192 -e task-clock -F 999 --call-graph fp \ + --pid $SPACETIME_PID -o perf.data sleep 30 +"$PERF_PATH" script -i perf.data \ + | /home/ubuntu/FlameGraph/stackcollapse-perf.pl \ + | /home/ubuntu/FlameGraph/flamegraph.pl > flamegraph.html +