[SandboxIR] Avoid repeated hash lookups (NFC) (#125337)
[llvm-project.git] / libcxx / utils / libcxx-benchmark-json
blob7f743c32caf40366ecfdba8096615f10d75a22c1
1 #!/usr/bin/env bash
3 set -e
5 PROGNAME="$(basename "${0}")"
6 MONOREPO_ROOT="$(realpath $(dirname "${PROGNAME}"))"
7 function usage() {
8 cat <<EOF
9 Usage:
10 ${PROGNAME} [-h|--help] <build-directory> benchmarks...
12 Print the path to the JSON files containing benchmark results for the given benchmarks.
14 This requires those benchmarks to have already been run, i.e. this only resolves the path
15 to the benchmark .json file within the build directory.
17 <build-directory> The path to the build directory.
18 benchmarks... Paths of the benchmarks to extract the results for. Those paths are relative to '<monorepo-root>'.
20 Example
21 =======
22 $ cmake -S runtimes -B build/ -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi"
23 $ libcxx-lit build/ -sv libcxx/test/benchmarks/algorithms/for_each.bench.cpp
24 $ less \$(${PROGNAME} build/ libcxx/test/benchmarks/algorithms/for_each.bench.cpp)
25 EOF
28 if [[ "${1}" == "-h" || "${1}" == "--help" ]]; then
29 usage
30 exit 0
33 if [[ $# -lt 1 ]]; then
34 usage
35 exit 1
38 build_dir="${1}"
39 shift
41 for benchmark in ${@}; do
42 # Normalize the paths by turning all benchmarks paths into absolute ones and then making them
43 # relative to the root of the monorepo.
44 benchmark="$(realpath ${benchmark})"
45 relative=$(python -c "import os; import sys; print(os.path.relpath(sys.argv[1], sys.argv[2]))" "${benchmark}" "${MONOREPO_ROOT}")
47 # Extract components of the benchmark path
48 directory="$(dirname ${relative})"
49 file="$(basename ${relative})"
51 # Reconstruct the (slightly weird) path to the benchmark json file. This should be kept in sync
52 # whenever the test suite changes.
53 json="${build_dir}/${directory}/Output/${file}.dir/benchmark-result.json"
54 if [[ -f "${json}" ]]; then
55 echo "${json}"
57 done