1 # Copyright (c) 2007 The Regents of The University of Michigan
2 # Copyright (c) 2010 The Hewlett-Packard Development Company
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.
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.
28 # Authors: Nathan Binkert
32 from m5
import internal
33 from m5
.objects
import Root
34 from m5
.util
import attrdict
, fatal
37 from m5
.internal
.stats
import schedStatEvent
as schedEvent
38 from m5
.internal
.stats
import periodicStatDump
41 def initText(filename
, desc
=True):
42 output
= internal
.stats
.initText(filename
, desc
)
43 outputList
.append(output
)
46 internal
.stats
.initSimStats()
47 internal
.stats
.registerPythonStatsHandlers()
53 '''Enable the statistics package. Before the statistics package is
54 enabled, all statistics must be created and initialized and once
55 the package is enabled, no more statistics can be created.'''
58 stats_list
= list(internal
.stats
.statsList())
60 for stat
in stats_list
:
61 if not stat
.check() or not stat
.baseCheck():
62 fatal("statistic '%s' (%d) was not properly initialized " \
63 "by a regStats() function\n", stat
.name
, stat
.id)
65 if not (stat
.flags
& flags
.display
):
66 stat
.name
= "__Stat%06d" % stat
.id
68 def less(stat1
, stat2
):
69 v1
= stat1
.name
.split('.')
70 v2
= stat2
.name
.split('.')
74 for stat
in stats_list
:
75 stats_dict
[stat
.name
] = stat
78 internal
.stats
.enable();
81 '''Prepare all stats for data access. This must be done before
82 dumping and serialization.'''
84 for stat
in stats_list
:
89 '''Dump all statistics data to the registered outputs'''
91 curTick
= m5
.curTick()
94 assert lastDump
<= curTick
95 if lastDump
== curTick
:
99 internal
.stats
.processDumpQueue()
103 for output
in outputList
:
106 for stat
in stats_list
:
111 '''Reset all statistics to the base state'''
113 # call reset stats on all SimObjects
114 root
= Root
.getInstance()
116 for obj
in root
.descendants(): obj
.resetStats()
118 # call any other registered stats reset callbacks
119 for stat
in stats_list
:
122 internal
.stats
.processResetQueue()