stat_control.cc revision 7840
113680Syazakram@ucdavis.edu/*
213680Syazakram@ucdavis.edu * Copyright (c) 2004-2005 The Regents of The University of Michigan
313680Syazakram@ucdavis.edu * All rights reserved.
413680Syazakram@ucdavis.edu *
513680Syazakram@ucdavis.edu * Redistribution and use in source and binary forms, with or without
613680Syazakram@ucdavis.edu * modification, are permitted provided that the following conditions are
713680Syazakram@ucdavis.edu * met: redistributions of source code must retain the above copyright
813680Syazakram@ucdavis.edu * notice, this list of conditions and the following disclaimer;
913680Syazakram@ucdavis.edu * redistributions in binary form must reproduce the above copyright
1013680Syazakram@ucdavis.edu * notice, this list of conditions and the following disclaimer in the
1113680Syazakram@ucdavis.edu * documentation and/or other materials provided with the distribution;
1213680Syazakram@ucdavis.edu * neither the name of the copyright holders nor the names of its
1313680Syazakram@ucdavis.edu * contributors may be used to endorse or promote products derived from
1413680Syazakram@ucdavis.edu * this software without specific prior written permission.
1513680Syazakram@ucdavis.edu *
1613680Syazakram@ucdavis.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1713680Syazakram@ucdavis.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1813680Syazakram@ucdavis.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1913680Syazakram@ucdavis.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2013680Syazakram@ucdavis.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2113680Syazakram@ucdavis.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2213680Syazakram@ucdavis.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2313680Syazakram@ucdavis.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2413680Syazakram@ucdavis.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2513680Syazakram@ucdavis.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2613680Syazakram@ucdavis.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2713680Syazakram@ucdavis.edu *
2813680Syazakram@ucdavis.edu * Authors: Nathan Binkert
2913680Syazakram@ucdavis.edu */
3013680Syazakram@ucdavis.edu
3113680Syazakram@ucdavis.edu// This file will contain default statistics for the simulator that
3213680Syazakram@ucdavis.edu// don't really belong to a specific simulator object
3313680Syazakram@ucdavis.edu
3413680Syazakram@ucdavis.edu#include <fstream>
3513680Syazakram@ucdavis.edu#include <iostream>
3613680Syazakram@ucdavis.edu#include <list>
3713680Syazakram@ucdavis.edu
3813680Syazakram@ucdavis.edu#include "base/callback.hh"
3913680Syazakram@ucdavis.edu#include "base/hostinfo.hh"
4013680Syazakram@ucdavis.edu#include "base/statistics.hh"
4113680Syazakram@ucdavis.edu#include "base/time.hh"
4213680Syazakram@ucdavis.edu
4313680Syazakram@ucdavis.edu#include "config/the_isa.hh"
4413680Syazakram@ucdavis.edu#if THE_ISA == NO_ISA
4513680Syazakram@ucdavis.edu#include "arch/noisa/cpu_dummy.hh"
4613680Syazakram@ucdavis.edu#else
4713680Syazakram@ucdavis.edu#include "cpu/base.hh"
4813680Syazakram@ucdavis.edu#endif
4913680Syazakram@ucdavis.edu
5013680Syazakram@ucdavis.edu#include "sim/eventq.hh"
5113680Syazakram@ucdavis.edu#include "sim/stat_control.hh"
5213680Syazakram@ucdavis.edu
5313680Syazakram@ucdavis.eduusing namespace std;
5413680Syazakram@ucdavis.edu
5513680Syazakram@ucdavis.eduStats::Formula simSeconds;
5613680Syazakram@ucdavis.eduStats::Value simTicks;
5713680Syazakram@ucdavis.eduStats::Value simFreq;
5813680Syazakram@ucdavis.edu
5913680Syazakram@ucdavis.edunamespace Stats {
6013680Syazakram@ucdavis.edu
6113680Syazakram@ucdavis.eduTime statTime(true);
6213680Syazakram@ucdavis.eduTick startTick;
6313680Syazakram@ucdavis.edu
64struct SimTicksReset : public Callback
65{
66    void process()
67    {
68        statTime.setTimer();
69        startTick = curTick();
70    }
71};
72
73double
74statElapsedTime()
75{
76    Time now;
77    now.setTimer();
78
79    Time elapsed = now - statTime;
80    return elapsed;
81}
82
83Tick
84statElapsedTicks()
85{
86    return curTick() - startTick;
87}
88
89SimTicksReset simTicksReset;
90
91struct Global
92{
93    Stats::Formula hostInstRate;
94    Stats::Formula hostTickRate;
95    Stats::Value hostMemory;
96    Stats::Value hostSeconds;
97
98    Stats::Value simInsts;
99
100    Global();
101};
102
103Global::Global()
104{
105    simInsts
106        .functor(BaseCPU::numSimulatedInstructions)
107        .name("sim_insts")
108        .desc("Number of instructions simulated")
109        .precision(0)
110        .prereq(simInsts)
111        ;
112
113    simSeconds
114        .name("sim_seconds")
115        .desc("Number of seconds simulated")
116        ;
117
118    simFreq
119        .scalar(SimClock::Frequency)
120        .name("sim_freq")
121        .desc("Frequency of simulated ticks")
122        ;
123
124    simTicks
125        .functor(statElapsedTicks)
126        .name("sim_ticks")
127        .desc("Number of ticks simulated")
128        ;
129
130    hostInstRate
131        .name("host_inst_rate")
132        .desc("Simulator instruction rate (inst/s)")
133        .precision(0)
134        .prereq(simInsts)
135        ;
136
137    hostMemory
138        .functor(memUsage)
139        .name("host_mem_usage")
140        .desc("Number of bytes of host memory used")
141        .prereq(hostMemory)
142        ;
143
144    hostSeconds
145        .functor(statElapsedTime)
146        .name("host_seconds")
147        .desc("Real time elapsed on the host")
148        .precision(2)
149        ;
150
151    hostTickRate
152        .name("host_tick_rate")
153        .desc("Simulator tick rate (ticks/s)")
154        .precision(0)
155        ;
156
157    simSeconds = simTicks / simFreq;
158    hostInstRate = simInsts / hostSeconds;
159    hostTickRate = simTicks / hostSeconds;
160
161    registerResetCallback(&simTicksReset);
162}
163
164void
165initSimStats()
166{
167    static Global global;
168}
169
170class StatEvent : public Event
171{
172  private:
173    bool dump;
174    bool reset;
175    Tick repeat;
176
177  public:
178    StatEvent(bool _dump, bool _reset, Tick _repeat)
179        : Event(Stat_Event_Pri), dump(_dump), reset(_reset), repeat(_repeat)
180    {
181        setFlags(AutoDelete);
182    }
183
184    virtual void
185    process()
186    {
187        if (dump)
188            Stats::dump();
189
190        if (reset)
191            Stats::reset();
192
193        if (repeat) {
194            Stats::schedStatEvent(dump, reset, curTick() + repeat, repeat);
195        }
196    }
197};
198
199void
200schedStatEvent(bool dump, bool reset, Tick when, Tick repeat)
201{
202    Event *event = new StatEvent(dump, reset, repeat);
203    mainEventQueue.schedule(event, when);
204}
205
206} // namespace Stats
207