mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
pgo: replace meson-pgo.sh with several script primitives
All scripts are in the ‘pgo’ directory:
* options: command line options for generate-alt-random-writes.py,
sourced by other scripts.
* pgo.sh: top-level script, generates a meson build directory, selects
a PGO method, generates the profiling data, re-configures the meson
build directory and does the final build.
This script is intended to be used by end-users, and shows _how_ to
integrate the script primitives.
Build servers will most likely *not* want to use this script as-is.
* partial.sh: generates alt-random-write data and runs “foot{,client}
--version”, and then feeds the alt-random data to the PGO helper
binary. Does not require a running Wayland session. Touches
$blddir/pgo-ok on success.
* full-inner.sh: runs “footclient --version”, and then a complex
“foot” command that first generates alt-random-write data, and then
“cat’s” it. Requires a running Wayland session, *but*, this script
is usually not called directly (see below). Touches $blddir/pgo-ok
onsucces..
* full-current-session.sh: runs full-inner.sh. That is, it runs foot
in the currently running Wayland session. Note that this will pop up a
foot window.
* full-headless-sway.sh: generates a custom Sway configuration that
exec’s foot-headless-sway-inner.sh (see below), and then executes a
headless Sway. In other words, this script does a *full* PGO build,
but *without* requiring a running Wayland session. Requires Sway >=
1.6.2.
* full-headless-sway.sh: runs full-inner.sh + “swaymsg exit”.
To do a custom PGO build, without using pgo.sh, you’d need to:
CFLAGS=”$CFLAGS -O3” meson --buildtype=release -Db_lto=true
meson configure -Db_pgo=generate
ninja
ninja test (only needed if tllist+fcft are built as subprojects)
Run *one* of:
- partial.sh
- full-current-session.sh
- full-headless-sway.sh
meson configure -D b_pgo=use
ninja
This commit is contained in:
parent
540310924b
commit
a43ae0d098
8 changed files with 202 additions and 154 deletions
154
meson-pgo.sh
154
meson-pgo.sh
|
|
@ -1,154 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# Requirements:
|
|
||||||
#
|
|
||||||
# * all: build directory must not exist; it is created by the script
|
|
||||||
# * all: LC_CTYPE must be set to an UTF-8 locale
|
|
||||||
# * full*: must have at least one font installed
|
|
||||||
# * full-headless-sway: Sway 1.6.2 must be installed
|
|
||||||
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
usage_and_die() {
|
|
||||||
echo "Usage: ${0} none|partial|full|full-headless-sway|[auto] <source-dir> <build-dir>"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
[ ${#} -ge 3 ] || usage_and_die
|
|
||||||
|
|
||||||
mode=${1}
|
|
||||||
source_dir=$(realpath "${2}")
|
|
||||||
build_dir=$(realpath "${3}")
|
|
||||||
shift 3
|
|
||||||
|
|
||||||
# meson will complain if source dir is invalid
|
|
||||||
|
|
||||||
if [ -d "${build_dir}" ]; then
|
|
||||||
echo "${build_dir}: build directory already exists"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
compiler=other
|
|
||||||
do_pgo=no
|
|
||||||
|
|
||||||
CFLAGS="${CFLAGS} -O3"
|
|
||||||
|
|
||||||
case $(${CC-cc} --version) in
|
|
||||||
*GCC*)
|
|
||||||
compiler=gcc
|
|
||||||
do_pgo=yes
|
|
||||||
;;
|
|
||||||
|
|
||||||
*clang*)
|
|
||||||
compiler=clang
|
|
||||||
|
|
||||||
if command -v llvm-profdata > /dev/null; then
|
|
||||||
do_pgo=yes
|
|
||||||
CFLAGS="${CFLAGS} -Wno-ignored-optimization-argument"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
case ${mode} in
|
|
||||||
partial|full|full-headless-sway)
|
|
||||||
;;
|
|
||||||
|
|
||||||
none)
|
|
||||||
do_pgo=no
|
|
||||||
;;
|
|
||||||
|
|
||||||
auto)
|
|
||||||
if command -v sway > /dev/null; then
|
|
||||||
mode=full-headless-sway
|
|
||||||
elif [ -n "${WAYLAND_DISPLAY+x}" ]; then
|
|
||||||
mode=full
|
|
||||||
else
|
|
||||||
mode=partial
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
|
|
||||||
*)
|
|
||||||
usage_and_die
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# echo "source: ${source_dir}"
|
|
||||||
# echo "build: ${build_dir}"
|
|
||||||
# echo "compiler: ${compiler}"
|
|
||||||
# echo "mode: ${mode}"
|
|
||||||
|
|
||||||
export CFLAGS
|
|
||||||
meson "${@}" "${build_dir}"
|
|
||||||
|
|
||||||
if [ ${do_pgo} = yes ]; then
|
|
||||||
find . -name "*.gcda" -delete
|
|
||||||
meson configure "${build_dir}" -Db_pgo=generate
|
|
||||||
ninja -C "${build_dir}"
|
|
||||||
|
|
||||||
# If fcft/tllist are subprojects, we need to ensure their tests
|
|
||||||
# have been executed, or we’ll get “profile count data file not
|
|
||||||
# found” errors.
|
|
||||||
ninja -C "${build_dir}" test
|
|
||||||
|
|
||||||
script_options="--scroll --scroll-region --colors-regular --colors-bright --colors-256 --colors-rgb --attr-bold --attr-italic --attr-underline --sixel"
|
|
||||||
|
|
||||||
tmp_file=$(mktemp)
|
|
||||||
pwd=$(pwd)
|
|
||||||
|
|
||||||
cleanup() {
|
|
||||||
rm -f "${tmp_file}"
|
|
||||||
cd "${pwd}"
|
|
||||||
}
|
|
||||||
trap cleanup EXIT INT HUP TERM
|
|
||||||
|
|
||||||
cd "${build_dir}"
|
|
||||||
case ${mode} in
|
|
||||||
full)
|
|
||||||
./footclient --version
|
|
||||||
./foot \
|
|
||||||
--config=/dev/null \
|
|
||||||
--term=xterm \
|
|
||||||
sh -c "${source_dir}/scripts/generate-alt-random-writes.py ${script_options} ${tmp_file} && cat ${tmp_file}"
|
|
||||||
;;
|
|
||||||
|
|
||||||
full-headless-sway)
|
|
||||||
./footclient --version
|
|
||||||
|
|
||||||
runtime_dir=$(mktemp -d)
|
|
||||||
sway_conf=$(mktemp)
|
|
||||||
|
|
||||||
echo "exec ${build_dir}/foot -o tweak.render-timer=log --config=/dev/null --term=xterm sh -c \"${source_dir}/scripts/generate-alt-random-writes.py ${script_options} ${tmp_file} && cat ${tmp_file}\" && swaymsg exit" > "${sway_conf}"
|
|
||||||
export XDG_RUNTIME_DIR=${runtime_dir}
|
|
||||||
export WLR_BACKENDS=headless
|
|
||||||
|
|
||||||
sway -c "${sway_conf}"
|
|
||||||
|
|
||||||
rm "${sway_conf}"
|
|
||||||
rm -rf "${runtime_dir}"
|
|
||||||
;;
|
|
||||||
|
|
||||||
partial)
|
|
||||||
./footclient --version
|
|
||||||
./foot --version
|
|
||||||
"${source_dir}"/scripts/generate-alt-random-writes.py \
|
|
||||||
--rows=67 \
|
|
||||||
--cols=135 \
|
|
||||||
${script_options} \
|
|
||||||
"${tmp_file}"
|
|
||||||
./pgo "${tmp_file}"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
cd "${pwd}"
|
|
||||||
rm "${tmp_file}"
|
|
||||||
|
|
||||||
if [ ${compiler} = clang ]; then
|
|
||||||
llvm-profdata \
|
|
||||||
merge \
|
|
||||||
"${build_dir}"/default_*.profraw \
|
|
||||||
--output="${build_dir}"/default.profdata
|
|
||||||
fi
|
|
||||||
|
|
||||||
meson configure "${build_dir}" -Db_pgo=use
|
|
||||||
fi
|
|
||||||
8
pgo/full-current-session.sh
Executable file
8
pgo/full-current-session.sh
Executable file
|
|
@ -0,0 +1,8 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
srcdir=$(realpath "${1}")
|
||||||
|
blddir=$(realpath "${2}")
|
||||||
|
|
||||||
|
"${srcdir}"/pgo/full-inner.sh "${srcdir}" "${blddir}"
|
||||||
9
pgo/full-headless-sway-inner.sh
Executable file
9
pgo/full-headless-sway-inner.sh
Executable file
|
|
@ -0,0 +1,9 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -u
|
||||||
|
|
||||||
|
srcdir=$(realpath "${1}")
|
||||||
|
blddir=$(realpath "${2}")
|
||||||
|
|
||||||
|
"${srcdir}"/pgo/full-inner.sh "${srcdir}" "${blddir}"
|
||||||
|
swaymsg exit
|
||||||
24
pgo/full-headless-sway.sh
Executable file
24
pgo/full-headless-sway.sh
Executable file
|
|
@ -0,0 +1,24 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
srcdir=$(realpath "${1}")
|
||||||
|
blddir=$(realpath "${2}")
|
||||||
|
|
||||||
|
runtime_dir=$(mktemp -d)
|
||||||
|
sway_conf=$(mktemp)
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
rm -f "${sway_conf}"
|
||||||
|
rm -rf "${runtime_dir}"
|
||||||
|
}
|
||||||
|
trap cleanup EXIT INT HUP TERM
|
||||||
|
|
||||||
|
# Generate a custom config that executes our generate-pgo-data script
|
||||||
|
> "${sway_conf}" echo "exec '${srcdir}'/pgo/full-headless-sway-inner.sh '${srcdir}' '${blddir}'"
|
||||||
|
|
||||||
|
# Run Sway. full-headless-sway-inner.sh ends with a ‘swaymsg exit’
|
||||||
|
XDG_RUNTIME_DIR="${runtime_dir}" WLR_BACKENDS=headless sway -c "${sway_conf}"
|
||||||
|
|
||||||
|
# Sway’s exit code doesn’t reflect our script’s exit code
|
||||||
|
[ -f "${blddir}"/pgo-ok ] || exit 1
|
||||||
31
pgo/full-inner.sh
Executable file
31
pgo/full-inner.sh
Executable file
|
|
@ -0,0 +1,31 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
srcdir=$(realpath "${1}")
|
||||||
|
blddir=$(realpath "${2}")
|
||||||
|
|
||||||
|
. "${srcdir}"/pgo/options
|
||||||
|
|
||||||
|
pgo_data=$(mktemp)
|
||||||
|
trap "rm -f ${pgo_data}" EXIT INT HUP TERM
|
||||||
|
|
||||||
|
rm -f "${blddir}"/pgo-ok
|
||||||
|
|
||||||
|
# To ensure profiling data is generated in the build directory
|
||||||
|
cd "${blddir}"
|
||||||
|
|
||||||
|
LC_CTYPE=en_US.UTF-8 "${blddir}"/footclient --version
|
||||||
|
LC_CTYPE=en_US.UTF-8 "${blddir}"/foot \
|
||||||
|
-o tweak.render-timer=log \
|
||||||
|
--config=/dev/null \
|
||||||
|
--term=xterm \
|
||||||
|
sh -c "
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
'${srcdir}/scripts/generate-alt-random-writes.py' \
|
||||||
|
${script_options} \"${pgo_data}\"
|
||||||
|
|
||||||
|
cat \"${pgo_data}\"
|
||||||
|
"
|
||||||
|
touch "${blddir}"/pgo-ok
|
||||||
1
pgo/options
Normal file
1
pgo/options
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
script_options="--scroll --scroll-region --colors-regular --colors-bright --colors-256 --colors-rgb --attr-bold --attr-italic --attr-underline --sixel"
|
||||||
28
pgo/partial.sh
Executable file
28
pgo/partial.sh
Executable file
|
|
@ -0,0 +1,28 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
srcdir=$(realpath "${1}")
|
||||||
|
blddir=$(realpath "${2}")
|
||||||
|
|
||||||
|
. "${srcdir}"/pgo/options
|
||||||
|
|
||||||
|
pgo_data=$(mktemp)
|
||||||
|
trap "rm -f ${pgo_data}" EXIT INT HUP TERM
|
||||||
|
|
||||||
|
rm -f "${blddir}"/pgo-ok
|
||||||
|
|
||||||
|
"${srcdir}"/scripts/generate-alt-random-writes.py \
|
||||||
|
--rows=67 \
|
||||||
|
--cols=135 \
|
||||||
|
${script_options} \
|
||||||
|
"${pgo_data}"
|
||||||
|
|
||||||
|
# To ensure profiling data is generated in the build directory
|
||||||
|
cd "${blddir}"
|
||||||
|
|
||||||
|
"${blddir}"/footclient --version
|
||||||
|
"${blddir}"/foot --version
|
||||||
|
"${blddir}"/pgo "${pgo_data}"
|
||||||
|
|
||||||
|
touch "${blddir}"/pgo-ok
|
||||||
101
pgo/pgo.sh
Executable file
101
pgo/pgo.sh
Executable file
|
|
@ -0,0 +1,101 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
usage_and_die() {
|
||||||
|
echo "Usage: ${0} none|partial|full-current-session|full-headless-sway|[auto] <source-dir> <build-dir> [meson options]"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
[ ${#} -ge 3 ] || usage_and_die
|
||||||
|
|
||||||
|
mode=${1}
|
||||||
|
srcdir=$(realpath "${2}")
|
||||||
|
blddir=$(realpath "${3}")
|
||||||
|
shift 3
|
||||||
|
|
||||||
|
if [ -e "${blddir}" ]; then
|
||||||
|
echo "error: ${blddir}: build directory already exists"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
compiler=other
|
||||||
|
do_pgo=no
|
||||||
|
|
||||||
|
CFLAGS="${CFLAGS-} -O3"
|
||||||
|
|
||||||
|
case $(${CC-cc} --version) in
|
||||||
|
*GCC*)
|
||||||
|
compiler=gcc
|
||||||
|
do_pgo=yes
|
||||||
|
;;
|
||||||
|
|
||||||
|
*clang*)
|
||||||
|
compiler=clang
|
||||||
|
|
||||||
|
if command -v llvm-profdata > /dev/null; then
|
||||||
|
do_pgo=yes
|
||||||
|
CFLAGS="${CFLAGS} -Wno-ignored-optimization-argument"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
case ${mode} in
|
||||||
|
partial|full-current-session|full-headless-sway)
|
||||||
|
;;
|
||||||
|
|
||||||
|
none)
|
||||||
|
do_pgo=no
|
||||||
|
;;
|
||||||
|
|
||||||
|
auto)
|
||||||
|
# TODO: once Sway 1.6.2 has been released, prefer
|
||||||
|
# full-headless-sway
|
||||||
|
|
||||||
|
if [ -n "${WAYLAND_DISPLAY+x}" ]; then
|
||||||
|
mode=full-current-session
|
||||||
|
elif command -v sway > /dev/null; then
|
||||||
|
mode=full-headless-sway
|
||||||
|
else
|
||||||
|
mode=partial
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
usage_and_die
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# echo "source: ${srcdir}"
|
||||||
|
# echo "build: ${blddir}"
|
||||||
|
# echo "compiler: ${compiler}"
|
||||||
|
# echo "mode: ${mode}"
|
||||||
|
# echo "CFLAGS: ${CFLAGS}"
|
||||||
|
|
||||||
|
export CFLAGS
|
||||||
|
meson "${@}" "${blddir}" "${srcdir}" --buildtype=release -Db_lto=true
|
||||||
|
|
||||||
|
if [ ${do_pgo} = yes ]; then
|
||||||
|
find . -name "*.gcda" -delete
|
||||||
|
meson configure "${blddir}" -Db_pgo=generate
|
||||||
|
ninja -C "${blddir}"
|
||||||
|
|
||||||
|
# If fcft/tllist are subprojects, we need to ensure their tests
|
||||||
|
# have been executed, or we’ll get “profile count data file not
|
||||||
|
# found” errors.
|
||||||
|
ninja -C "${blddir}" test
|
||||||
|
|
||||||
|
# Run mode-dependent script to generate profiling data
|
||||||
|
"${srcdir}"/pgo/${mode}.sh "${srcdir}" "${blddir}"
|
||||||
|
|
||||||
|
if [ ${compiler} = clang ]; then
|
||||||
|
llvm-profdata \
|
||||||
|
merge \
|
||||||
|
"${blddir}"/default_*.profraw \
|
||||||
|
--output="${blddir}"/default.profdata
|
||||||
|
fi
|
||||||
|
|
||||||
|
meson configure "${blddir}" -Db_pgo=use
|
||||||
|
fi
|
||||||
|
|
||||||
|
ninja -C "${blddir}"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue