~mvo/update-manager/pae-kernel-transtion

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
46
47
48
49
50
51
#!/usr/bin/python


import sys
import string
from heapq import heappush, heappop

if __name__ == "__main__":
    
    start_time = 0.0
    last_time = 0.0
    total_time = 0.0
    pkgs = {}
    last_pkgname = None

    log = open(sys.argv[1])
    for line in map(string.strip, log):
        line_data = line.split(":")

        # special cases
        if line_data[1].strip() == "Start":
            start_time = float(line_data[0])
            continue
        elif line_data[1].strip() == "Finished":
            total_time = float(line_data[0]) - start_time
            continue

        # we have a real pkg here
        current_time = float(line_data[0])
        pkgname = line_data[2]
        
        # special cases
        if not last_time:
            last_time = current_time
        if not pkgname in pkgs:
            pkgs[pkgname] = 0

        # add up time
        if last_pkgname:
            pkgs[last_pkgname] += (current_time-last_time)
        last_time = current_time
        last_pkgname = pkgname
    
    
    # put into heap and output by time it takes
    heap = []
    for pkg in pkgs:
        heappush(heap, (pkgs[pkg], pkg))
    while heap:
        print "%.6ss: %s" % heappop(heap)
    print "total: %4.7ss %4.6sm" % (total_time, total_time/60)