Skip to content

Commit

Permalink
chore: fix and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpwang committed Jan 6, 2025
1 parent efddca4 commit 6a9f089
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmark-call.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ jobs:
APP_ARG="--app_log_blowup ${{ inputs.app_log_blowup }}"
AGG_ARG="--leaf_log_blowup ${{ inputs.leaf_log_blowup }}"
MAX_SEGMENT_LENGTH="--max_segment_length ${{ inputs.max_segment_length }}"
OUTPUT_PATH="--output_path $METRIC_PATH"
OUTPUT_PATH="--output_path $(pwd)/$METRIC_PATH"
echo "INPUT_ARGS=${FEATURES} ${APP_ARG} ${AGG_ARG} ${MAX_SEGMENT_LENGTH} ${OUTPUT_PATH} ${INPUT_ARGS}" >> $GITHUB_ENV
##########################################################################
Expand Down
41 changes: 11 additions & 30 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -231,39 +231,20 @@ jobs:
# add metadata to markdown files
source ci/scripts/utils.sh
# Parse matrix data into associative arrays
while IFS= read -r line; do
while IFS= read -r metric_path; do
FLAMEGRAPHS=${{ github.event.inputs.flamegraphs || 'false' }}
# Convert .json to .md
md_file="${line%.json}.md"
md_path="${metric_path%.json}.md"
id=$(echo '${{ needs.create-matrix.outputs.matrix }}' | jq -r --arg file "$line" '.[] |
select(.id == ($file | split("-")[0])) |
{
max_segment_length: .max_segment_length,
instance_type: .instance_type,
memory_allocator: .memory_allocator
}')
matrix=${{ needs.create-matrix.outputs.matrix }}
add_metadata_and_flamegraphs \
"$metric_path" \
"$md_path" \
"$matrix" \
"$COMMIT_URL" \
"$BENCHMARK_WORKFLOW_URL"
export FLAMEGRAPHS=${{ github.event.inputs.flamegraphs || 'false' }}
if [[ "$FLAMEGRAPHS" == 'true' ]]; then
python3 ci/scripts/metric_unify/flamegraph.py $line
s5cmd cp '.bench_metrics/flamegraphs/*.svg' "${S3_FLAMEGRAPHS_PATH}/${CURRENT_SHA}/"
fi
if [ ! -z "$id" ]; then
max_segment_length=$(echo "$id" | jq -r '.max_segment_length')
instance_type=$(echo "$id" | jq -r '.instance_type')
memory_allocator=$(echo "$id" | jq -r '.memory_allocator')
# Call add_metadata for each file with its corresponding data
add_metadata \
"$md_file" \
"$max_segment_length" \
"$instance_type" \
"$memory_allocator" \
"$COMMIT_URL" \
"$BENCHMARK_WORKFLOW_URL"
fi
cp "$md_file" "${TMP_DIR}/"
cp "$md_path" "${TMP_DIR}/"
done <<< "$json_files"
echo "" >> summary.md
Expand Down
55 changes: 38 additions & 17 deletions ci/scripts/utils.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
generate_markdown() {
add_metadata_and_flamegraphs() {
local metric_path="$1"
local metric_name="$2"
local s3_metrics_path="$3"
local openvm_root="$4"
local md_path="$2"
local matrix="$3"
local commit_url="$4"
local benchmark_workflow_url="$5"
# vars: $FLAMEGRAPHS, $S3_FLAMEGRAPHS_PATH, $CURRENT_SHA

if [[ -f $metric_path ]]; then
prev_path="${s3_metrics_path}/main-${metric_name}.json"
count=`s5cmd ls $prev_path | wc -l`
id=${metric_path%%-*} # first part before -
echo $id

if [[ $count -gt 0 ]]; then
s5cmd cp $prev_path prev.json
python3 ${openvm_root}/ci/scripts/metric_unify/main.py $metric_path --prev prev.json --aggregation-json ${openvm_root}/ci/scripts/metric_unify/aggregation.json > results.md
else
echo "No previous benchmark on main branch found"
python3 ${openvm_root}/ci/scripts/metric_unify/main.py $metric_path --aggregation-json ${openvm_root}/ci/scripts/metric_unify/aggregation.json > results.md
fi
else
echo "No benchmark metrics found at ${metric_path}"
inputs=$(echo "$matrix" | jq -r --arg id "$id" '.[] |
select(.id == $id) |
{
max_segment_length: .max_segment_length,
instance_type: .instance_type,
memory_allocator: .memory_allocator
}')

if [[ "$FLAMEGRAPHS" == 'true' ]]; then
repo_root=$(git rev-parse --show-toplevel)
python3 ${repo_root}/ci/scripts/metric_unify/flamegraph.py $metric_path
s5cmd cp "'${repo_root}/.bench_metrics/flamegraphs/*.svg'" "${S3_FLAMEGRAPHS_PATH}/${CURRENT_SHA}/"
fi

if [ ! -z "$inputs" ]; then
max_segment_length=$(echo "$inputs" | jq -r '.max_segment_length')
instance_type=$(echo "$inputs" | jq -r '.instance_type')
memory_allocator=$(echo "$inputs" | jq -r '.memory_allocator')

# Call add_metadata for each file with its corresponding data
add_metadata \
"$md_path" \
"$max_segment_length" \
"$instance_type" \
"$memory_allocator" \
"$commit_url" \
"$benchmark_workflow_url"
fi
}

Expand All @@ -27,13 +46,15 @@ add_metadata() {
local memory_allocator="$4"
local commit_url="$5"
local benchmark_workflow_url="$6"
# vars: $FLAMEGRAPHS, $S3_FLAMEGRAPHS_PATH, $CURRENT_SHA

echo "" >> $result_path
if [[ "$FLAMEGRAPHS" == 'true' ]]; then
echo "<details>" >> $result_path
echo "<summary>Flamegraphs</summary>" >> $result_path
echo "" >> $result_path
for file in .bench_metrics/flamegraphs/*.svg; do
repo_root=$(git rev-parse --show-toplevel)
for file in $repo_root/.bench_metrics/flamegraphs/*.svg; do
filename=$(basename "$file")
flamegraph_url=${S3_FLAMEGRAPHS_PATH}/${CURRENT_SHA}/${filename}
echo "[![]($flamegraph_url)]($flamegraph_url)" >> $result_path
Expand Down

0 comments on commit 6a9f089

Please sign in to comment.