Make some general changes to stats package where things either could have been better or were just plain wrong.

statistics.hh:
fix a bug in binning that made bins a fixed size no matter what.  add GenBin class that is public but not templatized.
statistics.cc:
change map to statMap so others can use the map<> token without needing ::.  also, add a level of GenBin that is public base class for StatBin<>.

base/statistics.cc:
    change map to statMap so others can use the map<> token without needing ::.  also, add a level of GenBin that is public base class for StatBin<>.
base/statistics.hh:
    fix a bug in binning that made bins a fixed size no matter what.  add GenBin class that is public but not templatized.

--HG--
extra : convert_revision : 6976a891e414c9515cc5a613157f7cb86ef89008
This commit is contained in:
Lisa Hsu
2003-10-30 19:18:53 -05:00
parent 16e0a941c5
commit 2c451a0ad4
2 changed files with 37 additions and 23 deletions

View File

@@ -132,13 +132,13 @@ class Database
typedef list<Stat *> list_t;
typedef map<const Stat *, StatData *> map_t;
list<BinBase *> bins;
map<const BinBase *, std::string > bin_names;
list<GenBin *> bins;
map<const GenBin *, std::string > bin_names;
list_t binnedStats;
list_t allStats;
list_t printStats;
map_t map;
map_t statMap;
public:
Database();
@@ -151,7 +151,7 @@ class Database
void reset();
void regStat(Stat *stat);
StatData *print(Stat *stat);
void regBin(BinBase *bin, std::string name);
void regBin(GenBin *bin, std::string name);
};
Database::Database()
@@ -173,14 +173,14 @@ Database::dump(ostream &stream)
++i;
}
list<BinBase *>::iterator j = bins.begin();
list<BinBase *>::iterator bins_end=bins.end();
list<GenBin *>::iterator j = bins.begin();
list<GenBin *>::iterator bins_end=bins.end();
if (!bins.empty()) {
ccprintf(stream, "PRINTING BINNED STATS\n");
while (j != bins_end) {
(*j)->activate();
::map<const BinBase *, std::string>::const_iterator iter;
map<const GenBin *, std::string>::const_iterator iter;
iter = bin_names.find(*j);
if (iter == bin_names.end())
panic("a binned stat not found in names map!");
@@ -213,9 +213,9 @@ Database::dump(ostream &stream)
StatData *
Database::find(const Stat *stat)
{
map_t::const_iterator i = map.find(stat);
map_t::const_iterator i = statMap.find(stat);
if (i == map.end())
if (i == statMap.end())
return NULL;
return (*i).second;
@@ -265,19 +265,19 @@ Database::reset()
void
Database::regStat(Stat *stat)
{
if (map.find(stat) != map.end())
if (statMap.find(stat) != statMap.end())
panic("shouldn't register stat twice!");
allStats.push_back(stat);
StatData *data = new StatData;
bool success = (map.insert(make_pair(stat, data))).second;
assert(map.find(stat) != map.end());
bool success = (statMap.insert(make_pair(stat, data))).second;
assert(statMap.find(stat) != statMap.end());
assert(success && "this should never fail");
}
void
Database::regBin(BinBase *bin, std::string name)
Database::regBin(GenBin *bin, std::string name)
{
if (bin_names.find(bin) != bin_names.end())
panic("shouldn't register bin twice");
@@ -877,8 +877,8 @@ FancyDisplay(ostream &stream, const string &name, const string &desc,
PrintOne(stream, stdev, name + NAMESEP + "stdev", desc, precision, flags);
}
BinBase::BinBase(size_t size)
: memsize(CeilPow2(size)), mem(NULL)
BinBase::BinBase()
: mem(NULL), memsize(-1)
{
}
@@ -900,9 +900,9 @@ BinBase::memory()
}
void
BinBase::regBin(BinBase *bin, std::string name)
GenBin::regBin(GenBin *bin, std::string name)
{
StatDB().regBin(bin, name);
Detail::StatDB().regBin(bin, name);
}
} // namespace Detail

View File

@@ -59,6 +59,8 @@
#include "sim/host.hh"
#include "base/cprintf.hh"
//
// Un-comment this to enable weirdo-stat debugging
//
@@ -2145,24 +2147,32 @@ class Temp
class BinBase
{
private:
off_t memsize;
char *mem;
protected:
off_t memsize;
off_t size() const { return memsize; }
char *memory();
public:
BinBase(size_t size);
BinBase();
virtual ~BinBase();
virtual void activate() = 0;
void regBin(BinBase *bin, std::string name);
};
} // namespace Detail
class GenBin : public Detail::BinBase
{
public:
GenBin() : BinBase() {}
virtual ~GenBin() {};
virtual void activate() = 0;
void regBin(GenBin *bin, std::string name);
};
template <class BinType>
struct StatBin : public Detail::BinBase
struct StatBin : public GenBin
{
private:
std::string _name;
@@ -2193,9 +2203,13 @@ struct StatBin : public Detail::BinBase
return off;
}
explicit StatBin(std::string name, size_t size = 1024) : Detail::BinBase(size) { _name = name; this->regBin(this, name); }
explicit StatBin(std::string name) : GenBin() { _name = name; this->regBin(this, name); }
char *memory(off_t off) {
if (memsize == -1) {
memsize = CeilPow2((size_t) offset());
cprintf("this is memsize: %d\n", (uint64_t) memsize);
}
assert(offset() <= size());
return Detail::BinBase::memory() + off;
}