diff --git a/scripts/24-bit-color.sh b/scripts/24-bit-color.sh new file mode 100755 index 00000000..161608fc --- /dev/null +++ b/scripts/24-bit-color.sh @@ -0,0 +1,101 @@ +#!/bin/bash +# This file was originally taken from iterm2 https://github.com/gnachman/iTerm2/blob/master/tests/24-bit-color.sh +# +# This file echoes a bunch of 24-bit color codes +# to the terminal to demonstrate its functionality. +# The foreground escape sequence is ^[38;2;;;m +# The background escape sequence is ^[48;2;;;m +# range from 0 to 255 inclusive. +# The escape sequence ^[0m returns output to default + +setBackgroundColor() +{ + #printf '\x1bPtmux;\x1b\x1b[48;2;%s;%s;%sm' $1 $2 $3 + printf '\x1b[48;2;%s;%s;%sm' $1 $2 $3 +} + +resetOutput() +{ + echo -en "\x1b[0m\n" +} + +# Gives a color $1/255 % along HSV +# Who knows what happens when $1 is outside 0-255 +# Echoes "$red $green $blue" where +# $red $green and $blue are integers +# ranging between 0 and 255 inclusive +rainbowColor() +{ + let h=$1/43 + let f=$1-43*$h + let t=$f*255/43 + let q=255-t + + if [ $h -eq 0 ] + then + echo "255 $t 0" + elif [ $h -eq 1 ] + then + echo "$q 255 0" + elif [ $h -eq 2 ] + then + echo "0 255 $t" + elif [ $h -eq 3 ] + then + echo "0 $q 255" + elif [ $h -eq 4 ] + then + echo "$t 0 255" + elif [ $h -eq 5 ] + then + echo "255 0 $q" + else + # execution should never reach here + echo "0 0 0" + fi +} + +for i in `seq 0 127`; do + setBackgroundColor $i 0 0 + echo -en " " +done +resetOutput +for i in `seq 255 -1 128`; do + setBackgroundColor $i 0 0 + echo -en " " +done +resetOutput + +for i in `seq 0 127`; do + setBackgroundColor 0 $i 0 + echo -n " " +done +resetOutput +for i in `seq 255 -1 128`; do + setBackgroundColor 0 $i 0 + echo -n " " +done +resetOutput + +for i in `seq 0 127`; do + setBackgroundColor 0 0 $i + echo -n " " +done +resetOutput +for i in `seq 255 -1 128`; do + setBackgroundColor 0 0 $i + echo -n " " +done +resetOutput + +for i in `seq 0 127`; do + setBackgroundColor `rainbowColor $i` + echo -n " " +done +resetOutput +for i in `seq 255 -1 128`; do + setBackgroundColor `rainbowColor $i` + echo -n " " +done +resetOutput + diff --git a/scripts/README.md b/scripts/README.md index 39897c30..a560b3b6 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -1,20 +1,26 @@ -scripts +Scripts ======= -There are two scripts included at the time this README was written, and they -both support flamegraph generation on Ubuntu. The first script installs the -required dependencies: +## Flamegraph + +Run the release version of Alacritty while recording call stacks. After the +Alacritty process exits, a flamegraph will be generated and it's URI printed +as the only output to STDOUT. ```sh -scripts/ubuntu-install-perf.sh +./create-flamegraph.sh ``` -The second script will run Alacritty while recording call stacks. After the -Alacritty process exits, a flamegraph will be generated and its URI printed. +Running this script depends on an installation of `perf`. + +## ANSI Color Tests + +We include a few scripts for testing the color of text inside a terminal. The +first shows various foreground and background varients. The second enumerates +all the colors of a standard terminal. The third enumerates the 24-bit colors. ```sh -scripts/create-flamegraph.sh +./fg-bg.sh +./colors.sh +./24-bit-colors.sh ``` - -**NOTE**: The _create-flamegraph.sh_ script is intended to be run from the -alacritty project root. diff --git a/scripts/colors.sh b/scripts/colors.sh new file mode 100755 index 00000000..436d149e --- /dev/null +++ b/scripts/colors.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +for x in {0..8}; do + for i in {30..37}; do + for a in {40..47}; do + echo -ne "\e[$x;$i;$a""m\\\e[$x;$i;$a""m\e[0;37;40m " + done + echo + done +done +echo "" diff --git a/scripts/create-flamegraph.sh b/scripts/create-flamegraph.sh index 8c03aa28..71af6a93 100755 --- a/scripts/create-flamegraph.sh +++ b/scripts/create-flamegraph.sh @@ -1,19 +1,38 @@ #!/usr/bin/env bash -# Make sure FlameGraph scripts are available -if [ ! -e ./FlameGraph ] +# 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 + git clone https://github.com/BrendanGregg/FlameGraph \ + $DIR/create-flamegraph/FlameGraph fi -if [ ! -e target/release/alacritty ] +# 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 -# This will block while alacritty runs -perf record -g -F 99 target/release/alacritty -perf script | ./FlameGraph/stackcollapse-perf.pl | ./FlameGraph/flamegraph.pl --width 1920 > alacritty.svg +# Make sure perf is available. +if [ ! -x "$(command -v perf)" ] +then + echo "Cannot find perf, please make sure it's installed" + exit 1 +fi -echo "Flame graph created at file://$(pwd)/alacritty.svg" +# 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" diff --git a/scripts/ubuntu-install-perf.sh b/scripts/ubuntu-install-perf.sh deleted file mode 100755 index 85670039..00000000 --- a/scripts/ubuntu-install-perf.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -set -v - -# Get kernel info -UNAME=$(uname -r) - -# Install linux tools for the perf binary -sudo apt-get install -y \ - linux-tools-common \ - linux-tools-generic \ - linux-tools-$UNAME