typedef list<Stat *> list_t;
typedef map<const Stat *, StatData *> map_t;
+ list<BinBase *> bins;
+ map<const BinBase *, std::string > bin_names;
+ list_t binnedStats;
+
list_t allStats;
list_t printStats;
map_t map;
void check();
void regStat(Stat *stat);
StatData *print(Stat *stat);
+ void regBin(BinBase *bin, std::string name);
};
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<BinBase *>::iterator j = bins.begin();
+ list<BinBase *>::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;
+ 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 *
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)
{
if (reg)
StatDB().regStat(this);
+
#ifdef STAT_DEBUG
number = ++total_stats;
cprintf("I'm stat number %d\n",number);
return mem;
}
+void
+BinBase::regBin(BinBase *bin, std::string name)
+{
+ StatDB().regBin(bin, name);
+}
+
} // namespace Detail
void
#include "sim/host.hh"
//
-// Un-comment this to enable wierdo-stat debugging
+// Un-comment this to enable weirdo-stat debugging
//
// #define STAT_DEBUG
*/
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.
* @param stream The output stream.
*/
virtual void display(std::ostream &stream) const;
+
+ //need to document
+ virtual bool binned() const = 0;
};
void
* @param stream The output stream.
*/
virtual void display(std::ostream &stream) const;
+
+ //need to document
+ virtual bool binned() const = 0;
};
//////////////////////////////////////////////////////////////////////
* @return 1.
*/
virtual size_t size() const { return 1; }
+
+ virtual bool binned() const { return bin_t::binned; }
};
//////////////////////////////////////////////////////////////////////
* @return The size of the vector.
*/
virtual size_t size() const { return bin.size(); }
+
+ virtual bool binned() const { return bin_t::binned; }
};
/**
* @return 1.
*/
virtual size_t size() const { return 1; }
+
+ virtual bool binned() const { return false; }
};
template <typename T, template <typename T> class Storage, class Bin>
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
assert (index >= 0 && index < size());
return ScalarProxy<T, Storage, Bin>(*bin, *params, offset + index);
}
+
+ virtual bool binned() const { return false; }
};
template <typename T, template <typename T> class Storage, class Bin>
data()->display(stream, myname(), mydesc(), myprecision(), myflags(),
params);
}
+
+ virtual bool binned() const { return bin_t::binned; }
};
template <typename T, template <typename T> class Storage, class Bin>
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 <typename T, template <typename T> class Storage, class Bin>
data()->display(stream, name.str(), desc.str(),
cstat->myprecision(), cstat->myflags(), cstat->params);
}
+
+ virtual bool binned() const { return false; }
};
template <typename T, template <typename T> class Storage, class Bin>
* @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. */
virtual result_t total() const { return stat.val(); };
virtual size_t size() const { return 1; }
+
+ virtual bool binned() const { return stat.binned(); }
};
template <typename T, template <typename T> class Storage, class Bin>
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
virtual result_t total() const { return stat.total(); };
virtual size_t size() const { return stat.size(); }
+
+ virtual bool binned() const { return stat.binned(); }
};
template <typename T>
virtual result_t total() const { return data[0]; };
virtual size_t size() const { return 1; }
+ virtual bool binned() const { return false; }
};
template <typename T>
virtual result_t total() const { return (result_t)functor(); };
virtual size_t size() const { return 1; }
+ virtual bool binned() const { return false; }
};
template <typename T>
virtual result_t total() const { return (result_t)scalar; };
virtual size_t size() const { return 1; }
+ virtual bool binned() const { return false; }
};
template <class Op>
}
virtual size_t size() const { return l->size(); }
+ virtual bool binned() const { return l->binned(); }
};
template <class Op>
return ls;
}
}
+
+ virtual bool binned() const { return (l->binned() || r->binned()); }
};
template <class Op>
}
virtual size_t size() const { return 1; }
+ virtual bool binned() const { return l->binned(); }
};
/**
public:
BinBase(size_t size);
- ~BinBase();
+ virtual ~BinBase();
+ virtual void activate() = 0;
+ void regBin(BinBase *bin, std::string name);
};
} // namespace Detail
template <class BinType>
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;
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
typedef typename Storage::Params Params;
public:
+ enum { binned = true };
Bin() { allocate(sizeof(Storage)); }
bool initialized() const { return true; }
void init(const Params ¶ms) { }
{
public:
typedef typename Storage::Params Params;
+ enum { binned = false };
private:
char ptr[sizeof(Storage)];
{
public:
typedef typename Storage::Params Params;
+ enum { binned = false };
private:
char *ptr;
else
return root->size();
}
+
+ virtual bool binned() const { return root->binned(); }
};
/**