stat_control.cc revision 7823
111731Sjason@lowepower.com/* 211731Sjason@lowepower.com * Copyright (c) 2004-2005 The Regents of The University of Michigan 311731Sjason@lowepower.com * All rights reserved. 411731Sjason@lowepower.com * 511731Sjason@lowepower.com * Redistribution and use in source and binary forms, with or without 611731Sjason@lowepower.com * modification, are permitted provided that the following conditions are 711731Sjason@lowepower.com * met: redistributions of source code must retain the above copyright 811731Sjason@lowepower.com * notice, this list of conditions and the following disclaimer; 911731Sjason@lowepower.com * redistributions in binary form must reproduce the above copyright 1011731Sjason@lowepower.com * notice, this list of conditions and the following disclaimer in the 1111731Sjason@lowepower.com * documentation and/or other materials provided with the distribution; 1211731Sjason@lowepower.com * neither the name of the copyright holders nor the names of its 1311731Sjason@lowepower.com * contributors may be used to endorse or promote products derived from 1411731Sjason@lowepower.com * this software without specific prior written permission. 1511731Sjason@lowepower.com * 1611731Sjason@lowepower.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1711731Sjason@lowepower.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1811731Sjason@lowepower.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1911731Sjason@lowepower.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2011731Sjason@lowepower.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2111731Sjason@lowepower.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2211731Sjason@lowepower.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2311731Sjason@lowepower.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2411731Sjason@lowepower.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2511731Sjason@lowepower.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2611731Sjason@lowepower.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2711731Sjason@lowepower.com * 2811731Sjason@lowepower.com * Authors: Nathan Binkert 2911731Sjason@lowepower.com */ 3011731Sjason@lowepower.com 3111731Sjason@lowepower.com// This file will contain default statistics for the simulator that 3211731Sjason@lowepower.com// don't really belong to a specific simulator object 3311731Sjason@lowepower.com 3411731Sjason@lowepower.com#include <fstream> 3511731Sjason@lowepower.com#include <iostream> 3611731Sjason@lowepower.com#include <list> 3711731Sjason@lowepower.com 3811731Sjason@lowepower.com#include "base/callback.hh" 3911731Sjason@lowepower.com#include "base/hostinfo.hh" 4011731Sjason@lowepower.com#include "base/statistics.hh" 4111731Sjason@lowepower.com#include "base/time.hh" 4211731Sjason@lowepower.com 4311731Sjason@lowepower.com#include "config/the_isa.hh" 4411731Sjason@lowepower.com#if THE_ISA == NO_ISA 4511731Sjason@lowepower.com#include "arch/noisa/cpu_dummy.hh" 4611731Sjason@lowepower.com#else 4711731Sjason@lowepower.com#include "cpu/base.hh" 4811731Sjason@lowepower.com#endif 4911731Sjason@lowepower.com 5011731Sjason@lowepower.com#include "sim/eventq.hh" 5111731Sjason@lowepower.com#include "sim/stat_control.hh" 5211731Sjason@lowepower.com 5311731Sjason@lowepower.comusing namespace std; 5411731Sjason@lowepower.com 5511731Sjason@lowepower.comStats::Formula simSeconds; 5611731Sjason@lowepower.comStats::Value simTicks; 5711731Sjason@lowepower.comStats::Value simFreq; 5811731Sjason@lowepower.com 5911731Sjason@lowepower.comnamespace Stats { 6011731Sjason@lowepower.com 6111731Sjason@lowepower.comTime statTime(true); 6211731Sjason@lowepower.comTick startTick; 6311731Sjason@lowepower.com 6411731Sjason@lowepower.comstruct SimTicksReset : public Callback 6511731Sjason@lowepower.com{ 6611731Sjason@lowepower.com void process() 6711731Sjason@lowepower.com { 6811731Sjason@lowepower.com statTime.set(); 6911731Sjason@lowepower.com startTick = curTick(); 7011731Sjason@lowepower.com } 7111731Sjason@lowepower.com}; 7211731Sjason@lowepower.com 7311731Sjason@lowepower.comdouble 7411731Sjason@lowepower.comstatElapsedTime() 7511731Sjason@lowepower.com{ 7611731Sjason@lowepower.com Time now(true); 7711731Sjason@lowepower.com Time elapsed = now - statTime; 7811731Sjason@lowepower.com return elapsed(); 7911731Sjason@lowepower.com} 8011731Sjason@lowepower.com 8111731Sjason@lowepower.comTick 8211731Sjason@lowepower.comstatElapsedTicks() 8311731Sjason@lowepower.com{ 8411731Sjason@lowepower.com return curTick() - startTick; 8511731Sjason@lowepower.com} 8611731Sjason@lowepower.com 8711731Sjason@lowepower.comSimTicksReset simTicksReset; 8812137Sar4jc@virginia.edu 8911731Sjason@lowepower.comstruct Global 9011731Sjason@lowepower.com{ 9112137Sar4jc@virginia.edu Stats::Formula hostInstRate; 9211731Sjason@lowepower.com Stats::Formula hostTickRate; 9311731Sjason@lowepower.com Stats::Value hostMemory; 9411731Sjason@lowepower.com Stats::Value hostSeconds; 9511731Sjason@lowepower.com 9611731Sjason@lowepower.com Stats::Value simInsts; 9711731Sjason@lowepower.com 9811731Sjason@lowepower.com Global(); 9911731Sjason@lowepower.com}; 10011731Sjason@lowepower.com 10111731Sjason@lowepower.comGlobal::Global() 10211731Sjason@lowepower.com{ 10311731Sjason@lowepower.com simInsts 10411731Sjason@lowepower.com .functor(BaseCPU::numSimulatedInstructions) 10511731Sjason@lowepower.com .name("sim_insts") 10611731Sjason@lowepower.com .desc("Number of instructions simulated") 10711731Sjason@lowepower.com .precision(0) 10811731Sjason@lowepower.com .prereq(simInsts) 10911731Sjason@lowepower.com ; 11011731Sjason@lowepower.com 11111731Sjason@lowepower.com simSeconds 11211731Sjason@lowepower.com .name("sim_seconds") 11311731Sjason@lowepower.com .desc("Number of seconds simulated") 11411731Sjason@lowepower.com ; 11511731Sjason@lowepower.com 11611731Sjason@lowepower.com simFreq 11711731Sjason@lowepower.com .scalar(SimClock::Frequency) 11811731Sjason@lowepower.com .name("sim_freq") 11911731Sjason@lowepower.com .desc("Frequency of simulated ticks") 12011731Sjason@lowepower.com ; 12111731Sjason@lowepower.com 12211731Sjason@lowepower.com simTicks 12311731Sjason@lowepower.com .functor(statElapsedTicks) 12411731Sjason@lowepower.com .name("sim_ticks") 12511731Sjason@lowepower.com .desc("Number of ticks simulated") 12611731Sjason@lowepower.com ; 12712137Sar4jc@virginia.edu 12811731Sjason@lowepower.com hostInstRate 12911731Sjason@lowepower.com .name("host_inst_rate") 13011731Sjason@lowepower.com .desc("Simulator instruction rate (inst/s)") 13111731Sjason@lowepower.com .precision(0) 13211731Sjason@lowepower.com .prereq(simInsts) 13311731Sjason@lowepower.com ; 13411731Sjason@lowepower.com 13511731Sjason@lowepower.com hostMemory 13612137Sar4jc@virginia.edu .functor(memUsage) 13711731Sjason@lowepower.com .name("host_mem_usage") 13811731Sjason@lowepower.com .desc("Number of bytes of host memory used") 13911731Sjason@lowepower.com .prereq(hostMemory) 14012137Sar4jc@virginia.edu ; 14111731Sjason@lowepower.com 14212137Sar4jc@virginia.edu hostSeconds 14311731Sjason@lowepower.com .functor(statElapsedTime) 14412137Sar4jc@virginia.edu .name("host_seconds") 14511731Sjason@lowepower.com .desc("Real time elapsed on the host") 14611731Sjason@lowepower.com .precision(2) 14711731Sjason@lowepower.com ; 14811731Sjason@lowepower.com 14911731Sjason@lowepower.com hostTickRate 15011731Sjason@lowepower.com .name("host_tick_rate") 15111731Sjason@lowepower.com .desc("Simulator tick rate (ticks/s)") 15211731Sjason@lowepower.com .precision(0) 15311731Sjason@lowepower.com ; 15411731Sjason@lowepower.com 15511731Sjason@lowepower.com simSeconds = simTicks / simFreq; 15611731Sjason@lowepower.com hostInstRate = simInsts / hostSeconds; 15711731Sjason@lowepower.com hostTickRate = simTicks / hostSeconds; 15811731Sjason@lowepower.com 15911731Sjason@lowepower.com registerResetCallback(&simTicksReset); 16011731Sjason@lowepower.com} 16111731Sjason@lowepower.com 16211731Sjason@lowepower.comvoid 16311731Sjason@lowepower.cominitSimStats() 16411731Sjason@lowepower.com{ 16511731Sjason@lowepower.com static Global global; 16611731Sjason@lowepower.com} 16711731Sjason@lowepower.com 16811731Sjason@lowepower.comclass StatEvent : public Event 16911731Sjason@lowepower.com{ 17011731Sjason@lowepower.com private: 17111731Sjason@lowepower.com bool dump; 17211731Sjason@lowepower.com bool reset; 17311731Sjason@lowepower.com Tick repeat; 17411731Sjason@lowepower.com 17511731Sjason@lowepower.com public: 17611731Sjason@lowepower.com StatEvent(bool _dump, bool _reset, Tick _repeat) 17711731Sjason@lowepower.com : Event(Stat_Event_Pri), dump(_dump), reset(_reset), repeat(_repeat) 17811731Sjason@lowepower.com { 17911731Sjason@lowepower.com setFlags(AutoDelete); 18011731Sjason@lowepower.com } 18111731Sjason@lowepower.com 18211731Sjason@lowepower.com virtual void 18311731Sjason@lowepower.com process() 18411731Sjason@lowepower.com { 18511731Sjason@lowepower.com if (dump) 18611731Sjason@lowepower.com Stats::dump(); 18711731Sjason@lowepower.com 18811731Sjason@lowepower.com if (reset) 18911731Sjason@lowepower.com Stats::reset(); 19011731Sjason@lowepower.com 19111731Sjason@lowepower.com if (repeat) { 19211731Sjason@lowepower.com Stats::schedStatEvent(dump, reset, curTick() + repeat, repeat); 19311731Sjason@lowepower.com } 19411731Sjason@lowepower.com } 19511731Sjason@lowepower.com}; 19611731Sjason@lowepower.com 19711731Sjason@lowepower.comvoid 19811731Sjason@lowepower.comschedStatEvent(bool dump, bool reset, Tick when, Tick repeat) 19911731Sjason@lowepower.com{ 20011731Sjason@lowepower.com Event *event = new StatEvent(dump, reset, repeat); 20111731Sjason@lowepower.com mainEventQueue.schedule(event, when); 20211731Sjason@lowepower.com} 20311731Sjason@lowepower.com 20411731Sjason@lowepower.com} // namespace Stats 20511731Sjason@lowepower.com