gem5  v20.1.0.0
stats.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2019 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 2006 The Regents of The University of Michigan
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  */
40 
41 #include "config/use_hdf5.hh"
42 
43 #include "pybind11/pybind11.h"
44 #include "pybind11/stl.h"
45 
46 #include "base/statistics.hh"
47 #include "base/stats/text.hh"
48 #if USE_HDF5
49 #include "base/stats/hdf5.hh"
50 #endif
51 #include "sim/stat_control.hh"
52 #include "sim/stat_register.hh"
53 
54 
55 namespace py = pybind11;
56 
57 static const py::object
59 {
60  /* PyBind11 gets confused by the InfoProxy magic, so we need to
61  * explicitly cast to the right wrapper type. */
62 
63 #define TRY_CAST(T) do { \
64  auto _stat = dynamic_cast<const T *>(info); \
65  if (_stat) \
66  return py::cast(_stat); \
67  } while (0)
68 
70 
71  return py::cast(info);
72 
73 #undef TRY_CAST
74 }
75 
76 namespace Stats {
77 
78 void
80 {
81  py::module m = py::module::import("m5.stats");
82  m.attr("dump")();
83 }
84 
85 void
87 {
88  py::module m = py::module::import("m5.stats");
89  m.attr("reset")();
90 }
91 
92 }
93 
94 void
95 pybind_init_stats(py::module &m_native)
96 {
97  py::module m = m_native.def_submodule("stats");
98 
99  m
100  .def("initSimStats", &Stats::initSimStats)
101  .def("initText", &Stats::initText, py::return_value_policy::reference)
102 #if USE_HDF5
103  .def("initHDF5", &Stats::initHDF5)
104 #endif
105  .def("registerPythonStatsHandlers",
107  .def("schedStatEvent", &Stats::schedStatEvent)
108  .def("periodicStatDump", &Stats::periodicStatDump)
109  .def("updateEvents", &Stats::updateEvents)
110  .def("processResetQueue", &Stats::processResetQueue)
111  .def("processDumpQueue", &Stats::processDumpQueue)
112  .def("enable", &Stats::enable)
113  .def("enabled", &Stats::enabled)
114  .def("statsList", &Stats::statsList)
115  ;
116 
117  py::class_<Stats::Output>(m, "Output")
118  .def("begin", &Stats::Output::begin)
119  .def("end", &Stats::Output::end)
120  .def("valid", &Stats::Output::valid)
121  .def("beginGroup", &Stats::Output::beginGroup)
122  .def("endGroup", &Stats::Output::endGroup)
123  ;
124 
125  py::class_<Stats::Info, std::unique_ptr<Stats::Info, py::nodelete>>(
126  m, "Info")
127  .def_readwrite("name", &Stats::Info::name)
128  .def_readonly("desc", &Stats::Info::desc)
129  .def_readonly("id", &Stats::Info::id)
130  .def_property_readonly("flags", [](const Stats::Info &info) {
131  return (Stats::FlagsType)info.flags;
132  })
133  .def("check", &Stats::Info::check)
134  .def("baseCheck", &Stats::Info::baseCheck)
135  .def("enable", &Stats::Info::enable)
136  .def("prepare", &Stats::Info::prepare)
137  .def("reset", &Stats::Info::reset)
138  .def("zero", &Stats::Info::zero)
139  .def("visit", &Stats::Info::visit)
140  ;
141 
142  py::class_<Stats::ScalarInfo, Stats::Info,
143  std::unique_ptr<Stats::ScalarInfo, py::nodelete>>(
144  m, "ScalarInfo")
145  .def("value", &Stats::ScalarInfo::value)
146  .def("result", &Stats::ScalarInfo::result)
147  .def("total", &Stats::ScalarInfo::total)
148  ;
149 
150  py::class_<Stats::Group, std::unique_ptr<Stats::Group, py::nodelete>>(
151  m, "Group")
152  .def("regStats", &Stats::Group::regStats)
153  .def("resetStats", &Stats::Group::resetStats)
154  .def("preDumpStats", &Stats::Group::preDumpStats)
155  .def("getStats", [](const Stats::Group &self)
157 
158  auto stats = self.getStats();
159  std::vector<py::object> py_stats;
160  py_stats.reserve(stats.size());
161  std::transform(stats.begin(), stats.end(),
162  std::back_inserter(py_stats),
164  return py_stats;
165  })
166  .def("getStatGroups", &Stats::Group::getStatGroups)
167  .def("addStatGroup", &Stats::Group::addStatGroup)
168  .def("resolveStat", [](const Stats::Group &self,
169  const std::string &name) -> py::object {
170  const Stats::Info *stat = self.resolveStat(name);
171  if (!stat)
172  throw pybind11::key_error("Unknown stat name");
173 
174  return cast_stat_info(stat);
175  })
176  ;
177 }
Stats::Group::regStats
virtual void regStats()
Callback to set stat parameters.
Definition: group.cc:64
Stats::Info::zero
virtual bool zero() const =0
Stats::Info::visit
virtual void visit(Output &visitor)=0
Visitor entry for outputing statistics data.
Stats::Info::baseCheck
bool baseCheck() const
Definition: statistics.cc:256
Stats::Output::endGroup
virtual void endGroup()=0
Stats::Output::begin
virtual void begin()=0
Stats::processResetQueue
void processResetQueue()
Process all the callbacks in the reset callbacks queue.
Definition: statistics.cc:525
Stats::initText
Output * initText(const string &filename, bool desc, bool spaces)
Definition: text.cc:817
Stats::Output::beginGroup
virtual void beginGroup(const char *name)=0
Stats::enable
void enable()
Definition: statistics.cc:551
Stats::periodicStatDump
void periodicStatDump(Tick period)
Schedule periodic statistics dumping.
Definition: stat_control.cc:247
Stats::Group::getStatGroups
const std::map< std::string, Group * > & getStatGroups() const
Get all child groups associated with this object.
Definition: group.cc:159
Stats::initSimStats
void initSimStats()
Definition: stat_control.cc:197
Stats::Group::preDumpStats
virtual void preDumpStats()
Callback before stats are dumped.
Definition: group.cc:95
std::vector
STL vector class.
Definition: stl.hh:37
Stats::ScalarInfo::result
virtual Result result() const =0
Stats::registerPythonStatsHandlers
void registerPythonStatsHandlers()
Register py_...
Definition: stat_register.cc:48
Stats::ScalarInfo::total
virtual Result total() const =0
Stats::Info::check
virtual bool check() const =0
Check that this stat has been set up properly and is ready for use.
Stats::Group::resetStats
virtual void resetStats()
Callback to reset stats.
Definition: group.cc:82
Stats::Info::id
int id
Definition: info.hh:89
Stats::Info::enable
virtual void enable()
Enable the stat for use.
Definition: statistics.cc:278
stat_register.hh
Stats::ScalarInfo::value
virtual Counter value() const =0
Stats::enabled
bool enabled()
Definition: statistics.cc:545
statistics.hh
Stats::FlagsType
uint16_t FlagsType
Definition: info.hh:37
TRY_CAST
#define TRY_CAST(T)
Stats::Info::prepare
virtual void prepare()=0
Prepare the stat for dumping.
Stats::updateEvents
void updateEvents()
Update the events after resuming from a checkpoint.
Definition: stat_control.cc:277
Stats::statsList
list< Info * > & statsList()
Definition: statistics.cc:67
Stats::Info::reset
virtual void reset()=0
Reset the stat to the default state.
cast_stat_info
static const py::object cast_stat_info(const Stats::Info *info)
Definition: stats.cc:58
name
const std::string & name()
Definition: trace.cc:50
Stats::schedStatEvent
void schedStatEvent(bool dump, bool reset, Tick when, Tick repeat)
Schedule statistics dumping.
Definition: stat_control.cc:237
Stats::Info
Definition: info.hh:69
Stats::pythonReset
void pythonReset()
Definition: stats.cc:86
text.hh
stat_control.hh
Stats::processDumpQueue
void processDumpQueue()
Process all the callbacks in the dump callbacks queue.
Definition: statistics.cc:531
Stats::Output::valid
virtual bool valid() const =0
Stats::Info::flags
Flags flags
The formatting flags.
Definition: info.hh:79
Stats::Group
Statistics container.
Definition: group.hh:83
Stats::Info::name
std::string name
The name of the stat.
Definition: info.hh:73
Stats::initHDF5
std::unique_ptr< Output > initHDF5(const std::string &filename, unsigned chunking, bool desc, bool formulas)
Definition: hdf5.cc:316
Stats::Output::end
virtual void end()=0
Stats::ScalarInfo
Definition: info.hh:148
Stats::Info::desc
std::string desc
The description of the stat.
Definition: info.hh:77
pybind_init_stats
void pybind_init_stats(py::module &m_native)
Definition: stats.cc:95
Stats
Definition: statistics.cc:61
hdf5.hh
Stats::pythonDump
void pythonDump()
Definition: stats.cc:79
ArmISA::m
Bitfield< 0 > m
Definition: miscregs_types.hh:389
Stats::Group::addStatGroup
void addStatGroup(const char *name, Group *block)
Add a stat block as a child of this block.
Definition: group.cc:113

Generated on Wed Sep 30 2020 14:02:08 for gem5 by doxygen 1.8.17