__init__.py revision 10453
14126SN/A# Copyright (c) 2007 The Regents of The University of Michigan
28295Snate@binkert.org# Copyright (c) 2010 The Hewlett-Packard Development Company
34126SN/A# All rights reserved.
44126SN/A#
54126SN/A# Redistribution and use in source and binary forms, with or without
64126SN/A# modification, are permitted provided that the following conditions are
74126SN/A# met: redistributions of source code must retain the above copyright
84126SN/A# notice, this list of conditions and the following disclaimer;
94126SN/A# redistributions in binary form must reproduce the above copyright
104126SN/A# notice, this list of conditions and the following disclaimer in the
114126SN/A# documentation and/or other materials provided with the distribution;
124126SN/A# neither the name of the copyright holders nor the names of its
134126SN/A# contributors may be used to endorse or promote products derived from
144126SN/A# this software without specific prior written permission.
154126SN/A#
164126SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
174126SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
184126SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
194126SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
204126SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
214126SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
224126SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
234126SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
244126SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
254126SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
264126SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
274126SN/A#
284126SN/A# Authors: Nathan Binkert
294126SN/A
308296Snate@binkert.orgimport m5
318296Snate@binkert.org
328295Snate@binkert.orgfrom m5 import internal
338295Snate@binkert.orgfrom m5.internal.stats import schedStatEvent as schedEvent
348295Snate@binkert.orgfrom m5.objects import Root
358296Snate@binkert.orgfrom m5.util import attrdict, fatal
364126SN/A
378296Snate@binkert.orgoutputList = []
386126SN/Adef initText(filename, desc=True):
398296Snate@binkert.org    output = internal.stats.initText(filename, desc)
408296Snate@binkert.org    outputList.append(output)
414126SN/A
426001SN/Adef initSimStats():
436001SN/A    internal.stats.initSimStats()
4410453SAndrew.Bardsley@arm.com    internal.stats.registerPythonStatsHandlers()
456001SN/A
468295Snate@binkert.orgnames = []
478295Snate@binkert.orgstats_dict = {}
488295Snate@binkert.orgstats_list = []
498295Snate@binkert.orgraw_stats_list = []
506001SN/Adef enable():
518295Snate@binkert.org    '''Enable the statistics package.  Before the statistics package is
528295Snate@binkert.org    enabled, all statistics must be created and initialized and once
538295Snate@binkert.org    the package is enabled, no more statistics can be created.'''
548295Snate@binkert.org    __dynamic_cast = []
558295Snate@binkert.org    for k, v in internal.stats.__dict__.iteritems():
568295Snate@binkert.org        if k.startswith('dynamic_'):
578295Snate@binkert.org            __dynamic_cast.append(v)
588295Snate@binkert.org
598295Snate@binkert.org    for stat in internal.stats.statsList():
608295Snate@binkert.org        for cast in __dynamic_cast:
618295Snate@binkert.org            val = cast(stat)
628295Snate@binkert.org            if val is not None:
638295Snate@binkert.org                stats_list.append(val)
648295Snate@binkert.org                raw_stats_list.append(val)
658295Snate@binkert.org                break
668295Snate@binkert.org        else:
678295Snate@binkert.org            fatal("unknown stat type %s", stat)
688295Snate@binkert.org
698296Snate@binkert.org    for stat in stats_list:
708296Snate@binkert.org        if not stat.check() or not stat.baseCheck():
7110169SCurtis.Dunham@arm.com            fatal("statistic '%s' (%d) was not properly initialized " \
7210169SCurtis.Dunham@arm.com                  "by a regStats() function\n", stat.name, stat.id)
738296Snate@binkert.org
748296Snate@binkert.org        if not (stat.flags & flags.display):
758296Snate@binkert.org            stat.name = "__Stat%06d" % stat.id
768296Snate@binkert.org
778295Snate@binkert.org    def less(stat1, stat2):
788295Snate@binkert.org        v1 = stat1.name.split('.')
798295Snate@binkert.org        v2 = stat2.name.split('.')
808295Snate@binkert.org        return v1 < v2
818295Snate@binkert.org
828295Snate@binkert.org    stats_list.sort(less)
838295Snate@binkert.org    for stat in stats_list:
848295Snate@binkert.org        stats_dict[stat.name] = stat
858296Snate@binkert.org        stat.enable()
868295Snate@binkert.org
878986SAli.Saidi@ARM.com    internal.stats.enable();
888986SAli.Saidi@ARM.com
898296Snate@binkert.orgdef prepare():
908296Snate@binkert.org    '''Prepare all stats for data access.  This must be done before
918296Snate@binkert.org    dumping and serialization.'''
926001SN/A
938296Snate@binkert.org    for stat in stats_list:
948296Snate@binkert.org        stat.prepare()
958296Snate@binkert.org
968296Snate@binkert.orglastDump = 0
976001SN/Adef dump():
988296Snate@binkert.org    '''Dump all statistics data to the registered outputs'''
996001SN/A
1008296Snate@binkert.org    curTick = m5.curTick()
1018296Snate@binkert.org
1028296Snate@binkert.org    global lastDump
1038296Snate@binkert.org    assert lastDump <= curTick
1048296Snate@binkert.org    if lastDump == curTick:
1058296Snate@binkert.org        return
1068296Snate@binkert.org    lastDump = curTick
1078296Snate@binkert.org
1089042SMitchell.Hayenga@ARM.com    internal.stats.processDumpQueue()
1099042SMitchell.Hayenga@ARM.com
1108296Snate@binkert.org    prepare()
1118296Snate@binkert.org
1128296Snate@binkert.org    for output in outputList:
1138296Snate@binkert.org        if output.valid():
1148296Snate@binkert.org            output.begin()
1158296Snate@binkert.org            for stat in stats_list:
1168296Snate@binkert.org                output.visit(stat)
1178296Snate@binkert.org            output.end()
1186001SN/A
1196001SN/Adef reset():
1208296Snate@binkert.org    '''Reset all statistics to the base state'''
1218296Snate@binkert.org
1227527SN/A    # call reset stats on all SimObjects
1237527SN/A    root = Root.getInstance()
1247802SN/A    if root:
1257802SN/A        for obj in root.descendants(): obj.resetStats()
1267802SN/A
1277527SN/A    # call any other registered stats reset callbacks
1288296Snate@binkert.org    for stat in stats_list:
1298296Snate@binkert.org        stat.reset()
1308296Snate@binkert.org
1318296Snate@binkert.org    internal.stats.processResetQueue()
1328295Snate@binkert.org
1338295Snate@binkert.orgflags = attrdict({
1348295Snate@binkert.org    'none'    : 0x0000,
1358295Snate@binkert.org    'init'    : 0x0001,
1368295Snate@binkert.org    'display' : 0x0002,
1378295Snate@binkert.org    'total'   : 0x0010,
1388295Snate@binkert.org    'pdf'     : 0x0020,
1398295Snate@binkert.org    'cdf'     : 0x0040,
1408295Snate@binkert.org    'dist'    : 0x0080,
1418295Snate@binkert.org    'nozero'  : 0x0100,
1428295Snate@binkert.org    'nonan'   : 0x0200,
1438295Snate@binkert.org})
144