chore: add lakeprof benchmarks (#9709)

This commit is contained in:
Sebastian Ullrich 2025-08-06 13:25:45 +02:00 committed by GitHub
parent 42e472ff3f
commit 09600f2ca4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 90 additions and 8 deletions

View file

@ -1,9 +1,9 @@
#!/usr/bin/env bash
set -euo pipefail
set -euxo pipefail
cmake --preset release -DUSE_LAKE=ON 1>&2
# We benchmark against stage 2 to test new optimizations.
# We benchmark against stage2/bin to test new optimizations.
timeout -s KILL 1h time make -C build/release -j$(nproc) stage3 1>&2
export PATH=$PWD/build/release/stage2/bin:$PATH
@ -11,6 +11,86 @@ export PATH=$PWD/build/release/stage2/bin:$PATH
# easier to configure them statically.
cmake -B build/release/stage3 -S src -DLEAN_EXTRA_LAKEFILE_TOML='weakLeanArgs=["-Dprofiler=true", "-Dprofiler.threshold=9999999", "--stats"]' 1>&2
(
cd tests/bench
timeout -s KILL 1h time temci exec --config speedcenter.yaml --in speedcenter.exec.velcom.yaml 1>&2
temci report run_output.yaml --reporter codespeed2
)
if [ -d .git ]; then
DIR="$(git rev-parse @)"
BASE_URL="https://speed.lean-lang.org/lean4-out/$DIR"
{
cat <<'EOF'
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Lakeprof Report</title>
</head>
<h1>Lakeprof Report</h1>
<button type="button" id="btn_fetch">View build trace in Perfetto</button>
<script type="text/javascript">
const ORIGIN = 'https://ui.perfetto.dev';
const btnFetch = document.getElementById('btn_fetch');
async function fetchAndOpen(traceUrl) {
const resp = await fetch(traceUrl);
// Error checking is left as an exercise to the reader.
const blob = await resp.blob();
const arrayBuffer = await blob.arrayBuffer();
openTrace(arrayBuffer, traceUrl);
}
function openTrace(arrayBuffer, traceUrl) {
const win = window.open(ORIGIN);
if (!win) {
btnFetch.style.background = '#f3ca63';
btnFetch.onclick = () => openTrace(arrayBuffer);
btnFetch.innerText = 'Popups blocked, click here to open the trace file';
return;
}
const timer = setInterval(() => win.postMessage('PING', ORIGIN), 50);
const onMessageHandler = (evt) => {
if (evt.data !== 'PONG') return;
// We got a PONG, the UI is ready.
window.clearInterval(timer);
window.removeEventListener('message', onMessageHandler);
const reopenUrl = new URL(location.href);
reopenUrl.hash = `#reopen=${traceUrl}`;
win.postMessage({
perfetto: {
buffer: arrayBuffer,
title: 'Lake Build Trace',
url: reopenUrl.toString(),
}}, ORIGIN);
};
window.addEventListener('message', onMessageHandler);
}
// This is triggered when following the link from the Perfetto UI's sidebar.
if (location.hash.startsWith('#reopen=')) {
const traceUrl = location.hash.substr(8);
fetchAndOpen(traceUrl);
}
EOF
cat <<EOF
btnFetch.onclick = () => fetchAndOpen("$BASE_URL/lakeprof.trace_event");
</script>
EOF
echo "<pre><code>"
(cd src; lakeprof report -prc)
echo "</code></pre>"
echo "</body></html>"
} | tee index.html
curl -T index.html $BASE_URL/index.html
curl -T src/lakeprof.log $BASE_URL/lakeprof.log
curl -T src/lakeprof.trace_event $BASE_URL/lakeprof.trace_event
fi

View file

@ -6,8 +6,8 @@ import sys
cats = collections.defaultdict(lambda: 0)
for line in sys.stdin:
if m := re.match(r"(.+?) ([\d.]+)(m?)s", line) or \
re.match(r"\s*(number of imported bytes|number of imported consts|number of imported entries):\s+(\d+)()", line):
if m := re.search(r"\t(.+?) ([\d.]+)(m?)s$", line) or \
re.search(r"(number of imported bytes|number of imported consts|number of imported entries):\s+(\d+)()$", line):
cats[m[1].strip()] += float(m[2]) * (1e-3 if m[3] else 1)
sys.stderr.write(line)

View file

@ -17,16 +17,18 @@
rusage_properties: ["maxrss"]
run_config:
<<: *time
cwd: ../../src
cmd: |
# build only up to make-stdlib so Lake doesn't repeat its output, then finish the build to get
# the executables for further benchmarks, ignore output
bash -c 'set -eo pipefail; find ${BUILD:-../../build/release}/stage3 -name "*.olean" -delete; make LEAN_OPTS="-Dprofiler=true -Dprofiler.threshold=9999999 --stats" -C ${BUILD:-../../build/release}/stage3 --output-sync -j$(nproc) make_stdlib 2>&1 | ./accumulate_profile.py; make -C ${BUILD:-../../build/release}/stage3 -j$(nproc) 1>&2'
set -euxo pipefail
bash -c 'set -eo pipefail; find ${BUILD:-../build/release}/stage3 -name "*.olean" -delete; lakeprof record make -C ${BUILD:-../build/release}/stage3 -j$(nproc) 2>&1 | ../tests/bench/accumulate_profile.py'
lakeprof report -p | awk '{if ($3) cum = $3} END {print "longest build path: " cum}'
lakeprof report -r | awk '{if ($3) cum = $3} END {print "longest rebuild path: " cum}'
max_runs: 2
parse_output: true
# initialize stage2 cmake + warmup
build_config:
cmd: |
bash -c 'make -C ${BUILD:-../../build/release} stage3 -j$(nproc)'
bash -c 'make -C ${BUILD:-../build/release} stage3 -j$(nproc)'
- attributes:
description: stdlib size
tags: [deterministic, fast]