From a95d8e95cb784d6f46b35b823315970d3b42478a Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Tue, 23 Dec 2003 23:53:43 -0500 Subject: [PATCH] - change the FormatFlags into more general StatFlags - make init and print StatFlags - default_mode -> DefaultMode - the display mode is no longer needed as part of the stat pass it into the display functions so the mode can be determined from dump to dump - get rid of old simplescalar bug and make the distribution min_val work correctly - get rid of the DisplayMode parameter to distribution updates since it is no longer needed --HG-- extra : convert_revision : 386f69f4d12fb91faf60690aaab08542e009e555 --- base/statistics.cc | 69 +++++++++++++++++++++--------------------- base/statistics.hh | 75 ++++++++++++++++++++++------------------------ 2 files changed, 70 insertions(+), 74 deletions(-) diff --git a/base/statistics.cc b/base/statistics.cc index b8672661d..20b94e297 100644 --- a/base/statistics.cc +++ b/base/statistics.cc @@ -64,7 +64,7 @@ using namespace std; // This is a hack to get this parameter from the old stats package. namespace Statistics { bool PrintDescriptions = true; -DisplayMode default_mode = mode_simplescalar; +DisplayMode DefaultMode = mode_simplescalar; namespace Database { @@ -132,7 +132,7 @@ Data::display(ostream &stream, DisplayMode mode) while (j != end) { StatData *stat = *j; if (stat->dodisplay()) - stat->display(stream); + stat->display(stream, mode); ++j; } ++i; @@ -144,7 +144,7 @@ Data::display(ostream &stream, DisplayMode mode) while (i != end) { StatData *stat = *i; if (stat->dodisplay() && !stat->binned()) - stat->display(stream); + stat->display(stream, mode); ++i; } } @@ -235,10 +235,10 @@ Data::regPrint(void *stat) { StatData *data = find(stat); - if (data->print) + if (data->flags & print) return; - data->print = true; + data->flags |= print; list_t::iterator j = printStats.insert(printStats.end(), data); inplace_merge(printStats.begin(), j, printStats.end(), StatData::less); @@ -284,7 +284,7 @@ DataAccess::statData() const void DataAccess::setInit() { - statData()->init = true; + statData()->flags |= init; } void @@ -326,7 +326,7 @@ StatData::less(StatData *stat1, StatData *stat2) bool StatData::baseCheck() const { - if (!init) { + if (!(flags & init)) { #ifdef STAT_DEBUG cprintf("this is stat number %d\n",(*i)->number); #endif @@ -334,7 +334,7 @@ StatData::baseCheck() const return false; } - if (print && name.empty()) { + if ((flags & print) && name.empty()) { panic("all printable stats must be named"); return false; } @@ -368,14 +368,14 @@ struct ScalarPrint result_t value; string name; string desc; - int precision; + StatFlags flags; DisplayMode mode; - FormatFlags flags; + int precision; result_t pdf; result_t cdf; ScalarPrint() - : value(0.0), precision(0), mode(default_mode), flags(0), + : value(0.0), flags(0), mode(DefaultMode), precision(0), pdf(NAN), cdf(NAN) {} @@ -399,8 +399,7 @@ ScalarPrint::operator()(ostream &stream) const if (mode == mode_simplescalar && flags & __substat) { ccprintf(stream, "%32s %12s %10s %10s", name, - ValueToString(value, mode, precision), - pdfstr, cdfstr); + ValueToString(value, mode, precision), pdfstr, cdfstr); } else { ccprintf(stream, "%-40s %12s %10s %10s", name, ValueToString(value, mode, precision), pdfstr, cdfstr); @@ -419,15 +418,15 @@ struct VectorPrint string desc; vector subnames; vector subdescs; - int precision; + StatFlags flags; DisplayMode mode; - FormatFlags flags; + int precision; rvec_t vec; result_t total; VectorPrint() - : subnames(0), subdescs(0), precision(-1), mode(default_mode), - flags(0), total(NAN) + : subnames(0), subdescs(0), flags(0), mode(DefaultMode), + precision(-1), total(NAN) {} void operator()(ostream &stream) const; @@ -542,9 +541,9 @@ struct DistPrint { string name; string desc; - int precision; + StatFlags flags; DisplayMode mode; - FormatFlags flags; + int precision; result_t min_val; result_t max_val; @@ -573,6 +572,7 @@ DistPrint::operator()(ostream &stream) const print.precision = precision; print.flags = flags; + print.mode = mode; print.desc = desc; print.name = base + "mean"; @@ -603,9 +603,9 @@ DistPrint::operator()(ostream &stream) const ScalarPrint print; print.desc = (mode == mode_m5) ? desc : ""; - print.precision = precision; - print.mode = mode; print.flags = flags; + print.mode = mode; + print.precision = precision; if (mode == mode_simplescalar) { ccprintf(stream, "%-42s", base + "start_dist"); @@ -687,7 +687,7 @@ DistPrint::operator()(ostream &stream) const if (mode == mode_m5 || overflow > 0.0) { print.name = base + "overflows"; print.value = overflow; - if (mode == mode_m5 && total) { + if (total) { print.pdf = overflow / total; print.cdf += print.pdf; } @@ -723,20 +723,21 @@ DistPrint::operator()(ostream &stream) const } void -ScalarDataBase::display(ostream &stream) const +ScalarDataBase::display(ostream &stream, DisplayMode mode) const { ScalarPrint print; print.value = val(); print.name = name; print.desc = desc; - print.precision = precision; print.flags = flags; + print.mode = mode; + print.precision = precision; print(stream); } void -VectorDataBase::display(ostream &stream) const +VectorDataBase::display(ostream &stream, DisplayMode mode) const { int size = this->size(); const_cast(this)->update(); @@ -745,8 +746,8 @@ VectorDataBase::display(ostream &stream) const print.name = name; print.desc = desc; - print.mode = mode; print.flags = flags; + print.mode = mode; print.precision = precision; print.vec = val(); print.total = total(); @@ -771,7 +772,7 @@ VectorDataBase::display(ostream &stream) const } void -Vector2dDataBase::display(ostream &stream) const +Vector2dDataBase::display(ostream &stream, DisplayMode mode) const { const_cast(this)->update(); @@ -779,8 +780,8 @@ Vector2dDataBase::display(ostream &stream) const VectorPrint print; print.subnames = y_subnames; - print.mode = mode; print.flags = flags; + print.mode = mode; print.precision = precision; if (!subnames.empty()) { @@ -823,7 +824,7 @@ Vector2dDataBase::display(ostream &stream) const } void -DistDataBase::display(ostream &stream) const +DistDataBase::display(ostream &stream, DisplayMode mode) const { const_cast(this)->update(); @@ -831,9 +832,9 @@ DistDataBase::display(ostream &stream) const print.name = name; print.desc = desc; - print.precision = precision; - print.mode = mode; print.flags = flags; + print.mode = mode; + print.precision = precision; print.min_val = data.min_val; print.max_val = data.max_val; @@ -854,7 +855,7 @@ DistDataBase::display(ostream &stream) const } void -VectorDistDataBase::display(ostream &stream) const +VectorDistDataBase::display(ostream &stream, DisplayMode mode) const { const_cast(this)->update(); @@ -864,9 +865,9 @@ VectorDistDataBase::display(ostream &stream) const print.name = name + (subnames[i].empty() ? ("_" + to_string(i)) : subnames[i]); print.desc = subdescs[i].empty() ? desc : subdescs[i]; - print.precision = precision; - print.mode = mode; print.flags = flags; + print.mode = mode; + print.precision = precision; print.min_val = data[i].min_val; print.max_val = data[i].max_val; diff --git a/base/statistics.hh b/base/statistics.hh index 6013c74e7..2aeae9e7f 100644 --- a/base/statistics.hh +++ b/base/statistics.hh @@ -93,25 +93,31 @@ typedef std::vector rvec_t; * Define the storage for format flags. * @todo Can probably shrink this. */ -typedef u_int32_t FormatFlags; +typedef u_int32_t StatFlags; + /** Nothing extra to print. */ -const FormatFlags none = 0x0000; +const StatFlags none = 0x00000000; +/** This Stat is Initialized */ +const StatFlags init = 0x00000001; +/** Print this stat. */ +const StatFlags print = 0x00000002; /** Print the total. */ -const FormatFlags total = 0x0001; +const StatFlags total = 0x00000010; /** Print the percent of the total that this entry represents. */ -const FormatFlags pdf = 0x0002; +const StatFlags pdf = 0x00000020; /** Print the cumulative percentage of total upto this entry. */ -const FormatFlags cdf = 0x0004; +const StatFlags cdf = 0x00000040; +/** Print the distribution. */ +const StatFlags dist = 0x00000080; /** Don't print if this is zero. */ -const FormatFlags nozero = 0x0010; +const StatFlags nozero = 0x00000100; /** Don't print if this is NAN */ -const FormatFlags nonan = 0x0020; -/** Print the distribution. */ -const FormatFlags dist = 0x0100; +const StatFlags nonan = 0x00000200; /** Used for SS compatability. */ -const FormatFlags __substat = 0x8000; +const StatFlags __substat = 0x80000000; + /** Mask of flags that can't be set directly */ -const FormatFlags __reserved = __substat; +const StatFlags __reserved = init | print | __substat; enum DisplayMode { @@ -120,7 +126,7 @@ enum DisplayMode mode_python }; -extern DisplayMode default_mode; +extern DisplayMode DefaultMode; /* Contains the statistic implementation details */ ////////////////////////////////////////////////////////////////////// @@ -130,28 +136,21 @@ extern DisplayMode default_mode; ////////////////////////////////////////////////////////////////////// struct StatData { - /** True if the stat has been initialized. */ - bool init; - /** True if the stat should be printed. */ - bool print; /** The name of the stat. */ std::string name; /** The description of the stat. */ std::string desc; + /** The formatting flags. */ + StatFlags flags; /** The display precision. */ int precision; - /** Display Mode */ - DisplayMode mode; - /** The formatting flags. */ - FormatFlags flags; /** A pointer to a prerequisite Stat. */ const StatData *prereq; StatData() - : init(false), print(false), precision(-1), mode(default_mode), - flags(0), prereq(0) + : flags(none), precision(-1), prereq(0) {} virtual ~StatData(); @@ -165,7 +164,7 @@ struct StatData * Print this stat to the given ostream. * @param stream The stream to print to. */ - virtual void display(std::ostream &stream) const = 0; + virtual void display(std::ostream &stream, DisplayMode mode) const = 0; bool dodisplay() const { return !prereq || !prereq->zero(); } /** @@ -203,7 +202,7 @@ struct ScalarDataBase : public StatData virtual result_t val() const = 0; virtual result_t total() const = 0; - virtual void display(std::ostream &stream) const; + virtual void display(std::ostream &stream, DisplayMode mode) const; }; template @@ -229,7 +228,7 @@ struct VectorDataBase : public StatData mutable std::vector subnames; mutable std::vector subdescs; - virtual void display(std::ostream &stream) const; + virtual void display(std::ostream &stream, DisplayMode mode) const; virtual size_t size() const = 0; virtual const rvec_t &val() const = 0; @@ -298,7 +297,7 @@ struct DistDataBase : public StatData /** Local storage for the entry values, used for printing. */ DistDataData data; - virtual void display(std::ostream &stream) const; + virtual void display(std::ostream &stream, DisplayMode mode) const; virtual void update() = 0; }; @@ -330,7 +329,7 @@ struct VectorDistDataBase : public StatData mutable rvec_t vec; virtual size_t size() const = 0; - virtual void display(std::ostream &stream) const; + virtual void display(std::ostream &stream, DisplayMode mode) const; virtual void update() { int s = size(); @@ -375,7 +374,7 @@ struct Vector2dDataBase : public StatData mutable int x; mutable int y; - virtual void display(std::ostream &stream) const; + virtual void display(std::ostream &stream, DisplayMode mode) const; virtual void update() { if (subnames.size() < x) @@ -488,7 +487,7 @@ class Wrap : public Child * @param f The new flags. * @return A reference to this stat. */ - Parent &flags(FormatFlags _flags) + Parent &flags(StatFlags _flags) { statData()->flags |= _flags; return self(); @@ -1403,18 +1402,14 @@ struct DistStor return samples == 0; } - void update(DistDataData *data, DisplayMode mode, const Params ¶ms) + void update(DistDataData *data, const Params ¶ms) { data->min = params.min; data->max = params.max; data->bucket_size = params.bucket_size; data->size = params.size; - if (mode == mode_m5) - data->min_val = (min_val == INT_MAX) ? params.min : min_val; - else - data->min_val = params.min; - + data->min_val = (min_val == INT_MAX) ? 0 : min_val; data->max_val = (max_val == INT_MIN) ? 0 : max_val; data->underflow = underflow; data->overflow = overflow; @@ -1491,7 +1486,7 @@ struct FancyStor samples += number; } - void update(DistDataData *data, DisplayMode mode, const Params ¶ms) + void update(DistDataData *data, const Params ¶ms) { data->sum = sum; data->squares = squares; @@ -1559,7 +1554,7 @@ struct AvgFancy squares += value * value; } - void update(DistDataData *data, DisplayMode mode, const Params ¶ms) + void update(DistDataData *data, const Params ¶ms) { data->sum = sum; data->squares = squares; @@ -1657,7 +1652,7 @@ class DistBase : public DataAccess void update(DistDataBase *base) { base->data.fancy = storage_t::fancy; - data()->update(&(base->data), base->mode, params); + data()->update(&(base->data), params); } /** * @return True is stat is binned. @@ -1731,7 +1726,7 @@ class VectorDistBase : public DataAccess base->data.resize(size); for (int i = 0; i < size; ++i) { base->data[i].fancy = storage_t::fancy; - data(i)->update(&(base->data[i]), base->mode, params); + data(i)->update(&(base->data[i]), params); } } }; @@ -2956,7 +2951,7 @@ class Temp */ void check(); -void dump(std::ostream &stream, DisplayMode mode = mode_simplescalar); +void dump(std::ostream &stream, DisplayMode mode = DefaultMode); void reset(); void registerResetCallback(Callback *cb); -- 2.30.2