1#!/usr/bin/env bash
 2
 3# Notes for fixing this script if it's broken:
 4# - if you see an error about "can't find perf_6.1" you need to install `linux-perf` from the
 5#   version of Debian that matches the host (e.g. apt-get -t bookworm-backports install linux-perf)
 6# - if you see an error about `addr2line` you may need to install binutils
 7
 8set -euo pipefail
 9
10source script/lib/deploy-helpers.sh
11
12if [[ $# != 1 ]]; then
13  echo "Usage: $0 <production|staging>"
14  exit 1
15fi
16environment=$1
17
18target_zed_kube_cluster
19
20# 5s in production is ~200Mb..., in staging you probably want to bump this up.
21echo "Running perf on collab, collecting 5s of data..."
22
23kubectl -n $environment exec -it deployments/collab -- perf record -p 1 -g -m 64 --call-graph dwarf -- sleep 5
24
25run="collab-$environment-$(date -Iseconds)"
26echo "Processing data and downloading to '$run.perf'..."
27
28kubectl -n $environment exec -it deployments/collab -- perf --no-pager script > "$run.perf"
29
30which inferno-flamegraph 2>/dev/null || (echo "installing inferno..."; cargo install inferno)
31
32inferno-collapse-perf "$run.perf" | inferno-flamegraph > "$run.svg"
33open "./$run.svg"