Blame 0004-profile.py-parse-the-output-of-dracut-profile-for-pr.patch

Harald Hoyer 55891e
From e7b8fe03e8b76ec4aa4797759cd849fcf792b33c Mon Sep 17 00:00:00 2001
Harald Hoyer 55891e
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer 55891e
Date: Wed, 17 Aug 2011 10:08:23 +0200
Harald Hoyer 55891e
Subject: [PATCH] profile.py: parse the output of "dracut --profile" for
Harald Hoyer 55891e
 profiling
Harald Hoyer 55891e
Harald Hoyer 55891e
---
Harald Hoyer 55891e
 profile.py |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Harald Hoyer 55891e
 1 files changed, 58 insertions(+), 0 deletions(-)
Harald Hoyer 55891e
 create mode 100644 profile.py
Harald Hoyer 55891e
Harald Hoyer 55891e
diff --git a/profile.py b/profile.py
Harald Hoyer 55891e
new file mode 100644
Harald Hoyer 55891e
index 0000000..e1d0cab
Harald Hoyer 55891e
--- /dev/null
Harald Hoyer 55891e
+++ b/profile.py
Harald Hoyer 55891e
@@ -0,0 +1,58 @@
Harald Hoyer 55891e
+#
Harald Hoyer 55891e
+# parse the output of "dracut --profile" and produce profiling information
Harald Hoyer 55891e
+#
Harald Hoyer 55891e
+# Copyright 2011 Harald Hoyer <harald@redhat.com>
Harald Hoyer 55891e
+# Copyright 2011 Red Hat, Inc.  All rights reserved.
Harald Hoyer 55891e
+#
Harald Hoyer 55891e
+# This program is free software; you can redistribute it and/or modify
Harald Hoyer 55891e
+# it under the terms of the GNU General Public License as published by
Harald Hoyer 55891e
+# the Free Software Foundation; either version 2 of the License, or
Harald Hoyer 55891e
+# (at your option) any later version.
Harald Hoyer 55891e
+#
Harald Hoyer 55891e
+# This program is distributed in the hope that it will be useful,
Harald Hoyer 55891e
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
Harald Hoyer 55891e
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Harald Hoyer 55891e
+# GNU General Public License for more details.
Harald Hoyer 55891e
+#
Harald Hoyer 55891e
+# You should have received a copy of the GNU General Public License
Harald Hoyer 55891e
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Harald Hoyer 55891e
+#
Harald Hoyer 55891e
+
Harald Hoyer 55891e
+import sys
Harald Hoyer 55891e
+import operator
Harald Hoyer 55891e
+import re
Harald Hoyer 55891e
+loglines = sys.stdin
Harald Hoyer 55891e
+
Harald Hoyer 55891e
+logpats  = r'[+]+[ \t]+([^ \t]+)[ \t]+([^ \t:]+):[ ]+.*'
Harald Hoyer 55891e
+
Harald Hoyer 55891e
+logpat   = re.compile(logpats)
Harald Hoyer 55891e
+
Harald Hoyer 55891e
+groups   = (logpat.match(line) for line in loglines)
Harald Hoyer 55891e
+tuples   = (g.groups() for g in groups if g)
Harald Hoyer 55891e
+
Harald Hoyer 55891e
+def gen_times(t):
Harald Hoyer 55891e
+    oldx=None
Harald Hoyer 55891e
+    for x in t:
Harald Hoyer 55891e
+        fx=float(x[0])
Harald Hoyer 55891e
+        if oldx:
Harald Hoyer 55891e
+            #print fx - float(oldx[0]), x[0], x[1], oldx[0], oldx[1]
Harald Hoyer 55891e
+            yield (fx - float(oldx[0]), oldx[1])
Harald Hoyer 55891e
+
Harald Hoyer 55891e
+        oldx = x
Harald Hoyer 55891e
+
Harald Hoyer 55891e
+colnames = ('time','line')
Harald Hoyer 55891e
+
Harald Hoyer 55891e
+log      = (dict(zip(colnames,t)) for t in gen_times(tuples))
Harald Hoyer 55891e
+
Harald Hoyer 55891e
+if __name__ == '__main__':
Harald Hoyer 55891e
+    e={}
Harald Hoyer 55891e
+    for x in log:
Harald Hoyer 55891e
+        if not x['line'] in e:
Harald Hoyer 55891e
+            e[x['line']] = x['time']
Harald Hoyer 55891e
+        else:
Harald Hoyer 55891e
+            e[x['line']] += x['time']
Harald Hoyer 55891e
+
Harald Hoyer 55891e
+    sorted_x = sorted(e.iteritems(), key=operator.itemgetter(1), reverse=True)
Harald Hoyer 55891e
+    for x in sorted_x:
Harald Hoyer 55891e
+        print x[0], x[1]
Harald Hoyer 55891e
+