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

import argparse
import math

def calc_utilization(tasks):
    util = 0
    for task in tasks:
        util += task['wcet'] / task['period']
    return util

def main():
    parser = argparse.ArgumentParser(description='Generate plotable results from the experiments.')
    parser.add_argument('results', type=str, nargs='+', help='file containing experiment results.')
15
    parser.add_argument('analysis', type=str, nargs=1, help='name identifying the analysis results.')
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

    args = parser.parse_args()

    out = {}

    for result in args.results:
        with open(result, 'r') as result_file:
            tasks = {}
            instances = {}

            for line in result_file:
                tokens = line.strip().split(' ')
                if tokens[0] == 'task':
                    #task 0 wcet 5 period 39 deadline 32 executions 15480

                    task_id = int(tokens[1])
                    wcet = int(tokens[3])
                    period = int(tokens[5])
                    deadline = int(tokens[7])
                    executions = int(tokens[9])

                    tasks[task_id] = { 'id': task_id, 'wcet': wcet, 'period': period, 'deadline': deadline, 'executions': executions }
                    instances[task_id] = { 's2s':0, 'e2e':0, 'misses':0, 'response':0 }

                elif tokens[0] == 'instance':
                    #instance 12 start 478 end 487 core_id 0

                    start = int(tokens[3])
                    end = int(tokens[5])

                    if start == 0 and end == 0:
                        # Ignore not executed tasks, not realy that clean but it
                        # happens hardly, so nobody should care...
                        tasks[task_id]['executions'] -= 1
                        continue

                    release = start - (start % tasks[task_id]['period'])
                    abs_deadline = release + tasks[task_id]['deadline']

                    instances[task_id]['s2s'] += start - release
                    instances[task_id]['e2e'] += end - release
                    instances[task_id]['response'] += end - release
                    if end > abs_deadline:
                        instances[task_id]['misses'] += 1
                else:
                    continue

        util = calc_utilization(tasks.values())
        s2s = 0
        e2e = 0
        misses = 0
67 68
        misses_avrg = 0
        exec_cnt = 0
69 70
        response = 0
        for task_id, task in instances.items():
71
            exec_cnt += tasks[task_id]['executions']
72 73 74 75 76 77 78 79 80 81 82 83
            s2s += math.sqrt(task['s2s'] / tasks[task_id]['executions'])
            e2e += math.sqrt(task['e2e'] / tasks[task_id]['executions'])
            misses += task['misses']
            response += (task['response'] / tasks[task_id]['executions']) / tasks[task_id]['period']

        s2s /= len(tasks)
        e2e /= len(tasks)
        response /= len(tasks)

        outkey = round(util, 2)

        try:
84
            out[outkey].append((s2s, e2e, misses, response, exec_cnt))
85
        except KeyError:
86
            out[outkey] = [(s2s, e2e, misses, response, exec_cnt)]
87

88
    with open('analysis/{}_s2s.dat'.format(args.analysis), 'w') as s2sfile:
89 90
        for key, value in out.items():
            for elem in value:
91
                print('{}; {}; {}'.format(key, elem[0], elem[4]), file=s2sfile)
92

93
    with open('analysis/{}_e2e.dat'.format(args.analysis), 'w') as e2efile:
94 95
        for key, value in out.items():
            for elem in value:
Tobias Langer committed
96
                print('{}; {}; {}'.format(key, elem[1], elem[4]), file=e2efile)
97

98
    with open('analysis/{}_misses.dat'.format(args.analysis), 'w') as missesfile:
99 100
        for key, value in out.items():
            for elem in value:
Tobias Langer committed
101
                print('{}; {}; {}'.format(key, elem[2], elem[4]), file=missesfile)
102

103
    with open('analysis/{}_response.dat'.format(args.analysis), 'w') as responsefile:
104 105
        for key, value in out.items():
            for elem in value:
Tobias Langer committed
106
                print('{}; {}; {}'.format(key, elem[3], elem[4]), file=responsefile)
107 108 109

if __name__ == '__main__':
    main()