oprofile-top.py revision 1596:d11171f51a63
1#! /usr/bin/env python
2import sys
3import re
4import getopt
5from categories import *
6
7def category(app,sym):
8    if re.search("vmlinux-2.6", app):
9        name = sym
10    else:
11        name = app
12
13    if categories.has_key(name):
14        return categories[name]
15    for regexp, cat in categories_re:
16        if regexp.match(name):
17            return cat
18    print "no match for symbol %s" % name
19    return 'other'
20
21try:
22   (opts, files) = getopt.getopt(sys.argv[1:], 'i')
23except getopt.GetoptError:
24        print "usage", sys.argv[0], "[-i] <files>"
25        sys.exit(2)
26
27showidle = True
28
29for o,v in opts:
30    if o == "-i":
31        showidle = False
32print files
33f = open(files.pop())
34total = 0
35prof = {}
36linenum  = 0
37for line in f.readlines():
38    line = re.sub("\(no symbols\)", "nosym", line)
39    line = re.sub("anonymous.*", "nosym", line)
40    linenum += 1
41    if linenum < 4:
42        continue
43    (count, percent, app, sym) = line.split()
44    #total += int(count)
45    cat = category(app,sym)
46    if cat != 'idle' or showidle:
47      total += int(count)
48      prof[cat] = prof.get(cat,0) + int(count)
49
50cats = ['other', 'user', 'copy', 'bufmgt', 'stack', 'driver', 'interrupt', 'alignment' ]
51
52if showidle:
53   cats.insert(0,'idle')
54
55#syms = [(i[1], i[0]) for i in prof.items()]
56#syms.sort()
57#for i in range(len(syms)):
58#    print "%s -- %5.1f%% " % (prof[i][1], 100 * float(prof[i][0])/float(total))
59
60for d in cats:
61    if prof.has_key(d):
62        print "%s -- %5.1f%% " % (d, 100 * float(prof[d])/float(total))
63
64