stat_control.cc revision 707
11689SN/A/* 210785Sgope@wisc.edu * Copyright (c) 2003 The Regents of The University of Michigan 39480Snilay@cs.wisc.edu * All rights reserved. 49480Snilay@cs.wisc.edu * 510785Sgope@wisc.edu * Redistribution and use in source and binary forms, with or without 610785Sgope@wisc.edu * modification, are permitted provided that the following conditions are 710785Sgope@wisc.edu * met: redistributions of source code must retain the above copyright 810785Sgope@wisc.edu * notice, this list of conditions and the following disclaimer; 910785Sgope@wisc.edu * redistributions in binary form must reproduce the above copyright 1010785Sgope@wisc.edu * notice, this list of conditions and the following disclaimer in the 1110785Sgope@wisc.edu * documentation and/or other materials provided with the distribution; 1210785Sgope@wisc.edu * neither the name of the copyright holders nor the names of its 1310785Sgope@wisc.edu * contributors may be used to endorse or promote products derived from 1410785Sgope@wisc.edu * this software without specific prior written permission. 1510785Sgope@wisc.edu * 1610785Sgope@wisc.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 271689SN/A */ 281689SN/A 291689SN/A// This file will contain default statistics for the simulator that 301689SN/A// don't really belong to a specific simulator object 311689SN/A 321689SN/A#include <fstream> 331689SN/A#include <iostream> 341689SN/A#include <list> 351689SN/A 361689SN/A#include "base/callback.hh" 371689SN/A#include "base/hostinfo.hh" 381689SN/A#include "base/statistics.hh" 391689SN/A#include "base/str.hh" 401689SN/A#include "base/time.hh" 412665SN/A#include "base/stats/output.hh" 422665SN/A#include "cpu/base_cpu.hh" 431689SN/A#include "sim/eventq.hh" 441061SN/A#include "sim/sim_object.hh" 4510785Sgope@wisc.edu#include "sim/stat_control.hh" 461061SN/A#include "sim/universe.hh" 4710785Sgope@wisc.edu 4810785Sgope@wisc.eduusing namespace std; 4910785Sgope@wisc.edu 5010785Sgope@wisc.eduStatistics::Formula hostInstRate; 5110785Sgope@wisc.eduStatistics::Formula hostTickRate; 5210785Sgope@wisc.eduStatistics::Value hostMemory; 5310785Sgope@wisc.eduStatistics::Value hostSeconds; 5410785Sgope@wisc.edu 5510785Sgope@wisc.eduStatistics::Value simTicks; 5610785Sgope@wisc.eduStatistics::Value simInsts; 5710785Sgope@wisc.eduStatistics::Value simFreq; 5810785Sgope@wisc.eduStatistics::Formula simSeconds; 5910785Sgope@wisc.edu 6010785Sgope@wisc.edunamespace Statistics { 6110785Sgope@wisc.edu 6211432Smitch.hayenga@arm.comTime statTime(true); 6311432Smitch.hayenga@arm.comTick startTick; 6410785Sgope@wisc.edu 6510785Sgope@wisc.educlass SimTicksReset : public Callback 669480Snilay@cs.wisc.edu{ 6710785Sgope@wisc.edu public: 6810785Sgope@wisc.edu void process() 6910785Sgope@wisc.edu { 7010785Sgope@wisc.edu statTime.set(); 7110785Sgope@wisc.edu startTick = curTick; 7210785Sgope@wisc.edu } 7310785Sgope@wisc.edu}; 7410785Sgope@wisc.edu 7510785Sgope@wisc.edudouble 7610785Sgope@wisc.edustatElapsedTime() 7710785Sgope@wisc.edu{ 7810785Sgope@wisc.edu Time now(true); 7910785Sgope@wisc.edu Time elapsed = now - statTime; 8010785Sgope@wisc.edu return elapsed(); 8110785Sgope@wisc.edu} 8210785Sgope@wisc.edu 8310785Sgope@wisc.eduSimTicksReset simTicksReset; 8410785Sgope@wisc.edu 8510785Sgope@wisc.eduvoid 8610785Sgope@wisc.eduInitSimStats() 8710785Sgope@wisc.edu{ 8810785Sgope@wisc.edu simInsts 8910785Sgope@wisc.edu .functor(BaseCPU::numSimulatedInstructions) 9010785Sgope@wisc.edu .name("sim_insts") 9110785Sgope@wisc.edu .desc("Number of instructions simulated") 9210785Sgope@wisc.edu .precision(0) 9310785Sgope@wisc.edu .prereq(simInsts) 9410785Sgope@wisc.edu ; 9510785Sgope@wisc.edu 9610785Sgope@wisc.edu simSeconds 9710785Sgope@wisc.edu .name("sim_seconds") 9810785Sgope@wisc.edu .desc("Number of seconds simulated") 9910785Sgope@wisc.edu ; 10010785Sgope@wisc.edu 10110785Sgope@wisc.edu simFreq 10210785Sgope@wisc.edu .scalar(ticksPerSecond) 10310785Sgope@wisc.edu .name("sim_freq") 10410785Sgope@wisc.edu .desc("Frequency of simulated ticks") 10510785Sgope@wisc.edu ; 10610785Sgope@wisc.edu 10710785Sgope@wisc.edu simTicks 10810785Sgope@wisc.edu .scalar(curTick) 10910785Sgope@wisc.edu .name("sim_ticks") 11010785Sgope@wisc.edu .desc("Number of ticks simulated") 11110785Sgope@wisc.edu ; 11210785Sgope@wisc.edu 11310785Sgope@wisc.edu hostInstRate 11410785Sgope@wisc.edu .name("host_inst_rate") 11510785Sgope@wisc.edu .desc("Simulator instruction rate (inst/s)") 11610785Sgope@wisc.edu .precision(0) 11710785Sgope@wisc.edu .prereq(simInsts) 11810785Sgope@wisc.edu ; 11910785Sgope@wisc.edu 12010785Sgope@wisc.edu hostMemory 12110785Sgope@wisc.edu .functor(memUsage) 12210785Sgope@wisc.edu .name("host_mem_usage") 12310785Sgope@wisc.edu .desc("Number of bytes of host memory used") 12410785Sgope@wisc.edu .prereq(hostMemory) 12510785Sgope@wisc.edu ; 12610785Sgope@wisc.edu 12710785Sgope@wisc.edu hostSeconds 12810785Sgope@wisc.edu .functor(statElapsedTime) 12910785Sgope@wisc.edu .name("host_seconds") 13010785Sgope@wisc.edu .desc("Real time elapsed on the host") 13110785Sgope@wisc.edu .precision(2) 13210785Sgope@wisc.edu ; 13310785Sgope@wisc.edu 13410785Sgope@wisc.edu hostTickRate 13510785Sgope@wisc.edu .name("host_tick_rate") 13610785Sgope@wisc.edu .desc("Simulator tick rate (ticks/s)") 13710785Sgope@wisc.edu .precision(0) 13810785Sgope@wisc.edu ; 13910785Sgope@wisc.edu 14010785Sgope@wisc.edu simSeconds = simTicks / simFreq; 14110785Sgope@wisc.edu hostInstRate = simInsts / hostSeconds; 14210785Sgope@wisc.edu hostTickRate = simTicks / hostSeconds; 14310785Sgope@wisc.edu 14410785Sgope@wisc.edu registerResetCallback(&simTicksReset); 14510785Sgope@wisc.edu} 14610785Sgope@wisc.edu 14710785Sgope@wisc.educlass StatEvent : public Event 14810785Sgope@wisc.edu{ 14910785Sgope@wisc.edu protected: 15010785Sgope@wisc.edu int flags; 15110785Sgope@wisc.edu Tick repeat; 15210785Sgope@wisc.edu 15310785Sgope@wisc.edu public: 15410785Sgope@wisc.edu StatEvent(int _flags, Tick _when, Tick _repeat); 15510785Sgope@wisc.edu virtual void process(); 15610785Sgope@wisc.edu virtual const char *description(); 15710785Sgope@wisc.edu}; 15810785Sgope@wisc.edu 15910785Sgope@wisc.eduStatEvent::StatEvent(int _flags, Tick _when, Tick _repeat) 16010785Sgope@wisc.edu : Event(&mainEventQueue, Stat_Event_Pri), 16110785Sgope@wisc.edu flags(_flags), repeat(_repeat) 16210785Sgope@wisc.edu{ 16310785Sgope@wisc.edu setFlags(AutoDelete); 16410785Sgope@wisc.edu schedule(_when); 16510785Sgope@wisc.edu} 16610785Sgope@wisc.edu 16710785Sgope@wisc.educonst char * 16811429Sandreas.sandberg@arm.comStatEvent::description() 1699480Snilay@cs.wisc.edu{ 17010785Sgope@wisc.edu return "Statistics dump and/or reset"; 17111429Sandreas.sandberg@arm.com} 17210785Sgope@wisc.edu 17310785Sgope@wisc.eduvoid 17410785Sgope@wisc.eduStatEvent::process() 17510785Sgope@wisc.edu{ 17610785Sgope@wisc.edu if (flags & Statistics::Dump) 17710785Sgope@wisc.edu DumpNow(); 17810785Sgope@wisc.edu 17910785Sgope@wisc.edu if (flags & Statistics::Reset) 18010785Sgope@wisc.edu reset(); 18110785Sgope@wisc.edu 18210785Sgope@wisc.edu if (repeat) 18310785Sgope@wisc.edu schedule(curTick + repeat); 18410785Sgope@wisc.edu} 18510785Sgope@wisc.edu 18610785Sgope@wisc.edulist<Output *> OutputList; 18710785Sgope@wisc.edu 18810785Sgope@wisc.eduvoid 18910785Sgope@wisc.eduDumpNow() 19010785Sgope@wisc.edu{ 19110785Sgope@wisc.edu list<Output *>::iterator i = OutputList.begin(); 19210785Sgope@wisc.edu list<Output *>::iterator end = OutputList.end(); 19310785Sgope@wisc.edu for (; i != end; ++i) { 19410785Sgope@wisc.edu Output *output = *i; 19510785Sgope@wisc.edu if (!output->valid()) 19610785Sgope@wisc.edu continue; 19710785Sgope@wisc.edu 19810785Sgope@wisc.edu output->output(); 19910785Sgope@wisc.edu } 20010785Sgope@wisc.edu} 20110785Sgope@wisc.edu 20210785Sgope@wisc.eduvoid 20310785Sgope@wisc.eduSetupEvent(int flags, Tick when, Tick repeat) 20410785Sgope@wisc.edu{ 20510785Sgope@wisc.edu new StatEvent(flags, when, repeat); 20610785Sgope@wisc.edu} 20710785Sgope@wisc.edu 20810785Sgope@wisc.edu/* namespace Statistics */ } 20910785Sgope@wisc.edu 21010785Sgope@wisc.eduextern "C" void 21110785Sgope@wisc.edudebugDumpStats() 21210785Sgope@wisc.edu{ 21310785Sgope@wisc.edu Statistics::DumpNow(); 21410785Sgope@wisc.edu} 21510785Sgope@wisc.edu 21610785Sgope@wisc.edu