From e4f2678e25a2c9de366729ddd4ddf31af7f9c5c6 Mon Sep 17 00:00:00 2001 From: dan-mm <33732895+dan-mm@users.noreply.github.com> Date: Fri, 2 Jun 2023 16:51:29 +0200 Subject: [PATCH] =?UTF-8?q?added=20timer=20to=20measurement=20steps;=20sen?= =?UTF-8?q?d=20duration=20time;=20fixed=20formattin=E2=80=A6=20(#22)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * added timer to measurement steps; send duration time; fixed formatting error with one of the cpus * another cpu formatting fix --- action.yml | 23 +++++++++++++++++------ scripts/init_variables.sh | 4 ++-- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/action.yml b/action.yml index 161b389f..aec4b12e 100644 --- a/action.yml +++ b/action.yml @@ -149,6 +149,10 @@ runs: run: | killall -9 -q /tmp/eco-ci/demo-reporter || true /tmp/eco-ci/demo-reporter | tee -a /tmp/eco-ci/cpu-util-total.txt > /tmp/eco-ci/cpu-util.txt & + # start a timer + date +%s > /tmp/eco-ci/timer.txt + date +%s > /tmp/eco-ci/timer-total.txt + - if: inputs.task == 'get-measurement' id: run-lap-model @@ -160,7 +164,7 @@ runs: # first activate our venv source /tmp/eco-ci/venv/bin/activate - ## make a note that we cannot use --eneryg, skew the result as we do not have an input delay. + ## make a note that we cannot use --energy, skew the result as we do not have an input delay. # this works because demo-reporter is 1/second if [[ "$ECO_CI_MODEL_NAME" == "unknown" ]]; then cat /tmp/eco-ci/cpu-util.txt | python3.10 /tmp/eco-ci/spec-power-model/xgb.py --silent | tee -a /tmp/eco-ci/energy-total.txt > /tmp/eco-ci/energy.txt @@ -191,13 +195,16 @@ runs: label="Measurement #$GET_MEASUREMENT_COUNT" fi + # this is the time in seconds that the measurement took + measurement_time=$(($(date +%s) - $(cat /tmp/eco-ci/timer.txt))) + cpu_avg=$(awk '{ total += $1; count++ } END { print total/count }' /tmp/eco-ci/cpu-util.txt) total_energy=$(awk '{sum+=$1} END {print sum}' /tmp/eco-ci/energy.txt) power_avg=$(awk '{ total += $1; count++ } END { print total/count }' /tmp/eco-ci/energy.txt) # Append the information gathered here to an ENV variable string that will form the table to be # shown during display-results - display_line="$ECO_CI_MEASUREMENT_TABLE_LINES|${label}|${cpu_avg}|${total_energy}|${power_avg}|" + display_line="$ECO_CI_MEASUREMENT_TABLE_LINES|${label}|${cpu_avg}|${total_energy}|${power_avg}|${measurement_time}|" echo "ECO_CI_MEASUREMENT_TABLE_LINES=${display_line}\n" >> $GITHUB_ENV echo ${total_energy} >> /tmp/eco-ci/energy-values.txt @@ -212,7 +219,7 @@ runs: unit="mJ" eco_ci_model_name=$(echo $ECO_CI_MODEL_NAME | jq -Rr @uri) - curl -X POST "$add_endpoint" -H 'Content-Type: application/json' -d "{\"value\":\"$value_mJ\",\"unit\":\"$unit\",\"cpu\":\"$eco_ci_model_name\",\"commit_hash\":\"${{ github.sha }}\",\"repo\":\"${{ github.repository }}\",\"branch\":\"${{ inputs.branch }}\",\"workflow\":\"$ECO_CI_WORKFLOW_ID\",\"run_id\":\"${{ github.run_id }}\",\"project_id\":\"\",\"label\":\"$label\", \"source\":\"github\"}" + curl -X POST "$add_endpoint" -H 'Content-Type: application/json' -d "{\"value\":\"$value_mJ\",\"unit\":\"$unit\",\"cpu\":\"$eco_ci_model_name\",\"commit_hash\":\"${{ github.sha }}\",\"repo\":\"${{ github.repository }}\",\"branch\":\"${{ inputs.branch }}\",\"workflow\":\"$ECO_CI_WORKFLOW_ID\",\"run_id\":\"${{ github.run_id }}\",\"project_id\":\"\",\"label\":\"$label\", \"source\":\"github\",\"duration\":\"$measurement_time\"}" fi # write data to output @@ -226,6 +233,7 @@ runs: killall -9 -q /tmp/eco-ci/demo-reporter || true /tmp/eco-ci/demo-reporter | tee -a /tmp/eco-ci/cpu-util-total.txt > /tmp/eco-ci/cpu-util.txt & + date +%s > /tmp/eco-ci/timer.txt else echo "Skipping measurement as no data was collected since last call" fi @@ -250,14 +258,17 @@ runs: fi if [[ ${{ inputs.display-table }} == 'true' ]]; then - echo "|Label|🖥 avg. CPU utilization [%]|🔋 Total Energy [Joules]|🔌 avg. Power [Watts]|" >> $GITHUB_STEP_SUMMARY - echo "|---|---|---|---|" >> $GITHUB_STEP_SUMMARY + echo "|Label|🖥 avg. CPU utilization [%]|🔋 Total Energy [Joules]|🔌 avg. Power [Watts]|Duration [Seconds]|" >> $GITHUB_STEP_SUMMARY + echo "|---|---|---|---|---|" >> $GITHUB_STEP_SUMMARY cpu_avg=$(awk '{ total += $1; count++ } END { print total/count }' /tmp/eco-ci/cpu-util-total.txt) total_energy=$(awk '{sum+=$1} END {print sum}' /tmp/eco-ci/energy-total.txt) power_avg=$(awk '{ total += $1; count++ } END { print total/count }' /tmp/eco-ci/energy-total.txt) - final_line="$ECO_CI_MEASUREMENT_TABLE_LINES|Total Run|${cpu_avg}|${total_energy}|${power_avg}|" + # this is the time in seconds that the measurement took + measurement_time=$(($(date +%s) - $(cat /tmp/eco-ci/timer-total.txt))) + + final_line="$ECO_CI_MEASUREMENT_TABLE_LINES|Total Run|${cpu_avg}|${total_energy}|${power_avg}|${measurement_time}|" echo -e "$final_line" >> $GITHUB_STEP_SUMMARY echo '' >> $GITHUB_STEP_SUMMARY fi diff --git a/scripts/init_variables.sh b/scripts/init_variables.sh index 968db2a9..feafee5e 100755 --- a/scripts/init_variables.sh +++ b/scripts/init_variables.sh @@ -32,7 +32,7 @@ elif [[ "$model_name" == *"8370C"* ]]; then elif [[ "$model_name" == *"E5-2673 v4"* ]]; then echo "Found E5-2673 v4 model" - echo "ECO_CI_MODEL_NAME='E5-2673'" >> $GITHUB_ENV + echo "ECO_CI_MODEL_NAME=E5-2673v4" >> $GITHUB_ENV echo "ECO_CI_TDP=165" >> $GITHUB_ENV; echo "ECO_CI_CPU_THREADS=52" >> $GITHUB_ENV; @@ -46,7 +46,7 @@ elif [[ "$model_name" == *"E5-2673 v4"* ]]; then elif [[ "$model_name" == *"E5-2673 v3"* ]]; then echo "Found E5-2673 v3 model" - echo "ECO_CI_MODEL_NAME='E5-2673 v3'" >> $GITHUB_ENV + echo "ECO_CI_MODEL_NAME=E5-2673v3" >> $GITHUB_ENV echo "ECO_CI_TDP=110" >> $GITHUB_ENV; echo "ECO_CI_CPU_THREADS=24" >> $GITHUB_ENV;