Implement reset for stats.

base/statistics.cc:
base/statistics.hh:
    Implement a reset for for the statistics package.
    This will cause all stats to be set to their default value.
    Only the currently enabled bin will be reset.
test/Makefile:
    Make tests work again now that we're naming include dirs
    explicitly
test/stattest.cc:
    test reset

--HG--
extra : convert_revision : 8d21cedf6ee91ed0a2412042ea5cb12f79b90eb3
This commit is contained in:
Nathan Binkert 2003-10-20 23:08:27 -04:00
parent df488c0e70
commit 02bacb2dfd
4 changed files with 209 additions and 20 deletions

View file

@ -35,6 +35,7 @@
#include <math.h> #include <math.h>
#include "base/callback.hh"
#include "base/cprintf.hh" #include "base/cprintf.hh"
#include "base/intmath.hh" #include "base/intmath.hh"
#include "base/misc.hh" #include "base/misc.hh"
@ -143,6 +144,7 @@ class Database
StatData *find(const Stat *stat); StatData *find(const Stat *stat);
void check(); void check();
void reset();
void regStat(Stat *stat); void regStat(Stat *stat);
StatData *print(Stat *stat); StatData *print(Stat *stat);
}; };
@ -207,6 +209,18 @@ Database::check()
} }
} }
void
Database::reset()
{
list_t::iterator i = allStats.begin();
list_t::iterator end = allStats.end();
while (i != end) {
(*i)->reset();
++i;
}
}
void void
Database::regStat(Stat *stat) Database::regStat(Stat *stat)
{ {
@ -842,4 +856,19 @@ dump(ostream &stream)
Detail::StatDB().dump(stream); Detail::StatDB().dump(stream);
} }
CallbackQueue resetQueue;
void
regReset(Callback *cb)
{
resetQueue.add(cb);
}
void
reset()
{
Detail::StatDB().reset();
resetQueue.process();
}
} // namespace Statistics } // namespace Statistics

View file

