oprofile-top.py revision 2665
16145Snate@binkert.org#! /usr/bin/env python 26145Snate@binkert.org 36145Snate@binkert.org# Copyright (c) 2005 The Regents of The University of Michigan 46145Snate@binkert.org# All rights reserved. 56145Snate@binkert.org# 66145Snate@binkert.org# Redistribution and use in source and binary forms, with or without 76145Snate@binkert.org# modification, are permitted provided that the following conditions are 86145Snate@binkert.org# met: redistributions of source code must retain the above copyright 96145Snate@binkert.org# notice, this list of conditions and the following disclaimer; 106145Snate@binkert.org# redistributions in binary form must reproduce the above copyright 116145Snate@binkert.org# notice, this list of conditions and the following disclaimer in the 126145Snate@binkert.org# documentation and/or other materials provided with the distribution; 136145Snate@binkert.org# neither the name of the copyright holders nor the names of its 146145Snate@binkert.org# contributors may be used to endorse or promote products derived from 156145Snate@binkert.org# this software without specific prior written permission. 166145Snate@binkert.org# 176145Snate@binkert.org# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 186145Snate@binkert.org# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 196145Snate@binkert.org# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 206145Snate@binkert.org# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 216145Snate@binkert.org# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 226145Snate@binkert.org# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 236145Snate@binkert.org# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 246145Snate@binkert.org# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 256145Snate@binkert.org# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 266145Snate@binkert.org# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 276145Snate@binkert.org# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 286145Snate@binkert.org# 297039Snate@binkert.org# Authors: Ali Saidi 307039Snate@binkert.org# Nathan Binkert 316145Snate@binkert.org 327055Snate@binkert.org# Parse sampled function profile output (quick hack). 3311168Sandreas.hansson@arm.com 347055Snate@binkert.orgimport sys 359773Snilay@cs.wisc.eduimport re 368165Snilay@cs.wisc.eduimport getopt 379104Shestness@cs.utexas.edufrom categories import * 387039Snate@binkert.org 3910301Snilay@cs.wisc.edudef category(app,sym): 406285Snate@binkert.org if re.search("vmlinux-2.6", app): 419171Snilay@cs.wisc.edu name = sym 426145Snate@binkert.org else: 437039Snate@binkert.org name = app 447039Snate@binkert.org 458615Snilay@cs.wisc.edu if categories.has_key(name): 468615Snilay@cs.wisc.edu return categories[name] 479501Snilay@cs.wisc.edu for regexp, cat in categories_re: 486285Snate@binkert.org if regexp.match(name): 499501Snilay@cs.wisc.edu return cat 509501Snilay@cs.wisc.edu print "no match for symbol %s" % name 518615Snilay@cs.wisc.edu return 'other' 527039Snate@binkert.org 536285Snate@binkert.orgtry: 546285Snate@binkert.org (opts, files) = getopt.getopt(sys.argv[1:], 'i') 556763SBrad.Beckmann@amd.comexcept getopt.GetoptError: 566763SBrad.Beckmann@amd.com print "usage", sys.argv[0], "[-i] <files>" 579171Snilay@cs.wisc.edu sys.exit(2) 587039Snate@binkert.org 597039Snate@binkert.orgshowidle = True 606876Ssteve.reinhardt@amd.com 617039Snate@binkert.orgfor o,v in opts: 627039Snate@binkert.org if o == "-i": 636145Snate@binkert.org showidle = False 647039Snate@binkert.orgprint files 657039Snate@binkert.orgf = open(files.pop()) 6610012Snilay@cs.wisc.edutotal = 0 6710012Snilay@cs.wisc.eduprof = {} 6810012Snilay@cs.wisc.edulinenum = 0 699598Snilay@cs.wisc.edufor line in f.readlines(): 7011025Snilay@cs.wisc.edu line = re.sub("\(no symbols\)", "nosym", line) 717565SBrad.Beckmann@amd.com line = re.sub("anonymous.*", "nosym", line) 729773Snilay@cs.wisc.edu linenum += 1 739773Snilay@cs.wisc.edu if linenum < 4: 749773Snilay@cs.wisc.edu continue 759773Snilay@cs.wisc.edu (count, percent, app, sym) = line.split() 769773Snilay@cs.wisc.edu #total += int(count) 776145Snate@binkert.org cat = category(app,sym) 7811025Snilay@cs.wisc.edu if cat != 'idle' or showidle: 797565SBrad.Beckmann@amd.com total += int(count) 809773Snilay@cs.wisc.edu prof[cat] = prof.get(cat,0) + int(count) 819773Snilay@cs.wisc.edu 829773Snilay@cs.wisc.educats = ['other', 'user', 'copy', 'bufmgt', 'stack', 'driver', 'interrupt', 'alignment' ] 839773Snilay@cs.wisc.edu 849773Snilay@cs.wisc.eduif showidle: 857565SBrad.Beckmann@amd.com cats.insert(0,'idle') 868615Snilay@cs.wisc.edu 877039Snate@binkert.org#syms = [(i[1], i[0]) for i in prof.items()] 888688Snilay@cs.wisc.edu#syms.sort() 898688Snilay@cs.wisc.edu#for i in range(len(syms)): 909598Snilay@cs.wisc.edu# print "%s -- %5.1f%% " % (prof[i][1], 100 * float(prof[i][0])/float(total)) 919598Snilay@cs.wisc.edu 929598Snilay@cs.wisc.edufor d in cats: 939598Snilay@cs.wisc.edu if prof.has_key(d): 949598Snilay@cs.wisc.edu print "%s -- %5.1f%% " % (d, 100 * float(prof[d])/float(total)) 956145Snate@binkert.org 967055Snate@binkert.org