forked from lynxthecat/cake-autorate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench_cpu.sh
executable file
·28 lines (16 loc) · 859 Bytes
/
bench_cpu.sh
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
#!/usr/bin/env bash
# Simple CPU benchmark for cake-autorate on OpenWrt
test_period_s=${1:-60} # Number of seconds to run CPU usage test
printf "Running CPU benchmark for test period of: %ds.\n...\n" "${test_period_s}"
service cake-autorate stop 2> /dev/null
service cake-autorate start
sleep 10 # Give 10 seconds for CPU usage to settle
tstart=${EPOCHREALTIME/.}
cstart=$(awk 'NR==2,NR==3{sum+=$2};END{print sum;}' /sys/fs/cgroup/services/cake-autorate/cpu.stat)
sleep "${test_period_s}"
tstop=${EPOCHREALTIME/.}
cstop=$(awk 'NR==2,NR==3{sum+=$2};END{print sum;}' /sys/fs/cgroup/services/cake-autorate/cpu.stat)
(( cpu_usage=(100000*(cstop - cstart)) / (tstop - tstart) ))
cpu_usage=000${cpu_usage}
printf "Average CPU usage over test period of %ds was: %.3f%%\n" "${test_period_s}" "${cpu_usage::-3}.${cpu_usage: -3}"
service cake-autorate stop