diff options
author | Nathan Binkert <nate@binkert.org> | 2009-05-13 07:18:01 -0700 |
---|---|---|
committer | Nathan Binkert <nate@binkert.org> | 2009-05-13 07:18:01 -0700 |
commit | 74c595d73900312a5106780527d1c49a823994e9 (patch) | |
tree | 076288b8ddde346001fa220ed8ebb5b50a048752 /src | |
parent | 97a04b16eb8ebced6b6d7846f94f20a05a2e96fa (diff) | |
download | gem5-74c595d73900312a5106780527d1c49a823994e9.tar.xz |
stats: clean up the code for printing stats
Diffstat (limited to 'src')
-rw-r--r-- | src/base/stats/text.cc | 146 |
1 files changed, 64 insertions, 82 deletions
diff --git a/src/base/stats/text.cc b/src/base/stats/text.cc index d3eea7f49..599653244 100644 --- a/src/base/stats/text.cc +++ b/src/base/stats/text.cc @@ -192,10 +192,21 @@ struct ScalarPrint Result pdf; Result cdf; + void update(Result val, Result total); void operator()(ostream &stream) const; }; void +ScalarPrint::update(Result val, Result total) +{ + value = val; + if (total) { + pdf = val / total; + cdf += pdf; + } +} + +void ScalarPrint::operator()(ostream &stream) const { if ((flags.isSet(nozero) && value == 0.0) || @@ -255,8 +266,8 @@ VectorPrint::operator()(std::ostream &stream) const print.precision = precision; print.descriptions = descriptions; print.flags = flags; - print.pdf = NAN; - print.cdf = NAN; + print.pdf = _total ? 0.0 : NAN; + print.cdf = _total ? 0.0 : NAN; bool havesub = !subnames.empty(); @@ -272,13 +283,8 @@ VectorPrint::operator()(std::ostream &stream) const print.name = base + (havesub ? subnames[i] : to_string(i)); print.desc = subdescs.empty() ? desc : subdescs[i]; - print.value = vec[i]; - - if (_total && flags.isSet(pdf)) { - print.pdf = vec[i] / _total; - print.cdf += print.pdf; - } + print.update(vec[i], _total); print(stream); } @@ -351,52 +357,13 @@ DistPrint::init(const Text *text, const Info &info, const DistParams *params) 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 + "::"; - - print.precision = precision; - print.flags = flags; - print.descriptions = descriptions; - print.desc = desc; - print.pdf = NAN; - print.cdf = NAN; - - print.name = base + "mean"; - print.value = data.samples ? data.sum / data.samples : NAN; - print(stream); - - print.name = base + "stdev"; - print.value = stdev; - print(stream); - - print.name = "**Ignore: " + base + "TOT"; - print.value = data.samples; - print(stream); - return; - } - - assert(size == data.cvec.size()); - - Result total = 0.0; - - total += data.underflow; - for (off_type i = 0; i < size; ++i) - total += data.cvec[i]; - total += data.overflow; - string base = name + "::"; ScalarPrint print; - print.desc = desc; + print.precision = precision; print.flags = flags; print.descriptions = descriptions; - print.precision = precision; + print.desc = desc; print.pdf = NAN; print.cdf = NAN; @@ -404,17 +371,41 @@ DistPrint::operator()(ostream &stream) const print.value = data.samples; print(stream); - print.name = base + "min_value"; - print.value = data.min_val; + print.name = base + "mean"; + print.value = data.samples ? data.sum / data.samples : NAN; + print(stream); + + Result stdev = NAN; + if (data.samples) + stdev = sqrt((data.samples * data.squares - data.sum * data.sum) / + (data.samples * (data.samples - 1.0))); + print.name = base + "stdev"; + print.value = stdev; print(stream); - print.name = base + "underflows"; - print.value = data.underflow; + if (fancy) + return; + + assert(size == data.cvec.size()); + + Result total = 0.0; + if (data.underflow != NAN) + total += data.underflow; + for (off_type i = 0; i < size; ++i) + total += data.cvec[i]; + if (data.overflow != NAN) + total += data.overflow; + if (total) { - print.pdf = data.underflow / total; - print.cdf += print.pdf; + print.pdf = 0.0; + print.cdf = 0.0; + } + + if (data.underflow != NAN) { + print.name = base + "underflows"; + print.update(data.underflow, total); + print(stream); } - print(stream); for (off_type i = 0; i < size; ++i) { stringstream namestr; @@ -427,42 +418,33 @@ DistPrint::operator()(ostream &stream) const namestr << "-" << high; print.name = namestr.str(); - print.value = data.cvec[i]; - if (total) { - print.pdf = data.cvec[i] / total; - print.cdf += print.pdf; - } + print.update(data.cvec[i], total); print(stream); } - print.name = base + "overflows"; - print.value = data.overflow; - if (total) { - print.pdf = data.overflow / total; - print.cdf += print.pdf; - } else { - print.pdf = NAN; - print.cdf = NAN; + if (data.overflow != NAN) { + print.name = base + "overflows"; + print.update(data.overflow, total); + print(stream); } - print(stream); print.pdf = NAN; print.cdf = NAN; - print.name = base + "total"; - print.value = total; - print(stream); - - print.name = base + "max_value"; - print.value = data.max_val; - print(stream); + if (data.min_val != NAN) { + print.name = base + "min_value"; + print.value = data.min_val; + print(stream); + } - print.name = base + "mean"; - print.value = data.sum / data.samples; - print(stream); + if (data.max_val != NAN) { + print.name = base + "max_value"; + print.value = data.max_val; + print(stream); + } - print.name = base + "stdev"; - print.value = stdev; + print.name = base + "total"; + print.value = total; print(stream); } |