stat_control.cc revision 5883
1/*
2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Nathan Binkert
29 */
30
31// This file will contain default statistics for the simulator that
32// don't really belong to a specific simulator object
33
34#include <fstream>
35#include <iostream>
36#include <list>
37
38#include "base/callback.hh"
39#include "base/hostinfo.hh"
40#include "base/statistics.hh"
41#include "base/time.hh"
42#include "cpu/base.hh"
43#include "sim/eventq.hh"
44
45using namespace std;
46
47Stats::Formula simSeconds;
48
49namespace Stats {
50
51Time statTime(true);
52Tick startTick;
53
54struct SimTicksReset : public Callback
55{
56    void process()
57    {
58        statTime.set();
59        startTick = curTick;
60    }
61};
62
63double
64statElapsedTime()
65{
66    Time now(true);
67    Time elapsed = now - statTime;
68    return elapsed();
69}
70
71Tick
72statElapsedTicks()
73{
74    return curTick - startTick;
75}
76
77SimTicksReset simTicksReset;
78
79struct Global
80{
81    Stats::Formula hostInstRate;
82    Stats::Formula hostTickRate;
83    Stats::Value hostMemory;
84    Stats::Value hostSeconds;
85
86    Stats::Value simTicks;
87    Stats::Value simInsts;
88    Stats::Value simFreq;
89
90    Global();
91};
92
93Global::Global()
94{
95    simInsts
96        .functor(BaseCPU::numSimulatedInstructions)
97        .name("sim_insts")
98        .desc("Number of instructions simulated")
99        .precision(0)
100        .prereq(simInsts)
101        ;
102
103    simSeconds
104        .name("sim_seconds")
105        .desc("Number of seconds simulated")
106        ;
107
108    simFreq
109        .scalar(Clock::Frequency)
110        .name("sim_freq")
111        .desc("Frequency of simulated ticks")
112        ;
113
114    simTicks
115        .functor(statElapsedTicks)
116        .name("sim_ticks")
117        .desc("Number of ticks simulated")
118        ;
119
120    hostInstRate
121        .name("host_inst_rate")
122        .desc("Simulator instruction rate (inst/s)")
123        .precision(0)
124        .prereq(simInsts)
125        ;
126
127    hostMemory
128        .functor(memUsage)
129        .name("host_mem_usage")
130        .desc("Number of bytes of host memory used")
131        .prereq(hostMemory)
132        ;
133
134    hostSeconds
135        .functor(statElapsedTime)
136        .name("host_seconds")
137        .desc("Real time elapsed on the host")
138        .precision(2)
139        ;
140
141    hostTickRate
142        .name("host_tick_rate")
143        .desc("Simulator tick rate (ticks/s)")
144        .precision(0)
145        ;
146
147    simSeconds = simTicks / simFreq;
148    hostInstRate = simInsts / hostSeconds;
149    hostTickRate = simTicks / hostSeconds;
150
151    registerResetCallback(&simTicksReset);
152}
153
154void
155initSimStats()
156{
157    static Global global;
158}
159
160class _StatEvent : public Event
161{
162  private:
163    bool dump;
164    bool reset;
165    Tick repeat;
166
167  public:
168    _StatEvent(bool _dump, bool _reset, Tick _repeat)
169        : Event(Stat_Event_Pri), dump(_dump), reset(_reset), repeat(_repeat)
170    {
171        setFlags(AutoDelete);
172    }
173
174    virtual void
175    process()
176    {
177        if (dump)
178            Stats::dump();
179
180        if (reset)
181            Stats::reset();
182
183        if (repeat) {
184            Event *event = new _StatEvent(dump, reset, repeat);
185            mainEventQueue.schedule(event, curTick + repeat);
186        }
187    }
188};
189
190void
191StatEvent(bool dump, bool reset, Tick when, Tick repeat)
192{
193    Event *event = new _StatEvent(dump, reset, repeat);
194    mainEventQueue.schedule(event, when);
195}
196
197/* namespace Stats */ }
198