From 7cf8df4c3c616aee57af0d022b1a80963e4c4d71 Mon Sep 17 00:00:00 2001 From: Zejun Zhao Date: Fri, 13 Dec 2024 15:07:05 +0800 Subject: [PATCH] Make nth_occurrence configurable in benchmark CI --- test/benchmark/README.md | 3 ++- test/benchmark/bench_linux_and_aster.sh | 12 +++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/test/benchmark/README.md b/test/benchmark/README.md index 0bccf1d9e..d8b645150 100644 --- a/test/benchmark/README.md +++ b/test/benchmark/README.md @@ -242,7 +242,8 @@ The `bench_result.json` file configures how benchmark results are processed and // Settings for extracting benchmark results from raw outputs. "result_extraction": { "search_pattern": "sender", // Regex or string to locate results. - "result_index": 7 // Match index to use (e.g., 7th occurrence). + "nth_occurrence": 1, // Optional. Which matched occurrence to use (default to 1). + "result_index": 7 // Match index to use. }, // Configurations for how the results are displayed in charts. "chart": { diff --git a/test/benchmark/bench_linux_and_aster.sh b/test/benchmark/bench_linux_and_aster.sh index c6c866cf7..883ce4076 100755 --- a/test/benchmark/bench_linux_and_aster.sh +++ b/test/benchmark/bench_linux_and_aster.sh @@ -16,13 +16,14 @@ RESULT_TEMPLATE="${BENCHMARK_ROOT}/result_template.json" # Parse benchmark results parse_raw_results() { local search_pattern="$1" - local result_index="$2" - local result_file="$3" + local nth_occurrence="$2" + local result_index="$3" + local result_file="$4" # Extract and sanitize numeric results local linux_result aster_result - linux_result=$(awk "/${search_pattern}/ {result=\$$result_index} END {print result}" "${LINUX_OUTPUT}" | tr -d '\r' | sed 's/[^0-9.]*//g') - aster_result=$(awk "/${search_pattern}/ {result=\$$result_index} END {print result}" "${ASTER_OUTPUT}" | tr -d '\r' | sed 's/[^0-9.]*//g') + linux_result=$(awk "/${search_pattern}/ {print \$$result_index}" "${LINUX_OUTPUT}" | tr -d '\r' | sed 's/[^0-9.]*//g' | sed -n "${nth_occurrence}p") + aster_result=$(awk "/${search_pattern}/ {print \$$result_index}" "${ASTER_OUTPUT}" | tr -d '\r' | sed 's/[^0-9.]*//g' | sed -n "${nth_occurrence}p") # Ensure both results are valid if [ -z "${linux_result}" ] || [ -z "${aster_result}" ]; then @@ -138,12 +139,13 @@ parse_results() { local bench_result="$1" local search_pattern=$(jq -r '.result_extraction.search_pattern // empty' "$bench_result") + local nth_occurrence=$(jq -r '.result_extraction.nth_occurrence // 1' "$bench_result") local result_index=$(jq -r '.result_extraction.result_index // empty' "$bench_result") local unit=$(jq -r '.chart.unit // empty' "$bench_result") local legend=$(jq -r '.chart.legend // {system}' "$bench_result") generate_template "$unit" "$legend" - parse_raw_results "$search_pattern" "$result_index" "$(extract_result_file "$bench_result")" + parse_raw_results "$search_pattern" "$nth_occurrence" "$result_index" "$(extract_result_file "$bench_result")" } # Clean up temporary files