]> git.ipfire.org Git - thirdparty/dracut.git/blame - profile.py
iscsi: always popd, even if there is no iscsi device
[thirdparty/dracut.git] / profile.py
CommitLineData
e7b8fe03
HH
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
21import sys
22import operator
23import re
24loglines = sys.stdin
25
26logpats = r'[+]+[ \t]+([^ \t]+)[ \t]+([^ \t:]+):[ ]+.*'
27
28logpat = re.compile(logpats)
29
30groups = (logpat.match(line) for line in loglines)
31tuples = (g.groups() for g in groups if g)
32
33def 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]
28a6eef3
HH
39 if ((fx - float(oldx[0])) > 0):
40 yield (fx - float(oldx[0]), oldx[1])
e7b8fe03
HH
41
42 oldx = x
43
44colnames = ('time','line')
45
46log = (dict(zip(colnames,t)) for t in gen_times(tuples))
47
48if __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