From 3aebc7e51cb62e7ae70da0a01770581a437f321b Mon Sep 17 00:00:00 2001 From: Davide Baldo Date: Wed, 20 Mar 2024 19:34:14 +0100 Subject: [PATCH] feat: added relay profiling and improved result readability --- Cargo.toml | 1 - tools/profile/README.md | 1 + tools/profile/portal.perf | 7 +++-- tools/profile/portal.valgrind.dhat | 7 +++-- tools/profile/portal_two_nodes.perf | 7 +++-- tools/profile/relay_portal.perf | 46 +++++++++++++++++++++++++++++ 6 files changed, 62 insertions(+), 7 deletions(-) create mode 100755 tools/profile/relay_portal.perf diff --git a/Cargo.toml b/Cargo.toml index 23a17e0e325..85edce3e7af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,6 @@ inherits = "test" debug = 1 strip = "none" inherits = "release" -force-frame-pointers = "yes" # compromise: minimal optimization on selected dependencies # to reduce cli bootstrap time by ~5x diff --git a/tools/profile/README.md b/tools/profile/README.md index 220da696169..7118015cc65 100644 --- a/tools/profile/README.md +++ b/tools/profile/README.md @@ -5,6 +5,7 @@ This directory contains tools for profiling ockam. Two scenarios for performance profiling: - `portal.perf` - local portal, within one node - `portal_two_nodes.perf` - two nodes, one inlet and outlet +- `relay_port.perf` - one node, one inlet and outlet passing through a relay And one scenario for heap profiling: - `portal.valgrind.dhat` - local portal, within one node diff --git a/tools/profile/portal.perf b/tools/profile/portal.perf index b271d6f3aa7..13fb0a275ec 100755 --- a/tools/profile/portal.perf +++ b/tools/profile/portal.perf @@ -12,9 +12,12 @@ fi set -e -cargo build --profile profiling -p ockam_command +if [ -z "${OCKAM}" ]; then + RUSTFLAGS="-C force-frame-pointers=yes" cargo build --profile profiling -p ockam_command + OCKAM=target/profiling/ockam +fi -OCKAM=target/profiling/ockam +"${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=$! diff --git a/tools/profile/portal.valgrind.dhat b/tools/profile/portal.valgrind.dhat index be003c3c670..f7f556bf2a7 100755 --- a/tools/profile/portal.valgrind.dhat +++ b/tools/profile/portal.valgrind.dhat @@ -12,9 +12,12 @@ fi set -e -cargo build --profile profiling -p ockam_command +if [ -z "${OCKAM}" ]; then + RUSTFLAGS="-C force-frame-pointers=yes" cargo build --profile profiling -p ockam_command + OCKAM=target/profiling/ockam +fi -OCKAM=target/profiling/ockam +"${OCKAM}" node delete portal -y >/dev/null 2>&1 || true export OCKAM_LOG_LEVEL=info valgrind --tool=dhat --trace-children=yes --dhat-out-file=/tmp/ockam.valgrind.dhat -- "${OCKAM}" node create portal diff --git a/tools/profile/portal_two_nodes.perf b/tools/profile/portal_two_nodes.perf index 7e97b5d77b3..f4e44207fdc 100755 --- a/tools/profile/portal_two_nodes.perf +++ b/tools/profile/portal_two_nodes.perf @@ -12,9 +12,12 @@ fi set -e -cargo build --profile profiling -p ockam_command +if [ -z "${OCKAM}" ]; then + RUSTFLAGS="-C force-frame-pointers=yes" cargo build --profile profiling -p ockam_command + OCKAM=target/profiling/ockam +fi -OCKAM=target/profiling/ockam +"${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.inlet.perf -- "${OCKAM}" node create inlet -f & perf record --call-graph dwarf -F 99 --output /tmp/ockam.outlet.perf -- "${OCKAM}" node create outlet -f & diff --git a/tools/profile/relay_portal.perf b/tools/profile/relay_portal.perf new file mode 100755 index 00000000000..db150e899b6 --- /dev/null +++ b/tools/profile/relay_portal.perf @@ -0,0 +1,46 @@ +#!/bin/bash + +if ! [ -x "$(command -v iperf3)" ]; then + echo 'Error: iperf3 is not installed.' >&2 + 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 +fi + +set -e + +if [ -z "${OCKAM}" ]; then + RUSTFLAGS="-C force-frame-pointers=yes" cargo build --profile profiling -p ockam_command + OCKAM=target/profiling/ockam +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=$! + +sleep 1 +"${OCKAM}" tcp-outlet create --to 5000 --at portal +"${OCKAM}" relay create --to portal +"${OCKAM}" tcp-inlet create --from 8000 --to /project/default/service/forward_to_default/secure/api/service/outlet --at portal + +iperf3 --server --port 5000 --one-off & +iperf3_server_pid=$! + +sleep 0.3 # wait for server to start +iperf3 --zerocopy --client 127.0.0.1 --port 8000 --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/"