Skip to content

Commit

Permalink
Merge pull request #30 from green-coding-berlin/no-workflow-id-call
Browse files Browse the repository at this point in the history
only make calls to get workflow_id if send-data is set to true
  • Loading branch information
dan-mm authored Oct 2, 2023
2 parents 8b7451a + 37436bb commit ed1c64e
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 17 deletions.
12 changes: 9 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,15 @@ runs:
# we prefer this over manual startint / stopping as it is less error prone for users
run: |
${{github.action_path}}/scripts/setup.sh setup_python
curl_response=$(curl -s -H "Authorization: Bearer ${{github.token}}" ${{ github.api_url }}/repos/${{ github.repository }}/actions/workflows)
workflow_id=$(echo $curl_response | jq '.workflows[] | select(.name == "${{ github.workflow }}") | .id')
${{github.action_path}}/scripts/vars.sh add_var "WORKFLOW_ID" $workflow_id
if ${{inputs.send-data}}; then
curl_response=$(curl -s -H "Authorization: Bearer ${{github.token}}" ${{ github.api_url }}/repos/${{ github.repository }}/actions/workflows)
workflow_id=$(echo $curl_response | jq '.workflows[] | select(.name == "${{ github.workflow }}") | .id')
${{github.action_path}}/scripts/vars.sh add_var "WORKFLOW_ID" $workflow_id
else
${{github.action_path}}/scripts/vars.sh add_var "WORKFLOW_ID" ${{github.workflow}}
fi
${{github.action_path}}/scripts/setup.sh start_measurement
echo "ECO_CI_INIT=DONE" >> $GITHUB_ENV;
Expand Down
16 changes: 12 additions & 4 deletions scripts/add-data.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#!/bin/bash
set -euo pipefail

FILE=""
LABEL=""
CPU=""
ENERGY=""
POWER=""

# Parse named parameters
while [[ $# -gt 0 ]]; do
Expand Down Expand Up @@ -43,14 +50,15 @@ if [ ! -f "$FILE" ]; then
fi

# Define the data point to add to the JSON file
read -r -d '' NEW_STEP << EOM
NEW_STEP=$(cat <<EOM
{
"label": "$LABEL",
"cpu_avg_percent": $CPU,
"energy_joules": $ENERGY,
"power_avg_watts": $POWER
"cpu_avg_percent": "$CPU",
"energy_joules": "$ENERGY",
"power_avg_watts": "$POWER"
}
EOM
)

# Add the data point to the JSON file
if [ -s "$FILE" ]; then
Expand Down
7 changes: 7 additions & 0 deletions scripts/create-and-add-meta.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#!/bin/bash
set -euo pipefail

FILE=""
REPOSITORY=""
BRANCH=""
WORKFLOW=""
RUN_ID=""

# Parse named parameters
while [[ $# -gt 0 ]]; do
Expand Down
36 changes: 34 additions & 2 deletions scripts/display_results.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
#!/bin/bash
set -euo pipefail

# Call the function to read and set the variables
source "$(dirname "$0")/vars.sh" read_vars

function display_results {
# First get values, in case any are unbound
# this will set them to an empty string if they are missing entirely
MEASUREMENT_RAN=${MEASUREMENT_RAN:-}
MODEL_NAME=${MODEL_NAME:-}
TDP=${TDP:-}
CPU_THREADS=${CPU_THREADS:-}
CPU_CORES=${CPU_CORES:-}
CPU_MAKE=${CPU_MAKE:-}
RELEASE_YEAR=${RELEASE_YEAR:-}
RAM=${RAM:-}
CPU_FREQ=${CPU_FREQ:-}
CPU_CHIPS=${CPU_CHIPS:-}
VHOST_RATIO=${VHOST_RATIO:-}
PREVIOUS_VENV=${PREVIOUS_VENV:-}
MEASUREMENT_COUNT=${MEASUREMENT_COUNT:-}
WORKFLOW_ID=${WORKFLOW_ID:-}
API_BASE=${API_BASE:-}


output="/tmp/eco-ci/output.txt"
output_pr="/tmp/eco-ci/output-pr.txt"

Expand Down Expand Up @@ -114,11 +134,23 @@ function display_results {
# write data to output
total_data_file="/tmp/eco-ci/total-data.json"
run_id_enc=$( echo ${run_id} | jq -Rr @uri)
source "$(dirname "$0")/create-and-add-meta.sh" --file ${total_data_file} --repository ${repo_enc} --branch ${branch_enc} --workflow $WORKFLOW_ID --run_id ${run_id_enc}
source "$(dirname "$0")/add-data.sh" --file ${total_data_file} --label "TOTAL" --cpu ${cpu_avg} --energy ${total_energy} --power ${power_avg}

echo "show create-and-add-meta.sh output"
echo "--file $total_data_file --repository $repo_enc --branch $branch_enc --workflow $WORKFLOW_ID --run_id $run_id_enc"
source "$(dirname "$0")/create-and-add-meta.sh" --file "${total_data_file}" --repository "${repo_enc}" --branch "${branch_enc}" --workflow "$WORKFLOW_ID" --run_id "${run_id_enc}"
source "$(dirname "$0")/add-data.sh" --file "${total_data_file}" --label "TOTAL" --cpu "${cpu_avg}" --energy "${total_energy}" --power "${power_avg}"

}

branch=""
display_badge=""
run_id=""
repo=""
display_table=""
display_graph=""
send_data=""
source=""

while [[ $# -gt 0 ]]; do
opt="$1"

Expand Down
34 changes: 31 additions & 3 deletions scripts/make_measurement.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
#!/bin/bash
set -euo pipefail

# Call the function to read and set the variables
source "$(dirname "$0")/vars.sh" read_vars

function make_measurement() {
# First get values, in case any are unbound
# this will set them to an empty string if they are missing entirely
MODEL_NAME=${MODEL_NAME:-}
TDP=${TDP:-}
CPU_THREADS=${CPU_THREADS:-}
CPU_CORES=${CPU_CORES:-}
CPU_MAKE=${CPU_MAKE:-}
RELEASE_YEAR=${RELEASE_YEAR:-}
RAM=${RAM:-}
CPU_FREQ=${CPU_FREQ:-}
CPU_CHIPS=${CPU_CHIPS:-}
VHOST_RATIO=${VHOST_RATIO:-}
PREVIOUS_VENV=${PREVIOUS_VENV:-}
MEASUREMENT_COUNT=${MEASUREMENT_COUNT:-}
WORKFLOW_ID=${WORKFLOW_ID:-}
API_BASE=${API_BASE:-}

# check wc -l of cpu-util is greater than 0
echo $(cat /tmp/eco-ci/cpu-util.txt)
if [[ $(wc -l < /tmp/eco-ci/cpu-util.txt) -gt 0 ]]; then
# if a previous venv is already active,
if type deactivate &>/dev/null
Expand Down Expand Up @@ -79,9 +96,11 @@ function make_measurement() {
branch_enc=$( echo $branch | jq -Rr @uri)
run_id_enc=$( echo ${run_id} | jq -Rr @uri)

echo "show create-and-add-meta.sh output"
echo "--file $lap_data_file --repository $repo_enc --branch $branch_enc --workflow $WORKFLOW_ID --run_id $run_id_enc"

source "$(dirname "$0")/create-and-add-meta.sh" --file ${lap_data_file} --repository ${repo_enc} --branch ${branch_enc} --workflow $WORKFLOW_ID --run_id ${run_id_enc}
source "$(dirname "$0")/add-data.sh" --file ${lap_data_file} --label "$label" --cpu ${cpu_avg} --energy ${total_energy} --power ${power_avg}
source "$(dirname "$0")/create-and-add-meta.sh" --file "${lap_data_file}" --repository "${repo_enc}" --branch "${branch_enc}" --workflow "$WORKFLOW_ID" --run_id "${run_id_enc}"
source "$(dirname "$0")/add-data.sh" --file "${lap_data_file}" --label "$label" --cpu "${cpu_avg}" --energy "${total_energy}" --power "${power_avg}"

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 &
Expand All @@ -91,8 +110,17 @@ function make_measurement() {
fi
}

label=""
run_id=""
branch=""
repo=""
commit_hash=""
send_data=""
source=""

while [[ $# -gt 0 ]]; do
opt="$1"

case $opt in
-l|--label)
label="$2"
Expand Down
12 changes: 7 additions & 5 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -euo pipefail

# Call the function to read and set the variables
source "$(dirname "$0")/vars.sh" read_vars
Expand All @@ -14,12 +15,10 @@ function initialize {
git clone --depth 1 --single-branch --branch main https://github.com/green-coding-berlin/spec-power-model /tmp/eco-ci/spec-power-model

## Reimplement ascii graph when we find a better library
# also remember to look for and check for display_graphs
# install go ascii

if [[ $install_go == true ]]; then
go install github.com/guptarohit/asciigraph/cmd/asciigraph@latest
ascii_graph_path=$(go list -f '{{.Target}}' github.com/guptarohit/asciigraph/cmd/asciigraph)
fi

# check for gcc
Expand All @@ -39,8 +38,11 @@ function setup_python {
# Create a venv, and backup old
python3 -m venv /tmp/eco-ci/venv

if [[ $VIRTUAL_ENV != '' ]]; then
$PREVIOUS_VENV=$VIRTUAL_ENV
VENV_VALUE=${VIRTUAL_ENV:-}
PREVIOUS_VENV=''

if [[ $VENV_VALUE != '' ]]; then
PREVIOUS_VENV=$VENV_VALUE
source "$(dirname "$0")/vars.sh" add_var PREVIOUS_VENV $PREVIOUS_VENV
fi

Expand Down Expand Up @@ -99,7 +101,7 @@ esac
install_go=true
reset=true

while [[ $# -gt 0 ]]; do
while [[ $# -gt 1 ]]; do
opt="$2"

case $opt in
Expand Down
1 change: 1 addition & 0 deletions scripts/vars.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -euo pipefail

model_name=$(cat /proc/cpuinfo | grep "model name")

Expand Down

0 comments on commit ed1c64e

Please sign in to comment.