From 8c3eb1a1922a1129a398a6b6f1d5b11de66ff263 Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Wed, 22 Apr 2009 13:38:00 -0700 Subject: [PATCH] stats: Shuffle around info stuff so it can be accessed separately --- src/base/statistics.hh | 190 +--------------------------------- src/base/stats/info.hh | 220 ++++++++++++++++++++++++++++++++++++++++ src/base/stats/mysql.cc | 2 +- src/base/stats/text.cc | 11 +- 4 files changed, 233 insertions(+), 190 deletions(-) create mode 100644 src/base/stats/info.hh diff --git a/src/base/statistics.hh b/src/base/statistics.hh index 6758a6489..62f24b4b3 100644 --- a/src/base/statistics.hh +++ b/src/base/statistics.hh @@ -65,8 +65,9 @@ #include "base/refcnt.hh" #include "base/str.hh" #include "base/stats/flags.hh" -#include "base/stats/visit.hh" +#include "base/stats/info.hh" #include "base/stats/types.hh" +#include "base/stats/visit.hh" #include "sim/host.hh" class Callback; @@ -77,92 +78,6 @@ extern Tick curTick; /* A namespace for all of the Statistics */ namespace Stats { -struct StorageParams -{ - virtual ~StorageParams(); -}; - -////////////////////////////////////////////////////////////////////// -// -// Statistics Framework Base classes -// -////////////////////////////////////////////////////////////////////// -class Info -{ - public: - /** 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; - /** A pointer to a prerequisite Stat. */ - const Info *prereq; - /** - * A unique stat ID for each stat in the simulator. - * Can be used externally for lookups as well as for debugging. - */ - static int id_count; - int id; - - public: - const StorageParams *storageParams; - - public: - Info(); - virtual ~Info(); - - /** Set the name of this statistic */ - void setName(const std::string &name); - - /** - * Check that this stat has been set up properly and is ready for - * use - * @return true for success - */ - virtual bool check() const = 0; - bool baseCheck() const; - - /** - * Enable the stat for use - */ - virtual void enable(); - - /** - * Prepare the stat for dumping. - */ - virtual void prepare() = 0; - - /** - * Reset the stat to the default state. - */ - virtual void reset() = 0; - - /** - * @return true if this stat has a value and satisfies its - * requirement as a prereq - */ - virtual bool zero() const = 0; - - /** - * Visitor entry for outputing statistics data - */ - virtual void visit(Visit &visitor) = 0; - - /** - * Checks if the first stat's name is alphabetically less than the second. - * This function breaks names up at periods and considers each subname - * separately. - * @param stat1 The first stat. - * @param stat2 The second stat. - * @return stat1's name is alphabetically before stat2's - */ - static bool less(Info *stat1, Info *stat2); -}; -struct StorageParams; - template class InfoProxy : public Base { @@ -183,14 +98,6 @@ class InfoProxy : public Base bool zero() const { return s.zero(); } }; -class ScalarInfo : public Info -{ - public: - virtual Counter value() const = 0; - virtual Result result() const = 0; - virtual Result total() const = 0; -}; - template class ScalarInfoProxy : public InfoProxy { @@ -202,23 +109,6 @@ class ScalarInfoProxy : public InfoProxy Result total() const { return this->s.total(); } }; -class VectorInfo : public Info -{ - public: - /** Names and descriptions of subfields. */ - std::vector subnames; - std::vector subdescs; - - public: - void enable(); - - public: - virtual size_type size() const = 0; - virtual const VCounter &value() const = 0; - virtual const VResult &result() const = 0; - virtual Result total() const = 0; -}; - template class VectorInfoProxy : public InfoProxy { @@ -248,25 +138,6 @@ class VectorInfoProxy : public InfoProxy Result total() const { return this->s.total(); } }; -struct DistData -{ - Counter min_val; - Counter max_val; - Counter underflow; - Counter overflow; - VCounter cvec; - Counter sum; - Counter squares; - Counter samples; -}; - -class DistInfo : public Info -{ - public: - /** Local storage for the entry values, used for printing. */ - DistData data; -}; - template class DistInfoProxy : public InfoProxy { @@ -274,24 +145,6 @@ class DistInfoProxy : public InfoProxy DistInfoProxy(Stat &stat) : InfoProxy(stat) {} }; -class VectorDistInfo : public Info -{ - public: - std::vector data; - - /** Names and descriptions of subfields. */ - std::vector subnames; - std::vector subdescs; - void enable(); - - protected: - /** Local storage for the entry values, used for printing. */ - mutable VResult rvec; - - public: - virtual size_type size() const = 0; -}; - template class VectorDistInfoProxy : public InfoProxy { @@ -301,23 +154,6 @@ class VectorDistInfoProxy : public InfoProxy size_type size() const { return this->s.size(); } }; -class Vector2dInfo : public Info -{ - public: - /** Names and descriptions of subfields. */ - std::vector subnames; - std::vector subdescs; - std::vector y_subnames; - - size_type x; - size_type y; - - /** Local storage for the entry values, used for printing. */ - mutable VCounter cvec; - - void enable(); -}; - template class Vector2dInfoProxy : public InfoProxy { @@ -1427,22 +1263,6 @@ 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. */ @@ -2555,12 +2375,6 @@ class VectorAverageDeviation } }; -class FormulaInfo : public VectorInfo -{ - public: - virtual std::string str() const = 0; -}; - template class FormulaInfoProxy : public InfoProxy { diff --git a/src/base/stats/info.hh b/src/base/stats/info.hh new file mode 100644 index 000000000..d0ff6b170 --- /dev/null +++ b/src/base/stats/info.hh @@ -0,0 +1,220 @@ +/* + * Copyright (c) 2003-2005 The Regents of The University of Michigan + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Authors: Nathan Binkert + */ + +#include "base/stats/flags.hh" +#include "base/stats/types.hh" + +namespace Stats { + +struct StorageParams +{ + virtual ~StorageParams(); +}; + +struct Visit; + +class Info +{ + public: + /** 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; + /** A pointer to a prerequisite Stat. */ + const Info *prereq; + /** + * A unique stat ID for each stat in the simulator. + * Can be used externally for lookups as well as for debugging. + */ + static int id_count; + int id; + + public: + const StorageParams *storageParams; + + public: + Info(); + virtual ~Info(); + + /** Set the name of this statistic */ + void setName(const std::string &name); + + /** + * Check that this stat has been set up properly and is ready for + * use + * @return true for success + */ + virtual bool check() const = 0; + bool baseCheck() const; + + /** + * Enable the stat for use + */ + virtual void enable(); + + /** + * Prepare the stat for dumping. + */ + virtual void prepare() = 0; + + /** + * Reset the stat to the default state. + */ + virtual void reset() = 0; + + /** + * @return true if this stat has a value and satisfies its + * requirement as a prereq + */ + virtual bool zero() const = 0; + + /** + * Visitor entry for outputing statistics data + */ + virtual void visit(Visit &visitor) = 0; + + /** + * Checks if the first stat's name is alphabetically less than the second. + * This function breaks names up at periods and considers each subname + * separately. + * @param stat1 The first stat. + * @param stat2 The second stat. + * @return stat1's name is alphabetically before stat2's + */ + static bool less(Info *stat1, Info *stat2); +}; + +class ScalarInfo : public Info +{ + public: + virtual Counter value() const = 0; + virtual Result result() const = 0; + virtual Result total() const = 0; +}; + +class VectorInfo : public Info +{ + public: + /** Names and descriptions of subfields. */ + std::vector subnames; + std::vector subdescs; + + public: + void enable(); + + public: + virtual size_type size() const = 0; + virtual const VCounter &value() const = 0; + virtual const VResult &result() const = 0; + virtual Result total() const = 0; +}; + +struct DistData +{ + Counter min_val; + Counter max_val; + Counter underflow; + Counter overflow; + VCounter cvec; + Counter sum; + Counter squares; + Counter samples; +}; + +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) {} +}; + +class DistInfo : public Info +{ + public: + /** Local storage for the entry values, used for printing. */ + DistData data; +}; + +class VectorDistInfo : public Info +{ + public: + std::vector data; + + /** Names and descriptions of subfields. */ + std::vector subnames; + std::vector subdescs; + void enable(); + + protected: + /** Local storage for the entry values, used for printing. */ + mutable VResult rvec; + + public: + virtual size_type size() const = 0; +}; + +class Vector2dInfo : public Info +{ + public: + /** Names and descriptions of subfields. */ + std::vector subnames; + std::vector subdescs; + std::vector y_subnames; + + size_type x; + size_type y; + + /** Local storage for the entry values, used for printing. */ + mutable VCounter cvec; + + void enable(); +}; + +class FormulaInfo : public VectorInfo +{ + public: + virtual std::string str() const = 0; +}; + + +/* namespace Stats */ } diff --git a/src/base/stats/mysql.cc b/src/base/stats/mysql.cc index dff9a0ee0..84e131e4f 100644 --- a/src/base/stats/mysql.cc +++ b/src/base/stats/mysql.cc @@ -36,8 +36,8 @@ #include "base/misc.hh" #include "base/mysql.hh" -#include "base/statistics.hh" #include "base/stats/flags.hh" +#include "base/stats/info.hh" #include "base/stats/mysql.hh" #include "base/stats/mysql_run.hh" #include "base/stats/types.hh" diff --git a/src/base/stats/text.cc b/src/base/stats/text.cc index 8502ec747..fbb1ad1e6 100644 --- a/src/base/stats/text.cc +++ b/src/base/stats/text.cc @@ -36,13 +36,20 @@ #include #endif +#include +#ifdef __SUNPRO_CC +#include +#endif +#include #include #include #include #include +#include "base/cast.hh" #include "base/misc.hh" -#include "base/statistics.hh" +#include "base/str.hh" +#include "base/stats/info.hh" #include "base/stats/text.hh" #include "base/stats/visit.hh" @@ -72,6 +79,8 @@ __nan() namespace Stats { +std::list &statsList(); + Text::Text() : mystream(false), stream(NULL), descriptions(false) {