stat_control.cc revision 5883
1955SN/A/*
2955SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan
31762SN/A * All rights reserved.
4955SN/A *
5955SN/A * Redistribution and use in source and binary forms, with or without
6955SN/A * modification, are permitted provided that the following conditions are
7955SN/A * met: redistributions of source code must retain the above copyright
8955SN/A * notice, this list of conditions and the following disclaimer;
9955SN/A * redistributions in binary form must reproduce the above copyright
10955SN/A * notice, this list of conditions and the following disclaimer in the
11955SN/A * documentation and/or other materials provided with the distribution;
12955SN/A * neither the name of the copyright holders nor the names of its
13955SN/A * contributors may be used to endorse or promote products derived from
14955SN/A * this software without specific prior written permission.
15955SN/A *
16955SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17955SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18955SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19955SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20955SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21955SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22955SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23955SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24955SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25955SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26955SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27955SN/A *
282665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert
294762Snate@binkert.org */
30955SN/A
315522Snate@binkert.org// This file will contain default statistics for the simulator that
324762Snate@binkert.org// don't really belong to a specific simulator object
335522Snate@binkert.org
34955SN/A#include <fstream>
355522Snate@binkert.org#include <iostream>
36955SN/A#include <list>
375522Snate@binkert.org
384202Sbinkertn@umich.edu#include "base/callback.hh"
395742Snate@binkert.org#include "base/hostinfo.hh"
40955SN/A#include "base/statistics.hh"
414381Sbinkertn@umich.edu#include "base/time.hh"
424381Sbinkertn@umich.edu#include "cpu/base.hh"
43955SN/A#include "sim/eventq.hh"
44955SN/A
45955SN/Ausing namespace std;
464202Sbinkertn@umich.edu
47955SN/AStats::Formula simSeconds;
484382Sbinkertn@umich.edu
494382Sbinkertn@umich.edunamespace Stats {
504382Sbinkertn@umich.edu
515517Snate@binkert.orgTime statTime(true);
525517Snate@binkert.orgTick startTick;
534762Snate@binkert.org
544762Snate@binkert.orgstruct SimTicksReset : public Callback
554762Snate@binkert.org{
564762Snate@binkert.org    void process()
574762Snate@binkert.org    {
584762Snate@binkert.org        statTime.set();
594762Snate@binkert.org        startTick = curTick;
604762Snate@binkert.org    }
614762Snate@binkert.org};
624762Snate@binkert.org
635522Snate@binkert.orgdouble
645604Snate@binkert.orgstatElapsedTime()
655604Snate@binkert.org{
665604Snate@binkert.org    Time now(true);
674762Snate@binkert.org    Time elapsed = now - statTime;
684762Snate@binkert.org    return elapsed();
694762Snate@binkert.org}
705522Snate@binkert.org
715522Snate@binkert.orgTick
725522Snate@binkert.orgstatElapsedTicks()
735522Snate@binkert.org{
745604Snate@binkert.org    return curTick - startTick;
755604Snate@binkert.org}
764762Snate@binkert.org
774762Snate@binkert.orgSimTicksReset simTicksReset;
784762Snate@binkert.org
794762Snate@binkert.orgstruct Global
805522Snate@binkert.org{
814762Snate@binkert.org    Stats::Formula hostInstRate;
824762Snate@binkert.org    Stats::Formula hostTickRate;
835604Snate@binkert.org    Stats::Value hostMemory;
845604Snate@binkert.org    Stats::Value hostSeconds;
855604Snate@binkert.org
865604Snate@binkert.org    Stats::Value simTicks;
875604Snate@binkert.org    Stats::Value simInsts;
885604Snate@binkert.org    Stats::Value simFreq;
894762Snate@binkert.org
904762Snate@binkert.org    Global();
914762Snate@binkert.org};
924762Snate@binkert.org
935604Snate@binkert.orgGlobal::Global()
944762Snate@binkert.org{
955522Snate@binkert.org    simInsts
965522Snate@binkert.org        .functor(BaseCPU::numSimulatedInstructions)
975522Snate@binkert.org        .name("sim_insts")
984762Snate@binkert.org        .desc("Number of instructions simulated")
994382Sbinkertn@umich.edu        .precision(0)
1004762Snate@binkert.org        .prereq(simInsts)
1014382Sbinkertn@umich.edu        ;
1025522Snate@binkert.org
1034381Sbinkertn@umich.edu    simSeconds
1045522Snate@binkert.org        .name("sim_seconds")
1054762Snate@binkert.org        .desc("Number of seconds simulated")
1064762Snate@binkert.org        ;
1074762Snate@binkert.org
1085522Snate@binkert.org    simFreq
1095522Snate@binkert.org        .scalar(Clock::Frequency)
1105522Snate@binkert.org        .name("sim_freq")
1115522Snate@binkert.org        .desc("Frequency of simulated ticks")
1125522Snate@binkert.org        ;
1135522Snate@binkert.org
1145522Snate@binkert.org    simTicks
1155522Snate@binkert.org        .functor(statElapsedTicks)
1165522Snate@binkert.org        .name("sim_ticks")
1174762Snate@binkert.org        .desc("Number of ticks simulated")
1184762Snate@binkert.org        ;
1194762Snate@binkert.org
1204762Snate@binkert.org    hostInstRate
1214762Snate@binkert.org        .name("host_inst_rate")
1224762Snate@binkert.org        .desc("Simulator instruction rate (inst/s)")
1234762Snate@binkert.org        .precision(0)
1244762Snate@binkert.org        .prereq(simInsts)
1254762Snate@binkert.org        ;
1264762Snate@binkert.org
1274762Snate@binkert.org    hostMemory
1284762Snate@binkert.org        .functor(memUsage)
1294762Snate@binkert.org        .name("host_mem_usage")
1304762Snate@binkert.org        .desc("Number of bytes of host memory used")
1314762Snate@binkert.org        .prereq(hostMemory)
1324762Snate@binkert.org        ;
1334762Snate@binkert.org
1344762Snate@binkert.org    hostSeconds
1354762Snate@binkert.org        .functor(statElapsedTime)
1364762Snate@binkert.org        .name("host_seconds")
1374762Snate@binkert.org        .desc("Real time elapsed on the host")
1384762Snate@binkert.org        .precision(2)
1394762Snate@binkert.org        ;
1404762Snate@binkert.org
1414762Snate@binkert.org    hostTickRate
1424762Snate@binkert.org        .name("host_tick_rate")
1434762Snate@binkert.org        .desc("Simulator tick rate (ticks/s)")
1444762Snate@binkert.org        .precision(0)
1454762Snate@binkert.org        ;
1464762Snate@binkert.org
1474762Snate@binkert.org    simSeconds = simTicks / simFreq;
1484762Snate@binkert.org    hostInstRate = simInsts / hostSeconds;
1494762Snate@binkert.org    hostTickRate = simTicks / hostSeconds;
1504762Snate@binkert.org
1514762Snate@binkert.org    registerResetCallback(&simTicksReset);
152955SN/A}
1535584Snate@binkert.org
1545584Snate@binkert.orgvoid
1555584Snate@binkert.orginitSimStats()
1565584Snate@binkert.org{
1575584Snate@binkert.org    static Global global;
1585584Snate@binkert.org}
1595584Snate@binkert.org
1605584Snate@binkert.orgclass _StatEvent : public Event
1615584Snate@binkert.org{
1625584Snate@binkert.org  private:
1635584Snate@binkert.org    bool dump;
1645584Snate@binkert.org    bool reset;
1655584Snate@binkert.org    Tick repeat;
1664382Sbinkertn@umich.edu
1674202Sbinkertn@umich.edu  public:
1685522Snate@binkert.org    _StatEvent(bool _dump, bool _reset, Tick _repeat)
1694382Sbinkertn@umich.edu        : Event(Stat_Event_Pri), dump(_dump), reset(_reset), repeat(_repeat)
1704382Sbinkertn@umich.edu    {
1714382Sbinkertn@umich.edu        setFlags(AutoDelete);
1725584Snate@binkert.org    }
1734382Sbinkertn@umich.edu
1744382Sbinkertn@umich.edu    virtual void
1754382Sbinkertn@umich.edu    process()
1765192Ssaidi@eecs.umich.edu    {
1775192Ssaidi@eecs.umich.edu        if (dump)
1785192Ssaidi@eecs.umich.edu            Stats::dump();
1795192Ssaidi@eecs.umich.edu
1805192Ssaidi@eecs.umich.edu        if (reset)
1815192Ssaidi@eecs.umich.edu            Stats::reset();
1825192Ssaidi@eecs.umich.edu
1835192Ssaidi@eecs.umich.edu        if (repeat) {
1845192Ssaidi@eecs.umich.edu            Event *event = new _StatEvent(dump, reset, repeat);
1855192Ssaidi@eecs.umich.edu            mainEventQueue.schedule(event, curTick + repeat);
1865192Ssaidi@eecs.umich.edu        }
1875192Ssaidi@eecs.umich.edu    }
1885192Ssaidi@eecs.umich.edu};
1895192Ssaidi@eecs.umich.edu
1905192Ssaidi@eecs.umich.eduvoid
1915192Ssaidi@eecs.umich.eduStatEvent(bool dump, bool reset, Tick when, Tick repeat)
1925192Ssaidi@eecs.umich.edu{
1935192Ssaidi@eecs.umich.edu    Event *event = new _StatEvent(dump, reset, repeat);
1945192Ssaidi@eecs.umich.edu    mainEventQueue.schedule(event, when);
1955192Ssaidi@eecs.umich.edu}
1965192Ssaidi@eecs.umich.edu
1975192Ssaidi@eecs.umich.edu/* namespace Stats */ }
1985192Ssaidi@eecs.umich.edu