Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion aqpbm-core/src/harness/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ pub fn processes_memory(proc_root: &Path, pids: &[u32]) -> Result<ProcessesMemor

pub const MEMORY_SAMPLE_INTERVAL: Duration = Duration::from_millis(10);

const READING_ABOVE_WAIT4_MARGIN_DIVISOR: u64 = 20;

pub const SAMPLES_PROCESS_MEMORY: bool = cfg!(target_os = "linux");

#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
Expand Down Expand Up @@ -682,7 +684,7 @@ fn child_peak_memory(
.filter(|&harness| maximum_resident_set_size_bytes > harness)
.map(|_| maximum_resident_set_size_bytes);
let (bytes, source) = match (childs_own_peak_bytes, sampled_peak_bytes) {
(Some(own), Some(sampled)) if sampled > own => {
(Some(own), Some(sampled)) if sampled > own + own / READING_ABOVE_WAIT4_MARGIN_DIVISOR => {
(Some(sampled), PeakMemorySource::LargestReading)
}
(Some(own), _) => (Some(own), PeakMemorySource::Wait4MaximumResidentSetSize),
Expand Down Expand Up @@ -1604,3 +1606,33 @@ pub enum ProtocolError {
#[error("the job failed: {0}")]
Job(#[from] EngineError),
}

#[cfg(all(test, target_os = "linux"))]
mod child_peak_memory_tests {
use super::{child_peak_memory, PeakMemorySource};

const GIBIBYTE: u64 = 1 << 30;

fn kilobytes(bytes: u64) -> libc::c_long {
(bytes / 1024) as libc::c_long
}

#[test]
fn a_reading_a_little_above_wait4_is_counter_skew_and_wait4_stays_the_peak() {
assert_eq!(
child_peak_memory(kilobytes(GIBIBYTE), Some(GIBIBYTE + GIBIBYTE / 100)),
(
Some(GIBIBYTE),
Some(PeakMemorySource::Wait4MaximumResidentSetSize)
)
);
}

#[test]
fn a_reading_well_above_wait4_is_a_larger_peak_of_the_process_tree() {
assert_eq!(
child_peak_memory(kilobytes(GIBIBYTE), Some(2 * GIBIBYTE)),
(Some(2 * GIBIBYTE), Some(PeakMemorySource::LargestReading))
);
}
}
2 changes: 1 addition & 1 deletion aqpbm-core/tests/harness_child_peak_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn a_short_childs_peak_comes_from_wait4_and_a_run_with_no_reading_has_no_peak()
assert!(
usage
.sampled_peak_memory_bytes
.is_none_or(|sampled| sampled <= peak),
.is_none_or(|sampled| sampled <= peak + peak / 20),
"{usage:?}"
);

Expand Down
136 changes: 136 additions & 0 deletions scripts/leaderboard-data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#!/usr/bin/env bash
set -euo pipefail

usage() {
cat <<'EOF'
Pack saved benchmark results into one archive, and show an archive as the system leaderboard
or as Grafana dashboards, without running any system again.

scripts/leaderboard-data.sh pack <archive.tar.xz> [--one-shot <run-directory>]...
[--use-cases <runs-directory>]
scripts/leaderboard-data.sh web <archive.tar.xz | data-directory> [<port>]
scripts/leaderboard-data.sh grafana <archive.tar.xz | data-directory>

pack --one-shot a run directory of scripts/one-shot-workload.sh after one-shot-report;
its reports, results/ and workloads/ are kept, a DuckDB database is not
--use-cases the runs/ directory scripts/use_cases/run_use_case_on_systems.py writes
under its --data, holding index.json
web unpacks the archive under target/leaderboard-data/, writes
system-leaderboard/public/data/all.jsonl from it and starts the leaderboard
[port 5173]; needs python3 and node 20.19 or later
grafana unpacks the archive under target/leaderboard-data/, writes leaderboard/records.json
in it and starts tools/grafana/run.sh on it: the five use cases on systems and the
one-shot query dashboards

An archive holds one directory:
manifest.json when, from which ASAPBench commit, on which machine
one-shot/<run>/ one-shot-summary.csv, one-shot-tables.csv, results/, workloads/
phase3/runs/ index.json and one directory per use-case run
EOF
}

repo=$(cd "$(dirname "$0")/.." && pwd)
[ $# -ge 1 ] || { usage >&2; exit 2; }
case $1 in -h|--help) usage; exit 0 ;; esac
action=$1; shift

data_directory() {
local source=$1
if [ -d "$source" ]; then
[ -f "$source/manifest.json" ] || { echo "$source has no manifest.json" >&2; exit 1; }
realpath "$source"
return
fi
[ -f "$source" ] || { echo "no archive or directory at $source" >&2; exit 1; }
local name top target
name=$(basename "$source"); name=${name%.tar.xz}
target=$repo/target/leaderboard-data/$name
if [ ! -f "$target/manifest.json" ]; then
top=$(tar -tJf "$source" | head -1 | cut -d/ -f1)
case $top in ''|.|..|/*) echo "$source does not hold one top directory" >&2; exit 1 ;; esac
rm -rf "$target.unpacking"
mkdir -p "$target.unpacking"
tar -xJf "$source" -C "$target.unpacking" --no-same-owner
[ -f "$target.unpacking/$top/manifest.json" ] || { echo "$source has no $top/manifest.json" >&2; exit 1; }
rm -rf "$target"
mv "$target.unpacking/$top" "$target"
rmdir "$target.unpacking"
fi
echo "$target"
}

case $action in
pack)
[ $# -ge 1 ] || { usage >&2; exit 2; }
archive=$(realpath -m "$1"); shift
case $archive in *.tar.xz) ;; *) echo "the archive name ends in .tar.xz" >&2; exit 2 ;; esac
one_shot=(); use_cases=""
while [ $# -gt 0 ]; do
case $1 in
--one-shot) one_shot+=("$(realpath "$2")"); shift 2 ;;
--use-cases) use_cases=$(realpath "$2"); shift 2 ;;
*) usage >&2; exit 2 ;;
esac
done
[ ${#one_shot[@]} -gt 0 ] || [ -n "$use_cases" ] || { echo "nothing to pack" >&2; exit 2; }
name=$(basename "$archive" .tar.xz)
staging=$(mktemp -d)
trap 'rm -rf "$staging"' EXIT
mkdir -p "$staging/$name"
for run in "${one_shot[@]}"; do
[ -f "$run/one-shot-summary.csv" ] || { echo "$run has no one-shot-summary.csv; run one-shot-report first" >&2; exit 1; }
target=$staging/$name/one-shot/$(basename "$run")
mkdir -p "$target"
for item in one-shot-summary.csv one-shot-summary.md one-shot-tables.csv results workloads; do
[ -e "$run/$item" ] && cp -a "$run/$item" "$target/"
done
done
if [ -n "$use_cases" ]; then
[ -f "$use_cases/index.json" ] || { echo "$use_cases has no index.json" >&2; exit 1; }
mkdir -p "$staging/$name/phase3"
cp -a "$use_cases" "$staging/$name/phase3/runs"
fi
python3 - "$staging/$name" "$repo" <<'PY'
import datetime, glob, json, os, subprocess, sys
root, repo = sys.argv[1:]
machines = set()
for path in glob.glob(os.path.join(root, "one-shot", "*", "results", "*", "*.one-shot.json")):
with open(path) as file:
machine = json.load(file).get("machine")
if machine:
machines.add(json.dumps(machine, sort_keys=True))
commit = subprocess.run(["git", "-C", repo, "rev-parse", "HEAD"], capture_output=True, text=True).stdout.strip()
manifest = {
"packed_at": datetime.datetime.now(datetime.timezone.utc).isoformat(timespec="seconds"),
"asapbench_commit": commit or None,
"machines": [json.loads(m) for m in sorted(machines)],
"one_shot_runs": sorted(os.listdir(os.path.join(root, "one-shot"))) if os.path.isdir(os.path.join(root, "one-shot")) else [],
"use_case_runs": os.path.isdir(os.path.join(root, "phase3", "runs")),
}
with open(os.path.join(root, "manifest.json"), "w") as file:
json.dump(manifest, file, indent=2)
PY
mkdir -p "$(dirname "$archive")"
tar -C "$staging" -cJf "$archive" "$name"
echo "$archive: $(du -h "$archive" | cut -f1)"
;;
web)
[ $# -ge 1 ] || { usage >&2; exit 2; }
data=$(data_directory "$1"); port=${2:-5173}
python3 "$repo/scripts/system-leaderboard-data.py" --data "$data" \
--output "$repo/system-leaderboard/public/data/all.jsonl"
command -v npm >/dev/null || { echo "needs node 20.19 or later and npm" >&2; exit 1; }
cd "$repo/system-leaderboard"
[ -d node_modules ] || npm ci --no-audit --no-fund
exec npx vite --host 127.0.0.1 --port "$port" --strictPort
;;
grafana)
[ $# -ge 1 ] || { usage >&2; exit 2; }
data=$(data_directory "$1")
python3 "$repo/scripts/system-leaderboard-data.py" --data "$data" --format json \
--output "$data/leaderboard/records.json"
GRAFANA_DATA_DIR=$data exec "$repo/tools/grafana/run.sh" --phase 3 --one-shot
;;
*)
usage >&2; exit 2 ;;
esac
Loading
Loading