gem5  v21.1.0.2
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 GEM5_DEPRECATED_NAMESPACE(Stats, statistics);
87 namespace statistics
88 {
89 
90 void
92 {
93  py::module_ m = py::module_::import("m5.stats");
94  m.attr("dump")();
95 }
96 
97 void
99 {
100  py::module_ m = py::module_::import("m5.stats");
101  m.attr("reset")();
102 }
103 
104 }
105 
106 void
107 pybind_init_stats(py::module_ &m_native)
108 {
109  py::module_ m = m_native.def_submodule("stats");
110 
111  m
112  .def("initSimStats", &statistics::initSimStats)
113  .def("initText", &statistics::initText,
114  py::return_value_policy::reference)
115 #if HAVE_HDF5
116  .def("initHDF5", &statistics::initHDF5)
117 #endif
118  .def("registerPythonStatsHandlers",
120  .def("schedStatEvent", &statistics::schedStatEvent)
121  .def("periodicStatDump", &statistics::periodicStatDump)
122  .def("updateEvents", &statistics::updateEvents)
123  .def("processResetQueue", &statistics::processResetQueue)
124  .def("processDumpQueue", &statistics::processDumpQueue)
125  .def("enable", &statistics::enable)
126  .def("enabled", &statistics::enabled)
127  .def("statsList", &statistics::statsList)
128  ;
129 
130  py::class_<statistics::Output>(m, "Output")
131  .def("begin", &statistics::Output::begin)
132  .def("end", &statistics::Output::end)
133  .def("valid", &statistics::Output::valid)
134  .def("beginGroup", &statistics::Output::beginGroup)
135  .def("endGroup", &statistics::Output::endGroup)
136  ;
137 
138  py::class_<statistics::Info,
139  std::unique_ptr<statistics::Info, py::nodelete>>(m, "Info")
140  .def_readwrite("name", &statistics::Info::name)
141  .def_property_readonly("unit", [](const statistics::Info &info) {
142  return info.unit->getUnitString();
143  })
144  .def_readonly("desc", &statistics::Info::desc)
145  .def_readonly("id", &statistics::Info::id)
146  .def_property_readonly("flags", [](const statistics::Info &info) {
147  return (statistics::FlagsType)info.flags;
148  })
149  .def("check", &statistics::Info::check)
150  .def("baseCheck", &statistics::Info::baseCheck)
151  .def("enable", &statistics::Info::enable)
152  .def("prepare", &statistics::Info::prepare)
153  .def("reset", &statistics::Info::reset)
154  .def("zero", &statistics::Info::zero)
155  .def("visit", &statistics::Info::visit)
156  ;
157 
159  std::unique_ptr<statistics::ScalarInfo, py::nodelete>>(
160  m, "ScalarInfo")
161  .def_property_readonly("value",
162  [](const statistics::ScalarInfo &info) { return info.value(); })
163  .def_property_readonly("result",
164  [](const statistics::ScalarInfo &info) { return info.result(); })
165  .def_property_readonly("total",
166  [](const statistics::ScalarInfo &info) { return info.total(); })
167  ;
168 
170  std::unique_ptr<statistics::VectorInfo, py::nodelete>>(
171  m, "VectorInfo")
172  .def_readwrite("subnames", &statistics::VectorInfo::subnames)
173  .def_readwrite("subdescs", &statistics::VectorInfo::subdescs)
174  .def_property_readonly("size",
175  [](const statistics::VectorInfo &info) { return info.size(); })
176  .def_property_readonly("value",
177  [](const statistics::VectorInfo &info) { return info.value(); })
178  .def_property_readonly("result",
179  [](const statistics::VectorInfo &info) { return info.result(); })
180  .def_property_readonly("total",
181  [](const statistics::VectorInfo &info) { return info.total(); })
182  ;
183 
185  std::unique_ptr<statistics::FormulaInfo, py::nodelete>>(
186  m, "FormulaInfo")
187  .def_property_readonly("str",
188  [](const statistics::FormulaInfo &info) { return info.str(); })
189  ;
190 
192  std::unique_ptr<statistics::DistInfo, py::nodelete>>(
193  m, "DistInfo")
194  .def_property_readonly("min_val",
195  [](const statistics::DistInfo &info) { return info.data.min_val; })
196  .def_property_readonly("max_val",
197  [](const statistics::DistInfo &info) { return info.data.max_val; })
198  .def_property_readonly("bucket_size",
199  [](const statistics::DistInfo &info) {
200  return info.data.bucket_size;
201  })
202  .def_property_readonly("values",
203  [](const statistics::DistInfo &info) { return info.data.cvec; })
204  .def_property_readonly("overflow",
205  [](const statistics::DistInfo &info) {
206  return info.data.overflow;
207  })
208  .def_property_readonly("underflow",
209  [](const statistics::DistInfo &info) {
210  return info.data.underflow;
211  })
212  .def_property_readonly("sum",
213  [](const statistics::DistInfo &info) { return info.data.sum; })
214  .def_property_readonly("logs",
215  [](const statistics::DistInfo &info) { return info.data.logs; })
216  .def_property_readonly("squares",
217  [](const statistics::DistInfo &info) { return info.data.squares; })
218  ;
219 
220  py::class_<statistics::Group,
221  std::unique_ptr<statistics::Group, py::nodelete>>(m, "Group")
222  .def("regStats", &statistics::Group::regStats)
223  .def("resetStats", &statistics::Group::resetStats)
224  .def("preDumpStats", &statistics::Group::preDumpStats)
225  .def("getStats", [](const statistics::Group &self)
227 
228  auto stats = self.getStats();
229  std::vector<py::object> py_stats;
230  py_stats.reserve(stats.size());
231  std::transform(stats.begin(), stats.end(),
232  std::back_inserter(py_stats),
234  return py_stats;
235  })
236  .def("getStatGroups", &statistics::Group::getStatGroups)
237  .def("addStatGroup", &statistics::Group::addStatGroup)
238  .def("resolveStat", [](const statistics::Group &self,
239  const std::string &name) -> py::object {
240  const statistics::Info *stat = self.resolveStat(name);
241  if (!stat)
242  throw pybind11::key_error("Unknown stat name");
243 
244  return cast_stat_info(stat);
245  })
246  ;
247 }
248 
249 } // 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:76
gem5::statistics::VectorInfo::subdescs
std::vector< std::string > subdescs
Definition: info.hh:189
gem5::statistics::Info::enable
virtual void enable()
Enable the stat for use.
Definition: info.cc:195
gem5::statistics::Output::end
virtual void end()=0
gem5::statistics::DistData::min_val
Counter min_val
Definition: types.hh:73
gem5::statistics::DistInfo
Definition: info.hh:201
gem5::statistics::units::Base::getUnitString
virtual std::string getUnitString() const =0
gem5::statistics::FlagsType
uint16_t FlagsType
Definition: info.hh:50
gem5::statistics::registerPythonStatsHandlers
void registerPythonStatsHandlers()
Register py_...
Definition: stat_register.cc: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:78
gem5::statistics::VectorInfo
Definition: info.hh:184
gem5::statistics::pythonDump
void pythonDump()
Definition: stats.cc:91
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:77
gem5::statistics::VectorInfo::value
virtual const VCounter & value() const =0
gem5::statistics::ScalarInfo
Definition: info.hh:176
std::vector
STL vector class.
Definition: stl.hh:37
gem5::statistics::DistData::max_val
Counter max_val
Definition: types.hh:74
gem5::statistics::updateEvents
void updateEvents()
Update the events after resuming from a checkpoint.
Definition: stat_control.cc:147
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:92
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:102
stat_register.hh
gem5::statistics::Info::baseCheck
bool baseCheck() const
Definition: info.cc:173
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:67
gem5::statistics::DistData::bucket_size
Counter bucket_size
Definition: types.hh:71
gem5::statistics::FormulaInfo::str
virtual std::string str() const =0
gem5::statistics::enable
void enable()
Definition: statistics.cc:286
gem5::statistics::Info::unit
const units::Base * unit
The unit of the stat.
Definition: info.hh:88
statistics.hh
gem5::statistics::pythonReset
void pythonReset()
Definition: stats.cc:98
gem5::statistics::DistInfo::data
DistData data
Local storage for the entry values, used for printing.
Definition: info.hh:205
TRY_CAST
#define TRY_CAST(T)
gem5::statistics::processDumpQueue
void processDumpQueue()
Process all the callbacks in the dump callbacks queue.
Definition: statistics.cc:266
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:328
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
gem5::GEM5_DEPRECATED_NAMESPACE
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
name
const std::string & name()
Definition: trace.cc:49
gem5::statistics::Group::regStats
virtual void regStats()
Callback to set stat parameters.
Definition: group.cc:69
gem5::statistics::enabled
bool enabled()
Definition: statistics.cc:280
gem5::statistics::statsList
std::list< Info * > & statsList()
Definition: statistics.cc:62
text.hh
stat_control.hh
gem5::ArmISA::m
Bitfield< 0 > m
Definition: misc_types.hh:394
gem5::statistics::periodicStatDump
void periodicStatDump(Tick period)
Schedule periodic statistics dumping.
Definition: stat_control.cc:117
gem5::statistics::VectorInfo::size
virtual size_type size() const =0
gem5::statistics::DistData::logs
Counter logs
Definition: types.hh:80
gem5::statistics::processResetQueue
void processResetQueue()
Process all the callbacks in the reset callbacks queue.
Definition: statistics.cc:260
gem5::statistics::Info::desc
std::string desc
The description of the stat.
Definition: info.hh:90
gem5::statistics::DistData::underflow
Counter underflow
Definition: types.hh:75
gem5::statistics::DistData::squares
Counter squares
Definition: types.hh:79
gem5::statistics::ScalarInfo::value
virtual Counter value() const =0
gem5::statistics::Group
Statistics container.
Definition: group.hh:93
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: decoder.cc:40
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:107
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:188
gem5::statistics::Info::name
std::string name
The name of the stat.
Definition: info.hh:84
gem5::statistics::FormulaInfo
Definition: info.hh:245
gem5::statistics::Info
Definition: info.hh:80

Generated on Tue Sep 21 2021 12:25:01 for gem5 by doxygen 1.8.17