stat_control.cc revision 7840
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; 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 * Authors: Nathan Binkert 29 */ 30 31// This file will contain default statistics for the simulator that 32// don't really belong to a specific simulator object 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/time.hh" 42 43#include "config/the_isa.hh" 44#if THE_ISA == NO_ISA 45#include "arch/noisa/cpu_dummy.hh" 46#else 47#include "cpu/base.hh" 48#endif 49 50#include "sim/eventq.hh" 51#include "sim/stat_control.hh" 52 53using namespace std; 54 55Stats::Formula simSeconds; 56Stats::Value simTicks; 57Stats::Value simFreq; 58 59namespace Stats { 60 61Time statTime(true); 62Tick startTick; 63 64struct SimTicksReset : public Callback 65{ 66 void process() 67 { 68 statTime.setTimer(); 69 startTick = curTick(); 70 } 71}; 72 73double 74statElapsedTime() 75{ 76 Time now; 77 now.setTimer(); 78 79 Time elapsed = now - statTime; 80 return elapsed; 81} 82 83Tick 84statElapsedTicks() 85{ 86 return curTick() - startTick; 87} 88 89SimTicksReset simTicksReset; 90 91struct Global 92{ 93 Stats::Formula hostInstRate; 94 Stats::Formula hostTickRate; 95 Stats::Value hostMemory; 96 Stats::Value hostSeconds; 97 98 Stats::Value simInsts; 99 100 Global(); 101}; 102 103Global::Global() 104{ 105 simInsts 106 .functor(BaseCPU::numSimulatedInstructions) 107 .name("sim_insts") 108 .desc("Number of instructions simulated") 109 .precision(0) 110 .prereq(simInsts) 111 ; 112 113 simSeconds 114 .name("sim_seconds") 115 .desc("Number of seconds simulated") 116 ; 117 118 simFreq 119 .scalar(SimClock::Frequency) 120 .name("sim_freq") 121 .desc("Frequency of simulated ticks") 122 ; 123 124 simTicks 125 .functor(statElapsedTicks) 126 .name("sim_ticks") 127 .desc("Number of ticks simulated") 128 ; 129 130 hostInstRate 131 .name("host_inst_rate") 132 .desc("Simulator instruction rate (inst/s)") 133 .precision(0) 134 .prereq(simInsts) 135 ; 136 137 hostMemory 138 .functor(memUsage) 139 .name("host_mem_usage") 140 .desc("Number of bytes of host memory used") 141 .prereq(hostMemory) 142 ; 143 144 hostSeconds 145 .functor(statElapsedTime) 146 .name("host_seconds") 147 .desc("Real time elapsed on the host") 148 .precision(2) 149 ; 150 151 hostTickRate 152 .name("host_tick_rate") 153 .desc("Simulator tick rate (ticks/s)") 154 .precision(0) 155 ; 156 157 simSeconds = simTicks / simFreq; 158 hostInstRate = simInsts / hostSeconds; 159 hostTickRate = simTicks / hostSeconds; 160 161 registerResetCallback(&simTicksReset); 162} 163 164void 165initSimStats() 166{ 167 static Global global; 168} 169 170class StatEvent : public Event 171{ 172 private: 173 bool dump; 174 bool reset; 175 Tick repeat; 176 177 public: 178 StatEvent(bool _dump, bool _reset, Tick _repeat) 179 : Event(Stat_Event_Pri), dump(_dump), reset(_reset), repeat(_repeat) 180 { 181 setFlags(AutoDelete); 182 } 183 184 virtual void 185 process() 186 { 187 if (dump) 188 Stats::dump(); 189 190 if (reset) 191 Stats::reset(); 192 193 if (repeat) { 194 Stats::schedStatEvent(dump, reset, curTick() + repeat, repeat); 195 } 196 } 197}; 198 199void 200schedStatEvent(bool dump, bool reset, Tick when, Tick repeat) 201{ 202 Event *event = new StatEvent(dump, reset, repeat); 203 mainEventQueue.schedule(event, when); 204} 205 206} // namespace Stats 207