dmsquash-live: add dmsquash-generator
[dracut.git] / profile.py
blob7f98a136f4c2f60736733cb7ca8ea645b27221c0
2 # parse the output of "dracut --profile" and produce profiling information
4 # Copyright 2011 Harald Hoyer <harald@redhat.com>
5 # Copyright 2011 Red Hat, Inc. All rights reserved.
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.
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.
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/>.
21 import sys
22 import operator
23 import re
24 loglines = sys.stdin
26 logpats = r'[+]+[ \t]+([^ \t]+)[ \t]+([^ \t:]+):[ ]+.*'
28 logpat = re.compile(logpats)
30 groups = (logpat.match(line) for line in loglines)
31 tuples = (g.groups() for g in groups if g)
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])
42 oldx = x
44 colnames = ('time','line')
46 log = (dict(zip(colnames,t)) for t in gen_times(tuples))
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']
56 sorted_x = sorted(e.iteritems(), key=operator.itemgetter(1), reverse=True)
57 for x in sorted_x:
58 print x[0], x[1]