aboutsummaryrefslogtreecommitdiff
path: root/scripts/create-flamegraph.sh
blob: ddfee81361158610e1d0a9580527264ace02cdf5 (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
#!/usr/bin/env bash

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

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

# Install cargo-flamegraph
installed_flamegraph=0
if [ ! -x "$(command -v cargo-flamegraph)" ]; then
    echo "cargo-flamegraph not installed; installing ..."
    cargo install flamegraph
    installed_flamegraph=1
fi

# Create flamegraph
cargo flamegraph --bin=alacritty -- $@

# Uninstall cargo-flamegraph if it has been installed with this script
if [ $installed_flamegraph == 1 ]; then
    read -p "Would you like to uninstall cargo-flamegraph? [Y/n] " -n 1 -r
    echo
    if [[ "$REPLY" =~ ^[^Nn]*$ ]]; then
        cargo uninstall flamegraph
    fi
fi