run.py 2.45 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#!/usr/bin/env python3

import sys
import os
import argparse
import shutil
import subprocess

def get_exp_cnt(path):
    try:
        return len([name for name in os.listdir(path) if os.path.isfile(path + '/' + name)])
    except Exception:
        return 0

def main():
    parser = argparse.ArgumentParser('Run all the scripts so everything works fine.')
17
    parser.add_argument('experiments', type=int, nargs=1, default=1,
18
                        help='The number of experiments to be run.')
19 20 21
    parser.add_argument('utilization', type=float, nargs='?', default=1,
                        help='The utilization for the experiments to be run.',
                        default=None)
22 23 24 25 26 27 28 29 30 31 32 33 34

    args = parser.parse_args()
    cwd = os.getcwd()

    try:
        shutil.rmtree('./experiment_data')
    except FileNotFoundError:
        pass
    os.makedirs('./experiment_data')

    cnt = 0
    remain = args.experiments
    while remain > 0:
35 36 37 38 39 40 41 42 43 44
        if parser.utilization is not None:
            subprocess.call(['./tasksetgen.py', '--microseconds', '--uniform', '5',
                             '--utilization {}:{}'.format(args.utilization - 0.25, args.utilization + 0.25),
                            str(remain), 'experiments/ese2016_{}'.format(cnt),
                            'experiment_data'])
        else:
            subprocess.call(['./tasksetgen.py', '--microseconds', '--uniform', '5',
                            str(remain), 'experiments/ese2016_{}'.format(cnt),
                            'experiment_data'])

45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
        for experiment in os.listdir('experiments/ese2016_{}'.format(cnt)):
            subprocess.call(['./generate.py',
                            'experiments/ese2016_{}'.format(cnt) + '/' + experiment])
        shutil.copyfile('Makefile', './experiment_data/Makefile')
        subprocess.call(['./runner.py', './experiment_data'])

        os.makedirs('./experiment_data/{}'.format(cnt))
        for experiment in os.listdir('./experiment_data'):
            if experiment.isdigit() or experiment == 'results' or experiment == 'Makefile':
                   continue
            try:
                shutil.move('./experiment_data/' + experiment, './experiment_data/' + str(cnt))
            except Exception:
                pass

        cnt += 1
        remain = args.experiments - get_exp_cnt('./experiment_data/results')
        print('remain:', remain, 'experiments: ', args.experiments, get_exp_cnt('./experiment_data/results'))

if __name__ == '__main__':
    main()