gem5 v23.0.0.1
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 */
80
81 return py::cast(info);
82
83#undef TRY_CAST
84}
85
86namespace statistics
87{
88
89void
91{
92 py::module_ m = py::module_::import("m5.stats");
93 m.attr("dump")();
94}
95
96void
98{
99 py::module_ m = py::module_::import("m5.stats");
100 m.attr("reset")();
101}
102
103}
104
105void
106pybind_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();
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
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
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
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
void pythonDump()
Definition stats.cc:90
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:97
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
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
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 Mon Jul 10 2023 15:32:05 for gem5 by doxygen 1.9.7