stat_control.cc revision 695
14762Snate@binkert.org/* 24762Snate@binkert.org * Copyright (c) 2003 The Regents of The University of Michigan 34762Snate@binkert.org * All rights reserved. 44762Snate@binkert.org * 54762Snate@binkert.org * Redistribution and use in source and binary forms, with or without 64762Snate@binkert.org * modification, are permitted provided that the following conditions are 74762Snate@binkert.org * met: redistributions of source code must retain the above copyright 84762Snate@binkert.org * notice, this list of conditions and the following disclaimer; 94762Snate@binkert.org * redistributions in binary form must reproduce the above copyright 104762Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 114762Snate@binkert.org * documentation and/or other materials provided with the distribution; 124762Snate@binkert.org * neither the name of the copyright holders nor the names of its 134762Snate@binkert.org * contributors may be used to endorse or promote products derived from 144762Snate@binkert.org * this software without specific prior written permission. 154762Snate@binkert.org * 164762Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 174762Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 184762Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 194762Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 204762Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 214762Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 224762Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 234762Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 244762Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 254762Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 264762Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 274762Snate@binkert.org */ 284762Snate@binkert.org 294762Snate@binkert.org// This file will contain default statistics for the simulator that 304762Snate@binkert.org// don't really belong to a specific simulator object 314762Snate@binkert.org 324762Snate@binkert.org#include <fstream> 334762Snate@binkert.org#include <iostream> 344762Snate@binkert.org#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