Skip to content

Commit

Permalink
chore: added performance profiling for macos
Browse files Browse the repository at this point in the history
  • Loading branch information
davide-baldo committed Nov 10, 2024
1 parent 021ab69 commit 7eeaa16
Showing 1 changed file with 37 additions and 18 deletions.
55 changes: 37 additions & 18 deletions tools/profile/portal.perf
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ if ! [ -x "$(command -v iperf3)" ]; then
exit 1
fi

if ! [ -x "$(command -v perf)" ]; then
echo 'Error: perf is not installed. perf is linux-specific, see dtrace for macos.' >&2
exit 1
if [ "$(uname)" == "Darwin" ]; then
if ! [ -x "$(command -v xctrace)" ]; then
echo 'Error: xctrace is not installed.' >&2
exit 1
fi
else
if ! [ -x "$(command -v perf)" ]; then
echo 'Error: perf is not installed.' >&2
exit 1
fi
fi

set -e
Expand All @@ -19,27 +26,39 @@ fi

"${OCKAM}" node delete portal -y >/dev/null 2>&1 || true
export OCKAM_LOG_LEVEL=info
perf record --call-graph dwarf -F 99 --output /tmp/ockam.perf -- "${OCKAM}" node create portal -f &
perf_pid=$!
export OCKAM_OPENTELEMETRY_EXPORT=0

if [ "$(uname)" == "Darwin" ]; then
rm -rf /tmp/ockam.trace/
xctrace record --template 'CPU Counters' --output /tmp/ockam.trace --launch -- "${OCKAM}" node create portal -f &
trace_pid=$!
else
perf record --call-graph dwarf -F 99 --output /tmp/ockam.perf -- "${OCKAM}" node create portal -f &
perf_pid=$!
fi

sleep 1
"${OCKAM}" tcp-outlet create --to 5000 --at portal
"${OCKAM}" tcp-inlet create --from 8000 --to /secure/api/service/outlet --at portal
sleep 2
"${OCKAM}" tcp-outlet create --to 5500 --at portal
"${OCKAM}" tcp-inlet create --from 8200 --to /secure/api/service/outlet --at portal

iperf3 --server --port 5000 --one-off &
iperf3 --server --port 5500 --one-off &
iperf3_server_pid=$!

sleep 0.3 # wait for server to start
iperf3 --zerocopy --client 127.0.0.1 --port 8000 --time 60
iperf3 --zerocopy --client 127.0.0.1 --port 8200 --time 60

kill ${iperf3_server_pid}
"${OCKAM}" node delete portal -y

echo "Waiting for perf to finish writing /tmp/ockam.perf..."
wait ${perf_pid}

echo "Converting perf file to firefox profiler format, could take up to few minutes..."
perf script -F +pid --input /tmp/ockam.perf > /tmp/ockam.perf.firefox

echo "You can use firefox web profiler to open /tmp/ockam.perf.firefox file."
echo "https://profiler.firefox.com/"
if [ "$(uname)" == "Darwin" ]; then
echo "Waiting for xctrace to finish writing /tmp/ockam.trace..."
wait ${trace_pid}
echo "You can use XCode Instruments to open /tmp/ockam.trace"
else
echo "Waiting for perf to finish writing /tmp/ockam.perf..."
wait ${perf_pid}
echo "Converting perf file to firefox profiler format, could take up to few minutes..."
perf script -F +pid --input /tmp/ockam.perf > /tmp/ockam.perf.firefox
echo "You can use firefox web profiler to open /tmp/ockam.perf.firefox file."
echo "https://profiler.firefox.com/"
fi

0 comments on commit 7eeaa16

Please sign in to comment.