stat_control.cc revision 695
1/* 2 * Copyright (c) 2003 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 "sim/eventq.hh" 43#include "sim/sim_object.hh" 44#include "sim/stat_control.hh" 45#include "sim/universe.hh" 46 47using namespace std; 48 49Statistics::Formula hostInstRate; 50Statistics::Formula hostMemory; 51Statistics::Formula hostSeconds; 52Statistics::Formula hostTickRate; 53 54Statistics::Formula simInsts; 55Statistics::Formula simSeconds; 56Statistics::Formula simTicks; 57 58namespace Statistics { 59 60Time statTime(true); 61Tick startTick; 62 63class SimTicksReset : public Callback 64{ 65 public: 66 void process() 67 { 68 statTime.set(); 69 startTick = curTick; 70 } 71}; 72 73double 74statElapsedTime() 75{ 76 Time now(true); 77 Time elapsed = now - statTime; 78 return elapsed(); 79} 80 81SimTicksReset simTicksReset; 82 83void 84InitSimStats() 85{ 86 simInsts 87 .name("sim_insts") 88 .desc("Number of instructions simulated") 89 .precision(0) 90 .prereq(simInsts) 91 ; 92 93 simSeconds 94 .name("sim_seconds") 95 .desc("Number of seconds simulated") 96 ; 97 98 simTicks 99 .name("sim_ticks") 100 .desc("Number of ticks simulated") 101 ; 102 103 hostInstRate 104 .name("host_inst_rate") 105 .desc("Simulator instruction rate (inst/s)") 106 .precision(0) 107 .prereq(simInsts) 108 ; 109 110 hostMemory 111 .name("host_mem_usage") 112 .desc("Number of bytes of host memory used") 113 .prereq(hostMemory) 114 ; 115 116 hostSeconds 117 .name("host_seconds") 118 .desc("Real time elapsed on the host") 119 .precision(2) 120 ; 121 122 hostTickRate 123 .name("host_tick_rate") 124 .desc("Simulator tick rate (ticks/s)") 125 .precision(0) 126 ; 127 128 simInsts = constant(0); 129 simTicks = scalar(curTick) - scalar(startTick); 130 simSeconds = simTicks / scalar(ticksPerSecond); 131 hostMemory = functor(memUsage); 132 hostSeconds = functor(statElapsedTime); 133 hostInstRate = simInsts / hostSeconds; 134 hostTickRate = simTicks / hostSeconds; 135 136 registerResetCallback(&simTicksReset); 137} 138 139class StatEvent : public Event 140{ 141 protected: 142 int flags; 143 Tick repeat; 144 145 public: 146 StatEvent(int _flags, Tick _when, Tick _repeat); 147 virtual void process(); 148 virtual const char *description(); 149}; 150 151StatEvent::StatEvent(int _flags, Tick _when, Tick _repeat) 152 : Event(&mainEventQueue, Stat_Event_Pri), 153 flags(_flags), repeat(_repeat) 154{ 155 setFlags(AutoDelete); 156 schedule(_when); 157} 158 159const char * 160StatEvent::description() 161{ 162 return "Statistics dump and/or reset"; 163} 164 165void 166StatEvent::process() 167{ 168 if (flags & Statistics::Dump) 169 DumpNow(); 170 171 if (flags & Statistics::Reset) 172 reset(); 173 174 if (repeat) 175 schedule(curTick + repeat); 176} 177 178list<Output *> OutputList; 179 180void 181DumpNow() 182{ 183 list<Output *>::iterator i = OutputList.begin(); 184 list<Output *>::iterator end = OutputList.end(); 185 for (; i != end; ++i) { 186 Output *output = *i; 187 if (!output->valid()) 188 continue; 189 190 output->output(); 191 } 192} 193 194void 195SetupEvent(int flags, Tick when, Tick repeat) 196{ 197 new StatEvent(flags, when, repeat); 198} 199 200/* namespace Statistics */ } 201 202extern "C" void 203debugDumpStats() 204{ 205 Statistics::DumpNow(); 206} 207 208