mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-15 20:35:49 +00:00
add scaphandre 2
This commit is contained in:
parent
47fae9625c
commit
0672b5f13e
1 changed files with 108 additions and 69 deletions
177
.github/workflows/pipeline.yml
vendored
177
.github/workflows/pipeline.yml
vendored
|
@ -9,7 +9,7 @@ on:
|
||||||
jobs:
|
jobs:
|
||||||
build-with-metrics:
|
build-with-metrics:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 60
|
timeout-minutes: 15
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
@ -22,8 +22,10 @@ jobs:
|
||||||
source "$HOME/.cargo/env"
|
source "$HOME/.cargo/env"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Installer Scaphandre via Cargo
|
# Installer Scaphandre et configurer les permissions
|
||||||
cargo install scaphandre
|
cargo install scaphandre
|
||||||
|
sudo setcap cap_sys_rawio=+ep $(which scaphandre)
|
||||||
|
sudo chmod +r /dev/cpu/*/msr
|
||||||
|
|
||||||
- name: Setup directories and install dependencies
|
- name: Setup directories and install dependencies
|
||||||
run: |
|
run: |
|
||||||
|
@ -40,7 +42,11 @@ jobs:
|
||||||
linux-tools-common \
|
linux-tools-common \
|
||||||
linux-tools-generic \
|
linux-tools-generic \
|
||||||
python3-pip \
|
python3-pip \
|
||||||
python3-psutil
|
python3-psutil \
|
||||||
|
msr-tools
|
||||||
|
|
||||||
|
# Charger le module msr
|
||||||
|
sudo modprobe msr
|
||||||
|
|
||||||
# Installer dépendances Python
|
# Installer dépendances Python
|
||||||
pip3 install pandas numpy
|
pip3 install pandas numpy
|
||||||
|
@ -54,6 +60,7 @@ jobs:
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
|
import signal
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
def monitor_energy(command, output_file):
|
def monitor_energy(command, output_file):
|
||||||
|
@ -63,72 +70,64 @@ jobs:
|
||||||
# Préparer le fichier CSV
|
# Préparer le fichier CSV
|
||||||
with open(output_file, 'w', newline='') as csvfile:
|
with open(output_file, 'w', newline='') as csvfile:
|
||||||
writer = csv.writer(csvfile)
|
writer = csv.writer(csvfile)
|
||||||
writer.writerow([
|
writer.writerow(['Timestamp', 'Power_Watts', 'Component'])
|
||||||
'Timestamp',
|
|
||||||
'Power_Watts',
|
|
||||||
'Component'
|
|
||||||
])
|
|
||||||
|
|
||||||
# Commande scaphandre pour la sortie JSON
|
def signal_handler(signum, frame):
|
||||||
scaphandre_cmd = [
|
print("Signal reçu, arrêt du monitoring...")
|
||||||
'scaphandre', 'json',
|
sys.exit(0)
|
||||||
'-t', '120' # Timeout de 2 minutes max
|
|
||||||
]
|
|
||||||
|
|
||||||
# Lancer le monitoring en arrière-plan
|
signal.signal(signal.SIGTERM, signal_handler)
|
||||||
monitor_process = subprocess.Popen(
|
signal.signal(signal.SIGINT, signal_handler)
|
||||||
scaphandre_cmd,
|
|
||||||
stdout=subprocess.PIPE,
|
# Lancer la commande principale
|
||||||
stderr=subprocess.PIPE,
|
print(f"Exécution de la commande: {command}")
|
||||||
universal_newlines=True
|
main_process = subprocess.Popen(command, shell=True)
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Attendre un court instant pour que Scaphandre démarre
|
# Monitoring en continu pendant l'exécution de la commande
|
||||||
time.sleep(2)
|
while main_process.poll() is None:
|
||||||
|
try:
|
||||||
|
# Exécuter scaphandre pour une seule mesure
|
||||||
|
scaphandre_output = subprocess.check_output(
|
||||||
|
['sudo', 'scaphandre', 'json', '-n', '1'],
|
||||||
|
universal_newlines=True
|
||||||
|
)
|
||||||
|
|
||||||
# Exécuter la commande principale
|
# Traiter la mesure
|
||||||
main_process = subprocess.Popen(command, shell=True)
|
process_measurement(scaphandre_output, output_file)
|
||||||
main_process.wait()
|
|
||||||
|
|
||||||
# Attendre et traiter les données de Scaphandre
|
# Attendre 1 seconde avant la prochaine mesure
|
||||||
try:
|
time.sleep(1)
|
||||||
monitor_output, _ = monitor_process.communicate(timeout=10)
|
|
||||||
process_scaphandre_output(monitor_output, output_file)
|
except subprocess.CalledProcessError as e:
|
||||||
except subprocess.TimeoutExpired:
|
print(f"Erreur lors de la mesure: {e}")
|
||||||
print("Scaphandre monitoring timed out", file=sys.stderr)
|
continue
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Erreur inattendue: {e}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
return main_process.returncode
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
# Arrêter le monitoring
|
if main_process.poll() is None:
|
||||||
monitor_process.terminate()
|
main_process.terminate()
|
||||||
monitor_process.wait()
|
main_process.wait()
|
||||||
|
|
||||||
def process_scaphandre_output(output, output_file):
|
def process_measurement(output, output_file):
|
||||||
try:
|
try:
|
||||||
# Diviser le flux JSON en objets individuels
|
data = json.loads(output.strip())
|
||||||
json_objects = output.strip().split('\n')
|
timestamp = data.get('timestamp', datetime.now().isoformat())
|
||||||
|
power = data.get('power', {}).get('total_power', 0)
|
||||||
|
|
||||||
with open(output_file, 'a', newline='') as csvfile:
|
with open(output_file, 'a', newline='') as csvfile:
|
||||||
writer = csv.writer(csvfile)
|
writer = csv.writer(csvfile)
|
||||||
|
writer.writerow([timestamp, power, 'System'])
|
||||||
|
|
||||||
for json_str in json_objects:
|
except json.JSONDecodeError as e:
|
||||||
try:
|
print(f"Erreur de décodage JSON: {e}")
|
||||||
data = json.loads(json_str)
|
|
||||||
|
|
||||||
# Extraire les informations pertinentes
|
|
||||||
timestamp = data.get('timestamp', datetime.now().isoformat())
|
|
||||||
power = data.get('power', {}).get('total_power', 0)
|
|
||||||
|
|
||||||
writer.writerow([
|
|
||||||
timestamp,
|
|
||||||
power,
|
|
||||||
'System'
|
|
||||||
])
|
|
||||||
except json.JSONDecodeError:
|
|
||||||
print(f"Could not parse JSON: {json_str}", file=sys.stderr)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error processing Scaphandre output: {e}", file=sys.stderr)
|
print(f"Erreur de traitement: {e}")
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(sys.argv) < 3:
|
if len(sys.argv) < 3:
|
||||||
print("Usage: python energy_monitor.py 'command' output_file.csv")
|
print("Usage: python energy_monitor.py 'command' output_file.csv")
|
||||||
|
@ -137,8 +136,13 @@ jobs:
|
||||||
command = sys.argv[1]
|
command = sys.argv[1]
|
||||||
output_file = sys.argv[2]
|
output_file = sys.argv[2]
|
||||||
|
|
||||||
monitor_energy(command, output_file)
|
try:
|
||||||
|
exit_code = monitor_energy(command, output_file)
|
||||||
|
sys.exit(exit_code)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Erreur fatale: {e}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
EOL
|
EOL
|
||||||
|
@ -178,13 +182,13 @@ jobs:
|
||||||
|
|
||||||
- name: Build with Maven and measure energy
|
- name: Build with Maven and measure energy
|
||||||
id: build
|
id: build
|
||||||
timeout-minutes: 15
|
timeout-minutes: 5
|
||||||
env:
|
env:
|
||||||
MAVEN_OPTS: "-Xmx2048m -XX:+TieredCompilation -XX:TieredStopAtLevel=1"
|
MAVEN_OPTS: "-Xmx2048m -XX:+TieredCompilation -XX:TieredStopAtLevel=1"
|
||||||
run: |
|
run: |
|
||||||
set -eo pipefail
|
set -eo pipefail
|
||||||
|
|
||||||
# Ajouter Cargo et Scaphandre au PATH
|
# Ajouter Cargo au PATH
|
||||||
source "$HOME/.cargo/env"
|
source "$HOME/.cargo/env"
|
||||||
|
|
||||||
start_time=$(date +%s%N)
|
start_time=$(date +%s%N)
|
||||||
|
@ -193,8 +197,8 @@ jobs:
|
||||||
free -m > metrics/system/pre_build_memory.txt
|
free -m > metrics/system/pre_build_memory.txt
|
||||||
|
|
||||||
# Monitoring énergétique avec Scaphandre
|
# Monitoring énergétique avec Scaphandre
|
||||||
python3 energy_monitor.py \
|
sudo python3 energy_monitor.py \
|
||||||
"./mvnw -B verify -Dmaven.test.skip=true -Dcheckstyle.skip=true -T 1C" \
|
"./mvnw -B verify -Dmaven.test.skip=true" \
|
||||||
metrics/power/build_power_metrics.csv
|
metrics/power/build_power_metrics.csv
|
||||||
|
|
||||||
build_status=$?
|
build_status=$?
|
||||||
|
@ -206,16 +210,20 @@ jobs:
|
||||||
# Enregistrer le temps de build
|
# Enregistrer le temps de build
|
||||||
echo "$((($end_time - $start_time)/1000000))" > metrics/performance/build_time.txt
|
echo "$((($end_time - $start_time)/1000000))" > metrics/performance/build_time.txt
|
||||||
|
|
||||||
|
# Vérifier le contenu du fichier de métriques
|
||||||
|
echo "=== Build power metrics content ==="
|
||||||
|
cat metrics/power/build_power_metrics.csv
|
||||||
|
|
||||||
exit $build_status
|
exit $build_status
|
||||||
|
|
||||||
- name: Run tests with energy monitoring
|
- name: Run tests with energy monitoring
|
||||||
id: test
|
id: test
|
||||||
if: success()
|
if: success()
|
||||||
timeout-minutes: 20
|
timeout-minutes: 5
|
||||||
run: |
|
run: |
|
||||||
set -eo pipefail
|
set -eo pipefail
|
||||||
|
|
||||||
# Ajouter Cargo et Scaphandre au PATH
|
# Ajouter Cargo au PATH
|
||||||
source "$HOME/.cargo/env"
|
source "$HOME/.cargo/env"
|
||||||
|
|
||||||
start_time=$(date +%s%N)
|
start_time=$(date +%s%N)
|
||||||
|
@ -224,8 +232,8 @@ jobs:
|
||||||
free -m > metrics/system/pre_test_memory.txt
|
free -m > metrics/system/pre_test_memory.txt
|
||||||
|
|
||||||
# Monitoring énergétique avec Scaphandre
|
# Monitoring énergétique avec Scaphandre
|
||||||
python3 energy_monitor.py \
|
sudo python3 energy_monitor.py \
|
||||||
"./mvnw test -T 1C" \
|
"./mvnw test" \
|
||||||
metrics/power/test_power_metrics.csv
|
metrics/power/test_power_metrics.csv
|
||||||
|
|
||||||
test_status=$?
|
test_status=$?
|
||||||
|
@ -237,16 +245,20 @@ jobs:
|
||||||
# Enregistrer le temps des tests
|
# Enregistrer le temps des tests
|
||||||
echo "$((($end_time - $start_time)/1000000))" > metrics/performance/test_time.txt
|
echo "$((($end_time - $start_time)/1000000))" > metrics/performance/test_time.txt
|
||||||
|
|
||||||
|
# Vérifier le contenu du fichier de métriques
|
||||||
|
echo "=== Test power metrics content ==="
|
||||||
|
cat metrics/power/test_power_metrics.csv
|
||||||
|
|
||||||
exit $test_status
|
exit $test_status
|
||||||
|
|
||||||
- name: Build Docker image with energy monitoring
|
- name: Build Docker image with energy monitoring
|
||||||
id: docker-build
|
id: docker-build
|
||||||
if: success()
|
if: success()
|
||||||
timeout-minutes: 10
|
timeout-minutes: 5
|
||||||
run: |
|
run: |
|
||||||
set -eo pipefail
|
set -eo pipefail
|
||||||
|
|
||||||
# Ajouter Cargo et Scaphandre au PATH
|
# Ajouter Cargo au PATH
|
||||||
source "$HOME/.cargo/env"
|
source "$HOME/.cargo/env"
|
||||||
|
|
||||||
start_time=$(date +%s%N)
|
start_time=$(date +%s%N)
|
||||||
|
@ -256,8 +268,8 @@ jobs:
|
||||||
df -h > metrics/system/pre_docker_disk.txt
|
df -h > metrics/system/pre_docker_disk.txt
|
||||||
|
|
||||||
# Monitoring énergétique avec Scaphandre
|
# Monitoring énergétique avec Scaphandre
|
||||||
python3 energy_monitor.py \
|
sudo python3 energy_monitor.py \
|
||||||
"docker build -t app:latest -f .devcontainer/Dockerfile . --no-cache" \
|
"docker build -t app:latest -f .devcontainer/Dockerfile ." \
|
||||||
metrics/power/docker_build_power_metrics.csv
|
metrics/power/docker_build_power_metrics.csv
|
||||||
|
|
||||||
build_status=$?
|
build_status=$?
|
||||||
|
@ -273,6 +285,10 @@ jobs:
|
||||||
# Collecter la taille de l'image
|
# Collecter la taille de l'image
|
||||||
docker images app:latest --format "{{.Size}}" > metrics/performance/docker_image_size.txt
|
docker images app:latest --format "{{.Size}}" > metrics/performance/docker_image_size.txt
|
||||||
|
|
||||||
|
# Vérifier le contenu du fichier de métriques
|
||||||
|
echo "=== Docker build power metrics content ==="
|
||||||
|
cat metrics/power/docker_build_power_metrics.csv
|
||||||
|
|
||||||
exit $build_status
|
exit $build_status
|
||||||
|
|
||||||
- name: Collect final system metrics
|
- name: Collect final system metrics
|
||||||
|
@ -293,6 +309,29 @@ jobs:
|
||||||
# Marquer la fin du pipeline
|
# Marquer la fin du pipeline
|
||||||
date +%s%N > metrics/pipeline_end_time.txt
|
date +%s%N > metrics/pipeline_end_time.txt
|
||||||
|
|
||||||
|
- name: Verify metrics collection
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
echo "=== Checking power metrics files ==="
|
||||||
|
for file in metrics/power/*.csv; do
|
||||||
|
echo "=== Content of $file: ==="
|
||||||
|
cat "$file"
|
||||||
|
echo "Size of $file: $(wc -l < "$file") lines"
|
||||||
|
echo "File permissions: $(ls -l "$file")"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "=== Checking system metrics files ==="
|
||||||
|
for file in metrics/system/*; do
|
||||||
|
echo "=== Content of $file: ==="
|
||||||
|
cat "$file"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "=== Checking performance metrics files ==="
|
||||||
|
for file in metrics/performance/*; do
|
||||||
|
echo "=== Content of $file: ==="
|
||||||
|
cat "$file"
|
||||||
|
done
|
||||||
|
|
||||||
- name: Save metrics
|
- name: Save metrics
|
||||||
if: always()
|
if: always()
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
|
|
Loading…
Reference in a new issue