stat_control.cc (3133:ad45cbafebdd) | stat_control.cc (4078:3f73f808bbd4) |
---|---|
1/* 2 * Copyright (c) 2004-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 24 unchanged lines hidden (view full) --- 33 34#include <fstream> 35#include <iostream> 36#include <list> 37 38#include "base/callback.hh" 39#include "base/hostinfo.hh" 40#include "base/statistics.hh" | 1/* 2 * Copyright (c) 2004-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 24 unchanged lines hidden (view full) --- 33 34#include <fstream> 35#include <iostream> 36#include <list> 37 38#include "base/callback.hh" 39#include "base/hostinfo.hh" 40#include "base/statistics.hh" |
41#include "base/str.hh" | |
42#include "base/time.hh" | 41#include "base/time.hh" |
43#include "base/stats/output.hh" | |
44#include "cpu/base.hh" 45#include "sim/eventq.hh" | 42#include "cpu/base.hh" 43#include "sim/eventq.hh" |
46#include "sim/sim_object.hh" 47#include "sim/stat_control.hh" 48#include "sim/root.hh" | |
49 50using namespace std; 51 52Stats::Formula hostInstRate; 53Stats::Formula hostTickRate; 54Stats::Value hostMemory; 55Stats::Value hostSeconds; 56 57Stats::Value simTicks; 58Stats::Value simInsts; 59Stats::Value simFreq; 60Stats::Formula simSeconds; 61 62namespace Stats { 63 64Time statTime(true); 65Tick startTick; | 44 45using namespace std; 46 47Stats::Formula hostInstRate; 48Stats::Formula hostTickRate; 49Stats::Value hostMemory; 50Stats::Value hostSeconds; 51 52Stats::Value simTicks; 53Stats::Value simInsts; 54Stats::Value simFreq; 55Stats::Formula simSeconds; 56 57namespace Stats { 58 59Time statTime(true); 60Tick startTick; |
66Tick lastDump(0); | |
67 | 61 |
68class SimTicksReset : public Callback | 62struct SimTicksReset : public Callback |
69{ | 63{ |
70 public: | |
71 void process() 72 { 73 statTime.set(); 74 startTick = curTick; 75 } 76}; 77 78double --- 8 unchanged lines hidden (view full) --- 87statElapsedTicks() 88{ 89 return curTick - startTick; 90} 91 92SimTicksReset simTicksReset; 93 94void | 64 void process() 65 { 66 statTime.set(); 67 startTick = curTick; 68 } 69}; 70 71double --- 8 unchanged lines hidden (view full) --- 80statElapsedTicks() 81{ 82 return curTick - startTick; 83} 84 85SimTicksReset simTicksReset; 86 87void |
95InitSimStats() | 88initSimStats() |
96{ 97 simInsts 98 .functor(BaseCPU::numSimulatedInstructions) 99 .name("sim_insts") 100 .desc("Number of instructions simulated") 101 .precision(0) 102 .prereq(simInsts) 103 ; --- 44 unchanged lines hidden (view full) --- 148 149 simSeconds = simTicks / simFreq; 150 hostInstRate = simInsts / hostSeconds; 151 hostTickRate = simTicks / hostSeconds; 152 153 registerResetCallback(&simTicksReset); 154} 155 | 89{ 90 simInsts 91 .functor(BaseCPU::numSimulatedInstructions) 92 .name("sim_insts") 93 .desc("Number of instructions simulated") 94 .precision(0) 95 .prereq(simInsts) 96 ; --- 44 unchanged lines hidden (view full) --- 141 142 simSeconds = simTicks / simFreq; 143 hostInstRate = simInsts / hostSeconds; 144 hostTickRate = simTicks / hostSeconds; 145 146 registerResetCallback(&simTicksReset); 147} 148 |
156class StatEvent : public Event | 149class _StatEvent : public Event |
157{ | 150{ |
158 protected: 159 int flags; | 151 private: 152 bool dump; 153 bool reset; |
160 Tick repeat; 161 162 public: | 154 Tick repeat; 155 156 public: |
163 StatEvent(EventQueue *queue, int _flags, Tick _when, Tick _repeat); 164 virtual void process(); 165 virtual const char *description(); 166}; 167 168StatEvent::StatEvent(EventQueue *queue, int _flags, Tick _when, Tick _repeat) 169 : Event(queue, Stat_Event_Pri), 170 flags(_flags), repeat(_repeat) 171{ 172 setFlags(AutoDelete); 173 schedule(_when); 174} 175 176const char * 177StatEvent::description() 178{ 179 return "Statistics dump and/or reset"; 180} 181 182void 183StatEvent::process() 184{ 185 if (flags & Stats::Dump) 186 DumpNow(); 187 188 if (flags & Stats::Reset) { 189 cprintf("Resetting stats at cycle %d!\n", curTick); 190 reset(); | 157 _StatEvent(bool _dump, bool _reset, Tick _when, Tick _repeat) 158 : Event(&mainEventQueue, Stat_Event_Pri), dump(_dump), reset(_reset), 159 repeat(_repeat) 160 { 161 setFlags(AutoDelete); 162 schedule(_when); |
191 } 192 | 163 } 164 |
193 if (repeat) 194 schedule(curTick + repeat); 195} | 165 virtual void 166 process() 167 { 168 if (dump) 169 Stats::dump(); |
196 | 170 |
197list<Output *> OutputList; | 171 if (reset) 172 Stats::reset(); |
198 | 173 |
199void 200DumpNow() 201{ 202 assert(lastDump <= curTick); 203 if (lastDump == curTick) 204 return; 205 lastDump = curTick; 206 207 list<Output *>::iterator i = OutputList.begin(); 208 list<Output *>::iterator end = OutputList.end(); 209 for (; i != end; ++i) { 210 Output *output = *i; 211 if (!output->valid()) 212 continue; 213 214 output->output(); | 174 if (repeat) 175 new _StatEvent(dump, reset, curTick + repeat, repeat); |
215 } | 176 } |
216} | 177}; |
217 218void | 178 179void |
219SetupEvent(int flags, Tick when, Tick repeat, EventQueue *queue) | 180StatEvent(bool dump, bool reset, Tick when, Tick repeat) |
220{ | 181{ |
221 if (queue == NULL) 222 queue = &mainEventQueue; 223 224 new StatEvent(queue, flags, when, repeat); | 182 new _StatEvent(dump, reset, when, repeat); |
225} 226 227/* namespace Stats */ } | 183} 184 185/* namespace Stats */ } |
228 229void debugDumpStats() 230{ 231 Stats::DumpNow(); 232} 233 | |