run.py 2.54 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='?', default=1,
18
                        help='The number of experiments to be run.')
19
    parser.add_argument('utilization', type=float, nargs='?',
20 21
                        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
        if args.utilization is not None:
36 37 38 39 40
            utilization = '--utilization {} {}'.format(args.utilization - 0.25, args.utilization + 0.25)
            subprocess.call(['./tasksetgen.py', '--microseconds', '--utilization', str(args.utilization - 0.25),
                             str(args.utilization + 0.25), '--uniform', '5',
                             str(remain), 'experiments/ese2016_{}'.format(cnt),
                             'experiment_data'])
41 42 43 44 45
        else:
            subprocess.call(['./tasksetgen.py', '--microseconds', '--uniform', '5',
                            str(remain), 'experiments/ese2016_{}'.format(cnt),
                            'experiment_data'])

46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
        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()