stat_control.cc revision 1717
1/* 2 * Copyright (c) 2004 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; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29// This file will contain default statistics for the simulator that 30// don't really belong to a specific simulator object 31 32#include <fstream> 33#include <iostream> 34#include <list> 35 36#include "base/callback.hh" 37#include "base/hostinfo.hh" 38#include "base/statistics.hh" 39#include "base/str.hh" 40#include "base/time.hh" 41#include "base/stats/output.hh" 42#include "cpu/base.hh" 43#include "sim/eventq.hh" 44#include "sim/sim_object.hh" 45#include "sim/stat_control.hh" 46#include "sim/root.hh" 47 48using namespace std; 49 50Stats::Formula hostInstRate; 51Stats::Formula hostTickRate; 52Stats::Value hostMemory; 53Stats::Value hostSeconds; 54 55Stats::Value simTicks; 56Stats::Value simInsts; 57Stats::Value simFreq; 58Stats::Formula simSeconds; 59 60namespace Stats { 61 62Time statTime(true); 63Tick startTick; 64 65class SimTicksReset : public Callback 66{ 67 public: 68 void process() 69 { 70 statTime.set(); 71 startTick = curTick; 72 } 73}; 74 75double 76statElapsedTime() 77{ 78 Time now(true); 79 Time elapsed = now - statTime; 80 return elapsed(); 81} 82 83Tick 84statElapsedTicks() 85{ 86 return curTick - startTick; 87} 88 89SimTicksReset simTicksReset; 90 91void 92InitSimStats() 93{ 94 simInsts 95 .functor(BaseCPU::numSimulatedInstructions) 96 .name("sim_insts") 97 .desc("Number of instructions simulated") 98 .precision(0) 99 .prereq(simInsts) 100 ; 101 102 simSeconds 103 .name("sim_seconds") 104 .desc("Number of seconds simulated") 105 ; 106 107 simFreq 108 .scalar(Clock::Frequency) 109 .name("sim_freq") 110 .desc("Frequency of simulated ticks") 111 ; 112 113 simTicks 114 .functor(statElapsedTicks) 115 .name("sim_ticks") 116 .desc("Number of ticks simulated") 117 ; 118 119 hostInstRate 120 .name("host_inst_rate") 121 .desc("Simulator instruction rate (inst/s)") 122 .precision(0) 123 .prereq(simInsts) 124 ; 125 126 hostMemory 127 .functor(memUsage) 128 .name("host_mem_usage") 129 .desc("Number of bytes of host memory used") 130 .prereq(hostMemory) 131 ; 132 133 hostSeconds 134 .functor(statElapsedTime) 135 .name("host_seconds") 136 .desc("Real time elapsed on the host") 137 .precision(2) 138 ; 139 140 hostTickRate 141 .name("host_tick_rate") 142 .desc("Simulator tick rate (ticks/s)") 143 .precision(0) 144 ; 145 146 simSeconds = simTicks / simFreq; 147 hostInstRate = simInsts / hostSeconds; 148 hostTickRate = simTicks / hostSeconds; 149 150 registerResetCallback(&simTicksReset); 151} 152 153class StatEvent : public Event 154{ 155 protected: 156 int flags; 157 Tick repeat; 158 159 public: 160 StatEvent(int _flags, Tick _when, Tick _repeat); 161 virtual void process(); 162 virtual const char *description(); 163}; 164 165StatEvent::StatEvent(int _flags, Tick _when, Tick _repeat) 166 : Event(&mainEventQueue, Stat_Event_Pri), 167 flags(_flags), repeat(_repeat) 168{ 169 setFlags(AutoDelete); 170 schedule(_when); 171} 172 173const char * 174StatEvent::description() 175{ 176 return "Statistics dump and/or reset"; 177} 178 179void 180StatEvent::process() 181{ 182 if (flags & Stats::Dump) 183 DumpNow(); 184 185 if (flags & Stats::Reset) 186 reset(); 187 188 if (repeat) 189 schedule(curTick + repeat); 190} 191 192list<Output *> OutputList; 193 194void 195DumpNow() 196{ 197 list<Output *>::iterator i = OutputList.begin(); 198 list<Output *>::iterator end = OutputList.end(); 199 for (; i != end; ++i) { 200 Output *output = *i; 201 if (!output->valid()) 202 continue; 203 204 output->output(); 205 } 206} 207 208void 209SetupEvent(int flags, Tick when, Tick repeat) 210{ 211 new StatEvent(flags, when, repeat); 212} 213 214/* namespace Stats */ } 215 216extern "C" void 217debugDumpStats() 218{ 219 Stats::DumpNow(); 220} 221 222