From 4ff34a75bb866fc673608526c69d4ba2b3844c48 Mon Sep 17 00:00:00 2001 From: "Bobby R. Bruce" Date: Thu, 4 Apr 2024 08:33:48 -0700 Subject: [PATCH] stdlib: Fix 'nozero' for Scalar SimStats (#972) When the `statistics::nozero` flag is set gem5 does not output that stat if its value is zero. This was not the case for SimStats which output in this case. This patch correct this behavior. --- src/python/m5/stats/gem5stats.py | 6 +++++- src/python/pybind11/stats.cc | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/python/m5/stats/gem5stats.py b/src/python/m5/stats/gem5stats.py index 682149f380..eb79140c73 100644 --- a/src/python/m5/stats/gem5stats.py +++ b/src/python/m5/stats/gem5stats.py @@ -118,13 +118,17 @@ def __get_statistic(statistic: _m5.stats.Info) -> Optional[Statistic]: :param statistic: The Info object to be translated to a Statistic object. :returns: The Statistic object of the Info object. Returns ``None`` if - Info object cannot be translated. + Info object cannot, or should not, be translated. """ assert isinstance(statistic, _m5.stats.Info) statistic.prepare() if isinstance(statistic, _m5.stats.ScalarInfo): + if statistic.is_nozero and statistic.value == 0.0: + # In the case where the "nozero" flag is set, and the value is + # zero, we don't want to include this statistic so return None. + return None return __get_scaler(statistic) elif isinstance(statistic, _m5.stats.DistInfo): return __get_distribution(statistic) diff --git a/src/python/pybind11/stats.cc b/src/python/pybind11/stats.cc index 266f47e52a..fee8c52882 100644 --- a/src/python/pybind11/stats.cc +++ b/src/python/pybind11/stats.cc @@ -145,6 +145,9 @@ pybind_init_stats(py::module_ &m_native) .def_property_readonly("flags", [](const statistics::Info &info) { return (statistics::FlagsType)info.flags; }) + .def_property_readonly("is_nozero", [](const statistics::Info &info) { + return info.flags.isSet(statistics::nozero); + }) .def("check", &statistics::Info::check) .def("baseCheck", &statistics::Info::baseCheck) .def("enable", &statistics::Info::enable)