Skip to content

Commit

Permalink
Local testing script
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneTR committed Jun 14, 2024
1 parent b54d595 commit 62657cd
Show file tree
Hide file tree
Showing 11 changed files with 10,164 additions and 45 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
Eco-CI is a project aimed at estimating energy consumption in continuous integration (CI) environments. It provides functionality to calculate the energy consumption of CI jobs based on the power consumption characteristics of the underlying hardware.


## Requirements
Following packages are expected:
- `curl`
- `jq`
- `awk`

## Usage

Eco-CI supports both GitHub and GitLab as CI platforms. When you integrate it into your pipeline, you must call the start-measurement script to begin collecting power consumption data, then call the get-measurement script each time you wish to make a spot measurement. When you call get-measurment, you can also assign a label to it to more easily identify the measurement. At the end, call the display-results to see all the measurement results, overall total usage, and export the data.
Expand Down
99 changes: 99 additions & 0 deletions local_ci.example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/usr/bin/env bash
set -euo pipefail

ECO_CI_SEND_DATA="true"
ECO_CI_DISPLAY_BADGE="true"
ECO_CI_DISPLAY_TABLE="true"
ECO_CI_SHOW_CARBON="true"

ECO_CI_WORKFLOW_ID="YOUR WORKFLOW ID"

ECO_CI_COMPANY_UUID=""
ECO_CI_PROJECT_UUID=""
ECO_CI_MACHINE_UUID=""

# Please input valid UUIDs here if you want to use CarbonDB (https://www.green-coding.io/projects/carbondb/)
# Generate one here for example: https://www.freecodeformat.com/validate-uuid-guid.php
# ECO_CI_COMPANY_UUID="YOUR COMPANY UUID"
# ECO_CI_PROJECT_UUID="YOUR PROJECT UUID"
# ECO_CI_MACHINE_UUID="YOUR MACHINE UUID"

# Use a generated power curve from Cloud Energy here
MACHINE_POWER_DATA="default.sh"

# Initialize
echo "Initialize"

"$(dirname "$0")/scripts/setup.sh" initialize $MACHINE_POWER_DATA
"$(dirname "$0")/scripts/vars.sh" add_var "WORKFLOW_ID" $ECO_CI_WORKFLOW_ID
"$(dirname "$0")/scripts/setup.sh" start_measurement
echo "Duration: "$(($(date +%s) - $(cat /tmp/eco-ci/timer-total.txt)))

# Do some work
echo "Sleeping"
sleep 3s
echo "Duration: "$(($(date +%s) - $(cat /tmp/eco-ci/timer-total.txt)))


"$(dirname "$0")/scripts/make_measurement.sh" \
-l "Step sleep" \
-r "My Pipeline ID" \
-b "Branch Name" \
-R "Repo Name" \
-c "Commit SHA hash" \
-sd "$ECO_CI_SEND_DATA" \
-s "local" \
-n "Workflow nice name" \
-cbc "$ECO_CI_COMPANY_UUID" \
-cbp "$ECO_CI_PROJECT_UUID" \
-cbm "$ECO_CI_MACHINE_UUID"

# Do some other work
echo "ls -alhR"
timeout 3s ls -alhR / > /dev/null || true
echo "Duration: "$(($(date +%s) - $(cat /tmp/eco-ci/timer-total.txt)))

echo "Sleeping "
sleep 3
echo "Duration: "$(($(date +%s) - $(cat /tmp/eco-ci/timer-total.txt)))

"$(dirname "$0")/scripts/make_measurement.sh" \
-l "Step ls -alh" \
-r "My Pipeline ID" \
-b "Branch Name" \
-R "Repo Name" \
-c "Commit SHA hash" \
-sd "$ECO_CI_SEND_DATA" \
-s "local" \
-n "Workflow nice name" \
-cbc "$ECO_CI_COMPANY_UUID" \
-cbp "$ECO_CI_PROJECT_UUID" \
-cbm "$ECO_CI_MACHINE_UUID"

echo "Display Results"
echo "Duration: "$(($(date +%s) - $(cat /tmp/eco-ci/timer-total.txt)))

# Display results
ECO_CI_FORMAT_CLR="\e[44m"
ECO_CI_TXT_CLEAR="\e[0m"

echo "Dump files"
cat /tmp/eco-ci/energy-total.txt
cat /tmp/eco-ci/cpu-util-total.txt


"$(dirname "$0")/scripts/display_results.sh" \
-b "Branch Name" \
-db "$ECO_CI_DISPLAY_BADGE" \
-r "My Pipeline ID" \
-R "Repo Name" \
-dt "$ECO_CI_DISPLAY_TABLE" \
-sd "$ECO_CI_SEND_DATA" \
-s "local" \
-sc "$ECO_CI_SHOW_CARBON"

echo -e "$ECO_CI_FORMAT_CLR$(cat /tmp/eco-ci/output.txt)$ECO_CI_TXT_CLEAR"
echo "Duration: "$(($(date +%s) - $(cat /tmp/eco-ci/timer-total.txt)))

"$(dirname "$0")/scripts/setup.sh" end_measurement

Loading

0 comments on commit 62657cd

Please sign in to comment.