From fcaf1b74b0b4b40891a71b3b8bccd3f173aeff56 Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Sat, 7 Mar 2009 14:30:53 -0800 Subject: [PATCH] stats: cleanup text output stuff and fix mysql output --- src/base/statistics.hh | 39 +++++---- src/base/stats/mysql.cc | 15 ++-- src/base/stats/mysql.hh | 3 +- src/base/stats/text.cc | 173 +++++++++++++++++----------------------- 4 files changed, 106 insertions(+), 124 deletions(-) diff --git a/src/base/statistics.hh b/src/base/statistics.hh index 827c1d311..06c15a77d 100644 --- a/src/base/statistics.hh +++ b/src/base/statistics.hh @@ -1423,6 +1423,22 @@ class Vector2dBase : public DataWrapVec2d // ////////////////////////////////////////////////////////////////////// +struct DistParams : public StorageParams +{ + const bool fancy; + + /** The minimum value to track. */ + Counter min; + /** The maximum value to track. */ + Counter max; + /** The number of entries in each bucket. */ + Counter bucket_size; + /** The number of buckets. Equal to (max-min)/bucket_size. */ + size_type buckets; + + explicit DistParams(bool f) : fancy(f) {} +}; + /** * Templatized storage and interface for a distrbution stat. */ @@ -1430,18 +1446,9 @@ class DistStor { public: /** The parameters for a distribution stat. */ - struct Params : public StorageParams - { - /** The minimum value to track. */ - Counter min; - /** The maximum value to track. */ - Counter max; - /** The number of entries in each bucket. */ - Counter bucket_size; - /** The number of buckets. Equal to (max-min)/bucket_size. */ - size_type buckets; - - enum { fancy = false }; + struct Params : public DistParams + { + Params() : DistParams(false) {} }; private: @@ -1578,9 +1585,9 @@ class DistStor class FancyStor { public: - struct Params : public StorageParams + struct Params : public DistParams { - enum { fancy = true }; + Params() : DistParams(true) {} }; private: @@ -1654,9 +1661,9 @@ class FancyStor class AvgFancy { public: - struct Params : public StorageParams + struct Params : public DistParams { - enum { fancy = true }; + Params() : DistParams(true) {} }; private: diff --git a/src/base/stats/mysql.cc b/src/base/stats/mysql.cc index 58c620ed1..1e0c923f1 100644 --- a/src/base/stats/mysql.cc +++ b/src/base/stats/mysql.cc @@ -583,7 +583,8 @@ MySql::configure(const DistInfoBase &info) if (!configure(info, "DIST")) return; - const Params *params = safe_cast(info.storageParams); + const DistParams *params = + safe_cast(info.storageParams); if (!params->fancy) { stat.size = params->buckets; stat.min = params->min; @@ -599,7 +600,8 @@ MySql::configure(const VectorDistInfoBase &info) if (!configure(info, "VECTORDIST")) return; - const Params *params = safe_cast(info.storageParams); + const DistParams *params = + safe_cast(info.storageParams); if (!params->fancy) { stat.size = params->buckets; stat.min = params->min; @@ -765,7 +767,7 @@ MySql::output(const VectorInfoBase &info) } void -MySql::output(const DistData &data) +MySql::output(const DistData &data, const DistParams *params) { const int db_sum = -1; const int db_squares = -2; @@ -787,7 +789,7 @@ MySql::output(const DistData &data) newdata.data = data.samples; newdata.insert(); - if (data.samples && !data.fancy) { + if (data.samples && !params->fancy) { newdata.x = db_min_val; newdata.data = data.min_val; newdata.insert(); @@ -821,7 +823,7 @@ MySql::output(const DistInfoBase &info) newdata.stat = find(info.id); newdata.y = 0; - output(info.data); + output(info.data, safe_cast(info.storageParams)); } void @@ -835,7 +837,8 @@ MySql::output(const VectorDistInfoBase &info) size_type size = info.data.size(); for (off_type y = 0; y < size; ++y) { newdata.y = y; - output(info.data[y]); + output(info.data[y], + safe_cast(info.storageParams)); } } diff --git a/src/base/stats/mysql.hh b/src/base/stats/mysql.hh index f0f79bebd..86a4d6d23 100644 --- a/src/base/stats/mysql.hh +++ b/src/base/stats/mysql.hh @@ -56,6 +56,7 @@ struct SetupStat bool total; bool pdf; bool cdf; + double min; double max; double bktsize; @@ -177,7 +178,7 @@ class MySql : public Output void output(const VectorDistInfoBase &info); void output(const Vector2dInfoBase &info); void output(const FormulaInfoBase &info); - void output(const DistData &data); + void output(const DistData &data, const DistParams *params); void configure(); bool configure(const Info &info, std::string type); diff --git a/src/base/stats/text.cc b/src/base/stats/text.cc index 6c2078bd0..c3e484cf4 100644 --- a/src/base/stats/text.cc +++ b/src/base/stats/text.cc @@ -351,27 +351,63 @@ struct DistPrint bool descriptions; int precision; - Result min_val; - Result max_val; - Result underflow; - Result overflow; - VResult vec; - Result sum; - Result squares; - Result samples; - Counter min; Counter max; Counter bucket_size; size_type size; bool fancy; + const DistData &data; + + DistPrint(const DistInfoBase &info); + DistPrint(const VectorDistInfoBase &info, int i); + void init(const Info &info, const DistParams *params); void operator()(ostream &stream) const; }; +DistPrint::DistPrint(const DistInfoBase &info) + : data(info.data) +{ + init(info, safe_cast(info.storageParams)); +} + +DistPrint::DistPrint(const VectorDistInfoBase &info, int i) + : data(info.data[i]) +{ + init(info, safe_cast(info.storageParams)); + + name = info.name + "_" + + (info.subnames[i].empty() ? (to_string(i)) : info.subnames[i]); + + if (!info.subdescs[i].empty()) + desc = info.subdescs[i]; +} + +void +DistPrint::init(const Info &info, const DistParams *params) +{ + name = info.name; + desc = info.desc; + flags = info.flags; + compat = compat; + descriptions = descriptions; + precision = info.precision; + + fancy = params->fancy; + min = params->min; + max = params->max; + bucket_size = params->bucket_size; + size = params->buckets; +} + void DistPrint::operator()(ostream &stream) const { + Result stdev = NAN; + if (data.samples) + stdev = sqrt((data.samples * data.squares - data.sum * data.sum) / + (data.samples * (data.samples - 1.0))); + if (fancy) { ScalarPrint print; string base = name + (compat ? "_" : "::"); @@ -385,28 +421,27 @@ DistPrint::operator()(ostream &stream) const print.cdf = NAN; print.name = base + "mean"; - print.value = samples ? sum / samples : NAN; + print.value = data.samples ? data.sum / data.samples : NAN; print(stream); print.name = base + "stdev"; - print.value = samples ? sqrt((samples * squares - sum * sum) / - (samples * (samples - 1.0))) : NAN; + print.value = stdev; print(stream); print.name = "**Ignore: " + base + "TOT"; - print.value = samples; + print.value = data.samples; print(stream); return; } - assert(size == vec.size()); + assert(size == data.cvec.size()); Result total = 0.0; - total += underflow; + total += data.underflow; for (off_type i = 0; i < size; ++i) - total += vec[i]; - total += overflow; + total += data.cvec[i]; + total += data.overflow; string base = name + (compat ? "." : "::"); @@ -427,18 +462,18 @@ DistPrint::operator()(ostream &stream) const } print.name = base + "samples"; - print.value = samples; + print.value = data.samples; print(stream); print.name = base + "min_value"; - print.value = min_val; + print.value = data.min_val; print(stream); - if (!compat || underflow > 0.0) { + if (!compat || data.underflow > 0.0) { print.name = base + "underflows"; - print.value = underflow; + print.value = data.underflow; if (!compat && total) { - print.pdf = underflow / total; + print.pdf = data.underflow / total; print.cdf += print.pdf; } print(stream); @@ -456,9 +491,9 @@ DistPrint::operator()(ostream &stream) const namestr << "-" << high; print.name = namestr.str(); - print.value = vec[i]; + print.value = data.cvec[i]; if (total) { - print.pdf = vec[i] / total; + print.pdf = data.cvec[i] / total; print.cdf += print.pdf; } print(stream); @@ -471,17 +506,17 @@ DistPrint::operator()(ostream &stream) const print.flags = flags | __substat; for (off_type i = 0; i < size; ++i) { - if ((flags & nozero && vec[i] == 0.0) || - (flags & nonan && isnan(vec[i]))) + if ((flags & nozero && data.cvec[i] == 0.0) || + (flags & nonan && isnan(data.cvec[i]))) continue; _min = i * bucket_size + min; - _pdf = vec[i] / total * 100.0; + _pdf = data.cvec[i] / total * 100.0; _cdf += _pdf; print.name = ValueToString(_min, 0, compat); - print.value = vec[i]; + print.value = data.cvec[i]; print.pdf = (flags & pdf) ? _pdf : NAN; print.cdf = (flags & cdf) ? _cdf : NAN; print(stream); @@ -490,11 +525,11 @@ DistPrint::operator()(ostream &stream) const print.flags = flags; } - if (!compat || overflow > 0.0) { + if (!compat || data.overflow > 0.0) { print.name = base + "overflows"; - print.value = overflow; + print.value = data.overflow; if (!compat && total) { - print.pdf = overflow / total; + print.pdf = data.overflow / total; print.cdf += print.pdf; } else { print.pdf = NAN; @@ -513,17 +548,16 @@ DistPrint::operator()(ostream &stream) const } print.name = base + "max_value"; - print.value = max_val; + print.value = data.max_val; print(stream); - if (!compat && samples != 0) { + if (!compat && data.samples != 0) { print.name = base + "mean"; - print.value = sum / samples; + print.value = data.sum / data.samples; print(stream); print.name = base + "stdev"; - print.value = sqrt((samples * squares - sum * sum) / - (samples * (samples - 1.0))); + print.value = stdev; print(stream); } @@ -651,39 +685,7 @@ Text::visit(const DistInfoBase &info) if (noOutput(info)) return; - DistPrint print; - - print.name = info.name; - print.desc = info.desc; - print.flags = info.flags; - print.compat = compat; - print.descriptions = descriptions; - print.precision = info.precision; - - const DistData &data = info.data; - - print.min_val = data.min_val; - print.max_val = data.max_val; - print.underflow = data.underflow; - print.overflow = data.overflow; - print.vec.resize(data.cvec.size()); - for (off_type i = 0; i < print.vec.size(); ++i) - print.vec[i] = (Result)data.cvec[i]; - print.sum = data.sum; - print.squares = data.squares; - print.samples = data.samples; - - const DistStor::Params *params = - safe_cast(info.storageParams); - - print.fancy = params->fancy; - if (!params->fancy) { - print.min = params->min; - print.max = params->max; - print.bucket_size = params->bucket_size; - print.size = params->buckets; - } - + DistPrint print(info); print(*stream); } @@ -694,38 +696,7 @@ Text::visit(const VectorDistInfoBase &info) return; for (off_type i = 0; i < info.size(); ++i) { - DistPrint print; - - print.name = info.name + "_" + - (info.subnames[i].empty() ? (to_string(i)) : info.subnames[i]); - print.desc = info.subdescs[i].empty() ? info.desc : info.subdescs[i]; - print.flags = info.flags; - print.compat = compat; - print.descriptions = descriptions; - print.precision = info.precision; - - print.min_val = info.data[i].min_val; - print.max_val = info.data[i].max_val; - print.underflow = info.data[i].underflow; - print.overflow = info.data[i].overflow; - print.vec.resize(info.data[i].cvec.size()); - for (off_type j = 0; j < print.vec.size(); ++j) - print.vec[j] = (Result)info.data[i].cvec[j]; - print.sum = info.data[i].sum; - print.squares = info.data[i].squares; - print.samples = info.data[i].samples; - - const DistStor::Params *params = - safe_cast(info.storageParams); - - print.fancy = params->fancy; - if (!params->fancy) { - print.min = params->min; - print.max = params->max; - print.bucket_size = params->bucket_size; - print.size = params->buckets; - } - + DistPrint print(info, i); print(*stream); } } -- 2.30.2