typedef list<Stat *> list_t;
typedef map<const Stat *, StatData *> map_t;
- list<GenBin *> bins;
- map<const GenBin *, std::string > bin_names;
+ list<MainBin *> bins;
+ map<const MainBin *, std::string > bin_names;
list_t binnedStats;
list_t allStats;
void reset();
void regStat(Stat *stat);
StatData *print(Stat *stat);
- void regBin(GenBin *bin, std::string name);
+ void regBin(MainBin *bin, std::string name);
};
Database::Database()
}
#endif //FS_MEASURE
- list<GenBin *>::iterator j = bins.begin();
- list<GenBin *>::iterator bins_end=bins.end();
+ list<MainBin *>::iterator j = bins.begin();
+ list<MainBin *>::iterator bins_end=bins.end();
if (!bins.empty()) {
ccprintf(stream, "PRINTING BINNED STATS\n");
while (j != bins_end) {
(*j)->activate();
- map<const GenBin *, std::string>::const_iterator iter;
+ map<const MainBin *, std::string>::const_iterator iter;
iter = bin_names.find(*j);
if (iter == bin_names.end())
panic("a binned stat not found in names map!");
MainBin *orig = MainBin::curBin();
- list<GenBin *>::iterator bi = bins.begin();
- list<GenBin *>::iterator be = bins.end();
+ list<MainBin *>::iterator bi = bins.begin();
+ list<MainBin *>::iterator be = bins.end();
while (bi != be) {
- GenBin *bin = *bi;
+ MainBin *bin = *bi;
bin->activate();
i = allStats.begin();
}
void
-Database::regBin(GenBin *bin, std::string name)
+Database::regBin(MainBin *bin, std::string name)
{
if (bin_names.find(bin) != bin_names.end())
panic("shouldn't register bin twice");
PrintOne(stream, total, "**Ignore: " + name + NAMESEP + "TOT", desc, precision, flags);
}
-BinBase::BinBase()
- : mem(NULL), memsize(-1)
+} // namespace Detail
+
+MainBin::MainBin(const std::string &name)
+ : _name(name), mem(NULL), memsize(-1)
{
+ Detail::StatDB().regBin(this, name);
}
-BinBase::~BinBase()
+MainBin::~MainBin()
{
if (mem)
delete [] mem;
}
char *
-BinBase::memory()
+MainBin::memory(off_t off)
{
if (!mem) {
mem = new char[memsize];
memset(mem, 0, memsize);
}
- return mem;
-}
+ if (memsize == -1)
+ memsize = CeilPow2((size_t) offset());
-void
-GenBin::regBin(GenBin *bin, std::string name)
-{
- Detail::StatDB().regBin(bin, name);
+ assert(offset() <= size());
+ return mem + off;
}
-} // namespace Detail
-
void
check()
{
operator NodePtr() { return node;}
};
+} // namespace Detail
+
//////////////////////////////////////////////////////////////////////
//
// Binning Interface
//
//////////////////////////////////////////////////////////////////////
-
-class BinBase
+struct MainBin
{
private:
+ std::string _name;
char *mem;
protected:
off_t memsize;
off_t size() const { return memsize; }
- char *memory();
-
- public:
- BinBase();
- virtual ~BinBase();
-};
+ char *memory(off_t off);
-} // namespace Detail
-
-class GenBin : public Detail::BinBase
-{
public:
- GenBin() : BinBase() {}
- virtual ~GenBin() {};
-
- virtual void activate() = 0;
- virtual std::string name() const = 0;
- void regBin(GenBin *bin, std::string name);
-};
-
-template <class BinType>
-struct StatBin : public GenBin
-{
- private:
- std::string _name;
-
- public:
- std::string name() const { return _name;}
-
- static StatBin *&curBin() {
- static StatBin *current = NULL;
+ static MainBin *&curBin()
+ {
+ static MainBin *current = NULL;
return current;
}
- static void setCurBin(StatBin *bin) { curBin() = bin; }
- static StatBin *current() { assert(curBin()); return curBin(); }
+ static void setCurBin(MainBin *bin) { curBin() = bin; }
+ static MainBin *current() { assert(curBin()); return curBin(); }
- static off_t &offset() {
+ static off_t &offset()
+ {
static off_t offset = 0;
return offset;
}
- static off_t new_offset(size_t size) {
+ static off_t new_offset(size_t size)
+ {
size_t mask = sizeof(u_int64_t) - 1;
off_t off = offset();
return off;
}
- explicit StatBin(std::string name) : GenBin() { _name = name; this->regBin(this, name); }
+ public:
+ MainBin(const std::string &name);
+ ~MainBin();
- char *memory(off_t off) {
- if (memsize == -1) {
- memsize = CeilPow2((size_t) offset());
- }
- assert(offset() <= size());
- return Detail::BinBase::memory() + off;
+ const std::string &
+ name() const
+ {
+ return _name;
}
- virtual void activate() {
+ void
+ activate()
+ {
setCurBin(this);
#ifdef FS_MEASURE
DPRINTF(TCPIP, "activating %s Bin\n", name());
#endif
}
- static void activate(StatBin &bin) { setCurBin(&bin); }
class BinBase
{
public:
BinBase() : offset(-1) {}
- void allocate(size_t size) {
+ void allocate(size_t size)
+ {
offset = new_offset(size);
}
- char *access() {
+ char *access()
+ {
assert(offset != -1);
return current()->memory(offset);
}
int size() const { return 1; }
- Storage *data(Params ¶ms) {
+ Storage *
+ data(Params ¶ms)
+ {
assert(initialized());
char *ptr = access();
char *flags = ptr + sizeof(Storage);
}
return reinterpret_cast<Storage *>(ptr);
}
- void reset()
+
+ void
+ reset()
{
char *ptr = access();
char *flags = ptr + size() * sizeof(Storage);
VectorBin() : _size(0) {}
bool initialized() const { return _size > 0; }
- void init(int s, Params ¶ms) {
+ void init(int s, Params ¶ms)
+ {
assert(!initialized());
assert(s > 0);
_size = s;
int size() const { return _size; }
- Storage *data(int index, Params ¶ms) {
+ Storage *data(int index, Params ¶ms)
+ {
assert(initialized());
assert(index >= 0 && index < size());
char *ptr = access();
};
};
-class MainBinType {};
-typedef StatBin<MainBinType> MainBin;
-
struct NoBin
{
template <class Storage>
}
bool initialized() const { return true; }
- void init(Params ¶ms) {
+ void init(Params ¶ms)
+ {
new (ptr) Storage(params);
}
int size() const{ return 1; }
- Storage *data(Params ¶ms) {
+ Storage *data(Params ¶ms)
+ {
assert(initialized());
return reinterpret_cast<Storage *>(ptr);
}
}
bool initialized() const { return ptr != NULL; }
- void init(int s, Params ¶ms) {
+ void init(int s, Params ¶ms)
+ {
assert(s > 0 && "size must be positive!");
assert(!initialized());
_size = s;
int size() const { return _size; }
- Storage *data(int index, Params ¶ms) {
+ Storage *data(int index, Params ¶ms)
+ {
assert(initialized());
assert(index >= 0 && index < size());
return reinterpret_cast<Storage *>(ptr + index * sizeof(Storage));