Skip to content

Commit ff6bc05

Browse files
committed
json-to-command.sh: recover lockhammer command from json
This program recovers a lockhammer lh_test command line from the measurement record in a results json. Change-Id: I9ed51c01f94aa9ba592b7638bb7d937804c5a158 Signed-off-by: James Yang <[email protected]>
1 parent f46ade7 commit ff6bc05

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
3+
# SPDX-FileCopyrightText: Copyright 2025 Arm Limited and/or its affiliates <[email protected]>
4+
# SPDX-License-Identifier: BSD-3-Clause
5+
6+
# This program recovers a lockhammer lh command from a results json and the meas_number to rerun a measurement.
7+
8+
usage() {
9+
echo "$0 json_file [meas_number]"
10+
exit -1
11+
}
12+
13+
rebuild_flags() {
14+
local FILE=$1
15+
local MEAS_NUMBER=$2
16+
17+
local LH_COMMON_FLAGS='-Y -D 1 -M 1G'
18+
19+
local LH_EXE='build.\(.variant_name)\(if .tag then "."+.tag else "" end)/lh_\(.test_name)'
20+
local LH_CRIT='-c \(.nominal_critical)\(.nominal_critical_unit)'
21+
local LH_PAR='-p \(.nominal_parallel)\(.nominal_parallel_unit)'
22+
23+
# the old way to detect pinorder string is not a thread_num, but pinorder_string may now be a range and not always a pure number
24+
# local LH_PINORDER='\(if ((.pinorder_string | startswith("t")) or ((.pinorder_string | tonumber) == .num_threads)) then "-t"+.pinorder_string else "-o"+.pinorder_string end)'
25+
26+
local LH_PINORDER='\(if ((.pinorder_string | startswith("t"))) then "-t"+.pinorder_string else "-o"+.pinorder_string end)'
27+
28+
local LH_COMMAND="$LH_EXE $LH_CRIT $LH_PAR $LH_PINORDER $LH_COMMON_FLAGS"
29+
30+
# if no measurement number if given, then all of the results records are processed
31+
if [ -z "$MEAS_NUMBER" ]; then
32+
jq -e -r ".results[] | \"$LH_COMMAND\"" "$FILE"
33+
else
34+
jq -e --argjson i "$MEAS_NUMBER" -r ".results[] | select(.meas_number == \$i) | \"$LH_COMMAND\"" "$FILE"
35+
fi
36+
}
37+
38+
MEAS_NUMBER=$2
39+
FILE=$1
40+
41+
if [ -z "$FILE" ]; then
42+
echo "ERROR: missing json file"
43+
usage
44+
fi
45+
46+
if [ -n "$MEAS_NUMBER" ]; then
47+
48+
# check if there is a record with the value of the meas_number
49+
if ! jq -e --argjson i "$MEAS_NUMBER" -r ".results[] | select(.meas_number == \$i)" "$FILE" > /dev/null; then
50+
echo "ERROR: did not find a result with .meas_number == $MEAS_NUMBER in $FILE"
51+
exit -1
52+
fi
53+
fi
54+
55+
rebuild_flags "$FILE" $MEAS_NUMBER
56+
57+
exit 0

0 commit comments

Comments
 (0)