Application startup timing script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script allow you to test application startup times and compare them, | |
# including both native packaging (e.g. RPM or DEB) and snaps. You can test | |
# both cold startups (no data cached in memory) and hot startups (cached). | |
# If you have any suggestions for improvements, feel free to file a PR | |
# or email: snap-advocacy at canonical dot com. | |
# Version 1.0, Oct 2020 | |
######################### | |
##### Configuration ##### | |
######################### | |
# Application to install (may have different name for pkg and snap) | |
PTARGET="chromium-browser" | |
STARGET="chromium" | |
# Native package manager commands (change to match the target system) | |
# Example uses apt | |
PKGMGR="/usr/bin/apt" | |
PKGMGROPT="install -y" | |
SNAPCMD=`which snap` | |
# Snap commands (options can be empty) | |
# Example for SNAPOPTIONS="--channel=edge" | |
SNAPINST="$SNAPCMD install" | |
SNAPREFRESH="$SNAPCMD refresh" | |
SNAPOPTIONS="" | |
# Where to backup browser profile so user data is not accidentally destroyed | |
BACKUP=~/snap-testing-backup | |
# Tool to detect application window and close it | |
TIMER="xdotool" | |
# Log to save data | |
LOGF=~/startup-time-results.txt | |
##################### | |
##### Functions ##### | |
##################### | |
pkg_install() | |
{ | |
# If installed, the command will complete without changes | |
sudo $PKGMGR $PKGMGROPT $PTARGET | |
} | |
snap_install() | |
{ | |
# If installed and/or does not refresh, the commands will complete without changes | |
sudo $SNAPINST $SNAPOPTIONS $STARGET | |
sudo $SNAPREFRESH $SNAPOPTIONS $STARGET | |
} | |
timer_install() | |
{ | |
# If installed, the command will complete without changes | |
sudo $PKGMGR $PKGMGROPT $TIMER | |
} | |
drop_caches() | |
{ | |
for i in 1 2 3; do echo $i | sudo /usr/bin/tee /proc/sys/vm/drop_caches; done | |
sleep 2 | |
} | |
cp_profiles() | |
{ | |
/bin/cp -r ~/.config/chromium $BACKUP/bak-pkg-chromium-profile-`/bin/date +%x-%H-%M-%S` | |
/bin/cp -r ~/snap/chromium $BACKUP/bak-snap-chromium-profile-`/bin/date +%x-%H-%M-%S` | |
sleep 2 | |
} | |
detect_app_window() | |
{ | |
TIMERBIN=`which $TIMER` | |
id=$1 | |
for w in `$TIMERBIN search --sync --onlyvisible --class "$id"`; do $TIMERBIN getwindowpid $w | xargs kill; done | |
} | |
pkg_run() | |
{ | |
echo -e "Native package runtime results:\n" | /usr/bin/tee -a $LOGF | |
# EXplicitly calling binary under /usr/bin and not via which if snap is preferred in the PATH | |
detect_app_window $PTARGET & /usr/bin/time -a -o $LOGF /usr/bin/$PTARGET | |
echo -e "\n" | /usr/bin/tee -a $LOGF | |
sleep 2 | |
} | |
snap_run() | |
{ | |
echo -e "Snap package runtime results:\n" | /usr/bin/tee -a $LOGF | |
detect_app_window $STARGET & /usr/bin/time -a -o $LOGF $SNAPCMD run $STARGET | |
echo -e "\n" | /usr/bin/tee -a $LOGF | |
sleep 2 | |
} | |
################ | |
##### Main ##### | |
################ | |
# Uncomment the function below to run | |
#pkg_install | |
#snap_install | |
#timer_install | |
# Create log file | |
touch $LOGF | |
# Data backup (optional) | |
# Uncomment the function below to run | |
#cp_profiles | |
# Cold run | |
echo -e "Cold run:\n" | /usr/bin/tee -a $LOGF | |
# Uncomment the functions below to run | |
#drop_caches | |
#pkg_run | |
#snap_run | |
# Hot run | |
echo -e "Hot run:\n" | /usr/bin/tee -a $LOGF | |
# Uncomment the functions below to run | |
#pkg_run | |
#snap_run | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment