Skip to content

Commit

Permalink
Merge pull request #27 from green-coding-berlin/pr-comment-and-pip-fixes
Browse files Browse the repository at this point in the history
install python3.10 if not on system; allow use of ml model with other…
  • Loading branch information
dan-mm authored Jul 7, 2023
2 parents 4f697e3 + 30d2bc2 commit 1b0c2e9
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 22 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ jobs:
- `display-results` - Outputs the energy results to the`$GITHUB_STEP_SUMMARY`. Creates a table that shows the energy results of all the get-measurements, and then a final row for the entire run. Displays the avergae cpu utilization, the total Joules used, and average wattage for each measurment+total run. It will also display a graph of the energy used, and a badge for you to display.
- This badge will always be updated to display the total energy of the most recent run of the workflow that generated this badge.
- The total measurement of this task is provided as output `data-total-json` in json format (see example below).
- Can be used with `pr-comment` flag (see below) to post the results as a comment on the PR.
- `branch`: (optional) (default: ${{ github.ref_name }})
- Used with `get_measurement` and `display_results` to correctly identify this CI run for the Badge.
- `label`: (optional) (default: 'measurement ##')
Expand All @@ -94,6 +95,9 @@ jobs:
- used with display-results
- Shows the badge for the ci run during display-results step
- automatically false if send-data is also false
- `pr-comment`: (optional) (default: false)
- used with display-results
- if on, will post a comment on the PR issue with the Eco-CI results

#### Continuing on Errors

Expand Down
39 changes: 37 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ inputs:
description: 'Shows the badge for the ci run during display-results step'
default: true
required: false
pr-comment:
description: 'Add a comment to the PR with the results during display-results step'
default: false
outputs:
data-total-json:
description: "Contains the data of the total measurement which is retrieved by the 'display-results' task."
Expand All @@ -51,6 +54,22 @@ runs:
name: Setup
shell: bash
run: |
if command -v python3 &>/dev/null; then
echo "Python is already installed."
else
echo "Python is not installed. Installing..."
apt-get update
apt-get install -y python3.10 python3.10-venv
echo "Python has been installed."
fi
python_version=$(python3 --version 2>&1)
python_major_version=$(python3 -c 'import sys; print(sys.version_info[0])')
python_minor_version=$(python3 -c 'import sys; print(sys.version_info[1])')
python_cache_path="${base_root}venv/lib/python${python_major_version}.${python_minor_version}/site-packages"
echo "python_cache_path=$python_cache_path" >> $GITHUB_OUTPUT
# call the initialize function of setup.sh
${{github.action_path}}/scripts/setup.sh initialize -g ${{inputs.display-graph}}
Expand All @@ -72,7 +91,7 @@ runs:
cache-name: cache-pip-packages
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: /tmp/eco-ci/venv/lib/python3.10/site-packages
path: ${{ steps.initialize.outputs.python_cache_path }}
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ steps.hash-requirements.outputs.myhash }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-${{ steps.hash-requirements.outputs.myhash }}
Expand Down Expand Up @@ -123,4 +142,20 @@ runs:
${{github.action_path}}/scripts/display_results.sh -dt ${{inputs.display-table}} -dg ${{inputs.display-graph}} -db ${{inputs.display-badge}} -b "${{inputs.branch}}" -r ${{ github.run_id }} -R "${{ github.repository }}" -sd ${{inputs.send-data}} -s "github"
cat "/tmp/eco-ci/output.txt" >> $GITHUB_STEP_SUMMARY
total_data_file="/tmp/eco-ci/total-data.json"
echo "data-total-json=$(cat $total_data_file)" >> $GITHUB_OUTPUT
echo "data-total-json=$(cat $total_data_file)" >> $GITHUB_OUTPUT
- if: github.event_name == 'pull_request' && inputs.task == 'display-results' && inputs.pr-comment == 'true'
name: Comment on Pull Request
id: pr-comment
shell: bash
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
COMMENT=$(cat "/tmp/eco-ci/output-multiline.txt")
API_URL="${{ github.api_url }}/repos/${{ github.repository }}/issues/${PR_NUMBER}/comments"
curl -X POST -H "Authorization: Bearer ${{github.token}}" -d @- $API_URL <<EOF
{
"body": "$COMMENT"
}
EOF
36 changes: 20 additions & 16 deletions scripts/display_results.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ source "$(dirname "$0")/vars.sh" read_vars

function display_results {
output="/tmp/eco-ci/output.txt"
output_multiline="/tmp/eco-ci/output-multiline.txt"

if [[ $MEASUREMENT_RAN != true ]]; then
echo "Running a measurement to have at least one result to display."
source /tmp/eco-ci/venv/bin/activate

if [[ "$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
cat /tmp/eco-ci/cpu-util.txt | python3. /tmp/eco-ci/spec-power-model/xgb.py --silent | tee -a /tmp/eco-ci/energy-total.txt > /tmp/eco-ci/energy.txt
else
cat /tmp/eco-ci/cpu-util.txt | python3.10 /tmp/eco-ci/spec-power-model/xgb.py \
cat /tmp/eco-ci/cpu-util.txt | python3 /tmp/eco-ci/spec-power-model/xgb.py \
--tdp $TDP --cpu-threads $CPU_THREADS \
--cpu-cores $CPU_CORES --cpu-make $CPU_MAKE \
--release-year $RELEASE_YEAR --ram $RAM \
Expand Down Expand Up @@ -50,6 +51,22 @@ function display_results {
max_measurement_number=$measurement_number
done

echo "Eco-Ci Output:<br/><br/>" >> $output_multiline
echo "Total Energy [Joules]: $total_energy<br/>" >> $output_multiline
echo "Total Avg. CPU Utilization: $cpu_avg<br/>" >> $output_multiline
echo "Total Avg. Power [Watts]: $power_avg<br/>" >> $output_multiline
echo "Total Duration [seconds]: $time<br/>" >> $output_multiline
echo "--------------------------------<br/>" >> $output_multiline

for (( i=1; i<=$max_measurement_number; i++ )); do
echo "Label $i: $(eval echo \$label_$i)<br/>" >> $output_multiline
echo "Energy Used [Joules]: $(eval echo \$total_energy_$i)<br/>" >> $output_multiline
echo "Avg. CPU Utilization: $(eval echo \$cpu_avg_$i)<br/>" >> $output_multiline
echo "Avg. Power [Watts]: $(eval echo \$power_avg_$i)<br/>" >> $output_multiline
echo "Duration [seconds]: $(eval echo \$time_$i)<br/>" >> $output_multiline
echo "--------------------------------<br/>" >> $output_multiline
done

if [[ $source == 'github' ]]; then
echo "|Label|🖥 avg. CPU utilization [%]|🔋 Total Energy [Joules]|🔌 avg. Power [Watts]|Duration [Seconds]|" >> $output
echo "|---|---|---|---|---|" >> $output
Expand All @@ -63,20 +80,7 @@ function display_results {
# echo -e "$final_line" >> $output
echo '' >> $output
elif [[ $source == 'gitlab' ]]; then
echo "Total Energy [Joules]: $total_energy" >> $output
echo "Total Avg. CPU Utilization: $cpu_avg" >> $output
echo "Total Avg. Power [Watts]: $power_avg" >> $output
echo "Total Duration [seconds]: $time" >> $output
echo "----------------" >> $output

for (( i=1; i<=$max_measurement_number; i++ )); do
echo "Label $i: $(eval echo \$label_$i)" >> $output
echo "Energy Used [Joules]: $(eval echo \$total_energy_$i)" >> $output
echo "Avg. CPU Utilization: $(eval echo \$cpu_avg_$i)" >> $output
echo "Avg. Power [Watts]: $(eval echo \$power_avg_$i)" >> $output
echo "Duration [seconds]: $(eval echo \$time_$i)" >> $output
echo "----------------" >> $output
done
echo $(cat "/tmp/eco-ci/output-short.txt") >> $output
fi


Expand Down
4 changes: 2 additions & 2 deletions scripts/make_measurement.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ function make_measurement() {
## 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 [[ "$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
cat /tmp/eco-ci/cpu-util.txt | python3 /tmp/eco-ci/spec-power-model/xgb.py --silent | tee -a /tmp/eco-ci/energy-total.txt > /tmp/eco-ci/energy.txt
else
cat /tmp/eco-ci/cpu-util.txt | python3.10 /tmp/eco-ci/spec-power-model/xgb.py \
cat /tmp/eco-ci/cpu-util.txt | python3 /tmp/eco-ci/spec-power-model/xgb.py \
--tdp $TDP --cpu-threads $CPU_THREADS \
--cpu-cores $CPU_CORES --cpu-make $CPU_MAKE \
--release-year $RELEASE_YEAR --ram $RAM \
Expand Down
4 changes: 2 additions & 2 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function initialize {

function setup_python {
# Create a venv, and backup old
python3.10 -m venv /tmp/eco-ci/venv
python3 -m venv /tmp/eco-ci/venv

if [[ $VIRTUAL_ENV != '' ]]; then
$PREVIOUS_VENV=$VIRTUAL_ENV
Expand All @@ -47,7 +47,7 @@ function setup_python {
# Installing requirements
# first activate our venv
source /tmp/eco-ci/venv/bin/activate
python3.10 -m pip install -r /tmp/eco-ci/spec-power-model/requirements.txt
python3 -m pip install -r /tmp/eco-ci/spec-power-model/requirements.txt
# now reset to old venv
deactivate our venv
# reactivate the old one, if it was present
Expand Down

0 comments on commit 1b0c2e9

Please sign in to comment.