aboutsummaryrefslogtreecommitdiff
path: root/stm32/unittest/scripts/sum_profiles
blob: 706b8a262db9c37da2f5ccb91d0650559e1e65d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
#!/usr/bin/env python3
""" sum_profiles """

def sum_profiles(fin, frames):
    data = {}
    total_time = 0.0

    for line in fin:
        words = line.strip().split()
        if (len(words) == 3):
            part = words[0]
            time_str = words[1]
            time = float(time_str)
            total_time += time
            if (not part in data): data[part] = 0.0
            data[part] += time

    data_sorted = [(p, data[p]) for p in sorted(data, key=data.get, reverse=True)]

    print("Total time = {:.1f} ms".format(total_time))
    if (frames):
        print("{:.1f} per frame".format(total_time / args.frames))
        print("")

    for part, time in data_sorted:
        percent = int(100*(time / total_time))
        print('{:2d}% - {:10.3f} - {}'.format(percent, time, part))

    return(data)
    # end sum_profiles()


########################################
if __name__ == "__main__":
    import argparse

    #### Options 
    argparser = argparse.ArgumentParser()
    argparser.add_argument("-f", "--frames", action="store", type=int, default=0,
                                             help="Number of frames")
    argparser.add_argument("file", metavar="FILE", help="file to read")
    args = argparser.parse_args()

    fin = open(args.file, "r")
    sum_profiles(fin, args.frames)