forked from menault/2026_TD1_DEV51_Qualite_Algo
Documenter le TD et conserver les profils et mesures reproductibles
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Reproduit les mesures sans instrumentation, puis les profils gprof."""
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
import statistics
|
||||
import subprocess
|
||||
|
||||
RACINE = Path(__file__).resolve().parent
|
||||
|
||||
|
||||
def executer(*commande, **options):
|
||||
subprocess.run(commande, check=True, **options)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--destination', type=Path, default=RACINE / 'mesures_reproduction')
|
||||
args = parser.parse_args()
|
||||
destination = args.destination.resolve()
|
||||
# Dossier neuf pour préserver les profils et mesures précédents.
|
||||
destination.mkdir(parents=True, exist_ok=False)
|
||||
for version, source in [('avant', RACINE / 'mesures/analyseur_avant.c'),
|
||||
('apres', RACINE / 'analyseur.c')]:
|
||||
dossier = destination / version
|
||||
dossier.mkdir()
|
||||
executable = dossier / 'analyseur'
|
||||
executer('gcc', '-O0', '-g', '-Wall', '-Wextra', str(source), '-o', str(executable))
|
||||
temps = []
|
||||
for numero in range(1, 4):
|
||||
fichier_temps = dossier / f'temps_{numero}.txt'
|
||||
with (dossier / f'sortie_{numero}.txt').open('w') as sortie:
|
||||
executer('/usr/bin/time', '-f', 'reel=%e utilisateur=%U systeme=%S memoire_Kio=%M',
|
||||
'-o', str(fichier_temps), str(executable), cwd=dossier, stdout=sortie)
|
||||
temps.append(float(fichier_temps.read_text().split()[0].split('=')[1]))
|
||||
reference = (destination / 'avant/rapport.txt').read_bytes()
|
||||
assert (dossier / 'rapport.txt').read_bytes() == reference, 'Rapport modifié'
|
||||
assert (dossier / f'sortie_{numero}.txt').read_bytes() == (destination / 'avant/sortie_1.txt').read_bytes(), 'Sortie modifiée'
|
||||
print(f'{version}: médiane {statistics.median(temps):.2f} s ({temps})')
|
||||
executer('gcc', '-O0', '-g', '-pg', str(source), '-o', str(executable))
|
||||
with (dossier / 'sortie_pg.txt').open('w') as sortie:
|
||||
executer('/usr/bin/time', '-f', 'reel=%e utilisateur=%U systeme=%S memoire_Kio=%M',
|
||||
'-o', str(dossier / 'temps_pg.txt'), str(executable), cwd=dossier, stdout=sortie)
|
||||
(dossier / 'gmon.out').rename(dossier / f'gmon_{version}.out')
|
||||
with (destination / f'profil_{version}.txt').open('w') as profil:
|
||||
executer('gprof', '-b', str(executable), str(dossier / f'gmon_{version}.out'), stdout=profil)
|
||||
assert (dossier / 'rapport.txt').read_bytes() == reference, 'Rapport instrumenté modifié'
|
||||
assert (dossier / 'sortie_pg.txt').read_bytes() == (destination / 'avant/sortie_1.txt').read_bytes(), 'Sortie instrumentée modifiée'
|
||||
print('Rapports et sorties identiques ; profils conservés dans', destination)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user