gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 "pybind11/pybind11.h"
42 #include "pybind11/stl.h"
43 
44 #include "base/statistics.hh"
45 #include "base/stats/text.hh"
46 #include "config/have_hdf5.hh"
47 
48 #if HAVE_HDF5
49 #include "base/stats/hdf5.hh"
50 
51 #endif
52 #include "sim/stat_control.hh"
53 #include "sim/stat_register.hh"
54 
55 namespace py = pybind11;
56 
57 namespace gem5
58 {
59 
60 static const py::object
62 {
63  /* PyBind11 gets confused by the InfoProxy magic, so we need to
64  * explicitly cast to the right wrapper type. */
65 
66 #define TRY_CAST(T) do { \
67  auto _stat = dynamic_cast<const T *>(info); \
68  if (_stat) \
69  return py::cast(_stat); \
70  } while (0)
71 
73  /* FormulaInfo is a subclass of VectorInfo. Therefore, a cast to
74  * FormulaInfo must be attempted before a cast to VectorInfo. Otherwise
75  * instances of ForumlaInfo will be cast to VectorInfo.
76  */
80 
81  return py::cast(info);
82 
83 #undef TRY_CAST
84 }
85 
86 namespace statistics
87 {
88 
89 void
91 {
92  py::module_ m = py::module_::import("m5.stats");
93  m.attr("dump")();
94 }
95 
96 void
98 {
99  py::module_ m = py::module_::import("m5.stats");
100  m.attr("reset")();
101 }
102 
103 }
104 
105 void
106 pybind_init_stats(py::module_ &m_native)
107 {
108  py::module_ m = m_native.def_submodule("stats");
109 
110  m
111  .def("initSimStats", &statistics::initSimStats)
112  .def("initText", &statistics::initText,
113  py::return_value_policy::reference)
114 #if HAVE_HDF5
115  .def("initHDF5", &statistics::initHDF5)
116 #endif
117  .def("registerPythonStatsHandlers",
119  .def("schedStatEvent", &statistics::schedStatEvent)
120  .def("periodicStatDump", &statistics::periodicStatDump)
121  .def("updateEvents", &statistics::updateEvents)
122  .def("processResetQueue", &statistics::processResetQueue)
123  .def("processDumpQueue", &statistics::processDumpQueue)
124  .def("enable", &statistics::enable)
125  .def("enabled", &statistics::enabled)
126  .def("statsList", &statistics::statsList)
127  ;
128 
129  py::class_<statistics::Output>(m, "Output")
130  .def("begin", &statistics::Output::begin)
131  .def("end", &statistics::Output::end)
132  .def("valid", &statistics::Output::valid)
133  .def("beginGroup", &statistics::Output::beginGroup)
134  .def("endGroup", &statistics::Output::endGroup)
135  ;
136 
137  py::class_<statistics::Info,
138  std::unique_ptr<statistics::Info, py::nodelete>>(m, "Info")
139  .def_readwrite("name", &statistics::Info::name)
140  .def_property_readonly("unit", [](const statistics::Info &info) {
141  return info.unit->getUnitString();
142  })
143  .def_readonly("desc", &statistics::Info::desc)
144  .def_readonly("id", &statistics::Info::id)
145  .def_property_readonly("flags", [](const statistics::Info &info) {
146  return (statistics::FlagsType)info.flags;
147  })
148  .def("check", &statistics::Info::check)
149  .def("baseCheck", &statistics::Info::baseCheck)
150  .def("enable", &statistics::Info::enable)
151  .def("prepare", &statistics::Info::prepare)
152  .def("reset", &statistics::Info::reset)
153  .def("zero", &statistics::Info::zero)
154  .def("visit", &statistics::Info::visit)
155  ;
156 
158  std::unique_ptr<statistics::ScalarInfo, py::nodelete>>(
159  m, "ScalarInfo")
160  .def_property_readonly("value",
161  [](const statistics::ScalarInfo &info) { return info.value(); })
162  .def_property_readonly("result",
163  [](const statistics::ScalarInfo &info) { return info.result(); })
164  .def_property_readonly("total",
165  [](const statistics::ScalarInfo &info) { return info.total(); })
166  ;
167 
169  std::unique_ptr<statistics::VectorInfo, py::nodelete>>(
170  m, "VectorInfo")
171  .def_readwrite("subnames", &statistics::VectorInfo::subnames)
172  .def_readwrite("subdescs", &statistics::VectorInfo::subdescs)
173  .def_property_readonly("size",
174  [](const statistics::VectorInfo &info) { return info.size(); })
175  .def_property_readonly("value",
176  [](const statistics::VectorInfo &info) { return info.value(); })
177  .def_property_readonly("result",
178  [](const statistics::VectorInfo &info) { return info.result(); })
179  .def_property_readonly("total",
180  [](const statistics::VectorInfo &info) { return info.total(); })
181  ;
182 
184  std::unique_ptr<statistics::FormulaInfo, py::nodelete>>(
185  m, "FormulaInfo")
186  .def_property_readonly("str",
187  [](const statistics::FormulaInfo &info) { return info.str(); })
188  ;
189 
191  std::unique_ptr<statistics::DistInfo, py::nodelete>>(
192  m, "DistInfo")
193  .def_property_readonly("min_val",
194  [](const statistics::DistInfo &info) { return info.data.min_val; })
195  .def_property_readonly("max_val",
196  [](const statistics::DistInfo &info) { return info.data.max_val; })
197  .def_property_readonly("bucket_size",
198  [](const statistics::DistInfo &info) {
199  return info.data.bucket_size;
200  })
201  .def_property_readonly("values",
202  [](const statistics::DistInfo &info) { return info.data.cvec; })
203  .def_property_readonly("overflow",
204  [](const statistics::DistInfo &info) {
205  return info.data.overflow;
206  })
207  .def_property_readonly("underflow",
208  [](const statistics::DistInfo &info) {
209  return info.data.underflow;
210  })
211  .def_property_readonly("sum",
212  [](const statistics::DistInfo &info) { return info.data.sum; })
213  .def_property_readonly("logs",
214  [](const statistics::DistInfo &info) { return info.data.logs; })
215  .def_property_readonly("squares",
216  [](const statistics::DistInfo &info) { return info.data.squares; })
217  ;
218 
219  py::class_<statistics::Group,
220  std::unique_ptr<statistics::Group, py::nodelete>>(m, "Group")
221  .def("regStats", &statistics::Group::regStats)
222  .def("resetStats", &statistics::Group::resetStats)
223  .def("preDumpStats", &statistics::Group::preDumpStats)
224  .def("getStats", [](const statistics::Group &self)
226 
227  auto stats = self.getStats();
228  std::vector<py::object> py_stats;
229  py_stats.reserve(stats.size());
230  std::transform(stats.begin(), stats.end(),
231  std::back_inserter(py_stats),
233  return py_stats;
234  })
235  .def("getStatGroups", &statistics::Group::getStatGroups)
236  .def("addStatGroup", &statistics::Group::addStatGroup)
237  .def("resolveStat", [](const statistics::Group &self,
238  const std::string &name) -> py::object {
239  const statistics::Info *stat = self.resolveStat(name);
240  if (!stat)
241  throw pybind11::key_error("Unknown stat name");
242 
243  return cast_stat_info(stat);
244  })
245  ;
246 }
247 
248 } // namespace gem5
gem5::statistics::Info::check
virtual bool check() const =0
Check that this stat has been set up properly and is ready for use.
gem5::statistics::DistData::overflow
Counter overflow
Definition: types.hh:75
gem5::statistics::VectorInfo::subdescs
std::vector< std::string > subdescs
Definition: info.hh:188
gem5::statistics::Info::enable
virtual void enable()
Enable the stat for use.
Definition: info.cc:192
gem5::statistics::Output::end
virtual void end()=0
gem5::statistics::DistData::min_val
Counter min_val
Definition: types.hh:72
gem5::statistics::DistInfo
Definition: info.hh:200
gem5::statistics::units::Base::getUnitString
virtual std::string getUnitString() const =0
gem5::statistics::FlagsType
uint16_t FlagsType
Definition: info.hh:49
gem5::statistics::registerPythonStatsHandlers
void registerPythonStatsHandlers()
Register py_...
Definition: stat_register.cc:51
gem5::VegaISA::m
m
Definition: pagetable.hh:52
gem5::statistics::Output::endGroup
virtual void endGroup()=0
gem5::statistics::Info::visit
virtual void visit(Output &visitor)=0
Visitor entry for outputing statistics data.
gem5::statistics::Info::zero
virtual bool zero() const =0
gem5::statistics::DistData::sum
Counter sum
Definition: types.hh:77
gem5::statistics::VectorInfo
Definition: info.hh:183
gem5::statistics::pythonDump
void pythonDump()
Definition: stats.cc:90
gem5::statistics::VectorInfo::result
virtual const VResult & result() const =0
gem5::pybind_init_stats
void pybind_init_stats(pybind11::module_ &m_native)
gem5::statistics::Output::valid
virtual bool valid() const =0
gem5::statistics::DistData::cvec
VCounter cvec
Definition: types.hh:76
gem5::statistics::VectorInfo::value
virtual const VCounter & value() const =0
gem5::statistics::ScalarInfo
Definition: info.hh:175
std::vector
STL vector class.
Definition: stl.hh:37
gem5::statistics::DistData::max_val
Counter max_val
Definition: types.hh:73
gem5::statistics::updateEvents
void updateEvents()
Update the events after resuming from a checkpoint.
Definition: stat_control.cc:146
gem5::statistics::Group::resetStats
virtual void resetStats()
Callback to reset stats.
Definition: group.cc:86
gem5::statistics::Info::flags
Flags flags
The formatting flags.
Definition: info.hh:91
gem5::cast_stat_info
static const py::object cast_stat_info(const statistics::Info *info)
Definition: stats.cc:61
gem5::statistics::Info::reset
virtual void reset()=0
Reset the stat to the default state.
gem5::statistics::ScalarInfo::result
virtual Result result() const =0
gem5::statistics::Info::id
int id
Definition: info.hh:101
stat_register.hh
gem5::statistics::Info::baseCheck
bool baseCheck() const
Definition: info.cc:172
gem5::statistics::ScalarInfo::total
virtual Result total() const =0
gem5::statistics::Info::prepare
virtual void prepare()=0
Prepare the stat for dumping.
gem5::statistics::initSimStats
void initSimStats()
Definition: stat_control.cc:66
gem5::statistics::DistData::bucket_size
Counter bucket_size
Definition: types.hh:70
gem5::statistics::FormulaInfo::str
virtual std::string str() const =0
gem5::statistics::enable
void enable()
Definition: statistics.cc:291
gem5::statistics::Info::unit
const units::Base * unit
The unit of the stat.
Definition: info.hh:87
statistics.hh
gem5::statistics::pythonReset
void pythonReset()
Definition: stats.cc:97
gem5::statistics::DistInfo::data
DistData data
Local storage for the entry values, used for printing.
Definition: info.hh:204
TRY_CAST
#define TRY_CAST(T)
gem5::statistics::processDumpQueue
void processDumpQueue()
Process all the callbacks in the dump callbacks queue.
Definition: statistics.cc:271
gem5::statistics::Group::addStatGroup
void addStatGroup(const char *name, Group *block)
Add a stat block as a child of this block.
Definition: group.cc:117
gem5::statistics::initHDF5
std::unique_ptr< Output > initHDF5(const std::string &filename, unsigned chunking, bool desc, bool formulas)
Definition: hdf5.cc:331
gem5::statistics::Output::begin
virtual void begin()=0
gem5::statistics::VectorInfo::total
virtual Result total() const =0
gem5::statistics::Output::beginGroup
virtual void beginGroup(const char *name)=0
name
const std::string & name()
Definition: trace.cc:48
gem5::statistics::Group::regStats
virtual void regStats()
Callback to set stat parameters.
Definition: group.cc:68
gem5::statistics::enabled
bool enabled()
Definition: statistics.cc:285
gem5::statistics::statsList
std::list< Info * > & statsList()
Definition: statistics.cc:61
text.hh
stat_control.hh
gem5::statistics::periodicStatDump
void periodicStatDump(Tick period)
Schedule periodic statistics dumping.
Definition: stat_control.cc:116
gem5::statistics::VectorInfo::size
virtual size_type size() const =0
gem5::statistics::DistData::logs
Counter logs
Definition: types.hh:79
gem5::statistics::processResetQueue
void processResetQueue()
Process all the callbacks in the reset callbacks queue.
Definition: statistics.cc:265
gem5::statistics::Info::desc
std::string desc
The description of the stat.
Definition: info.hh:89
gem5::statistics::DistData::underflow
Counter underflow
Definition: types.hh:74
gem5::statistics::DistData::squares
Counter squares
Definition: types.hh:78
gem5::statistics::ScalarInfo::value
virtual Counter value() const =0
gem5::statistics::Group
Statistics container.
Definition: group.hh:92
gem5::statistics::Group::getStatGroups
const std::map< std::string, Group * > & getStatGroups() const
Get all child groups associated with this object.
Definition: group.cc:181
hdf5.hh
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::statistics::initText
Output * initText(const std::string &filename, bool desc, bool spaces)
Definition: text.cc:804
gem5::statistics::schedStatEvent
void schedStatEvent(bool dump, bool reset, Tick when, Tick repeat)
Schedule statistics dumping.
Definition: stat_control.cc:106
gem5::statistics::Group::preDumpStats
virtual void preDumpStats()
Callback before stats are dumped.
Definition: group.cc:99
gem5::statistics::VectorInfo::subnames
std::vector< std::string > subnames
Names and descriptions of subfields.
Definition: info.hh:187
gem5::statistics::Info::name
std::string name
The name of the stat.
Definition: info.hh:83
gem5::statistics::FormulaInfo
Definition: info.hh:244
gem5::statistics::Info
Definition: info.hh:79

Generated on Sun Jul 30 2023 01:56:52 for gem5 by doxygen 1.8.17