gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
55namespace py = pybind11;
56
57namespace gem5
58{
59
60static 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 */
82
83 return py::cast(info);
84
85#undef TRY_CAST
86}
87
88namespace statistics
89{
90
91void
93{
94 py::module_ m = py::module_::import("m5.stats");
95 m.attr("dump")();
96}
97
98void
100{
101 py::module_ m = py::module_::import("m5.stats");
102 m.attr("reset")();
103}
104
105}
106
107void
108pybind_init_stats(py::module_ &m_native)
109{
110 py::module_ m = m_native.def_submodule("stats");
111
112 m
113 .def("initSimStats", &statistics::initSimStats)
114 .def("initText", &statistics::initText,
115 py::return_value_policy::reference)
116#if HAVE_HDF5
117 .def("initHDF5", &statistics::initHDF5)
118#endif
119 .def("registerPythonStatsHandlers",
121 .def("schedStatEvent", &statistics::schedStatEvent)
122 .def("periodicStatDump", &statistics::periodicStatDump)
123 .def("updateEvents", &statistics::updateEvents)
124 .def("processResetQueue", &statistics::processResetQueue)
125 .def("processDumpQueue", &statistics::processDumpQueue)
126 .def("enable", &statistics::enable)
127 .def("enabled", &statistics::enabled)
128 .def("statsList", &statistics::statsList)
129 ;
130
131 py::class_<statistics::Output>(m, "Output")
132 .def("begin", &statistics::Output::begin)
133 .def("end", &statistics::Output::end)
134 .def("valid", &statistics::Output::valid)
135 .def("beginGroup", &statistics::Output::beginGroup)
136 .def("endGroup", &statistics::Output::endGroup)
137 ;
138
139 py::class_<statistics::Info,
140 std::unique_ptr<statistics::Info, py::nodelete>>(m, "Info")
141 .def_readwrite("name", &statistics::Info::name)
142 .def_property_readonly("unit", [](const statistics::Info &info) {
143 return info.unit->getUnitString();
144 })
145 .def_readonly("desc", &statistics::Info::desc)
146 .def_readonly("id", &statistics::Info::id)
147 .def_property_readonly("flags", [](const statistics::Info &info) {
148 return (statistics::FlagsType)info.flags;
149 })
150 .def_property_readonly("is_nozero", [](const statistics::Info &info) {
151 return info.flags.isSet(statistics::nozero);
152 })
153 .def("check", &statistics::Info::check)
154 .def("baseCheck", &statistics::Info::baseCheck)
155 .def("enable", &statistics::Info::enable)
156 .def("prepare", &statistics::Info::prepare)
157 .def("reset", &statistics::Info::reset)
158 .def("zero", &statistics::Info::zero)
159 .def("visit", &statistics::Info::visit)
160 ;
161
163 std::unique_ptr<statistics::ScalarInfo, py::nodelete>>(
164 m, "ScalarInfo")
165 .def_property_readonly("value",
166 [](const statistics::ScalarInfo &info) { return info.value(); })
167 .def_property_readonly("result",
168 [](const statistics::ScalarInfo &info) { return info.result(); })
169 .def_property_readonly("total",
170 [](const statistics::ScalarInfo &info) { return info.total(); })
171 ;
172
174 std::unique_ptr<statistics::VectorInfo, py::nodelete>>(
175 m, "VectorInfo")
176 .def_readwrite("subnames", &statistics::VectorInfo::subnames)
177 .def_readwrite("subdescs", &statistics::VectorInfo::subdescs)
178 .def_property_readonly("size",
179 [](const statistics::VectorInfo &info) { return info.size(); })
180 .def_property_readonly("value",
181 [](const statistics::VectorInfo &info) { return info.value(); })
182 .def_property_readonly("result",
183 [](const statistics::VectorInfo &info) { return info.result(); })
184 .def_property_readonly("total",
185 [](const statistics::VectorInfo &info) { return info.total(); })
186 ;
187
189 std::unique_ptr<statistics::Vector2dInfo, py::nodelete>>(
190 m, "Vector2dInfo")
191 .def_readonly("x_size", &statistics::Vector2dInfo::x)
192 .def_readonly("y_size", &statistics::Vector2dInfo::y)
193 .def_readonly("subnames", &statistics::Vector2dInfo::subnames)
194 .def_readonly("subdescs", &statistics::Vector2dInfo::subdescs)
195 .def_readonly("ysubnames", &statistics::Vector2dInfo::y_subnames)
196 .def_readonly("value", &statistics::Vector2dInfo::cvec)
197 ;
198
200 std::unique_ptr<statistics::SparseHistInfo, py::nodelete>>(
201 m, "SparseHistInfo")
202 .def_property_readonly("values", //A Dict[float, int] of sample & count
203 [](const statistics::SparseHistInfo &info) {
204 return info.data.cmap;
205 })
206 ;
207
209 std::unique_ptr<statistics::FormulaInfo, py::nodelete>>(
210 m, "FormulaInfo")
211 .def_property_readonly("str",
212 [](const statistics::FormulaInfo &info) { return info.str(); })
213 ;
214
216 std::unique_ptr<statistics::DistInfo, py::nodelete>>(
217 m, "DistInfo")
218 .def_property_readonly("min_val",
219 [](const statistics::DistInfo &info) { return info.data.min_val; })
220 .def_property_readonly("max_val",
221 [](const statistics::DistInfo &info) { return info.data.max_val; })
222 .def_property_readonly("bucket_size",
223 [](const statistics::DistInfo &info) {
224 return info.data.bucket_size;
225 })
226 .def_property_readonly("values",
227 [](const statistics::DistInfo &info) { return info.data.cvec; })
228 .def_property_readonly("overflow",
229 [](const statistics::DistInfo &info) {
230 return info.data.overflow;
231 })
232 .def_property_readonly("underflow",
233 [](const statistics::DistInfo &info) {
234 return info.data.underflow;
235 })
236 .def_property_readonly("sum",
237 [](const statistics::DistInfo &info) { return info.data.sum; })
238 .def_property_readonly("logs",
239 [](const statistics::DistInfo &info) { return info.data.logs; })
240 .def_property_readonly("squares",
241 [](const statistics::DistInfo &info) { return info.data.squares; })
242 ;
243
244 py::class_<statistics::Group,
245 std::unique_ptr<statistics::Group, py::nodelete>>(m, "Group")
246 .def("regStats", &statistics::Group::regStats)
247 .def("resetStats", &statistics::Group::resetStats)
248 .def("preDumpStats", &statistics::Group::preDumpStats)
249 .def("getStats", [](const statistics::Group &self)
251
252 auto stats = self.getStats();
254 py_stats.reserve(stats.size());
255 std::transform(stats.begin(), stats.end(),
256 std::back_inserter(py_stats),
258 return py_stats;
259 })
260 .def("getStatGroups", &statistics::Group::getStatGroups)
261 .def("addStatGroup", &statistics::Group::addStatGroup)
262 .def("resolveStat", [](const statistics::Group &self,
263 const std::string &name) -> py::object {
264 const statistics::Info *stat = self.resolveStat(name);
265 if (!stat)
266 throw pybind11::key_error("Unknown stat name");
267
268 return cast_stat_info(stat);
269 })
270 ;
271}
272
273} // namespace gem5
DistData data
Local storage for the entry values, used for printing.
Definition info.hh:204
virtual std::string str() const =0
Statistics container.
Definition group.hh:93
const Info * resolveStat(std::string name) const
Resolve a stat by its name within this group.
Definition group.cc:128
Flags flags
The formatting flags.
Definition info.hh:91
const units::Base * unit
The unit of the stat.
Definition info.hh:87
virtual void enable()
Enable the stat for use.
Definition info.cc:192
std::string name
The name of the stat.
Definition info.hh:83
std::string desc
The description of the stat.
Definition info.hh:89
virtual bool zero() const =0
virtual void prepare()=0
Prepare the stat for dumping.
bool baseCheck() const
Definition info.cc:172
virtual void reset()=0
Reset the stat to the default state.
virtual void visit(Output &visitor)=0
Visitor entry for outputing statistics data.
virtual bool check() const =0
Check that this stat has been set up properly and is ready for use.
virtual Result total() const =0
virtual Result result() const =0
virtual Counter value() const =0
SparseHistData data
Local storage for the entry values, used for printing.
Definition info.hh:254
std::vector< std::string > subdescs
Definition info.hh:230
std::vector< std::string > y_subnames
Definition info.hh:231
std::vector< std::string > subnames
Names and descriptions of subfields.
Definition info.hh:229
VCounter cvec
Local storage for the entry values, used for printing.
Definition info.hh:237
std::vector< std::string > subdescs
Definition info.hh:188
std::vector< std::string > subnames
Names and descriptions of subfields.
Definition info.hh:187
virtual std::string getUnitString() const =0
STL vector class.
Definition stl.hh:37
bool isSet(Type mask) const
Verifies whether any bit matching the given mask is set.
Definition flags.hh:83
const std::map< std::string, Group * > & getStatGroups() const
Get all child groups associated with this object.
Definition group.cc:181
const std::vector< Info * > & getStats() const
Get all stats associated with this object.
Definition group.cc:187
virtual void regStats()
Callback to set stat parameters.
Definition group.cc:68
void addStatGroup(const char *name, Group *block)
Add a stat block as a child of this block.
Definition group.cc:117
virtual void preDumpStats()
Callback before stats are dumped.
Definition group.cc:99
virtual void resetStats()
Callback to reset stats.
Definition group.cc:86
Bitfield< 0 > m
void schedStatEvent(bool dump, bool reset, Tick when, Tick repeat)
Schedule statistics dumping.
uint16_t FlagsType
Definition info.hh:49
const FlagsType nozero
Don't print if this is zero.
Definition info.hh:67
void pythonDump()
Definition stats.cc:92
void processResetQueue()
Process all the callbacks in the reset callbacks queue.
std::unique_ptr< Output > initHDF5(const std::string &filename, unsigned chunking, bool desc, bool formulas)
Definition hdf5.cc:331
void pythonReset()
Definition stats.cc:99
void periodicStatDump(Tick period)
Schedule periodic statistics dumping.
void updateEvents()
Update the events after resuming from a checkpoint.
void registerPythonStatsHandlers()
Register py_... functions as the statistics handlers.
std::list< Info * > & statsList()
Definition statistics.cc:61
void processDumpQueue()
Process all the callbacks in the dump callbacks queue.
Output * initText(const std::string &filename, bool desc, bool spaces)
Definition text.cc:804
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
void pybind_init_stats(pybind11::module_ &m_native)
static const py::object cast_stat_info(const statistics::Info *info)
Definition stats.cc:61
#define TRY_CAST(T)
Declaration of Statistics objects.
virtual void end()=0
virtual void begin()=0
virtual bool valid() const =0
virtual void beginGroup(const char *name)=0
virtual void endGroup()=0
const std::string & name()
Definition trace.cc:48

Generated on Tue Jun 18 2024 16:24:06 for gem5 by doxygen 1.11.0