-
Notifications
You must be signed in to change notification settings - Fork 9
/
dietpi-distro_comparison
165 lines (135 loc) · 5.61 KB
/
dietpi-distro_comparison
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/bash
# This script runs a few commands to check resource usage and performance stats.
# It aims to make the comparison of different OS/distro images against each other easy and transparent.
# It aims to replace the very outdated DietPi spreadsheet and comparisons, done in the past:
# - https://docs.google.com/spreadsheets/d/1mDHGZC-H6tU6_O8kuLTG8d4A8Nt7lV1Q7MXTR_6qw30/edit#gid=0
# - https://dietpi.com/phpbb/viewtopic.php?t=262
### IMPORTANT ###
# Execution instructions to assure fair, comparable and reproducible results on all tests:
# - Keep image, boot and system configs untouched, when possible, e.g. DHCP and CPU frequencies.
# - Only when there are significant differences, like one image necessarily requires a static IP to be set, do the same on DietPi via dietpi.txt, to make it better comparable.
# - Use the same console to run the script on both systems, e.g. local console, SSH or serial console.
# - Source the script, instead of executing it, to avoid additional processes and RAM usage for the script execution itself:
# curl -sSfLO https://raw.githubusercontent.com/MichaIng/hacks/main/dietpi-distro_comparison
# . ./dietpi-distro_comparison
# Wait for boot/login tasks to finish
while pgrep -f 'postboot' > /dev/null
do
echo 'Waiting for DietPi-Postboot to finish'
sleep 1
done
while pgrep -f 'dietpi-update' > /dev/null
do
echo 'Waiting for DietPi-Update to finish'
sleep 1
done
while pgrep -f 'apt-get' > /dev/null
do
echo 'Waiting for APT calls to finish'
sleep 1
done
# First of all, we bring the OS onto current package state and disable possibly generated swap files to make the comparison fair.
if [[ ! -f '/dietpi-distro_comparison.flag' ]]
then
echo -e '\nUpgrading all APT packages and removing all swap files...
NB: A flag file will be created to skip this on next script execution.\n'
# Disabling Bluetooth which leads to hanging boot on RPi's without onboard Bluetooth
systemctl is-failed hciuart &> /dev/null && systemctl disable --now hciuart
apt-get -y update
apt-get -y dist-upgrade
apt-get -y autopurge
[[ -f '/boot/dietpi/func/dietpi-set_swapfile' ]] && /boot/dietpi/func/dietpi-set_swapfile 0
if command -v dphys-swapfile > /dev/null
then
dphys-swapfile swapoff
dphys-swapfile uninstall
fi
while read -r file
do
swapoff "$file"
[[ -f $file ]] && rm -v "$file"
done < <(swapon --show NAME --noheadings | mawk '{print $1}')
sed -i '/[[:blank:]]swap[[:blank:]]/d' /etc/fstab
> /dietpi-distro_comparison.flag
read -rp 'The system will now reboot, press any key to continue...'
reboot
exit 0
fi
# Disk usage
total=0
for i in / /boot /boot/efi /boot/firmware
do
size=$(findmnt -Ufnrbo USED -M "$i")
(( $size )) || continue
echo "$i filesystem disk usage: \"findmnt -Ufnrbo USED -M $i\""
echo "$size bytes"
((total+=size))
done
echo "Total disk usage:"
echo "$((total/1024**2)) MiB"
echo
# Memory usage
# shellcheck disable=SC2016
echo 'Total memory usage: "free -th | mawk '\''/^Total:/{print $3}'\''"'
free -th | mawk '/^Total:/{print $3}'
echo
# Pre-installed packages
echo 'Number of pre-installed DEB packages: "dpkg --get-selections | wc -l"'
dpkg --get-selections | wc -l
echo
# Processes
# shellcheck disable=SC2016
echo 'Number of running processes: "echo $(( $(pstree -Ta | wc -l) - 3 ))" (minus echo, pstree and wc)'
echo $(( $(pstree -Ta | wc -l) - 3 ))
echo
# Boot duration
# shellcheck disable=SC2016
echo 'Boot duration: "systemd-analyze | mawk '\''{print $(NF-1)" "$NF;exit}'\''"'
systemd-analyze | mawk '{print $(NF-1)" "$NF;exit}'
echo
# Check for /tmp mount
tmp_mount=$(findmnt -Ufnro FSTYPE -M /tmp)
if [[ ! $tmp_mount ]]
then
echo '/tmp is no dedicated mount, which is bad since volatile files lead to rootfs disk I/O.'
elif [[ $tmp_mount == 'tmpfs' ]]
then
echo '/tmp is a tmpfs, which is good to reduce disk I/O.'
elif [[ $tmp_mount == 'ramfs' ]]
then
echo '/tmp is a ramfs, which is good to reduce disk I/O, but better switch to successor tmpfs.'
elif [[ $(findmnt -Ufnro SOURCE -M /tmp) == *'zram'* ]]
then
echo '/tmp is a zram mount, which is good to reduce disk I/O with minimal additional memory usage, but at the cost of additional CPU utilisation for (de)compression.'
else
echo '/tmp is a dedicated mount, which is good to reduce disk I/O on rootfs, but it is no (known) RAM disk.'
fi
echo
# Check for /var/log mount
log_mount=$(findmnt -Ufnro FSTYPE -M /var/log)
if [[ ! $log_mount ]]
then
echo '/var/log is no dedicated mount, which is bad for disk I/O, but logs are preserved on system crash.'
elif [[ $log_mount == 'tmpfs' ]]
then
echo '/var/log is a tmpfs, which is good to reduce disk I/O, but logs are lost on system crash.'
elif [[ $log_mount == 'ramfs' ]]
then
echo '/var/log is a ramfs, which is good to reduce disk I/O, but logs are lost on system crash. Also better switch to successor tmpfs.'
elif [[ $(findmnt -Ufnro SOURCE -M /var/log) == *'zram'* ]]
then
echo '/var/log is a zram mount, which is good to reduce disk I/O with minimal additional memory usage, but at the cost of additional CPU utilisation for (de)compression. Logs are however lost on system crash.'
else
echo '/var/log is a dedicated mount, which is good to reduce disk I/O on rootfs. Since it is no (known) RAM disk, logs create disk I/O on another drive, but survive system crashes.'
fi
echo
# SSH
if ss -tln | grep -q ':22'
then
echo 'This image comes with an SSH server pre-installed.'
[[ $SSH_TTY ]] && echo 'The script was executed from within an SSH session, which increases the process count above by one, compared to a local console session.
Assure to run the script via SSH as well on other systems you want to compare.'
else
echo 'This image has no SSH server pre-installed.'
fi
echo