File: sum_profiles

package info (click to toggle)
codec2 1.2.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 76,376 kB
  • sloc: ansic: 436,819; cpp: 2,091; objc: 1,736; sh: 1,510; python: 1,405; asm: 683; makefile: 605
file content (45 lines) | stat: -rw-r--r-- 1,321 bytes parent folder | download | duplicates (4)
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)