__init__.py revision 8295
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
308295Snate@binkert.orgfrom m5 import internal
318295Snate@binkert.orgfrom m5.internal.stats import schedStatEvent as schedEvent
328295Snate@binkert.orgfrom m5.objects import Root
338295Snate@binkert.orgfrom m5.util import attrdict
344126SN/A
356126SN/Adef initText(filename, desc=True):
366126SN/A    internal.stats.initText(filename, desc)
374126SN/A
384126SN/Adef initMySQL(host, database, user='', passwd='', project='test', name='test',
394126SN/A              sample='0'):
404126SN/A    if not user:
414126SN/A        import getpass
424126SN/A        user = getpass.getuser()
434126SN/A
444126SN/A    internal.stats.initMySQL(host, database, user, passwd, project, name,
454126SN/A                             sample)
466001SN/A
476001SN/Adef initSimStats():
486001SN/A    internal.stats.initSimStats()
496001SN/A
508295Snate@binkert.orgnames = []
518295Snate@binkert.orgstats_dict = {}
528295Snate@binkert.orgstats_list = []
538295Snate@binkert.orgraw_stats_list = []
546001SN/Adef enable():
558295Snate@binkert.org    '''Enable the statistics package.  Before the statistics package is
568295Snate@binkert.org    enabled, all statistics must be created and initialized and once
578295Snate@binkert.org    the package is enabled, no more statistics can be created.'''
588295Snate@binkert.org    __dynamic_cast = []
598295Snate@binkert.org    for k, v in internal.stats.__dict__.iteritems():
608295Snate@binkert.org        if k.startswith('dynamic_'):
618295Snate@binkert.org            __dynamic_cast.append(v)
628295Snate@binkert.org
638295Snate@binkert.org    for stat in internal.stats.statsList():
648295Snate@binkert.org        for cast in __dynamic_cast:
658295Snate@binkert.org            val = cast(stat)
668295Snate@binkert.org            if val is not None:
678295Snate@binkert.org                stats_list.append(val)
688295Snate@binkert.org                raw_stats_list.append(val)
698295Snate@binkert.org                break
708295Snate@binkert.org        else:
718295Snate@binkert.org            fatal("unknown stat type %s", stat)
728295Snate@binkert.org
738295Snate@binkert.org    def less(stat1, stat2):
748295Snate@binkert.org        v1 = stat1.name.split('.')
758295Snate@binkert.org        v2 = stat2.name.split('.')
768295Snate@binkert.org        return v1 < v2
778295Snate@binkert.org
788295Snate@binkert.org    stats_list.sort(less)
798295Snate@binkert.org    for stat in stats_list:
808295Snate@binkert.org        stats_dict[stat.name] = stat
818295Snate@binkert.org
826001SN/A    internal.stats.enable()
836001SN/A
846001SN/Adef dump():
856001SN/A    # Currently prepare happens in the dump, but we should maybe move
866001SN/A    # that out.
876001SN/A
886001SN/A    #internal.stats.prepare()
896001SN/A    internal.stats.dump()
906001SN/A
916001SN/Adef reset():
927527SN/A    # call reset stats on all SimObjects
937527SN/A    root = Root.getInstance()
947802SN/A    if root:
957802SN/A        for obj in root.descendants(): obj.resetStats()
967802SN/A
977527SN/A    # call any other registered stats reset callbacks
986001SN/A    internal.stats.reset()
998295Snate@binkert.org
1008295Snate@binkert.orgflags = attrdict({
1018295Snate@binkert.org    'none'    : 0x0000,
1028295Snate@binkert.org    'init'    : 0x0001,
1038295Snate@binkert.org    'display' : 0x0002,
1048295Snate@binkert.org    'total'   : 0x0010,
1058295Snate@binkert.org    'pdf'     : 0x0020,
1068295Snate@binkert.org    'cdf'     : 0x0040,
1078295Snate@binkert.org    'dist'    : 0x0080,
1088295Snate@binkert.org    'nozero'  : 0x0100,
1098295Snate@binkert.org    'nonan'   : 0x0200,
1108295Snate@binkert.org})
111