From 66f115a2df61ab56e5ede8ba31836e20c622e0b3 Mon Sep 17 00:00:00 2001 From: Lisa Hsu Date: Tue, 21 Oct 2003 23:56:31 -0400 Subject: [PATCH 1/2] statistics.hh: same - bin printing statistics.cc: printing of bins! now all the nice binning functionality is actually useful cuz you can see the data it so nicely took. this prints out only the individual bin values. totals to come. statistics.hh: add a binned() function to each stat so that at print time, we can know if it's binned in order to print it right. base/statistics.hh: add a binned() function to each stat so that at print time, we can know if it's binned in order to print it right. base/statistics.cc: printing of bins! now all the nice binning functionality is actually useful cuz you can see the data it so nicely took. this prints out only the individual bin values. totals to come. base/statistics.hh: same - bin printing --HG-- extra : convert_revision : 09df9aae62b0e522230ee6bedcb51079346735a4 --- base/statistics.cc | 69 ++++++++++++++++++++++++++++++++++++++++++++-- base/statistics.hh | 57 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 120 insertions(+), 6 deletions(-) diff --git a/base/statistics.cc b/base/statistics.cc index abebcae53..a564ce4be 100644 --- a/base/statistics.cc +++ b/base/statistics.cc @@ -131,6 +131,10 @@ class Database typedef list list_t; typedef map map_t; + list bins; + map bin_names; + list_t binnedStats; + list_t allStats; list_t printStats; map_t map; @@ -145,6 +149,7 @@ class Database void check(); void regStat(Stat *stat); StatData *print(Stat *stat); + void regBin(BinBase *bin, std::string name); }; Database::Database() @@ -156,15 +161,51 @@ Database::~Database() void Database::dump(ostream &stream) { + list_t::iterator i = printStats.begin(); list_t::iterator end = printStats.end(); - while (i != end) { Stat *stat = *i; - if (stat->dodisplay()) - stat->display(stream); + if (stat->binned()) + binnedStats.push_back(stat); ++i; } + + list::iterator j = bins.begin(); + list::iterator bins_end=bins.end(); + + if (!bins.empty()) { + ccprintf(stream, "PRINTING BINNED STATS\n"); + while (j != bins_end) { + (*j)->activate(); + ::map::const_iterator iter; + iter = bin_names.find(*j); + if (iter == bin_names.end()) + panic("a binned stat not found in names map!"); + ccprintf(stream,"---%s Bin------------\n", (*iter).second); + + list_t::iterator i = binnedStats.begin(); + list_t::iterator end = binnedStats.end(); + while (i != end) { + Stat *stat = *i; + if (stat->dodisplay()) + stat->display(stream); + ++i; + } + ++j; + ccprintf(stream, "---------------------------------\n"); + } + } + + list_t::iterator k = printStats.begin(); + list_t::iterator endprint = printStats.end(); + ccprintf(stream, "*****ALL STATS*****\n"); + while (k != endprint) { + Stat *stat = *k; + if (stat->dodisplay() && !stat->binned()) + stat->display(stream); + ++k; + } } StatData * @@ -221,6 +262,21 @@ Database::regStat(Stat *stat) assert(success && "this should never fail"); } +void +Database::regBin(BinBase *bin, std::string name) +{ + if (bin_names.find(bin) != bin_names.end()) + panic("shouldn't register bin twice"); + + bins.push_back(bin); + + bool success = (bin_names.insert(make_pair(bin,name))).second; + assert(bin_names.find(bin) != bin_names.end()); + assert(success && "this should not fail"); + + cprintf("registering %s\n", name); +} + bool Stat::less(Stat *stat1, Stat *stat2) { @@ -274,6 +330,7 @@ Stat::Stat(bool reg) if (reg) StatDB().regStat(this); + #ifdef STAT_DEBUG number = ++total_stats; cprintf("I'm stat number %d\n",number); @@ -828,6 +885,12 @@ BinBase::memory() return mem; } +void +BinBase::regBin(BinBase *bin, std::string name) +{ + StatDB().regBin(bin, name); +} + } // namespace Detail void diff --git a/base/statistics.hh b/base/statistics.hh index bd70cf8a0..45efbb864 100644 --- a/base/statistics.hh +++ b/base/statistics.hh @@ -60,7 +60,7 @@ #include "sim/host.hh" // -// Un-comment this to enable wierdo-stat debugging +// Un-comment this to enable weirdo-stat debugging // // #define STAT_DEBUG @@ -226,6 +226,8 @@ class Stat */ virtual bool zero() const = 0; + //need to document + virtual bool binned() const = 0; /** * Set the name and marks this stat to print at the end of simulation. @@ -320,6 +322,9 @@ class ScalarStat : public Stat * @param stream The output stream. */ virtual void display(std::ostream &stream) const; + + //need to document + virtual bool binned() const = 0; }; void @@ -363,6 +368,9 @@ class VectorStat : public Stat * @param stream The output stream. */ virtual void display(std::ostream &stream) const; + + //need to document + virtual bool binned() const = 0; }; ////////////////////////////////////////////////////////////////////// @@ -608,6 +616,8 @@ class ScalarBase : public ScalarStat * @return 1. */ virtual size_t size() const { return 1; } + + virtual bool binned() const { return bin_t::binned; } }; ////////////////////////////////////////////////////////////////////// @@ -732,6 +742,8 @@ class VectorBase : public VectorStat * @return The size of the vector. */ virtual size_t size() const { return bin.size(); } + + virtual bool binned() const { return bin_t::binned; } }; /** @@ -855,6 +867,8 @@ class ScalarProxy : public ScalarStat * @return 1. */ virtual size_t size() const { return 1; } + + virtual bool binned() const { return false; } }; template class Storage, class Bin> @@ -931,6 +945,7 @@ class Vector2dBase : public Stat virtual size_t size() const { return bin.size(); } virtual bool zero() const { return data(0)->value(params) == 0.0; } + virtual bool binned() const { return bin_t::binned; } virtual void display(std::ostream &out) const @@ -1058,6 +1073,8 @@ class VectorProxy : public VectorStat assert (index >= 0 && index < size()); return ScalarProxy(*bin, *params, offset + index); } + + virtual bool binned() const { return false; } }; template class Storage, class Bin> @@ -1433,6 +1450,8 @@ class DistBase : public Stat data()->display(stream, myname(), mydesc(), myprecision(), myflags(), params); } + + virtual bool binned() const { return bin_t::binned; } }; template class Storage, class Bin> @@ -1472,6 +1491,7 @@ class VectorDistBase : public Stat virtual size_t size() const { return bin.size(); } virtual bool zero() const { return false; } virtual void display(std::ostream &stream) const; + virtual bool binned() const { return bin_t::binned; } }; template class Storage, class Bin> @@ -1528,6 +1548,8 @@ class VectorDistProxy : public Stat data()->display(stream, name.str(), desc.str(), cstat->myprecision(), cstat->myflags(), cstat->params); } + + virtual bool binned() const { return false; } }; template class Storage, class Bin> @@ -1598,6 +1620,8 @@ class Node : public RefCounted * @return The total of the result vector. */ virtual result_t total() const = 0; + + virtual bool binned() const = 0; }; /** Reference counting pointer to a function Node. */ @@ -1615,6 +1639,8 @@ class ScalarStatNode : public Node virtual result_t total() const { return stat.val(); }; virtual size_t size() const { return 1; } + + virtual bool binned() const { return stat.binned(); } }; template class Storage, class Bin> @@ -1631,6 +1657,8 @@ class ScalarProxyNode : public Node virtual result_t total() const { return proxy.val(); }; virtual size_t size() const { return 1; } + + virtual bool binned() const { return proxy.binned(); } }; class VectorStatNode : public Node @@ -1644,6 +1672,8 @@ class VectorStatNode : public Node virtual result_t total() const { return stat.total(); }; virtual size_t size() const { return stat.size(); } + + virtual bool binned() const { return stat.binned(); } }; template @@ -1658,6 +1688,7 @@ class ConstNode : public Node virtual result_t total() const { return data[0]; }; virtual size_t size() const { return 1; } + virtual bool binned() const { return false; } }; template @@ -1676,6 +1707,7 @@ class FunctorNode : public Node virtual result_t total() const { return (result_t)functor(); }; virtual size_t size() const { return 1; } + virtual bool binned() const { return false; } }; template @@ -1694,6 +1726,7 @@ class ScalarNode : public Node virtual result_t total() const { return (result_t)scalar; }; virtual size_t size() const { return 1; } + virtual bool binned() const { return false; } }; template @@ -1726,6 +1759,7 @@ class UnaryNode : public Node } virtual size_t size() const { return l->size(); } + virtual bool binned() const { return l->binned(); } }; template @@ -1786,6 +1820,8 @@ class BinaryNode : public Node return ls; } } + + virtual bool binned() const { return (l->binned() || r->binned()); } }; template @@ -1827,6 +1863,7 @@ class SumNode : public Node } virtual size_t size() const { return 1; } + virtual bool binned() const { return l->binned(); } }; /** @@ -1953,7 +1990,9 @@ class BinBase public: BinBase(size_t size); - ~BinBase(); + virtual ~BinBase(); + virtual void activate() = 0; + void regBin(BinBase *bin, std::string name); }; } // namespace Detail @@ -1961,6 +2000,12 @@ class BinBase template struct StatBin : public Detail::BinBase { + private: + std::string _name; + + public: + std::string name() const { return _name;} + static StatBin *&curBin() { static StatBin *current = NULL; return current; @@ -1984,13 +2029,14 @@ struct StatBin : public Detail::BinBase return off; } - explicit StatBin(size_t size = 1024) : Detail::BinBase(size) {} + explicit StatBin(std::string name, size_t size = 1024) : Detail::BinBase(size) { _name = name; this->regBin(this, name); } char *memory(off_t off) { assert(offset() <= size()); return Detail::BinBase::memory() + off; } + virtual void activate() { setCurBin(this); } static void activate(StatBin &bin) { setCurBin(&bin); } class BinBase @@ -2016,6 +2062,7 @@ struct StatBin : public Detail::BinBase typedef typename Storage::Params Params; public: + enum { binned = true }; Bin() { allocate(sizeof(Storage)); } bool initialized() const { return true; } void init(const Params ¶ms) { } @@ -2081,6 +2128,7 @@ struct NoBin { public: typedef typename Storage::Params Params; + enum { binned = false }; private: char ptr[sizeof(Storage)]; @@ -2102,6 +2150,7 @@ struct NoBin { public: typedef typename Storage::Params Params; + enum { binned = false }; private: char *ptr; @@ -2454,6 +2503,8 @@ class Formula : public Detail::VectorStat else return root->size(); } + + virtual bool binned() const { return root->binned(); } }; /** From ffd083b8da0c82d8f3e284f69eb6f4e09a6c9816 Mon Sep 17 00:00:00 2001 From: Lisa Hsu Date: Wed, 22 Oct 2003 00:30:04 -0400 Subject: [PATCH 2/2] Automerge --HG-- extra : convert_revision : d14536880d6f55d4304c0bab1fa08a5121bd1846 --- base/statistics.hh | 204 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 179 insertions(+), 25 deletions(-) diff --git a/base/statistics.hh b/base/statistics.hh index 45efbb864..00f103919 100644 --- a/base/statistics.hh +++ b/base/statistics.hh @@ -76,6 +76,8 @@ float __nan(); /** Print stats out in SS format. */ #define STAT_DISPLAY_COMPAT +class Callback; + /** The current simulated cycle. */ extern Tick curTick; @@ -215,6 +217,10 @@ class Stat * @param stream The stream to print to. */ virtual void display(std::ostream &stream) const = 0; + /** + * Reset this stat to the default state. + */ + virtual void reset() = 0; /** * Return the number of entries in this stat. * @return The number of entries. @@ -430,6 +436,10 @@ struct StatStor * @return The value of this stat. */ T value(const Params &p) const { return data; } + /** + * Reset stat value to default + */ + void reset() { data = T(); } }; /** @@ -500,6 +510,15 @@ struct AvgStor * @return The current count. */ T value(const Params &p) const { return current; } + /** + * Reset stat value to default + */ + void reset() + { + current = T(); + total = 0; + last = curTick; + } }; /** @@ -616,8 +635,12 @@ class ScalarBase : public ScalarStat * @return 1. */ virtual size_t size() const { return 1; } - virtual bool binned() const { return bin_t::binned; } + + /** + * Reset stat value to default + */ + void reset() { bin.reset(); } }; ////////////////////////////////////////////////////////////////////// @@ -742,8 +765,11 @@ class VectorBase : public VectorStat * @return The size of the vector. */ virtual size_t size() const { return bin.size(); } - virtual bool binned() const { return bin_t::binned; } + /** + * Reset stat value to default + */ + virtual void reset() { bin.reset(); } }; /** @@ -867,8 +893,11 @@ class ScalarProxy : public ScalarStat * @return 1. */ virtual size_t size() const { return 1; } - virtual bool binned() const { return false; } + /** + * This stat has no state. Nothing to reset + */ + virtual void reset() { } }; template class Storage, class Bin> @@ -995,6 +1024,10 @@ class Vector2dBase : public Stat } } + /** + * Reset stat value to default + */ + virtual void reset() { bin.reset(); } }; template class Storage, class Bin> @@ -1073,8 +1106,12 @@ class VectorProxy : public VectorStat assert (index >= 0 && index < size()); return ScalarProxy(*bin, *params, offset + index); } - virtual bool binned() const { return false; } + + /** + * This stat has no state. Nothing to reset. + */ + virtual void reset() { } }; template class Storage, class Bin> @@ -1137,8 +1174,11 @@ struct DistStor */ DistStor(const Params ¶ms) : min_val(INT_MAX), max_val(INT_MIN), underflow(0), overflow(0), - vec(params.size) { + vec(params.size) + { + reset(); } + /** * Add a value to the distribution for the given number of times. * @param val The value to add. @@ -1217,6 +1257,21 @@ struct DistStor rvec, params.min, params.max, params.bucket_size, params.size); } + /** + * Reset stat value to default + */ + void reset() + { + min_val = INT_MAX; + max_val = INT_MIN; + underflow = 0; + overflow = 0; + + int size = vec.size(); + for (int i = 0; i < size; ++i) + vec[i] = T(); + } + }; void FancyDisplay(std::ostream &stream, const std::string &name, @@ -1248,7 +1303,7 @@ struct FancyStor /** * Create and initialize this storage. */ - FancyStor(const Params &) : sum(0), squares(0), total(0) {} + FancyStor(const Params &) : sum(T()), squares(T()), total(0) {} /** * Add a value the given number of times to this running average. @@ -1303,6 +1358,15 @@ struct FancyStor * @return True if no samples have been added. */ bool zero(const Params &) const { return total == 0; } + /** + * Reset stat value to default + */ + virtual void reset() + { + sum = T(); + squares = T(); + total = 0; + } }; /** @@ -1326,7 +1390,7 @@ struct AvgFancy /** * Create and initialize this storage. */ - AvgFancy(const Params &) : sum(0), squares(0) {} + AvgFancy(const Params &) : sum(T()), squares(T()) {} /** * Add a value to the distribution for the given number of times. @@ -1369,6 +1433,14 @@ struct AvgFancy * @return True if the sum is zero. */ bool zero(const Params ¶ms) const { return sum == 0; } + /** + * Reset stat value to default + */ + virtual void reset() + { + sum = T(); + squares = T(); + } }; /** @@ -1452,10 +1524,17 @@ class DistBase : public Stat } virtual bool binned() const { return bin_t::binned; } + /** + * Reset stat value to default + */ + virtual void reset() + { + bin.reset(); + } }; template class Storage, class Bin> -class VectorDistProxy; +class DistProxy; template class Storage, class Bin> class VectorDistBase : public Stat @@ -1484,18 +1563,25 @@ class VectorDistBase : public Stat VectorDistBase() : Stat(true) { } ~VectorDistBase() { } - friend class VectorDistProxy; - VectorDistProxy operator[](int index); - const VectorDistProxy operator[](int index) const; + friend class DistProxy; + DistProxy operator[](int index); + const DistProxy operator[](int index) const; virtual size_t size() const { return bin.size(); } virtual bool zero() const { return false; } virtual void display(std::ostream &stream) const; virtual bool binned() const { return bin_t::binned; } + /** + * Reset stat value to default + */ + virtual void reset() + { + bin.reset(); + } }; template class Storage, class Bin> -class VectorDistProxy : public Stat +class DistProxy : public Stat { protected: typedef Storage storage_t; @@ -1515,11 +1601,11 @@ class VectorDistProxy : public Stat const storage_t *data() const { return cstat->data(index); } public: - VectorDistProxy(const VectorDistBase &s, int i) + DistProxy(const VectorDistBase &s, int i) : Stat(false), cstat(&s), index(i) {} - VectorDistProxy(const VectorDistProxy &sp) + DistProxy(const DistProxy &sp) : Stat(false), cstat(sp.cstat), index(sp.index) {} - const VectorDistProxy &operator=(const VectorDistProxy &sp) { + const DistProxy &operator=(const DistProxy &sp) { cstat = sp.cstat; index = sp.index; return *this; } @@ -1550,22 +1636,26 @@ class VectorDistProxy : public Stat } virtual bool binned() const { return false; } + /** + * Proxy has no state. Nothing to reset. + */ + virtual void reset() { } }; template class Storage, class Bin> -inline VectorDistProxy +inline DistProxy VectorDistBase::operator[](int index) { assert (index >= 0 && index < size()); - return VectorDistProxy(*this, index); + return DistProxy(*this, index); } template class Storage, class Bin> -inline const VectorDistProxy +inline const DistProxy VectorDistBase::operator[](int index) const { assert (index >= 0 && index < size()); - return VectorDistProxy(*this, index); + return DistProxy(*this, index); } /** @@ -1576,7 +1666,7 @@ void VectorDistBase::display(std::ostream &stream) const { for (int i = 0; i < size(); ++i) { - VectorDistProxy proxy(*this, i); + DistProxy proxy(*this, i); proxy.display(stream); } } @@ -2079,6 +2169,16 @@ struct StatBin : public Detail::BinBase } return reinterpret_cast(ptr); } + void reset() + { + char *ptr = access(); + char *flags = ptr + size() * sizeof(Storage); + if (!(*flags & 0x1)) + return; + + Storage *s = reinterpret_cast(ptr); + s->reset(); + } }; template @@ -2115,6 +2215,19 @@ struct StatBin : public Detail::BinBase } return reinterpret_cast(ptr + index * sizeof(Storage)); } + void reset() + { + char *ptr = access(); + char *flags = ptr + size() * sizeof(Storage); + if (!(*flags & 0x1)) + return; + + for (int i = 0; i < _size; ++i) { + char *p = ptr + i * sizeof(Storage); + Storage *s = reinterpret_cast(p); + s->reset(); + } + } }; }; @@ -2134,6 +2247,11 @@ struct NoBin char ptr[sizeof(Storage)]; public: + ~Bin() + { + reinterpret_cast(ptr)->~Storage(); + } + bool initialized() const { return true; } void init(const Params ¶ms) { new (ptr) Storage(params); @@ -2143,6 +2261,11 @@ struct NoBin assert(initialized()); return reinterpret_cast(ptr); } + void reset() + { + Storage *s = reinterpret_cast(ptr); + s->reset(); + } }; template @@ -2158,10 +2281,18 @@ struct NoBin public: VectorBin() : ptr(NULL) { } - ~VectorBin() { - if (initialized()) - delete [] ptr; + ~VectorBin() + { + if (!initialized()) + return; + + for (int i = 0; i < _size; ++i) { + char *p = ptr + i * sizeof(Storage); + reinterpret_cast(p)->~Storage(); + } + delete [] ptr; } + bool initialized() const { return ptr != NULL; } void init(int s, const Params ¶ms) { assert(s > 0 && "size must be positive!"); @@ -2179,6 +2310,14 @@ struct NoBin assert(index >= 0 && index < size()); return reinterpret_cast(ptr + index * sizeof(Storage)); } + void reset() + { + for (int i = 0; i < _size; ++i) { + char *p = ptr + i * sizeof(Storage); + Storage *s = reinterpret_cast(p); + s->reset(); + } + } }; }; @@ -2484,12 +2623,20 @@ class Formula : public Detail::VectorStat } /** - * Return the vector of values of this formula. + * Return the result of the Fomula in a vector. If there were no Vector + * components to the Formula, then the vector is size 1. If there were, + * like x/y with x being a vector of size 3, then the result returned will + * be x[0]/y, x[1]/y, x[2]/y, respectively. * @return The result vector. */ const rvec_t &val() const { return root->val(); } /** - * Return the total of the result vector. + * Return the total Formula result. If there is a Vector component to this + * Formula, then this is the result of the Formula if the formula is applied + * after summing all the components of the Vector. For example, if Formula + * is x/y where x is size 3, then total() will return (x[1]+x[2]+x[3])/y. If there is no + * Vector component, total() returns the same value as the first entry in the rvec_t + * val() returns. * @return The total of the result vector. */ result_t total() const { return root->total(); } @@ -2505,6 +2652,11 @@ class Formula : public Detail::VectorStat } virtual bool binned() const { return root->binned(); } + + /** + * Formulas don't need to be reset + */ + virtual void reset() {} }; /** @@ -2513,6 +2665,8 @@ class Formula : public Detail::VectorStat void check(); void dump(std::ostream &stream); +void reset(); +void regReset(Callback *cb); inline Detail::Temp operator+(Detail::Temp l, Detail::Temp r)