summaryrefslogtreecommitdiff
path: root/subprojects/pixpat/scripts/build_profiles.sh
blob: 0ae6d639b6ea4a2e9e2c1f2f4fe021ecd2bb233f (plain)
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
#!/usr/bin/env bash
# Build every codegen profile under gcc+clang release and report .so sizes.
# Always wipes existing build dirs to ensure a clean configure.
# Profiles are discovered from pixpat-native/profiles/*.toml.

set -euo pipefail

# Meson setup flags applied to every (compiler × profile) build dir.
# Add new -D flags or buildtype overrides here.
MESON_SETUP_ARGS=(
	--buildtype=release
)

# name → toml path.
PROFILES=()
profile_dir="pixpat-native/profiles"
for toml in "$profile_dir"/*.toml; do
	[[ -e "$toml" ]] || continue
	name="$(basename "$toml" .toml)"
	PROFILES+=("$name:$toml")
done

COMPILERS=(
	"gcc:gcc:g++"
	"clang:clang:clang++"
)

build_one() {
	local cc_name=$1 cc=$2 cxx=$3 name=$4 toml=$5 log=$6
	local dir="build-$cc_name-$name"

	local setup_args=("${MESON_SETUP_ARGS[@]}")
	[[ -d "$dir/meson-info" ]] && setup_args+=(--wipe)
	setup_args+=("-Dconfig=$toml")

	# Capture meson output so we can show it on failure; on success discard
	# it and let ninja write its (warnings-only with --quiet) output instead.
	if ! CC=$cc CXX=$cxx meson setup "$dir" "${setup_args[@]}" >"$log" 2>&1; then
		return 1
	fi
	: >"$log"
	ninja -C "$dir" --quiet >"$log" 2>&1
}

pids=()
labels=()
logs=()
for comp in "${COMPILERS[@]}"; do
	IFS=: read -r cc_name cc cxx <<<"$comp"
	for entry in "${PROFILES[@]}"; do
		name="${entry%%:*}"
		toml="${entry#*:}"
		dir="build-$cc_name-$name"
		log=$(mktemp)
		echo "==> launching $dir"
		build_one "$cc_name" "$cc" "$cxx" "$name" "$toml" "$log" &
		pids+=($!)
		labels+=("$dir")
		logs+=("$log")
	done
done

failed=0
for i in "${!pids[@]}"; do
	if wait "${pids[$i]}"; then
		if [[ -s "${logs[$i]}" ]]; then
			echo "==> ${labels[$i]} ok (warnings):"
			cat "${logs[$i]}"
		else
			echo "==> ${labels[$i]} ok"
		fi
	else
		echo "==> ${labels[$i]} FAILED:"
		cat "${logs[$i]}"
		failed=1
	fi
	rm -f "${logs[$i]}"
done
(( failed == 0 )) || exit 1

CASES=(
	"RGB888 -> BGR888"
	"NV12 -> BGR888"
	"BGR888 -> NV12"
	"NV12 -> YUV420"
	"smpte -> BGR888"
	"smpte -> NV12"
	"kmstest -> BGR888"
)
LABELS=("RGB->BGR" "NV12->BGR" "BGR->NV12" "NV12->YUV" "smpte/BGR" "smpte/NV12" "kmstest/BGR")

PERF_TEST="pixpat-python/scripts/perf_test.py"

join_cases() {
	local out=""
	local c
	for c in "$@"; do
		out+="${out:+,}$c"
	done
	printf '%s' "$out"
}
cases_arg=$(join_cases "${CASES[@]}")

echo
echo "=== libpixpat.so.0.0.0 sizes + pixpat MP/s (release, --iters 5 --warmup 2) ==="
printf "%-28s  %10s" "build-dir" "bytes"
for lbl in "${LABELS[@]}"; do
	printf "  %10s" "$lbl"
done
echo

for comp in "${COMPILERS[@]}"; do
	cc_name="${comp%%:*}"
	for entry in "${PROFILES[@]}"; do
		name="${entry%%:*}"
		dir="build-$cc_name-$name"
		so="$dir/libpixpat.so.0.0.0"
		if [[ ! -f "$so" ]]; then
			printf "%-28s  %10s\n" "$dir" "MISSING"
			continue
		fi

		bytes=$(stat -c%s "$so")
		tsv=$(PIXPAT_LIB="$so" python3 "$PERF_TEST" \
			--tsv --iters 5 --warmup 2 \
			--cases "$cases_arg" 2>/dev/null || true)

		printf "%-28s  %10d" "$dir" "$bytes"
		for c in "${CASES[@]}"; do
			val=$(awk -F'\t' -v want="$c" '$1 == want { print $2; exit }' <<<"$tsv")
			printf "  %10s" "${val:--}"
		done
		echo
	done
done