mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-07 05:43:14 +00:00
perf: add RPC auth profiling diagnostics (#5775)
perf: add rpc auth profiling diagnostics Co-authored-by: heihutu <heihutu@gmail.com> Co-authored-by: zhi22915 <qiuzgang@gmail.com>
This commit is contained in:
Executable
+79
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
PID=""
|
||||
DURATION_SECS=""
|
||||
OUTPUT=""
|
||||
RATE="999"
|
||||
PRESYMBOLICATE="true"
|
||||
|
||||
usage() {
|
||||
cat <<'USAGE'
|
||||
Usage: scripts/run_samply_attach_window.sh --pid <pid> --duration-secs <n> --output <profile.json.gz> [options]
|
||||
|
||||
Attach samply to an already-running process for a bounded window and force a
|
||||
Ctrl+C-style shutdown so samply writes the profile artifact.
|
||||
|
||||
Options:
|
||||
--pid <pid> Existing process id to profile.
|
||||
--duration-secs <n> Sampling window in seconds.
|
||||
--output <path> Profile output path.
|
||||
--rate <hz> Sampling rate. Default: 999.
|
||||
--no-presymbolicate Do not request samply's .syms.json sidecar.
|
||||
-h, --help Show this help.
|
||||
USAGE
|
||||
}
|
||||
|
||||
die() {
|
||||
echo "error: $*" >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--pid) PID="${2:-}"; shift 2 ;;
|
||||
--duration-secs) DURATION_SECS="${2:-}"; shift 2 ;;
|
||||
--output) OUTPUT="${2:-}"; shift 2 ;;
|
||||
--rate) RATE="${2:-}"; shift 2 ;;
|
||||
--no-presymbolicate) PRESYMBOLICATE="false"; shift ;;
|
||||
-h|--help) usage; exit 0 ;;
|
||||
*) die "unknown argument: $1" ;;
|
||||
esac
|
||||
done
|
||||
|
||||
[[ "$PID" =~ ^[0-9]+$ ]] || die "--pid must be a positive integer"
|
||||
[[ "$DURATION_SECS" =~ ^[0-9]+$ && "$DURATION_SECS" -gt 0 ]] || die "--duration-secs must be a positive integer"
|
||||
[[ "$RATE" =~ ^[0-9]+$ && "$RATE" -gt 0 ]] || die "--rate must be a positive integer"
|
||||
[[ -n "$OUTPUT" ]] || die "--output is required"
|
||||
kill -0 "$PID" 2>/dev/null || die "process $PID is not running"
|
||||
command -v timeout >/dev/null 2>&1 || die "timeout is required"
|
||||
command -v samply >/dev/null 2>&1 || die "samply is required"
|
||||
|
||||
mkdir -p "$(dirname "$OUTPUT")"
|
||||
|
||||
cmd=(samply record -p "$PID" -r "$RATE" --save-only)
|
||||
if [[ "$PRESYMBOLICATE" == "true" ]]; then
|
||||
cmd+=(--unstable-presymbolicate)
|
||||
fi
|
||||
cmd+=(-o "$OUTPUT")
|
||||
|
||||
set +e
|
||||
timeout -s INT --kill-after=10s "${DURATION_SECS}s" "${cmd[@]}"
|
||||
status=$?
|
||||
set -e
|
||||
|
||||
case "$status" in
|
||||
0|124|130) ;;
|
||||
*) exit "$status" ;;
|
||||
esac
|
||||
|
||||
[[ -s "$OUTPUT" ]] || die "samply did not write profile output: $OUTPUT"
|
||||
if [[ "$PRESYMBOLICATE" == "true" ]]; then
|
||||
syms_output="${OUTPUT%.gz}.syms.json"
|
||||
[[ -s "$syms_output" ]] || die "samply did not write symbol sidecar: $syms_output"
|
||||
fi
|
||||
|
||||
echo "profile=$OUTPUT"
|
||||
if [[ "$PRESYMBOLICATE" == "true" ]]; then
|
||||
echo "symbols=${OUTPUT%.gz}.syms.json"
|
||||
fi
|
||||
Executable
+71
@@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
RUNNER="${SCRIPT_DIR}/run_samply_attach_window.sh"
|
||||
TMP_DIR="$(mktemp -d)"
|
||||
cleanup() {
|
||||
if [[ -n "${TARGET_PID:-}" ]]; then
|
||||
kill "$TARGET_PID" 2>/dev/null || true
|
||||
wait "$TARGET_PID" 2>/dev/null || true
|
||||
fi
|
||||
rm -rf "$TMP_DIR"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
mkdir -p "$TMP_DIR/bin"
|
||||
cat >"$TMP_DIR/bin/samply" <<'MOCK'
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
out=""
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
-o) out="$2"; shift 2 ;;
|
||||
*) shift ;;
|
||||
esac
|
||||
done
|
||||
[[ -n "$out" ]] || exit 2
|
||||
write_outputs() {
|
||||
printf '{"profile":"ok"}\n' >"$out"
|
||||
printf '{"symbols":"ok"}\n' >"${out%.gz}.syms.json"
|
||||
exit 0
|
||||
}
|
||||
trap write_outputs INT TERM
|
||||
while true; do sleep 1; done
|
||||
MOCK
|
||||
chmod +x "$TMP_DIR/bin/samply"
|
||||
cat >"$TMP_DIR/bin/timeout" <<'MOCK'
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
-s) shift 2 ;;
|
||||
--kill-after=*) shift ;;
|
||||
*) break ;;
|
||||
esac
|
||||
done
|
||||
shift
|
||||
out=""
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
-o) out="$2"; shift 2 ;;
|
||||
*) shift ;;
|
||||
esac
|
||||
done
|
||||
[[ -n "$out" ]] || exit 2
|
||||
printf '{"profile":"ok"}\n' >"$out"
|
||||
printf '{"symbols":"ok"}\n' >"${out%.gz}.syms.json"
|
||||
exit 124
|
||||
MOCK
|
||||
chmod +x "$TMP_DIR/bin/timeout"
|
||||
|
||||
sleep 30 &
|
||||
TARGET_PID=$!
|
||||
|
||||
OUTPUT="$TMP_DIR/profile.json.gz"
|
||||
PATH="$TMP_DIR/bin:$PATH" "$RUNNER" --pid "$TARGET_PID" --duration-secs 1 --output "$OUTPUT" --rate 99 >"$TMP_DIR/run.out"
|
||||
|
||||
test -s "$OUTPUT"
|
||||
test -s "$TMP_DIR/profile.json.syms.json"
|
||||
grep -qx "profile=$OUTPUT" "$TMP_DIR/run.out"
|
||||
grep -qx "symbols=$TMP_DIR/profile.json.syms.json" "$TMP_DIR/run.out"
|
||||
Reference in New Issue
Block a user