-
Notifications
You must be signed in to change notification settings - Fork 162
/
benchmark.sh
executable file
·89 lines (78 loc) · 2.44 KB
/
benchmark.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
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
#!/bin/sh
set -eu
width=1920
height=1080
fps=60
timeout=180
video_url="https://google.github.io/mediapipe/images/selfie_segmentation_web.mp4"
for ffmpeg in ffmpeg avconv ""; do
test -n "$ffmpeg" || {
echo "This script needs ffmpeg or avconv."
exit 1
}
command -v "$ffmpeg" >/dev/null && break || :
done
# get sudo password and keep it active
sudo -v
( while sleep 1; do sudo -v; done; ) &
pids="$!"
# create file for test video
video="$(mktemp)"
# registister cleanup function
cleanup() {
rm -f -- "$video"
kill $pids; wait
sudo -- $SHELL -c 'modprobe -r v4l2loopback; modprobe v4l2loopback'
}
trap cleanup EXIT
# create the necessary v4l2loopback devices
sudo -- $SHELL -s <<EOF
modprobe -r v4l2loopback
modprobe v4l2loopback devices=2 exclusive_caps=1,1 video_nr=99,100
EOF
# download video and loop it to /dev/video99
wget -qO "$video" "$video_url"
"$ffmpeg" -hide_banner -loglevel quiet -hwaccel auto \
-re -stream_loop -1 -i "$video" \
-vf scale="$width:$height" -r "$fps" \
-f v4l2 -an -vcodec rawvideo -pix_fmt yuyv422 /dev/video99 &
pids="$pids $!"
sleep 3
git_head="$(git rev-parse HEAD)"
{
echo "${width}x${height}@$fps for $timeout seconds"
test $# -eq 0 || echo "extra arguments: $*"
echo "HEAD: $git_head"; echo
# system information
uname -srvmo
sed -n 's/^model name\s*:\s*//p' /proc/cpuinfo | sort | uniq -c; echo
# python information
python3 -c '
import importlib.metadata, sys
venv = (hasattr(sys, "real_prefix") or
(hasattr(sys, "base_prefix") and sys.base_prefix != sys.prefix))
print("python", sys.version)
print("virtualenv", venv)
print()
for module in sys.argv[1:]:
try:
print(module, importlib.metadata.version(module))
except importlib.metadata.PackageNotFoundError:
print(module, "not found")
' $(sed -rn 's/^([A-Z0-9][A-Z0-9._-]*[A-Z0-9]).*/\1/pi' requirements.txt); echo
# run fake.py for specified timeout and gather statistics
export PYTHONUNBUFFERED=yes
timeout --foreground --preserve-status -s QUIT "$timeout" \
./fake.py -w /dev/video99 -v /dev/video100 \
-W "$width" -H "$height" -F "$fps" --no-ondemand "$@" |
stdbuf -oL tr '\r' '\n' |
python3 -c '
import sys, statistics
fps = []
for line in sys.stdin:
if line.startswith("FPS:"):
fps.append(float(line.split(":")[-1].strip()))
print(fps[-1], end="\r", file=sys.stderr)
print("avg %.2f, stdev %.2f" %(statistics.mean(fps), statistics.stdev(fps)))
'
} | tee "benchmark.$git_head.txt"