41#include "pybind11/pybind11.h"
42#include "pybind11/stl.h"
46#include "config/have_hdf5.hh"
55namespace py = pybind11;
60static const py::object
66#define TRY_CAST(T) do { \
67 auto _stat = dynamic_cast<const T *>(info); \
69 return py::cast(_stat); \
83 return py::cast(info);
94 py::module_
m = py::module_::import(
"m5.stats");
101 py::module_
m = py::module_::import(
"m5.stats");
110 py::module_
m = m_native.def_submodule(
"stats");
115 py::return_value_policy::reference)
119 .def(
"registerPythonStatsHandlers",
131 py::class_<statistics::Output>(
m,
"Output")
140 std::unique_ptr<statistics::Info, py::nodelete>>(
m,
"Info")
163 std::unique_ptr<statistics::ScalarInfo, py::nodelete>>(
165 .def_property_readonly(
"value",
167 .def_property_readonly(
"result",
169 .def_property_readonly(
"total",
174 std::unique_ptr<statistics::VectorInfo, py::nodelete>>(
178 .def_property_readonly(
"size",
180 .def_property_readonly(
"value",
182 .def_property_readonly(
"result",
184 .def_property_readonly(
"total",
189 std::unique_ptr<statistics::Vector2dInfo, py::nodelete>>(
200 std::unique_ptr<statistics::SparseHistInfo, py::nodelete>>(
202 .def_property_readonly(
"values",
209 std::unique_ptr<statistics::FormulaInfo, py::nodelete>>(
211 .def_property_readonly(
"str",
216 std::unique_ptr<statistics::DistInfo, py::nodelete>>(
218 .def_property_readonly(
"min_val",
220 .def_property_readonly(
"max_val",
222 .def_property_readonly(
"bucket_size",
226 .def_property_readonly(
"values",
228 .def_property_readonly(
"overflow",
232 .def_property_readonly(
"underflow",
236 .def_property_readonly(
"sum",
238 .def_property_readonly(
"logs",
240 .def_property_readonly(
"squares",
245 std::unique_ptr<statistics::Group, py::nodelete>>(
m,
"Group")
254 py_stats.reserve(stats.size());
255 std::transform(stats.begin(), stats.end(),
256 std::back_inserter(py_stats),
263 const std::string &
name) -> py::object {
266 throw pybind11::key_error(
"Unknown stat name");
DistData data
Local storage for the entry values, used for printing.
const Info * resolveStat(std::string name) const
Resolve a stat by its name within this group.
Flags flags
The formatting flags.
const units::Base * unit
The unit of the stat.
virtual void enable()
Enable the stat for use.
std::string name
The name of the stat.
std::string desc
The description of the stat.
virtual bool zero() const =0
virtual void prepare()=0
Prepare the stat for dumping.
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.
std::vector< std::string > subdescs
std::vector< std::string > y_subnames
std::vector< std::string > subnames
Names and descriptions of subfields.
VCounter cvec
Local storage for the entry values, used for printing.
std::vector< std::string > subdescs
std::vector< std::string > subnames
Names and descriptions of subfields.
virtual std::string getUnitString() const =0
bool isSet(Type mask) const
Verifies whether any bit matching the given mask is set.
const std::map< std::string, Group * > & getStatGroups() const
Get all child groups associated with this object.
const std::vector< Info * > & getStats() const
Get all stats associated with this object.
virtual void regStats()
Callback to set stat parameters.
void addStatGroup(const char *name, Group *block)
Add a stat block as a child of this block.
virtual void preDumpStats()
Callback before stats are dumped.
virtual void resetStats()
Callback to reset stats.
void schedStatEvent(bool dump, bool reset, Tick when, Tick repeat)
Schedule statistics dumping.
const FlagsType nozero
Don't print if this is zero.
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)
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()
void processDumpQueue()
Process all the callbacks in the dump callbacks queue.
Output * initText(const std::string &filename, bool desc, bool spaces)
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
void pybind_init_stats(pybind11::module_ &m_native)
static const py::object cast_stat_info(const statistics::Info *info)
Declaration of Statistics objects.
virtual bool valid() const =0
virtual void beginGroup(const char *name)=0
virtual void endGroup()=0
const std::string & name()