stat_control.cc revision 8834
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" 427768SAli.Saidi@ARM.com#include "config/the_isa.hh" 437768SAli.Saidi@ARM.com#if THE_ISA == NO_ISA 447768SAli.Saidi@ARM.com#include "arch/noisa/cpu_dummy.hh" 457768SAli.Saidi@ARM.com#else 461717SN/A#include "cpu/base.hh" 477768SAli.Saidi@ARM.com#endif 487768SAli.Saidi@ARM.com 49695SN/A#include "sim/eventq.hh" 507822Ssteve.reinhardt@amd.com#include "sim/stat_control.hh" 51695SN/A 52695SN/Ausing namespace std; 53695SN/A 54729SN/AStats::Formula simSeconds; 557068Snate@binkert.orgStats::Value simTicks; 568720SAli.Saidi@ARM.comStats::Value finalTick; 577068Snate@binkert.orgStats::Value simFreq; 58695SN/A 59729SN/Anamespace Stats { 60695SN/A 61695SN/ATime statTime(true); 62695SN/ATick startTick; 63695SN/A 644078Sbinkertn@umich.edustruct SimTicksReset : public Callback 65695SN/A{ 66695SN/A void process() 67695SN/A { 687840Snate@binkert.org statTime.setTimer(); 697823Ssteve.reinhardt@amd.com startTick = curTick(); 70695SN/A } 71695SN/A}; 72695SN/A 73695SN/Adouble 74695SN/AstatElapsedTime() 75695SN/A{ 767840Snate@binkert.org Time now; 777840Snate@binkert.org now.setTimer(); 787840Snate@binkert.org 79695SN/A Time elapsed = now - statTime; 807840Snate@binkert.org return elapsed; 81695SN/A} 82695SN/A 831020SN/ATick 841020SN/AstatElapsedTicks() 851020SN/A{ 867823Ssteve.reinhardt@amd.com return curTick() - startTick; 871020SN/A} 881020SN/A 898720SAli.Saidi@ARM.comTick 908720SAli.Saidi@ARM.comstatFinalTick() 918720SAli.Saidi@ARM.com{ 928720SAli.Saidi@ARM.com return curTick(); 938720SAli.Saidi@ARM.com} 948720SAli.Saidi@ARM.com 95695SN/ASimTicksReset simTicksReset; 96695SN/A 975883Snate@binkert.orgstruct Global 985883Snate@binkert.org{ 995883Snate@binkert.org Stats::Formula hostInstRate; 1008834Satgutier@umich.edu Stats::Formula hostOpRate; 1015883Snate@binkert.org Stats::Formula hostTickRate; 1025883Snate@binkert.org Stats::Value hostMemory; 1035883Snate@binkert.org Stats::Value hostSeconds; 1045883Snate@binkert.org 1055883Snate@binkert.org Stats::Value simInsts; 1068834Satgutier@umich.edu Stats::Value simOps; 1075883Snate@binkert.org 1085883Snate@binkert.org Global(); 1095883Snate@binkert.org}; 1105883Snate@binkert.org 1115883Snate@binkert.orgGlobal::Global() 112695SN/A{ 113695SN/A simInsts 1148834Satgutier@umich.edu .functor(BaseCPU::numSimulatedInsts) 115695SN/A .name("sim_insts") 116695SN/A .desc("Number of instructions simulated") 117695SN/A .precision(0) 118695SN/A .prereq(simInsts) 119695SN/A ; 120695SN/A 1218834Satgutier@umich.edu simOps 1228834Satgutier@umich.edu .functor(BaseCPU::numSimulatedOps) 1238834Satgutier@umich.edu .name("sim_ops") 1248834Satgutier@umich.edu .desc("Number of ops (including micro ops) simulated") 1258834Satgutier@umich.edu .precision(0) 1268834Satgutier@umich.edu .prereq(simOps) 1278834Satgutier@umich.edu ; 1288834Satgutier@umich.edu 129695SN/A simSeconds 130695SN/A .name("sim_seconds") 131695SN/A .desc("Number of seconds simulated") 132695SN/A ; 133695SN/A 134707SN/A simFreq 1357064Snate@binkert.org .scalar(SimClock::Frequency) 136707SN/A .name("sim_freq") 137707SN/A .desc("Frequency of simulated ticks") 138707SN/A ; 139707SN/A 140695SN/A simTicks 1411020SN/A .functor(statElapsedTicks) 142695SN/A .name("sim_ticks") 143695SN/A .desc("Number of ticks simulated") 144695SN/A ; 145695SN/A 1468720SAli.Saidi@ARM.com finalTick 1478720SAli.Saidi@ARM.com .functor(statFinalTick) 1488720SAli.Saidi@ARM.com .name("final_tick") 1498720SAli.Saidi@ARM.com .desc("Number of ticks from beginning of simulation \ 1508720SAli.Saidi@ARM.com(restored from checkpoints and never reset)") 1518720SAli.Saidi@ARM.com ; 1528720SAli.Saidi@ARM.com 153695SN/A hostInstRate 154695SN/A .name("host_inst_rate") 155695SN/A .desc("Simulator instruction rate (inst/s)") 156695SN/A .precision(0) 157695SN/A .prereq(simInsts) 158695SN/A ; 159695SN/A 1608834Satgutier@umich.edu hostOpRate 1618834Satgutier@umich.edu .name("host_op_rate") 1628834Satgutier@umich.edu .desc("Simulator op (including micro ops) rate (op/s)") 1638834Satgutier@umich.edu .precision(0) 1648834Satgutier@umich.edu .prereq(simOps) 1658834Satgutier@umich.edu ; 1668834Satgutier@umich.edu 167695SN/A hostMemory 168707SN/A .functor(memUsage) 169695SN/A .name("host_mem_usage") 170695SN/A .desc("Number of bytes of host memory used") 171695SN/A .prereq(hostMemory) 172695SN/A ; 173695SN/A 174695SN/A hostSeconds 175707SN/A .functor(statElapsedTime) 176695SN/A .name("host_seconds") 177695SN/A .desc("Real time elapsed on the host") 178695SN/A .precision(2) 179695SN/A ; 180695SN/A 181695SN/A hostTickRate 182695SN/A .name("host_tick_rate") 183695SN/A .desc("Simulator tick rate (ticks/s)") 184695SN/A .precision(0) 185695SN/A ; 186695SN/A 187707SN/A simSeconds = simTicks / simFreq; 188695SN/A hostInstRate = simInsts / hostSeconds; 1898834Satgutier@umich.edu hostOpRate = simOps / hostSeconds; 190695SN/A hostTickRate = simTicks / hostSeconds; 191695SN/A 192695SN/A registerResetCallback(&simTicksReset); 193695SN/A} 194695SN/A 1955883Snate@binkert.orgvoid 1965883Snate@binkert.orginitSimStats() 1975883Snate@binkert.org{ 1985883Snate@binkert.org static Global global; 1995883Snate@binkert.org} 2005883Snate@binkert.org 2017822Ssteve.reinhardt@amd.comclass StatEvent : public Event 202695SN/A{ 2034078Sbinkertn@umich.edu private: 2044078Sbinkertn@umich.edu bool dump; 2054078Sbinkertn@umich.edu bool reset; 206695SN/A Tick repeat; 207695SN/A 208695SN/A public: 2097822Ssteve.reinhardt@amd.com StatEvent(bool _dump, bool _reset, Tick _repeat) 2108581Ssteve.reinhardt@amd.com : Event(Stat_Event_Pri, AutoDelete), 2118581Ssteve.reinhardt@amd.com dump(_dump), reset(_reset), repeat(_repeat) 2124078Sbinkertn@umich.edu { 2134078Sbinkertn@umich.edu } 2144078Sbinkertn@umich.edu 2154078Sbinkertn@umich.edu virtual void 2164078Sbinkertn@umich.edu process() 2174078Sbinkertn@umich.edu { 2184078Sbinkertn@umich.edu if (dump) 2194078Sbinkertn@umich.edu Stats::dump(); 2204078Sbinkertn@umich.edu 2214078Sbinkertn@umich.edu if (reset) 2224078Sbinkertn@umich.edu Stats::reset(); 2234078Sbinkertn@umich.edu 2245606Snate@binkert.org if (repeat) { 2257823Ssteve.reinhardt@amd.com Stats::schedStatEvent(dump, reset, curTick() + repeat, repeat); 2265606Snate@binkert.org } 2274078Sbinkertn@umich.edu } 228695SN/A}; 229695SN/A 2304078Sbinkertn@umich.eduvoid 2317822Ssteve.reinhardt@amd.comschedStatEvent(bool dump, bool reset, Tick when, Tick repeat) 232695SN/A{ 2337822Ssteve.reinhardt@amd.com Event *event = new StatEvent(dump, reset, repeat); 2345606Snate@binkert.org mainEventQueue.schedule(event, when); 235695SN/A} 236695SN/A 2377811Ssteve.reinhardt@amd.com} // namespace Stats 238