-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathprofile-mac.sh
More file actions
executable file
·81 lines (71 loc) · 2.32 KB
/
profile-mac.sh
File metadata and controls
executable file
·81 lines (71 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env bash
#
# profile-mac.sh -- Run test_benchmark under Xcode Instruments on Apple Silicon
# (or any Mac with Xcode CLT).
#
# Usage:
# scripts/profile-mac.sh [--template NAME] [--frames N] [--warmup N]
# [--blitter fast|accurate] [--rom PATH] [--open]
#
# Defaults:
# template = "Time Profiler"
# frames = 600 warmup = 60 blitter = accurate
# rom = test/roms/yarc.j64
# --open = open the .trace bundle in Instruments when finished
#
# Common templates:
# "Time Profiler" -- where time is being spent (call tree / flame)
# "CPU Counters" -- Apple Silicon PMU (cycles, instr, branches, misses)
# "System Trace" -- syscalls, scheduler, VM events
#
set -euo pipefail
TEMPLATE="Time Profiler"
FRAMES=600
WARMUP=60
BLITTER=accurate
ROM="test/roms/yarc.j64"
OPEN_TRACE=0
while [ $# -gt 0 ]; do
case "$1" in
--template) TEMPLATE="$2"; shift 2 ;;
--frames) FRAMES="$2"; shift 2 ;;
--warmup) WARMUP="$2"; shift 2 ;;
--blitter) BLITTER="$2"; shift 2 ;;
--rom) ROM="$2"; shift 2 ;;
--open) OPEN_TRACE=1; shift ;;
-h|--help)
sed -n '2,20p' "$0"
exit 0 ;;
*)
echo "Unknown arg: $1" >&2
exit 2 ;;
esac
done
if ! command -v xctrace >/dev/null 2>&1; then
echo "xctrace not found. Install Xcode Command Line Tools: xcode-select --install" >&2
exit 1
fi
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
mkdir -p build
TRACE="build/profile-$(date +%Y%m%d-%H%M%S).trace"
# Make sure the core + harness are built (no BENCH_PROFILE; profiling
# instrumentation skews sampling results).
make -j"$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 4)" >/dev/null
cc -O2 -Wall -std=c99 -I. -I./libretro-common/include \
-o test/tools/test_benchmark test/tools/test_benchmark.c
CORE="./virtualjaguar_libretro.dylib"
HARNESS="./test/tools/test_benchmark"
echo ">>> xctrace template: $TEMPLATE"
echo ">>> trace output: $TRACE"
echo ">>> rom / blitter: $ROM / $BLITTER"
echo ">>> frames (+warmup): $FRAMES (+$WARMUP)"
xctrace record \
--template "$TEMPLATE" \
--output "$TRACE" \
--launch -- "$HARNESS" "$CORE" "$ROM" "$FRAMES" \
--warmup "$WARMUP" --blitter "$BLITTER"
echo ">>> trace written to $TRACE"
if [ "$OPEN_TRACE" = "1" ]; then
open "$TRACE"
fi