#include "base/callback.hh"
#include "base/hostinfo.hh"
#include "base/statistics.hh"
-#include "base/str.hh"
#include "base/time.hh"
-#include "base/stats/output.hh"
+#include "config/the_isa.hh"
+#if THE_ISA == NO_ISA
+#include "arch/noisa/cpu_dummy.hh"
+#else
#include "cpu/base.hh"
+#endif
+
#include "sim/eventq.hh"
-#include "sim/sim_object.hh"
#include "sim/stat_control.hh"
-#include "sim/root.hh"
using namespace std;
-Stats::Formula hostInstRate;
-Stats::Formula hostTickRate;
-Stats::Value hostMemory;
-Stats::Value hostSeconds;
-
+Stats::Formula simSeconds;
Stats::Value simTicks;
-Stats::Value simInsts;
Stats::Value simFreq;
-Stats::Formula simSeconds;
namespace Stats {
Time statTime(true);
Tick startTick;
-Tick lastDump(0);
-class SimTicksReset : public Callback
+struct SimTicksReset : public Callback
{
- public:
void process()
{
- statTime.set();
- startTick = curTick;
+ statTime.setTimer();
+ startTick = curTick();
}
};
double
statElapsedTime()
{
- Time now(true);
+ Time now;
+ now.setTimer();
+
Time elapsed = now - statTime;
- return elapsed();
+ return elapsed;
}
Tick
statElapsedTicks()
{
- return curTick - startTick;
+ return curTick() - startTick;
}
SimTicksReset simTicksReset;
-void
-InitSimStats()
+struct Global
+{
+ Stats::Formula hostInstRate;
+ Stats::Formula hostTickRate;
+ Stats::Value hostMemory;
+ Stats::Value hostSeconds;
+
+ Stats::Value simInsts;
+
+ Global();
+};
+
+Global::Global()
{
simInsts
.functor(BaseCPU::numSimulatedInstructions)
;
simFreq
- .scalar(Clock::Frequency)
+ .scalar(SimClock::Frequency)
.name("sim_freq")
.desc("Frequency of simulated ticks")
;
registerResetCallback(&simTicksReset);
}
-class StatEvent : public Event
-{
- protected:
- int flags;
- Tick repeat;
-
- public:
- StatEvent(EventQueue *queue, int _flags, Tick _when, Tick _repeat);
- virtual void process();
- virtual const char *description();
-};
-
-StatEvent::StatEvent(EventQueue *queue, int _flags, Tick _when, Tick _repeat)
- : Event(queue, Stat_Event_Pri),
- flags(_flags), repeat(_repeat)
-{
- setFlags(AutoDelete);
- schedule(_when);
-}
-
-const char *
-StatEvent::description()
+void
+initSimStats()
{
- return "Statistics dump and/or reset";
+ static Global global;
}
-void
-StatEvent::process()
+class StatEvent : public Event
{
- if (flags & Stats::Dump)
- DumpNow();
+ private:
+ bool dump;
+ bool reset;
+ Tick repeat;
- if (flags & Stats::Reset) {
- cprintf("Resetting stats at cycle %d!\n", curTick);
- reset();
+ public:
+ StatEvent(bool _dump, bool _reset, Tick _repeat)
+ : Event(Stat_Event_Pri), dump(_dump), reset(_reset), repeat(_repeat)
+ {
+ setFlags(AutoDelete);
}
- if (repeat)
- schedule(curTick + repeat);
-}
+ virtual void
+ process()
+ {
+ if (dump)
+ Stats::dump();
-list<Output *> OutputList;
+ if (reset)
+ Stats::reset();
-void
-DumpNow()
-{
- assert(lastDump <= curTick);
- if (lastDump == curTick)
- return;
- lastDump = curTick;
-
- list<Output *>::iterator i = OutputList.begin();
- list<Output *>::iterator end = OutputList.end();
- for (; i != end; ++i) {
- Output *output = *i;
- if (!output->valid())
- continue;
-
- output->output();
+ if (repeat) {
+ Stats::schedStatEvent(dump, reset, curTick() + repeat, repeat);
+ }
}
-}
+};
void
-SetupEvent(int flags, Tick when, Tick repeat, EventQueue *queue)
-{
- if (queue == NULL)
- queue = &mainEventQueue;
-
- new StatEvent(queue, flags, when, repeat);
-}
-
-/* namespace Stats */ }
-
-void debugDumpStats()
+schedStatEvent(bool dump, bool reset, Tick when, Tick repeat)
{
- Stats::DumpNow();
+ Event *event = new StatEvent(dump, reset, repeat);
+ mainEventQueue.schedule(event, when);
}
+} // namespace Stats