From 73fd69fcb41add275db30ca135091930b640e7c4 Mon Sep 17 00:00:00 2001 From: Don Isaac Date: Wed, 8 Jan 2025 19:56:55 -0600 Subject: [PATCH] chore: add script to trace allocations with Instruments (#16191) --- scripts/trace.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 scripts/trace.sh diff --git a/scripts/trace.sh b/scripts/trace.sh new file mode 100644 index 0000000000..32655bc526 --- /dev/null +++ b/scripts/trace.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# @file trace.sh +# @summary build + run bun with Instruments. All args are forwarded to `bun-debug`. +# +# @description +# This script builds bun, signs it with debug entitlements, and runs it with an +# Allocations template. After running, a `.trace` folder will be created. Open +# it with `open foo.trace` to view it in Instruments. +# +# This script requires xcode command line tools to be installed and only works +# on MacOS. + +set -e -o pipefail + +BUN="bun-debug" +DEBUG_BUN="build/debug/${BUN}" + +file_to_run=$1 +if [[ -z $file_to_run ]]; then + echo "Usage: $0 [bun args]" + echo " $0 test [bun args]" + exit 1 +fi + +bun run build + +echo "Signing bun binary..." +codesign --entitlements $(realpath entitlements.debug.plist) --force --timestamp --sign - -vvvv --deep --strict ${DEBUG_BUN} + +export BUN_JSC_logJITCodeForPerf=1 +export BUN_JSC_collectExtraSamplingProfilerData=1 +export BUN_JSC_sampleCCode=1 +export BUN_JSC_alwaysGeneratePCToCodeOriginMap=1 + +echo "Tracing ${file_to_run}..." +xcrun xctrace record --template "Allocations" -output . --launch -- "./${DEBUG_BUN}" $file_to_run +# perf record -k 1 --sample-cpu -e cycles:u -j any --call-graph dwarf,16384 -F 499 -p (pgrep -f "${BUN}") + +# DEBUGINFOD_URLS="" perf inject --jit --input perf.data --output=perf.jit.data -v