stat_control.cc revision 4078
1695SN/A/* 21762SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan 3695SN/A * All rights reserved. 4695SN/A * 5695SN/A * Redistribution and use in source and binary forms, with or without 6695SN/A * modification, are permitted provided that the following conditions are 7695SN/A * met: redistributions of source code must retain the above copyright 8695SN/A * notice, this list of conditions and the following disclaimer; 9695SN/A * redistributions in binary form must reproduce the above copyright 10695SN/A * notice, this list of conditions and the following disclaimer in the 11695SN/A * documentation and/or other materials provided with the distribution; 12695SN/A * neither the name of the copyright holders nor the names of its 13695SN/A * contributors may be used to endorse or promote products derived from 14695SN/A * this software without specific prior written permission. 15695SN/A * 16695SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17695SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18695SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19695SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20695SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21695SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22695SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23695SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24695SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25695SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26695SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert 29695SN/A */ 30695SN/A 31695SN/A// This file will contain default statistics for the simulator that 32695SN/A// don't really belong to a specific simulator object 33695SN/A 34695SN/A#include <fstream> 35695SN/A#include <iostream> 36695SN/A#include <list> 37695SN/A 38695SN/A#include "base/callback.hh" 39695SN/A#include "base/hostinfo.hh" 40695SN/A#include "base/statistics.hh" 41695SN/A#include "base/time.hh" 421717SN/A#include "cpu/base.hh" 43695SN/A#include "sim/eventq.hh" 44695SN/A 45695SN/Ausing namespace std; 46695SN/A 47729SN/AStats::Formula hostInstRate; 48729SN/AStats::Formula hostTickRate; 49729SN/AStats::Value hostMemory; 50729SN/AStats::Value hostSeconds; 51695SN/A 52729SN/AStats::Value simTicks; 53729SN/AStats::Value simInsts; 54729SN/AStats::Value simFreq; 55729SN/AStats::Formula simSeconds; 56695SN/A 57729SN/Anamespace Stats { 58695SN/A 59695SN/ATime statTime(true); 60695SN/ATick startTick; 61695SN/A 624078Sbinkertn@umich.edustruct SimTicksReset : public Callback 63695SN/A{ 64695SN/A void process() 65695SN/A { 66695SN/A statTime.set(); 67695SN/A startTick = curTick; 68695SN/A } 69695SN/A}; 70695SN/A 71695SN/Adouble 72695SN/AstatElapsedTime() 73695SN/A{ 74695SN/A Time now(true); 75695SN/A Time elapsed = now - statTime; 76695SN/A return elapsed(); 77695SN/A} 78695SN/A 791020SN/ATick 801020SN/AstatElapsedTicks() 811020SN/A{ 821020SN/A return curTick - startTick; 831020SN/A} 841020SN/A 85695SN/ASimTicksReset simTicksReset; 86695SN/A 87695SN/Avoid 884078Sbinkertn@umich.eduinitSimStats() 89695SN/A{ 90695SN/A simInsts 91707SN/A .functor(BaseCPU::numSimulatedInstructions) 92695SN/A .name("sim_insts") 93695SN/A .desc("Number of instructions simulated") 94695SN/A .precision(0) 95695SN/A .prereq(simInsts) 96695SN/A ; 97695SN/A 98695SN/A simSeconds 99695SN/A .name("sim_seconds") 100695SN/A .desc("Number of seconds simulated") 101695SN/A ; 102695SN/A 103707SN/A simFreq 1041609SN/A .scalar(Clock::Frequency) 105707SN/A .name("sim_freq") 106707SN/A .desc("Frequency of simulated ticks") 107707SN/A ; 108707SN/A 109695SN/A simTicks 1101020SN/A .functor(statElapsedTicks) 111695SN/A .name("sim_ticks") 112695SN/A .desc("Number of ticks simulated") 113695SN/A ; 114695SN/A 115695SN/A hostInstRate 116695SN/A .name("host_inst_rate") 117695SN/A .desc("Simulator instruction rate (inst/s)") 118695SN/A .precision(0) 119695SN/A .prereq(simInsts) 120695SN/A ; 121695SN/A 122695SN/A hostMemory 123707SN/A .functor(memUsage) 124695SN/A .name("host_mem_usage") 125695SN/A .desc("Number of bytes of host memory used") 126695SN/A .prereq(hostMemory) 127695SN/A ; 128695SN/A 129695SN/A hostSeconds 130707SN/A .functor(statElapsedTime) 131695SN/A .name("host_seconds") 132695SN/A .desc("Real time elapsed on the host") 133695SN/A .precision(2) 134695SN/A ; 135695SN/A 136695SN/A hostTickRate 137695SN/A .name("host_tick_rate") 138695SN/A .desc("Simulator tick rate (ticks/s)") 139695SN/A .precision(0) 140695SN/A ; 141695SN/A 142707SN/A simSeconds = simTicks / simFreq; 143695SN/A hostInstRate = simInsts / hostSeconds; 144695SN/A hostTickRate = simTicks / hostSeconds; 145695SN/A 146695SN/A registerResetCallback(&simTicksReset); 147695SN/A} 148695SN/A 1494078Sbinkertn@umich.educlass _StatEvent : public Event 150695SN/A{ 1514078Sbinkertn@umich.edu private: 1524078Sbinkertn@umich.edu bool dump; 1534078Sbinkertn@umich.edu bool reset; 154695SN/A Tick repeat; 155695SN/A 156695SN/A public: 1574078Sbinkertn@umich.edu _StatEvent(bool _dump, bool _reset, Tick _when, Tick _repeat) 1584078Sbinkertn@umich.edu : Event(&mainEventQueue, Stat_Event_Pri), dump(_dump), reset(_reset), 1594078Sbinkertn@umich.edu repeat(_repeat) 1604078Sbinkertn@umich.edu { 1614078Sbinkertn@umich.edu setFlags(AutoDelete); 1624078Sbinkertn@umich.edu schedule(_when); 1634078Sbinkertn@umich.edu } 1644078Sbinkertn@umich.edu 1654078Sbinkertn@umich.edu virtual void 1664078Sbinkertn@umich.edu process() 1674078Sbinkertn@umich.edu { 1684078Sbinkertn@umich.edu if (dump) 1694078Sbinkertn@umich.edu Stats::dump(); 1704078Sbinkertn@umich.edu 1714078Sbinkertn@umich.edu if (reset) 1724078Sbinkertn@umich.edu Stats::reset(); 1734078Sbinkertn@umich.edu 1744078Sbinkertn@umich.edu if (repeat) 1754078Sbinkertn@umich.edu new _StatEvent(dump, reset, curTick + repeat, repeat); 1764078Sbinkertn@umich.edu } 177695SN/A}; 178695SN/A 1794078Sbinkertn@umich.eduvoid 1804078Sbinkertn@umich.eduStatEvent(bool dump, bool reset, Tick when, Tick repeat) 181695SN/A{ 1824078Sbinkertn@umich.edu new _StatEvent(dump, reset, when, repeat); 183695SN/A} 184695SN/A 185729SN/A/* namespace Stats */ } 186