-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: implement energy consumption check (WIP)
- Loading branch information
Showing
3 changed files
with
104 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: store energy baseline | ||
|
||
on: | ||
# push: | ||
workflow_dispatch: | ||
|
||
permissions: | ||
actions: read | ||
contents: read | ||
|
||
jobs: | ||
call-ci: | ||
uses: ./.github/workflows/ci.yaml | ||
with: | ||
upload: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import fs from "fs"; | ||
|
||
function compareEnergy() { | ||
try { | ||
// Read the energy values | ||
const currentData = JSON.parse(fs.readFileSync('/tmp/eco-ci/total-data.json', 'utf8')); | ||
const baselineData = JSON.parse(fs.readFileSync(`${process.env.GITHUB_WORKSPACE}/baseline-data/total-data.json`, 'utf8')); | ||
|
||
const currentEnergy = currentData.energy_joules; | ||
const baselineEnergy = baselineData.energy_joules; | ||
|
||
// Calculate percentage difference | ||
let percentDiff = ((currentEnergy - baselineEnergy) / baselineEnergy) * 100; | ||
const threshold = 10; | ||
|
||
percentDiff = Number.parseFloat(percentDiff).toFixed(2) | ||
// Log results | ||
console.log('Energy Consumption Analysis:'); | ||
console.log(`Current: ${Number.parseFloat(currentEnergy).toFixed(2)} joules`); | ||
console.log(`Baseline: ${Number.parseFloat(baselineEnergy).toFixed(2)} joules`); | ||
console.log(`Difference: ${percentDiff}%`); | ||
|
||
let message | ||
// Evaluate results | ||
if (percentDiff > threshold) { | ||
message = `Energy consumption increased by ${percentDiff}% (above ${threshold}% threshold)`; | ||
} else if (percentDiff < 0) { | ||
message = `Energy consumption decreased by ${percentDiff}%`; | ||
} else { | ||
message = `Energy consumption increased by ${percentDiff}% (within ${threshold}% threshold)`; | ||
} | ||
console.log(message) | ||
|
||
} catch (error) { | ||
console.log(`Error occurred: ${error.message}`); | ||
} | ||
} | ||
|
||
compareEnergy(); |