summaryrefslogtreecommitdiffstats
path: root/scripts/create-flamegraph.sh
blob: 71af6a93efa80c2d187b2e499dc727f38a26bcfe (plain)
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
#!/usr/bin/env bash

# The full path to the script directory, regardless of pwd.
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)

# Current UNIX time.
TIME=$(date +%s)

# Make sure FlameGraph scripts are available.
if [ ! -e $DIR/FlameGraph ]
then
    git clone https://github.com/BrendanGregg/FlameGraph \
        $DIR/create-flamegraph/FlameGraph
fi

# Make sure a release build of Alacritty is available.
if [ ! -e $DIR/../target/release/alacritty ]
then
    echo "Must build alacritty first: cargo build --release"
    exit 1
fi

# Make sure perf is available.
if [ ! -x "$(command -v perf)" ]
then
    echo "Cannot find perf, please make sure it's installed"
    exit 1
fi

# Run perf, this will block while alacritty runs.
perf record -g -F 99 $DIR/../target/release/alacritty
perf script \
    | $DIR/create-flamegraph/FlameGraph/stackcollapse-perf.pl \
    | $DIR/create-flamegraph/FlameGraph/flamegraph.pl --width 1920 \
    > flame-$TIME.svg

# Tell users where the file is.
echo "Flame graph created at: file://$(pwd)/flame-$TIME.svg"