stat_control.cc revision 7064
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 simSeconds;
48695SN/A
49729SN/Anamespace Stats {
50695SN/A
51695SN/ATime statTime(true);
52695SN/ATick startTick;
53695SN/A
544078Sbinkertn@umich.edustruct SimTicksReset : public Callback
55695SN/A{
56695SN/A    void process()
57695SN/A    {
58695SN/A        statTime.set();
59695SN/A        startTick = curTick;
60695SN/A    }
61695SN/A};
62695SN/A
63695SN/Adouble
64695SN/AstatElapsedTime()
65695SN/A{
66695SN/A    Time now(true);
67695SN/A    Time elapsed = now - statTime;
68695SN/A    return elapsed();
69695SN/A}
70695SN/A
711020SN/ATick
721020SN/AstatElapsedTicks()
731020SN/A{
741020SN/A    return curTick - startTick;
751020SN/A}
761020SN/A
77695SN/ASimTicksReset simTicksReset;
78695SN/A
795883Snate@binkert.orgstruct Global
805883Snate@binkert.org{
815883Snate@binkert.org    Stats::Formula hostInstRate;
825883Snate@binkert.org    Stats::Formula hostTickRate;
835883Snate@binkert.org    Stats::Value hostMemory;
845883Snate@binkert.org    Stats::Value hostSeconds;
855883Snate@binkert.org
865883Snate@binkert.org    Stats::Value simTicks;
875883Snate@binkert.org    Stats::Value simInsts;
885883Snate@binkert.org    Stats::Value simFreq;
895883Snate@binkert.org
905883Snate@binkert.org    Global();
915883Snate@binkert.org};
925883Snate@binkert.org
935883Snate@binkert.orgGlobal::Global()
94695SN/A{
95695SN/A    simInsts
96707SN/A        .functor(BaseCPU::numSimulatedInstructions)
97695SN/A        .name("sim_insts")
98695SN/A        .desc("Number of instructions simulated")
99695SN/A        .precision(0)
100695SN/A        .prereq(simInsts)
101695SN/A        ;
102695SN/A
103695SN/A    simSeconds
104695SN/A        .name("sim_seconds")
105695SN/A        .desc("Number of seconds simulated")
106695SN/A        ;
107695SN/A
108707SN/A    simFreq
1097064Snate@binkert.org        .scalar(SimClock::Frequency)
110707SN/A        .name("sim_freq")
111707SN/A        .desc("Frequency of simulated ticks")
112707SN/A        ;
113707SN/A
114695SN/A    simTicks
1151020SN/A        .functor(statElapsedTicks)
116695SN/A        .name("sim_ticks")
117695SN/A        .desc("Number of ticks simulated")
118695SN/A        ;
119695SN/A
120695SN/A    hostInstRate
121695SN/A        .name("host_inst_rate")
122695SN/A        .desc("Simulator instruction rate (inst/s)")
123695SN/A        .precision(0)
124695SN/A        .prereq(simInsts)
125695SN/A        ;
126695SN/A
127695SN/A    hostMemory
128707SN/A        .functor(memUsage)
129695SN/A        .name("host_mem_usage")
130695SN/A        .desc("Number of bytes of host memory used")
131695SN/A        .prereq(hostMemory)
132695SN/A        ;
133695SN/A
134695SN/A    hostSeconds
135707SN/A        .functor(statElapsedTime)
136695SN/A        .name("host_seconds")
137695SN/A        .desc("Real time elapsed on the host")
138695SN/A        .precision(2)
139695SN/A        ;
140695SN/A
141695SN/A    hostTickRate
142695SN/A        .name("host_tick_rate")
143695SN/A        .desc("Simulator tick rate (ticks/s)")
144695SN/A        .precision(0)
145695SN/A        ;
146695SN/A
147707SN/A    simSeconds = simTicks / simFreq;
148695SN/A    hostInstRate = simInsts / hostSeconds;
149695SN/A    hostTickRate = simTicks / hostSeconds;
150695SN/A
151695SN/A    registerResetCallback(&simTicksReset);
152695SN/A}
153695SN/A
1545883Snate@binkert.orgvoid
1555883Snate@binkert.orginitSimStats()
1565883Snate@binkert.org{
1575883Snate@binkert.org    static Global global;
1585883Snate@binkert.org}
1595883Snate@binkert.org
1604078Sbinkertn@umich.educlass _StatEvent : public Event
161695SN/A{
1624078Sbinkertn@umich.edu  private:
1634078Sbinkertn@umich.edu    bool dump;
1644078Sbinkertn@umich.edu    bool reset;
165695SN/A    Tick repeat;
166695SN/A
167695SN/A  public:
1685606Snate@binkert.org    _StatEvent(bool _dump, bool _reset, Tick _repeat)
1695606Snate@binkert.org        : Event(Stat_Event_Pri), dump(_dump), reset(_reset), repeat(_repeat)
1704078Sbinkertn@umich.edu    {
1714078Sbinkertn@umich.edu        setFlags(AutoDelete);
1724078Sbinkertn@umich.edu    }
1734078Sbinkertn@umich.edu
1744078Sbinkertn@umich.edu    virtual void
1754078Sbinkertn@umich.edu    process()
1764078Sbinkertn@umich.edu    {
1774078Sbinkertn@umich.edu        if (dump)
1784078Sbinkertn@umich.edu            Stats::dump();
1794078Sbinkertn@umich.edu
1804078Sbinkertn@umich.edu        if (reset)
1814078Sbinkertn@umich.edu            Stats::reset();
1824078Sbinkertn@umich.edu
1835606Snate@binkert.org        if (repeat) {
1845606Snate@binkert.org            Event *event = new _StatEvent(dump, reset, repeat);
1855606Snate@binkert.org            mainEventQueue.schedule(event, curTick + repeat);
1865606Snate@binkert.org        }
1874078Sbinkertn@umich.edu    }
188695SN/A};
189695SN/A
1904078Sbinkertn@umich.eduvoid
1914078Sbinkertn@umich.eduStatEvent(bool dump, bool reset, Tick when, Tick repeat)
192695SN/A{
1935606Snate@binkert.org    Event *event = new _StatEvent(dump, reset, repeat);
1945606Snate@binkert.org    mainEventQueue.schedule(event, when);
195695SN/A}
196695SN/A
197729SN/A/* namespace Stats */ }
198