@ -76,6 +76,8 @@ float __nan();
/** Print stats out in SS format. */ /** Print stats out in SS format. */
#define STAT_DISPLAY_COMPAT #define STAT_DISPLAY_COMPAT
class Callback;
/** The current simulated cycle. */ /** The current simulated cycle. */
extern Tick curTick; extern Tick curTick;
@ -215,6 +217,10 @@ class Stat
* @param stream The stream to print to. * @param stream The stream to print to.
*/ */
virtual void display(std::ostream &stream) const = 0; 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 in this stat.
* @return The number of entries. * @return The number of entries.
@ -422,6 +428,10 @@ struct StatStor
* @return The value of this stat. * @return The value of this stat.
*/ */
T value(const Params &p) const { return data; } T value(const Params &p) const { return data; }
/**
* Reset stat value to default
*/
void reset() { data = T(); }
}; };
/** /**
@ -492,6 +502,15 @@ struct AvgStor
* @return The current count. * @return The current count.
*/ */
T value(const Params &p) const { return current; } T value(const Params &p) const { return current; }
/**
* Reset stat value to default
*/
void reset()
{
current = T();
total = 0;
last = curTick;
}
}; };
/** /**
@ -608,6 +627,11 @@ class ScalarBase : public ScalarStat
* @return 1. * @return 1.
*/ */
virtual size_t size() const { return 1; } virtual size_t size() const { return 1; }
/**
* Reset stat value to default
*/
void reset() { bin.reset(); }
}; };
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
@ -732,6 +756,10 @@ class VectorBase : public VectorStat
* @return The size of the vector. * @return The size of the vector.
*/ */
virtual size_t size() const { return bin.size(); } virtual size_t size() const { return bin.size(); }
/**
* Reset stat value to default
*/
virtual void reset() { bin.reset(); }
}; };
/** /**
@ -855,6 +883,10 @@ class ScalarProxy : public ScalarStat
* @return 1. * @return 1.
*/ */
virtual size_t size() const { return 1; } virtual size_t size() const { return 1; }
/**
* This stat has no state. Nothing to reset
*/
virtual void reset() { }
}; };
template <typename T, template <typename T> class Storage, class Bin> template <typename T, template <typename T> class Storage, class Bin>
@ -980,6 +1012,10 @@ class Vector2dBase : public Stat
} }
} }
/**
* Reset stat value to default
*/
virtual void reset() { bin.reset(); }
}; };
template <typename T, template <typename T> class Storage, class Bin> template <typename T, template <typename T> class Storage, class Bin>
@ -1058,6 +1094,11 @@ class VectorProxy : public VectorStat
assert (index >= 0 && index < size()); assert (index >= 0 && index < size());
return ScalarProxy<T, Storage, Bin>(*bin, *params, offset + index); return ScalarProxy<T, Storage, Bin>(*bin, *params, offset + index);
} }
/**
* This stat has no state. Nothing to reset.
*/
virtual void reset() { }
}; };
template <typename T, template <typename T> class Storage, class Bin> template <typename T, template <typename T> class Storage, class Bin>
@ -1120,8 +1161,11 @@ struct DistStor
*/ */
DistStor(const Params &params) DistStor(const Params &params)
: min_val(INT_MAX), max_val(INT_MIN), underflow(0), overflow(0), : 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. * Add a value to the distribution for the given number of times.
* @param val The value to add. * @param val The value to add.
@ -1200,6 +1244,21 @@ struct DistStor
rvec, params.min, params.max, params.bucket_size, rvec, params.min, params.max, params.bucket_size,
params.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, void FancyDisplay(std::ostream &stream, const std::string &name,
@ -1231,7 +1290,7 @@ struct FancyStor
/** /**
* Create and initialize this storage. * 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. * Add a value the given number of times to this running average.
@ -1286,6 +1345,15 @@ struct FancyStor
* @return True if no samples have been added. * @return True if no samples have been added.
*/ */
bool zero(const Params &) const { return total == 0; } bool zero(const Params &) const { return total == 0; }
/**
* Reset stat value to default
*/
virtual void reset()
{
sum = T();
squares = T();
total = 0;
}
}; };
/** /**
@ -1309,7 +1377,7 @@ struct AvgFancy
/** /**
* Create and initialize this storage. * 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. * Add a value to the distribution for the given number of times.
@ -1352,6 +1420,14 @@ struct AvgFancy
* @return True if the sum is zero. * @return True if the sum is zero.
*/ */
bool zero(const Params &params) const { return sum == 0; } bool zero(const Params &params) const { return sum == 0; }
/**
* Reset stat value to default
*/
virtual void reset()
{
sum = T();
squares = T();
}
}; };
/** /**
@ -1433,6 +1509,13 @@ class DistBase : public Stat
data()->display(stream, myname(), mydesc(), myprecision(), myflags(), data()->display(stream, myname(), mydesc(), myprecision(), myflags(),
params); params);
} }
/**
* Reset stat value to default
*/
virtual void reset()
{
bin.reset();
}
}; };
template <typename T, template <typename T> class Storage, class Bin> template <typename T, template <typename T> class Storage, class Bin>
@ -1472,6 +1555,13 @@ class VectorDistBase : public Stat
virtual size_t size() const { return bin.size(); } virtual size_t size() const { return bin.size(); }
virtual bool zero() const { return false; } virtual bool zero() const { return false; }
virtual void display(std::ostream &stream) const; virtual void display(std::ostream &stream) const;
/**
* Reset stat value to default
*/
virtual void reset()
{
bin.reset();
}
}; };
template <typename T, template <typename T> class Storage, class Bin> template <typename T, template <typename T> class Storage, class Bin>
@ -1528,6 +1618,10 @@ class VectorDistProxy : public Stat
data()->display(stream, name.str(), desc.str(), data()->display(stream, name.str(), desc.str(),
cstat->myprecision(), cstat->myflags(), cstat->params); cstat->myprecision(), cstat->myflags(), cstat->params);
} }
/**
* Proxy has no state. Nothing to reset.
*/
virtual void reset() { }
}; };
template <typename T, template <typename T> class Storage, class Bin> template <typename T, template <typename T> class Storage, class Bin>
@ -2032,6 +2126,16 @@ struct StatBin : public Detail::BinBase
} }
return reinterpret_cast<Storage *>(ptr); return reinterpret_cast<Storage *>(ptr);
} }
void reset()
{
char *ptr = access();
char *flags = ptr + size() * sizeof(Storage);
if (!(*flags & 0x1))
return;
Storage *s = reinterpret_cast<Storage *>(ptr);
s->reset();
}
}; };
template <class Storage> template <class Storage>
@ -2068,6 +2172,19 @@ struct StatBin : public Detail::BinBase
} }
return reinterpret_cast<Storage *>(ptr + index * sizeof(Storage)); return reinterpret_cast<Storage *>(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<Storage *>(p);
s->reset();
}
}
}; };
}; };
@ -2086,6 +2203,11 @@ struct NoBin
char ptr[sizeof(Storage)]; char ptr[sizeof(Storage)];
public: public:
~Bin()
{
reinterpret_cast<Storage *>(ptr)->~Storage();
}
bool initialized() const { return true; } bool initialized() const { return true; }
void init(const Params &params) { void init(const Params &params) {
new (ptr) Storage(params); new (ptr) Storage(params);
@ -2095,6 +2217,11 @@ struct NoBin
assert(initialized()); assert(initialized());
return reinterpret_cast<Storage *>(ptr); return reinterpret_cast<Storage *>(ptr);
} }
void reset()
{
Storage *s = reinterpret_cast<Storage *>(ptr);
s->reset();
}
}; };
template <class Storage> template <class Storage>
@ -2109,10 +2236,18 @@ struct NoBin
public: public:
VectorBin() : ptr(NULL) { } VectorBin() : ptr(NULL) { }
~VectorBin() { ~VectorBin()
if (initialized()) {
delete [] ptr; if (!initialized())
return;
for (int i = 0; i < _size; ++i) {
char *p = ptr + i * sizeof(Storage);
reinterpret_cast<Storage *>(p)->~Storage();
}
delete [] ptr;
} }
bool initialized() const { return ptr != NULL; } bool initialized() const { return ptr != NULL; }
void init(int s, const Params &params) { void init(int s, const Params &params) {
assert(s > 0 && "size must be positive!"); assert(s > 0 && "size must be positive!");
@ -2130,6 +2265,14 @@ struct NoBin
assert(index >= 0 && index < size()); assert(index >= 0 && index < size());
return reinterpret_cast<Storage *>(ptr + index * sizeof(Storage)); return reinterpret_cast<Storage *>(ptr + index * sizeof(Storage));
} }
void reset()
{
for (int i = 0; i < _size; ++i) {
char *p = ptr + i * sizeof(Storage);
Storage *s = reinterpret_cast<Storage *>(p);
s->reset();
}
}
}; };
}; };
@ -2454,6 +2597,11 @@ class Formula : public Detail::VectorStat
else else
return root->size(); return root->size();
} }
/**
* Formulas don't need to be reset
*/
virtual void reset() {}
}; };
/** /**
@ -2462,6 +2610,8 @@ class Formula : public Detail::VectorStat
void check(); void check();
void dump(std::ostream &stream); void dump(std::ostream &stream);
void reset();
void regReset(Callback *cb);
inline Detail::Temp inline Detail::Temp
operator+(Detail::Temp l, Detail::Temp r) operator+(Detail::Temp l, Detail::Temp r)

View file

@ -4,15 +4,15 @@ CC= gcc
CXX= g++ CXX= g++
CURDIR?= $(shell /bin/pwd) CURDIR?= $(shell /bin/pwd)
SRCDIR?= . SRCDIR?= ..
TARGET?= alpha TARGET?= alpha
TEST_SRCDIR?= $(SRCDIR) TEST_SRCDIR?= $(SRCDIR)/test
ARCH_SRCDIR?= $(SRCDIR)/../arch/$(TARGET) ARCH_SRCDIR?= $(SRCDIR)/arch/$(TARGET)
BASE_SRCDIR?= $(SRCDIR)/../base BASE_SRCDIR?= $(SRCDIR)/base
SIM_SRCDIR?= $(SRCDIR)/../sim SIM_SRCDIR?= $(SRCDIR)/sim
CACHE_SRCDIR?= $(SRCDIR)/../sim/cache CACHE_SRCDIR?= $(SRCDIR)/sim/cache
OLD_SRCDIR= $(SRCDIR)/../old OLD_SRCDIR= $(SRCDIR)/old
vpath % $(TEST_SRCDIR) vpath % $(TEST_SRCDIR)
vpath % $(BASE_SRCDIR) vpath % $(BASE_SRCDIR)
@ -20,13 +20,14 @@ vpath % $(SIM_SRCDIR)
vpath % $(CACHE_SRCDIR) vpath % $(CACHE_SRCDIR)
vpath % $(OLD_SRCDIR) vpath % $(OLD_SRCDIR)
INCLDIRS= -I$(ARCH_SRCDIR) -I$(BASE_SRCDIR) -I$(SIM_SRCDIR) \ CCFLAGS= -g -O0 -MMD -I. -I$(SRCDIR) -I- -DTRACING_ON=0
-I$(CACHE_SRCDIR) -I$(OLD_SRCDIR)
CCFLAGS= -g -O0 -MMD -I. $(INCLDIRS) -I- -DTRACING_ON=0
default: default:
@echo "You must specify a target" @echo "You must specify a target"
targetarch:
ln -s ../arch/$(TARGET) targetarch
bitvectest: bitvectest.o bitvectest: bitvectest.o
$(CXX) $(LFLAGS) -o $@ $^ $(CXX) $(LFLAGS) -o $@ $^
@ -51,7 +52,8 @@ offtest: offtest.o
rangetest: rangetest.o str.o rangetest: rangetest.o str.o
$(CXX) $(LFLAGS) -o $@ $^ $(CXX) $(LFLAGS) -o $@ $^
stattest: statistics.o stattest.o cprintf.o misc.o omisc.o str.o stattest: cprintf.o hostinfo.o misc.o sim_stats.o sim_time.o \
statistics.o stattest.o str.o
$(CXX) $(LFLAGS) -o $@ $^ $(CXX) $(LFLAGS) -o $@ $^
strnumtest: strnumtest.o str.o strnumtest: strnumtest.o str.o
@ -63,7 +65,7 @@ symtest: misc.o symtest.o symtab.o str.o
tokentest: tokentest.o str.o tokentest: tokentest.o str.o
$(CXX) $(LFLAGS) -o $@ $^ $(CXX) $(LFLAGS) -o $@ $^
tracetest: tracetest.o trace.o trace_flags.o cprintf.o str.o misc.o omisc.o tracetest: tracetest.o trace.o trace_flags.o cprintf.o str.o misc.o
$(CXX) $(LFLAGS) -o $@ $^ $(CXX) $(LFLAGS) -o $@ $^
clean: clean:

View file

@ -32,15 +32,16 @@
#include <unistd.h> #include <unistd.h>
#include "base/cprintf.hh" #include "base/cprintf.hh"
#include "sim/host.hh"
#include "base/misc.hh" #include "base/misc.hh"
#include "base/statistics.hh" #include "base/statistics.hh"
#include "sim/host.hh"
#include "sim/sim_stats.hh"
using namespace std; using namespace std;
using namespace Statistics; using namespace Statistics;
Tick curTick = 0; Tick curTick = 0;
//Tick ticksPerSecond = ULL(2000000000); Tick ticksPerSecond = ULL(2000000000);
Scalar<> s1; Scalar<> s1;
Scalar<> s2; Scalar<> s2;
@ -493,10 +494,17 @@ main(int argc, char *argv[])
s12.sample(100); s12.sample(100);
MainBin::activate(bin1); MainBin::activate(bin1);
cout << "dump 1" << endl;
dump(cout); dump(cout);
cout << endl << endl; cout << endl << endl;
MainBin::activate(bin2); MainBin::activate(bin2);
cout << "dump 2" << endl;
dump(cout);
cout << endl << endl;
cout << "dump 3" << endl;
reset();
dump(cout); dump(cout);
cout << endl << endl; cout << endl << endl;