summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Binkert <binkertn@umich.edu>2003-10-20 23:08:27 -0400
committerNathan Binkert <binkertn@umich.edu>2003-10-20 23:08:27 -0400
commit02bacb2dfdfcb3161f8fbada4bf3108566989fcd (patch)
treef3db2a424695f8634fdc70e51e35c21a0721f306
parentdf488c0e70eb827d895c12aba85d5de168505b02 (diff)
downloadgem5-02bacb2dfdfcb3161f8fbada4bf3108566989fcd.tar.xz
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
-rw-r--r--base/statistics.cc29
-rw-r--r--base/statistics.hh162
-rw-r--r--test/Makefile26
-rw-r--r--test/stattest.cc12
4 files changed, 209 insertions, 20 deletions
diff --git a/base/statistics.cc b/base/statistics.cc
index abebcae53..2f52314b9 100644
--- a/base/statistics.cc
+++ b/base/statistics.cc
@@ -35,6 +35,7 @@
#include <math.h>
+#include "base/callback.hh"
#include "base/cprintf.hh"
#include "base/intmath.hh"
#include "base/misc.hh"
@@ -143,6 +144,7 @@ class Database
StatData *find(const Stat *stat);
void check();
+ void reset();
void regStat(Stat *stat);
StatData *print(Stat *stat);
};
@@ -208,6 +210,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
Database::regStat(Stat *stat)
{
if (map.find(stat) != map.end())
@@ -842,4 +856,19 @@ dump(ostream &stream)
Detail::StatDB().dump(stream);
}
+CallbackQueue resetQueue;
+
+void
+regReset(Callback *cb)
+{
+ resetQueue.add(cb);
+}
+
+void
+reset()
+{
+ Detail::StatDB().reset();
+ resetQueue.process();
+}
+
} // namespace Statistics
diff --git a/base/statistics.hh b/base/statistics.hh
index bd70cf8a0..d4353bd11 100644
--- a/base/statistics.hh
+++ b/base/statistics.hh
@@ -76,6 +76,8 @@ float __nan();
/** Print stats out in SS format. */
#define STAT_DISPLAY_COMPAT
+class Callback;
+
/** The current simulated cycle. */
extern Tick curTick;
@@ -216,6 +218,10 @@ class Stat
*/
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.
*/
@@ -422,6 +428,10 @@ struct StatStor
* @return The value of this stat.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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>
@@ -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>
@@ -1058,6 +1094,11 @@ class VectorProxy : public VectorStat
assert (index >= 0 && index < size());
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>
@@ -1120,8 +1161,11 @@ struct DistStor
*/
DistStor(const Params &params)
: 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.
* @param val The value to add.
@@ -1200,6 +1244,21 @@ struct DistStor
rvec, params.min, params.max, params.bucket_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,
@@ -1231,7 +1290,7 @@ struct FancyStor
/**
* 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.
@@ -1286,6 +1345,15 @@ struct FancyStor
* @return True if no samples have been added.
*/
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.
*/
- 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.
@@ -1352,6 +1420,14 @@ struct AvgFancy
* @return True if the sum is zero.
*/
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(),
params);
}
+ /**
+ * Reset stat value to default
+ */
+ virtual void reset()
+ {
+ bin.reset();
+ }
};
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 bool zero() const { return false; }
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>
@@ -1528,6 +1618,10 @@ class VectorDistProxy : public Stat
data()->display(stream, name.str(), desc.str(),
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>
@@ -2032,6 +2126,16 @@ struct StatBin : public Detail::BinBase
}
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>
@@ -2068,6 +2172,19 @@ struct StatBin : public Detail::BinBase
}
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)];
public:
+ ~Bin()
+ {
+ reinterpret_cast<Storage *>(ptr)->~Storage();
+ }
+
bool initialized() const { return true; }
void init(const Params &params) {
new (ptr) Storage(params);
@@ -2095,6 +2217,11 @@ struct NoBin
assert(initialized());
return reinterpret_cast<Storage *>(ptr);
}
+ void reset()
+ {
+ Storage *s = reinterpret_cast<Storage *>(ptr);
+ s->reset();
+ }
};
template <class Storage>
@@ -2109,10 +2236,18 @@ struct NoBin
public:
VectorBin() : ptr(NULL) { }
- ~VectorBin() {
- if (initialized())
- delete [] ptr;
+ ~VectorBin()
+ {
+ 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; }
void init(int s, const Params &params) {
assert(s > 0 && "size must be positive!");
@@ -2130,6 +2265,14 @@ struct NoBin
assert(index >= 0 && index < size());
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
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 dump(std::ostream &stream);
+void reset();
+void regReset(Callback *cb);
inline Detail::Temp
operator+(Detail::Temp l, Detail::Temp r)
diff --git a/test/Makefile b/test/Makefile
index 8c36f9806..c95f8cb8d 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -4,15 +4,15 @@ CC= gcc
CXX= g++
CURDIR?= $(shell /bin/pwd)
-SRCDIR?= .
+SRCDIR?= ..
TARGET?= alpha
-TEST_SRCDIR?= $(SRCDIR)
-ARCH_SRCDIR?= $(SRCDIR)/../arch/$(TARGET)
-BASE_SRCDIR?= $(SRCDIR)/../base
-SIM_SRCDIR?= $(SRCDIR)/../sim
-CACHE_SRCDIR?= $(SRCDIR)/../sim/cache
-OLD_SRCDIR= $(SRCDIR)/../old
+TEST_SRCDIR?= $(SRCDIR)/test
+ARCH_SRCDIR?= $(SRCDIR)/arch/$(TARGET)
+BASE_SRCDIR?= $(SRCDIR)/base
+SIM_SRCDIR?= $(SRCDIR)/sim
+CACHE_SRCDIR?= $(SRCDIR)/sim/cache
+OLD_SRCDIR= $(SRCDIR)/old
vpath % $(TEST_SRCDIR)
vpath % $(BASE_SRCDIR)
@@ -20,13 +20,14 @@ vpath % $(SIM_SRCDIR)
vpath % $(CACHE_SRCDIR)
vpath % $(OLD_SRCDIR)
-INCLDIRS= -I$(ARCH_SRCDIR) -I$(BASE_SRCDIR) -I$(SIM_SRCDIR) \
- -I$(CACHE_SRCDIR) -I$(OLD_SRCDIR)
-CCFLAGS= -g -O0 -MMD -I. $(INCLDIRS) -I- -DTRACING_ON=0
+CCFLAGS= -g -O0 -MMD -I. -I$(SRCDIR) -I- -DTRACING_ON=0
default:
@echo "You must specify a target"
+targetarch:
+ ln -s ../arch/$(TARGET) targetarch
+
bitvectest: bitvectest.o
$(CXX) $(LFLAGS) -o $@ $^
@@ -51,7 +52,8 @@ offtest: offtest.o
rangetest: rangetest.o str.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 $@ $^
strnumtest: strnumtest.o str.o
@@ -63,7 +65,7 @@ symtest: misc.o symtest.o symtab.o str.o
tokentest: tokentest.o str.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 $@ $^
clean:
diff --git a/test/stattest.cc b/test/stattest.cc
index a009c16d8..38a15900d 100644
--- a/test/stattest.cc
+++ b/test/stattest.cc
@@ -32,15 +32,16 @@
#include <unistd.h>
#include "base/cprintf.hh"
-#include "sim/host.hh"
#include "base/misc.hh"
#include "base/statistics.hh"
+#include "sim/host.hh"
+#include "sim/sim_stats.hh"
using namespace std;
using namespace Statistics;
Tick curTick = 0;
-//Tick ticksPerSecond = ULL(2000000000);
+Tick ticksPerSecond = ULL(2000000000);
Scalar<> s1;
Scalar<> s2;
@@ -493,10 +494,17 @@ main(int argc, char *argv[])
s12.sample(100);
MainBin::activate(bin1);
+ cout << "dump 1" << endl;
dump(cout);
cout << endl << endl;
MainBin::activate(bin2);
+ cout << "dump 2" << endl;
+ dump(cout);
+ cout << endl << endl;
+
+ cout << "dump 3" << endl;
+ reset();
dump(cout);
cout << endl << endl;