Remove unnecessary settings on checkisomd5@.service
[platform/upstream/dracut.git] / profile.py
1 #
2 # parse the output of "dracut --profile" and produce profiling information
3 #
4 # Copyright 2011 Harald Hoyer <harald@redhat.com>
5 # Copyright 2011 Red Hat, Inc.  All rights reserved.
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20
21 import sys
22 import operator
23 import re
24 loglines = sys.stdin
25
26 logpats  = r'[+]+[ \t]+([^ \t]+)[ \t]+([^ \t:]+):[ ]+.*'
27
28 logpat   = re.compile(logpats)
29
30 groups   = (logpat.match(line) for line in loglines)
31 tuples   = (g.groups() for g in groups if g)
32
33 def gen_times(t):
34     oldx=None
35     for x in t:
36         fx=float(x[0])
37         if oldx:
38             #print fx - float(oldx[0]), x[0], x[1], oldx[0], oldx[1]
39             if ((fx - float(oldx[0])) > 0):
40                     yield (fx - float(oldx[0]), oldx[1])
41
42         oldx = x
43
44 colnames = ('time','line')
45
46 log      = (dict(zip(colnames,t)) for t in gen_times(tuples))
47
48 if __name__ == '__main__':
49     e={}
50     for x in log:
51         if not x['line'] in e:
52             e[x['line']] = x['time']
53         else:
54             e[x['line']] += x['time']
55
56     sorted_x = sorted(e.iteritems(), key=operator.itemgetter(1), reverse=True)
57     for x in sorted_x:
58         print x[0], x[1]
59