-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcreate-flamegraph
executable file
·43 lines (34 loc) · 1.26 KB
/
create-flamegraph
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
#!/bin/sh
set -e -u
# rm -Rf ../../target/release/deps/benchmark-*
# See CARGO_PROFILE_RELEASE_DEBUG=true for why CARGO_PROFILE_RELEASE_DEBUG=true
CARGO_PROFILE_BENCH_DEBUG=true CARGO_PROFILE_RELEASE_DEBUG=true cargo build --release --bench benchmark
# RUSTFLAGS='-g'
FILE_TO_RUN=`find ../../target/release/deps -type f -perm u=rwx | grep benchmark | grep -v iai`
FILTER=$1
echo "Running benchmark with filter $FILTER"
AS_ROOT=0
FLAMEGRAPH=flamegraph
if [ `uname` = Darwin ]; then
FLAMEGRAPH="sudo flamegraph"
AS_ROOT=1
fi
# https://bheisler.github.io/criterion.rs/book/user_guide/command_line_options.html
# --profile-time:
# To iterate each benchmark for a fixed length of time without saving, analyzing or
# plotting the results, use cargo bench -- --profile-time <num_seconds>. This is
# useful when profiling the benchmarks. It reduces the amount of unrelated clutter
# in the profiling results and prevents Criterion.rs' normal dynamic sampling logic
# from greatly increasing the runtime of the benchmarks.
$FLAMEGRAPH \
$FILE_TO_RUN \
--bench \
--profile-time 20 \
"$FILTER"
if [ $AS_ROOT = 1 ]; then
sudo chown $USER flamegraph.svg
fi
cp flamegraph.svg flamegraph-$FILTER.svg
if [ `which open` &> /dev/null ]; then
open flamegraph-$FILTER.svg
fi