Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: added performance profiling for macos #8616

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading