Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- Main() {
- # check whether we're running in monitoring or benchmark mode
- if [ "X$1" = "Xm" ]; then
- interval=$2
- MonitorBoard
- else
- SwitchToPerformance >/dev/null 2>&1
- InstallPrerequisits
- InitialMonitoring
- RunTinyMemBench
- Run7ZipBenchmark
- RunOpenSSLBenchmark
- FinalMonitoring
- fi
- } # Main
- SwitchToPerformance() {
- CPUCores=$(grep -c '^processor' /proc/cpuinfo)
- for ((i=0;i<CPUCores;i++)); do
- echo performance >/sys/devices/system/cpu/cpu${i}/cpufreq/scaling_governor
- done
- } # SwitchToPerformance
- MonitorBoard() {
- # In Armbian we can rely on /etc/armbianmonitor/datasources/soctemp
- if [ -f /etc/armbianmonitor/datasources/soctemp ]; then
- TempSource=/etc/armbianmonitor/datasources/soctemp
- else
- TempSource="$(mktemp /tmp/soctemp.XXXXXX)"
- if [[ -d "/sys/devices/platform/a20-tp-hwmon" ]]; then
- # Allwinner A20 with old 3.4 kernel
- ln -fs /sys/devices/platform/a20-tp-hwmon/temp1_input ${TempSource}
- elif [[ -f /sys/class/hwmon/hwmon0/temp1_input ]]; then
- # usual convention with modern kernels
- ln -fs /sys/class/hwmon/hwmon0/temp1_input ${TempSource}
- else
- # all other boards/kernels use the same sysfs node except of Actions Semi S500
- # so on LeMaker Guitar, Roseapple Pi or Allo Sparky it must read "thermal_zone1"
- ln -fs /sys/devices/virtual/thermal/thermal_zone0/temp ${TempSource}
- fi
- fi
- # Try to renice to 19 to not interfere with benchmark behaviour
- renice 19 $BASHPID >/dev/null 2>&1
- LastUserStat=0
- LastNiceStat=0
- LastSystemStat=0
- LastIdleStat=0
- LastIOWaitStat=0
- LastIrqStat=0
- LastSoftIrqStat=0
- LastCpuStatCheck=0
- LastTotal=0
- SleepInterval=${interval:-5}
- if [ -f /usr/bin/vcgencmd ]; then
- DisplayHeader="Time fake/real load %cpu %sys %usr %nice %io %irq CPU VCore"
- CPUs=raspberrypi
- elif [ -f /sys/devices/system/cpu/cpu4/cpufreq/cpuinfo_cur_freq ]; then
- DisplayHeader="Time big.LITTLE load %cpu %sys %usr %nice %io %irq CPU"
- CPUs=biglittle
- elif [ -f /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq ]; then
- DisplayHeader="Time CPU load %cpu %sys %usr %nice %io %irq CPU"
- CPUs=normal
- else
- DisplayHeader="Time CPU n/a load %cpu %sys %usr %nice %io %irq CPU"
- CPUs=notavailable
- fi
- [ -f "${TempSource}" ] || SocTemp='n/a'
- echo -e "${DisplayHeader}"
- while true ; do
- LoadAvg=$(cut -f1 -d" " </proc/loadavg)
- if [ "X${SocTemp}" != "Xn/a" ]; then
- read SocTemp <"${TempSource}"
- if [ ${SocTemp} -ge 1000 ]; then
- SocTemp=$(awk '{printf ("%0.1f",$1/1000); }' <<<${SocTemp})
- fi
- fi
- case ${CPUs} in
- raspberrypi)
- FakeFreq=$(awk '{printf ("%0.0f",$1/1000); }' </sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq) 2>/dev/null
- RealFreq=$(/usr/bin/vcgencmd measure_clock arm | awk -F"=" '{printf ("%0.0f",$2/1000000); }' )
- CoreVoltage=$(/usr/bin/vcgencmd measure_volts | cut -f2 -d= | sed 's/000//')
- ProcessStats
- echo -e "$(date "+%H:%M:%S"): $(printf "%4s" ${FakeFreq})/$(printf "%4s" ${RealFreq})MHz $(printf "%5s" ${LoadAvg}) ${procStats} $(printf "%4s" ${SocTemp})°C ${CoreVoltage}"
- ;;
- biglittle)
- BigFreq=$(awk '{printf ("%0.0f",$1/1000); }' </sys/devices/system/cpu/cpu4/cpufreq/cpuinfo_cur_freq) 2>/dev/null
- LittleFreq=$(awk '{printf ("%0.0f",$1/1000); }' </sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq) 2>/dev/null
- ProcessStats
- echo -e "$(date "+%H:%M:%S"): $(printf "%4s" ${BigFreq})/$(printf "%4s" ${LittleFreq})MHz $(printf "%5s" ${LoadAvg}) ${procStats} $(printf "%4s" ${SocTemp})°C"
- ;;
- normal)
- CpuFreq=$(awk '{printf ("%0.0f",$1/1000); }' </sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq) 2>/dev/null
- ProcessStats
- echo -e "$(date "+%H:%M:%S"): $(printf "%4s" ${CpuFreq})MHz $(printf "%5s" ${LoadAvg}) ${procStats} $(printf "%4s" ${SocTemp})°C"
- ;;
- notavailable)
- ProcessStats
- echo -e "$(date "+%H:%M:%S"): --- $(printf "%5s" ${LoadAvg}) ${procStats} $(printf "%4s" ${SocTemp})°C"
- ;;
- esac
- sleep ${SleepInterval}
- done
- } # MonitorBoard
- ProcessStats() {
- procStatLine=(`sed -n 's/^cpu\s//p' /proc/stat`)
- UserStat=${procStatLine[0]}
- NiceStat=${procStatLine[1]}
- SystemStat=${procStatLine[2]}
- IdleStat=${procStatLine[3]}
- IOWaitStat=${procStatLine[4]}
- IrqStat=${procStatLine[5]}
- SoftIrqStat=${procStatLine[6]}
- Total=0
- for eachstat in ${procStatLine[@]}; do
- Total=$(( ${Total} + ${eachstat} ))
- done
- UserDiff=$(( ${UserStat} - ${LastUserStat} ))
- NiceDiff=$(( ${NiceStat} - ${LastNiceStat} ))
- SystemDiff=$(( ${SystemStat} - ${LastSystemStat} ))
- IOWaitDiff=$(( ${IOWaitStat} - ${LastIOWaitStat} ))
- IrqDiff=$(( ${IrqStat} - ${LastIrqStat} ))
- SoftIrqDiff=$(( ${SoftIrqStat} - ${LastSoftIrqStat} ))
- diffIdle=$(( ${IdleStat} - ${LastIdleStat} ))
- diffTotal=$(( ${Total} - ${LastTotal} ))
- diffX=$(( ${diffTotal} - ${diffIdle} ))
- CPULoad=$(( ${diffX}* 100 / ${diffTotal} ))
- UserLoad=$(( ${UserDiff}* 100 / ${diffTotal} ))
- SystemLoad=$(( ${SystemDiff}* 100 / ${diffTotal} ))
- NiceLoad=$(( ${NiceDiff}* 100 / ${diffTotal} ))
- IOWaitLoad=$(( ${IOWaitDiff}* 100 / ${diffTotal} ))
- IrqCombined=$(( ${IrqDiff} + ${SoftIrqDiff} ))
- IrqCombinedLoad=$(( ${IrqCombined}* 100 / ${diffTotal} ))
- LastUserStat=${UserStat}
- LastNiceStat=${NiceStat}
- LastSystemStat=${SystemStat}
- LastIdleStat=${IdleStat}
- LastIOWaitStat=${IOWaitStat}
- LastIrqStat=${IrqStat}
- LastSoftIrqStat=${SoftIrqStat}
- LastTotal=${Total}
- procStats=$(echo -e "$(printf "%3s" ${CPULoad})%$(printf "%4s" ${SystemLoad})%$(printf "%4s" ${UserLoad})%$(printf "%4s" ${NiceLoad})%$(printf "%4s" ${IOWaitLoad})%$(printf "%4s" ${IrqCombinedLoad})%")
- } # ProcessStats
- InstallPrerequisits() {
- echo -e "Installing needed tools. This may take some time...\c"
- SevenZip=$(which 7za || which 7zr)
- [ -z "${SevenZip}" ] && apt -f -qq -y install p7zip && SevenZip=/usr/bin/7zr >/dev/null 2>&1
- [ -z "${SevenZip}" ] && (echo "No 7-zip binary found and could not be installed. Aborting" >&2 ; exit 1)
- which iostat >/dev/null 2>&1 || apt -f -qq -y install sysstat >/dev/null 2>&1
- which git >/dev/null 2>&1 || apt -f -qq -y install git >/dev/null 2>&1
- which openssl >/dev/null 2>&1 || apt -f -qq -y install openssl >/dev/null 2>&1
- # get/build tinymembench if not already there
- if [ ! -x /tmp/tinymembench/tinymembench ]; then
- cd /tmp
- git clone https://github.com/ssvb/tinymembench >/dev/null 2>&1
- cd tinymembench
- make >/dev/null 2>&1
- fi
- } # InstallPrerequisits
- InitialMonitoring() {
- TempDir="$(mktemp -d /tmp/${0##*/}.XXXXXX)"
- TempLog="${TempDir}/temp.log"
- ResultLog="${TempDir}/results.log"
- MonitorLog="${TempDir}/monitor.log"
- trap "rm -rf \"${TempDir}\" ; exit 0" 0 1 2 3 15
- [ -f /etc/armbian-release ] && (grep -v "#" /etc/armbian-release ; echo "") >${ResultLog}
- which lsb_release >/dev/null 2>&1 && (lsb_release -a 2>/dev/null) >>${ResultLog}
- [ -f /etc/armbian-release ] || echo -e "Architecture:\t$(dpkg --print-architecture)\n" >>${ResultLog}
- echo -e "$(uname -a)\n\n$(uptime)\n\n$(iostat)\n\n$(free -h)\n\n$(cat /proc/swaps 2>/dev/null)\n" \
- >>${ResultLog}
- # Check cpufreq statistics prior and after benchmark to detect throttling (won't work on
- # the RPi since RPi Trading folks are cheaters. Cpufreq support via sysfs is bogus and
- # with latest ThreadX (firmware) update they even cheat wrt 'vcgencmd get_throttled'
- # https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=217056#p1334921
- find /sys -name time_in_state | while read ; do
- Number=$(echo ${REPLY} | tr -c -d '[:digit:]')
- Entries=$(wc -l ${REPLY} | awk -F" " '{print $1}')
- head -n $(( ${Entries} - 1 )) ${REPLY} >${TempDir}/time_in_state_before_${Number}
- done
- } # InitialMonitoring
- RunTinyMemBench() {
- echo -e " Done.\nExecuting tinymembench. This will take a long time...\c"
- echo -e "System health while running tinymembench:\n" >${MonitorLog}
- "${0}" m 60 >>${MonitorLog} &
- MonitoringPID=$!
- sleep 10
- if [ ${CPUCores} -gt 4 ]; then
- # big.LITTLE SoC, we execute one time on a little and one time on a big core
- echo -e "Executing tinymembench on a little core:\n" >${TempLog}
- taskset -c 0 /tmp/tinymembench/tinymembench >>${TempLog} 2>&1
- echo -e "\nExecuting tinymembench on a big core:\n" >>${TempLog}
- taskset -c $(( ${CPUCores} -1 )) /tmp/tinymembench/tinymembench >>${TempLog} 2>&1
- else
- /tmp/tinymembench/tinymembench >${TempLog} 2>&1
- fi
- kill ${MonitoringPID}
- cat ${TempLog} >>${ResultLog}
- } # RunTinyMemBench
- Run7ZipBenchmark() {
- echo -e " Done.\nExecuting 7-zip benchmark. This will take a long time...\c"
- echo -e "\nSystem health while running 7-zip single core benchmark:\n" >>${MonitorLog}
- echo -e "\c" >${TempLog}
- "${0}" m 15 >>${MonitorLog} &
- MonitoringPID=$!
- if [ ${CPUCores} -gt 4 ]; then
- # big.LITTLE SoC, we execute one time on a little and one time on a big core
- taskset -c 0 "${SevenZip}" b >>${TempLog}
- taskset -c $(( ${CPUCores} - 1 )) "${SevenZip}" b >>${TempLog}
- else
- taskset -c 0 "${SevenZip}" b >>${TempLog}
- fi
- kill ${MonitoringPID}
- cat ${TempLog} >>${ResultLog}
- echo -e "\nSystem health while running 7-zip multi core benchmark:\n" >>${MonitorLog}
- echo -e "\c" >${TempLog}
- "${0}" m 45 >>${MonitorLog} &
- MonitoringPID=$!
- RunHowManyTimes=3
- sleep 10
- for ((i=1;i<=RunHowManyTimes;i++)); do
- "${SevenZip}" b >>${TempLog}
- done
- kill ${MonitoringPID}
- cat ${TempLog} >>${ResultLog}
- sed -i 's/|//' ${TempLog}
- CompScore=$(awk -F" " '/^Avr:/ {print $4}' <${TempLog} | tr '\n' ', ' | sed 's/,$//')
- DecompScore=$(awk -F" " '/^Avr:/ {print $7}' <${TempLog} | tr '\n' ', ' | sed 's/,$//')
- TotScore=$(awk -F" " '/^Tot:/ {print $4}' <${TempLog} | tr '\n' ', ' | sed 's/,$//')
- echo -e "\nCompression: ${CompScore}" >>${ResultLog}
- echo -e "Decompression: ${DecompScore}" >>${ResultLog}
- echo -e "Total: ${TotScore}\n" >>${ResultLog}
- } # Run7ZipBenchmark
- RunOpenSSLBenchmark() {
- echo -e " Done.\nExecuting OpenSSL benchmark. This will take a long time...\c"
- echo -e "\nSystem health while running OpenSSL benchmark:\n" >>${MonitorLog}
- "${0}" m 10 >>${MonitorLog} &
- MonitoringPID=$!
- sleep 10
- for i in 128 192 256 ; do
- if [ ${CPUCores} -gt 4 ]; then
- # big.LITTLE SoC, we execute one time on a little and one time on a big core
- taskset -c 0 openssl speed -elapsed -evp aes-${i}-cbc 2>/dev/null
- taskset -c $(( ${CPUCores} -1 )) openssl speed -elapsed -evp aes-${i}-cbc 2>/dev/null
- else
- openssl speed -elapsed -evp aes-${i}-cbc 2>/dev/null
- openssl speed -elapsed -evp aes-${i}-cbc 2>/dev/null
- fi
- done >${TempLog}
- kill ${MonitoringPID}
- echo -e "$(openssl version)\n$(grep '^type' ${TempLog} | head -n1)" >>${ResultLog}
- grep '^aes-' ${TempLog} >>${ResultLog}
- } # RunOpenSSLBenchmark
- FinalMonitoring() {
- echo -e " Done.\n"
- [ ${CPUCores} -gt 4 ] && BigLittle=" (on big.LITTLE systems measured individually)"
- find /sys -name time_in_state | while read ; do
- Number=$(echo ${REPLY} | tr -c -d '[:digit:]')
- Entries=$(wc -l ${REPLY} | awk -F" " '{print $1}')
- head -n $(( ${Entries} - 1 )) ${REPLY} >${TempDir}/time_in_state_after_${Number}
- diff ${TempDir}/time_in_state_after_${Number} ${TempDir}/time_in_state_before_${Number} >/dev/null 2>&1 \
- || echo -e "ATTENTION: Throttling occured on CPU cluster ${Number}. Check the uploaded log for details."
- done
- echo -e "\nBelow benchmark results:\n"
- echo -e "\n\nMonitoring data for each run:\n" >>${ResultLog}
- cat ${MonitorLog} >>${ResultLog}
- echo -e "\n\n$(iostat)\n\n$(free -h)\n\n$(cat /proc/swaps 2>/dev/null)\n" >>${ResultLog}
- [ -f /boot/config.txt ] && echo -e "/boot/config.txt:\n$(grep -v '#' /boot/config.txt | sed '/^\s*$/d')\n" >>${ResultLog}
- UploadURL=$(curl -s -F 'f:1=<-' ix.io <${ResultLog} 2>/dev/null || curl -s -F 'f:1=<-' ix.io <${ResultLog} 2>/dev/null)
- echo -e "Memory performance${BigLittle}:"
- awk -F" " '/^ standard/ {print $2": "$4" "$5" "$6}' <${ResultLog}
- echo -e "\n7-zip total scores (three runs): $(awk -F" " '/^Total:/ {print $2}' ${ResultLog})"
- echo -e "\nOpenSSL results${BigLittle}:\n$(grep '^type' ${TempLog} | head -n1)"
- grep '^aes-' ${TempLog}
- echo -e "\nFull results uploaded to ${UploadURL}. Please check the log for anomalies (e.g. swapping\nor throttling happenend) and otherwise share this URL.\n"
- } # FinalMonitoring
- Main "$@"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement