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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
#!/usr/bin/env zsh
# vim: sw=2 ts=2 et
#set -x
typeset -g ITERATIONS; ITERATIONS=20
function stats/usage () {
echo "Usage: $0 --zsh /path/to/zsh --antigen /path/to/antigen"
}
# Usage:
# stats/main $@
function stats/main () {
zparseopts -A opts z:=zsh -zsh:=zsh \
a:=antigen -antigen:=antigen || stats/usage
local zsh=$zsh[2]
local antigen=$antigen[2]
if [[ ! -f "$zsh" ]]; then
if (( ! $+commands[zsh] )); then
echo "Define the path to ZSH binary with '--zsh' argument. Given: $zsh"
exit 1
fi
fi
if [[ ! -d "$antigen" ]]; then
echo "Define a path to Antigen with '--antigen' argument. Given: $antigen"
exit 1
fi
echo "Using zsh: $zsh ($($zsh --version))"
echo "Using Antigen from: $antigen ($(cat $antigen/VERSION || echo unknown))"
local antigenrc=$(mktemp -d /tmp/dot-antigen-stats-XXXXXX)
local mtime=$antigenrc/stats-time.log
stats/configure $antigenrc $antigen
stats/exec $zsh $mtime $ITERATIONS
stats/parse $mtime
}
# Usage
# stats/configure $ADOTDIR /path/to/zshrc_antigenrc
function stats/configure () {
export ADOTDIR=$1
local configs=$2
export ZDOTDIR=$ADOTDIR
mkdir -p $ADOTDIR
cp $configs/tests/.antigenrc $ADOTDIR
# Fix path for non-container based stats
sed -e "s|/antigen/tests|$ADOTDIR|" -e "s|/antigen|$configs|" $configs/tests/.zshrc > $ADOTDIR/.zshrc
echo "Antigen configuration path: $ADOTDIR"
echo "Using zsh configuration from: $ADOTDIR/.zshrc"
echo "System information:"
uname -a
lscpu
echo
echo "Configuration:"
echo ">>>>"
cat $ADOTDIR/.zshrc
echo "<<<<"
echo
echo "Antigen configuration:"
echo ">>>>"
cat $ADOTDIR/.antigenrc
echo "<<<<"
echo
}
# Usage:
# stats/exec $path_to_zsh $path_to_output_file $iterations_count
function stats/exec() {
local zsh=$1
local output=$2
local iterations=${3:-20}
export ANTIGEN=$ADOTDIR
echo Installing bundles...
if [[ -d $ADOTDIR/bundles || -d $ADOTDIR/repos ]]; then
echo Bundles present in ADOTDIR.
fi
$zsh -ic 'exit'
if [[ $? != 0 ]]; then
exit 1
fi
echo
echo Installed bundles:
$zsh -ic 'antigen list'
if [[ $? != 0 ]]; then
exit 1
fi
echo
echo Performance testing...
:> $output
for x in $(seq 1 $iterations); do
(time $zsh -ic exit) 2>&1 | tr "\n" ' ' &>> $output
echo &>> $output
tail -1 $output
done
}
# Usage:
# stats/parse $path_to_output_file
function stats/parse() {
local data=$1
awk '{
sub("m","",$7); total += $7;
sub("m","", $1); user += $1;
sub("m", "", $3); sys += $3;
count++
} END {
printf "\nAverage:\ntotal %.3fs user %.3fs sys %.3fs\n", total/count, user/count, sys/count
}' $data
}
stats/main $@
|