__init__.py revision 8295:221013f9fd2f
1# Copyright (c) 2007 The Regents of The University of Michigan
2# Copyright (c) 2010 The Hewlett-Packard Development Company
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met: redistributions of source code must retain the above copyright
8# notice, this list of conditions and the following disclaimer;
9# redistributions in binary form must reproduce the above copyright
10# notice, this list of conditions and the following disclaimer in the
11# documentation and/or other materials provided with the distribution;
12# neither the name of the copyright holders nor the names of its
13# contributors may be used to endorse or promote products derived from
14# this software without specific prior written permission.
15#
16# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27#
28# Authors: Nathan Binkert
29
30from m5 import internal
31from m5.internal.stats import schedStatEvent as schedEvent
32from m5.objects import Root
33from m5.util import attrdict
34
35def initText(filename, desc=True):
36    internal.stats.initText(filename, desc)
37
38def initMySQL(host, database, user='', passwd='', project='test', name='test',
39              sample='0'):
40    if not user:
41        import getpass
42        user = getpass.getuser()
43
44    internal.stats.initMySQL(host, database, user, passwd, project, name,
45                             sample)
46
47def initSimStats():
48    internal.stats.initSimStats()
49
50names = []
51stats_dict = {}
52stats_list = []
53raw_stats_list = []
54def enable():
55    '''Enable the statistics package.  Before the statistics package is
56    enabled, all statistics must be created and initialized and once
57    the package is enabled, no more statistics can be created.'''
58    __dynamic_cast = []
59    for k, v in internal.stats.__dict__.iteritems():
60        if k.startswith('dynamic_'):
61            __dynamic_cast.append(v)
62
63    for stat in internal.stats.statsList():
64        for cast in __dynamic_cast:
65            val = cast(stat)
66            if val is not None:
67                stats_list.append(val)
68                raw_stats_list.append(val)
69                break
70        else:
71            fatal("unknown stat type %s", stat)
72
73    def less(stat1, stat2):
74        v1 = stat1.name.split('.')
75        v2 = stat2.name.split('.')
76        return v1 < v2
77
78    stats_list.sort(less)
79    for stat in stats_list:
80        stats_dict[stat.name] = stat
81
82    internal.stats.enable()
83
84def dump():
85    # Currently prepare happens in the dump, but we should maybe move
86    # that out.
87
88    #internal.stats.prepare()
89    internal.stats.dump()
90
91def reset():
92    # call reset stats on all SimObjects
93    root = Root.getInstance()
94    if root:
95        for obj in root.descendants(): obj.resetStats()
96
97    # call any other registered stats reset callbacks
98    internal.stats.reset()
99
100flags = attrdict({
101    'none'    : 0x0000,
102    'init'    : 0x0001,
103    'display' : 0x0002,
104    'total'   : 0x0010,
105    'pdf'     : 0x0020,
106    'cdf'     : 0x0040,
107    'dist'    : 0x0080,
108    'nozero'  : 0x0100,
109    'nonan'   : 0x0200,
110})
111