stat_control.cc revision 7068:08c34d3fb19d
13549SN/A/* 23549SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan 33549SN/A * All rights reserved. 43549SN/A * 53549SN/A * Redistribution and use in source and binary forms, with or without 63549SN/A * modification, are permitted provided that the following conditions are 73549SN/A * met: redistributions of source code must retain the above copyright 83549SN/A * notice, this list of conditions and the following disclaimer; 93549SN/A * redistributions in binary form must reproduce the above copyright 103549SN/A * notice, this list of conditions and the following disclaimer in the 113549SN/A * documentation and/or other materials provided with the distribution; 123549SN/A * neither the name of the copyright holders nor the names of its 133549SN/A * contributors may be used to endorse or promote products derived from 143549SN/A * this software without specific prior written permission. 153549SN/A * 163549SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 173549SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 183549SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 193549SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 203549SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 213549SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 223549SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 233549SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 243549SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 253549SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 263549SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 273549SN/A * 283549SN/A * Authors: Nathan Binkert 293549SN/A */ 303549SN/A 313549SN/A// This file will contain default statistics for the simulator that 323565Sgblack@eecs.umich.edu// don't really belong to a specific simulator object 3311793Sbrandon.potter@amd.com 343565Sgblack@eecs.umich.edu#include <fstream> 353549SN/A#include <iostream> 363549SN/A#include <list> 375567Snate@binkert.org 383549SN/A#include "base/callback.hh" 393549SN/A#include "base/hostinfo.hh" 403549SN/A#include "base/statistics.hh" 413549SN/A#include "base/time.hh" 425569Snate@binkert.org#include "cpu/base.hh" 4313614Sgabeblack@google.com#include "sim/eventq.hh" 445569Snate@binkert.org 455569Snate@binkert.orgusing namespace std; 463549SN/A 473549SN/AStats::Formula simSeconds; 48Stats::Value simTicks; 49Stats::Value simFreq; 50 51namespace Stats { 52 53Time statTime(true); 54Tick startTick; 55 56struct SimTicksReset : public Callback 57{ 58 void process() 59 { 60 statTime.set(); 61 startTick = curTick; 62 } 63}; 64 65double 66statElapsedTime() 67{ 68 Time now(true); 69 Time elapsed = now - statTime; 70 return elapsed(); 71} 72 73Tick 74statElapsedTicks() 75{ 76 return curTick - startTick; 77} 78 79SimTicksReset simTicksReset; 80 81struct Global 82{ 83 Stats::Formula hostInstRate; 84 Stats::Formula hostTickRate; 85 Stats::Value hostMemory; 86 Stats::Value hostSeconds; 87 88 Stats::Value simInsts; 89 90 Global(); 91}; 92 93Global::Global() 94{ 95 simInsts 96 .functor(BaseCPU::numSimulatedInstructions) 97 .name("sim_insts") 98 .desc("Number of instructions simulated") 99 .precision(0) 100 .prereq(simInsts) 101 ; 102 103 simSeconds 104 .name("sim_seconds") 105 .desc("Number of seconds simulated") 106 ; 107 108 simFreq 109 .scalar(SimClock::Frequency) 110 .name("sim_freq") 111 .desc("Frequency of simulated ticks") 112 ; 113 114 simTicks 115 .functor(statElapsedTicks) 116 .name("sim_ticks") 117 .desc("Number of ticks simulated") 118 ; 119 120 hostInstRate 121 .name("host_inst_rate") 122 .desc("Simulator instruction rate (inst/s)") 123 .precision(0) 124 .prereq(simInsts) 125 ; 126 127 hostMemory 128 .functor(memUsage) 129 .name("host_mem_usage") 130 .desc("Number of bytes of host memory used") 131 .prereq(hostMemory) 132 ; 133 134 hostSeconds 135 .functor(statElapsedTime) 136 .name("host_seconds") 137 .desc("Real time elapsed on the host") 138 .precision(2) 139 ; 140 141 hostTickRate 142 .name("host_tick_rate") 143 .desc("Simulator tick rate (ticks/s)") 144 .precision(0) 145 ; 146 147 simSeconds = simTicks / simFreq; 148 hostInstRate = simInsts / hostSeconds; 149 hostTickRate = simTicks / hostSeconds; 150 151 registerResetCallback(&simTicksReset); 152} 153 154void 155initSimStats() 156{ 157 static Global global; 158} 159 160class _StatEvent : public Event 161{ 162 private: 163 bool dump; 164 bool reset; 165 Tick repeat; 166 167 public: 168 _StatEvent(bool _dump, bool _reset, Tick _repeat) 169 : Event(Stat_Event_Pri), dump(_dump), reset(_reset), repeat(_repeat) 170 { 171 setFlags(AutoDelete); 172 } 173 174 virtual void 175 process() 176 { 177 if (dump) 178 Stats::dump(); 179 180 if (reset) 181 Stats::reset(); 182 183 if (repeat) { 184 Event *event = new _StatEvent(dump, reset, repeat); 185 mainEventQueue.schedule(event, curTick + repeat); 186 } 187 } 188}; 189 190void 191StatEvent(bool dump, bool reset, Tick when, Tick repeat) 192{ 193 Event *event = new _StatEvent(dump, reset, repeat); 194 mainEventQueue.schedule(event, when); 195} 196 197/* namespace Stats */ } 198