__init__.py revision 10453
12155SN/A# Copyright (c) 2007 The Regents of The University of Michigan 22155SN/A# Copyright (c) 2010 The Hewlett-Packard Development Company 32155SN/A# All rights reserved. 42155SN/A# 52155SN/A# Redistribution and use in source and binary forms, with or without 62155SN/A# modification, are permitted provided that the following conditions are 72155SN/A# met: redistributions of source code must retain the above copyright 82155SN/A# notice, this list of conditions and the following disclaimer; 92155SN/A# redistributions in binary form must reproduce the above copyright 102155SN/A# notice, this list of conditions and the following disclaimer in the 112155SN/A# documentation and/or other materials provided with the distribution; 122155SN/A# neither the name of the copyright holders nor the names of its 132155SN/A# contributors may be used to endorse or promote products derived from 142155SN/A# this software without specific prior written permission. 152155SN/A# 162155SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172155SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182155SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192155SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202155SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212155SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222155SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232155SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242155SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252155SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262155SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272155SN/A# 282665Ssaidi@eecs.umich.edu# Authors: Nathan Binkert 292665Ssaidi@eecs.umich.edu 302155SN/Aimport m5 314202Sbinkertn@umich.edu 322155SN/Afrom m5 import internal 337768SAli.Saidi@ARM.comfrom m5.internal.stats import schedStatEvent as schedEvent 347768SAli.Saidi@ARM.comfrom m5.objects import Root 357768SAli.Saidi@ARM.comfrom m5.util import attrdict, fatal 362178SN/A 372178SN/AoutputList = [] 382178SN/Adef initText(filename, desc=True): 392178SN/A output = internal.stats.initText(filename, desc) 402178SN/A outputList.append(output) 412178SN/A 422178SN/Adef initSimStats(): 432178SN/A internal.stats.initSimStats() 442178SN/A internal.stats.registerPythonStatsHandlers() 452178SN/A 462178SN/Anames = [] 472155SN/Astats_dict = {} 485865Sksewell@umich.edustats_list = [] 496181Sksewell@umich.eduraw_stats_list = [] 506181Sksewell@umich.edudef enable(): 515865Sksewell@umich.edu '''Enable the statistics package. Before the statistics package is 523918Ssaidi@eecs.umich.edu enabled, all statistics must be created and initialized and once 535865Sksewell@umich.edu the package is enabled, no more statistics can be created.''' 542623SN/A __dynamic_cast = [] 553918Ssaidi@eecs.umich.edu for k, v in internal.stats.__dict__.iteritems(): 562155SN/A if k.startswith('dynamic_'): 572155SN/A __dynamic_cast.append(v) 582292SN/A 596181Sksewell@umich.edu for stat in internal.stats.statsList(): 606181Sksewell@umich.edu for cast in __dynamic_cast: 613918Ssaidi@eecs.umich.edu val = cast(stat) 622292SN/A if val is not None: 632292SN/A stats_list.append(val) 642292SN/A raw_stats_list.append(val) 653918Ssaidi@eecs.umich.edu break 662292SN/A else: 672292SN/A fatal("unknown stat type %s", stat) 682766Sktlim@umich.edu 692766Sktlim@umich.edu for stat in stats_list: 702766Sktlim@umich.edu if not stat.check() or not stat.baseCheck(): 712921Sktlim@umich.edu fatal("statistic '%s' (%d) was not properly initialized " \ 722921Sktlim@umich.edu "by a regStats() function\n", stat.name, stat.id) 732766Sktlim@umich.edu 742766Sktlim@umich.edu if not (stat.flags & flags.display): 755529Snate@binkert.org stat.name = "__Stat%06d" % stat.id 762766Sktlim@umich.edu 774762Snate@binkert.org def less(stat1, stat2): 782155SN/A v1 = stat1.name.split('.') 792155SN/A v2 = stat2.name.split('.') 802155SN/A return v1 < v2 812155SN/A 822155SN/A stats_list.sort(less) 832155SN/A for stat in stats_list: 842766Sktlim@umich.edu stats_dict[stat.name] = stat 852155SN/A stat.enable() 865865Sksewell@umich.edu 872155SN/A internal.stats.enable(); 882155SN/A 892155SN/Adef prepare(): 902155SN/A '''Prepare all stats for data access. This must be done before 912178SN/A dumping and serialization.''' 922178SN/A 937756SAli.Saidi@ARM.com for stat in stats_list: 942766Sktlim@umich.edu stat.prepare() 952178SN/A 962178SN/AlastDump = 0 976994Snate@binkert.orgdef dump(): 982178SN/A '''Dump all statistics data to the registered outputs''' 992766Sktlim@umich.edu 1002766Sktlim@umich.edu curTick = m5.curTick() 1012766Sktlim@umich.edu 1022788Sktlim@umich.edu global lastDump 1032178SN/A assert lastDump <= curTick 1042733Sktlim@umich.edu if lastDump == curTick: 1052733Sktlim@umich.edu return 1062817Sksewell@umich.edu lastDump = curTick 1072733Sktlim@umich.edu 1084486Sbinkertn@umich.edu internal.stats.processDumpQueue() 1094486Sbinkertn@umich.edu 1104776Sgblack@eecs.umich.edu prepare() 1114776Sgblack@eecs.umich.edu 1128739Sgblack@eecs.umich.edu for output in outputList: 1136365Sgblack@eecs.umich.edu if output.valid(): 1144486Sbinkertn@umich.edu output.begin() 1154202Sbinkertn@umich.edu for stat in stats_list: 1164202Sbinkertn@umich.edu output.visit(stat) 1174202Sbinkertn@umich.edu output.end() 1188541Sgblack@eecs.umich.edu 1194202Sbinkertn@umich.edudef reset(): 1204202Sbinkertn@umich.edu '''Reset all statistics to the base state''' 1214776Sgblack@eecs.umich.edu 1228739Sgblack@eecs.umich.edu # call reset stats on all SimObjects 1236365Sgblack@eecs.umich.edu root = Root.getInstance() 1244202Sbinkertn@umich.edu if root: 1258777Sgblack@eecs.umich.edu for obj in root.descendants(): obj.resetStats() 1264202Sbinkertn@umich.edu 1274202Sbinkertn@umich.edu # call any other registered stats reset callbacks 1284202Sbinkertn@umich.edu for stat in stats_list: 1295217Ssaidi@eecs.umich.edu stat.reset() 1304202Sbinkertn@umich.edu 1312155SN/A internal.stats.processResetQueue() 1324202Sbinkertn@umich.edu 1334776Sgblack@eecs.umich.eduflags = attrdict({ 1344776Sgblack@eecs.umich.edu 'none' : 0x0000, 1354776Sgblack@eecs.umich.edu 'init' : 0x0001, 1364776Sgblack@eecs.umich.edu 'display' : 0x0002, 1372766Sktlim@umich.edu 'total' : 0x0010, 1384202Sbinkertn@umich.edu 'pdf' : 0x0020, 1398335Snate@binkert.org 'cdf' : 0x0040, 1402733Sktlim@umich.edu 'dist' : 0x0080, 1412733Sktlim@umich.edu 'nozero' : 0x0100, 1422733Sktlim@umich.edu 'nonan' : 0x0200, 1432733Sktlim@umich.edu}) 1442733Sktlim@umich.edu