stat_control.cc revision 8581
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"
427768SAli.Saidi@ARM.com#include "config/the_isa.hh"
437768SAli.Saidi@ARM.com#if THE_ISA == NO_ISA
447768SAli.Saidi@ARM.com#include "arch/noisa/cpu_dummy.hh"
457768SAli.Saidi@ARM.com#else
461717SN/A#include "cpu/base.hh"
477768SAli.Saidi@ARM.com#endif
487768SAli.Saidi@ARM.com
49695SN/A#include "sim/eventq.hh"
507822Ssteve.reinhardt@amd.com#include "sim/stat_control.hh"
51695SN/A
52695SN/Ausing namespace std;
53695SN/A
54729SN/AStats::Formula simSeconds;
557068Snate@binkert.orgStats::Value simTicks;
567068Snate@binkert.orgStats::Value simFreq;
57695SN/A
58729SN/Anamespace Stats {
59695SN/A
60695SN/ATime statTime(true);
61695SN/ATick startTick;
62695SN/A
634078Sbinkertn@umich.edustruct SimTicksReset : public Callback
64695SN/A{
65695SN/A    void process()
66695SN/A    {
677840Snate@binkert.org        statTime.setTimer();
687823Ssteve.reinhardt@amd.com        startTick = curTick();
69695SN/A    }
70695SN/A};
71695SN/A
72695SN/Adouble
73695SN/AstatElapsedTime()
74695SN/A{
757840Snate@binkert.org    Time now;
767840Snate@binkert.org    now.setTimer();
777840Snate@binkert.org
78695SN/A    Time elapsed = now - statTime;
797840Snate@binkert.org    return elapsed;
80695SN/A}
81695SN/A
821020SN/ATick
831020SN/AstatElapsedTicks()
841020SN/A{
857823Ssteve.reinhardt@amd.com    return curTick() - startTick;
861020SN/A}
871020SN/A
88695SN/ASimTicksReset simTicksReset;
89695SN/A
905883Snate@binkert.orgstruct Global
915883Snate@binkert.org{
925883Snate@binkert.org    Stats::Formula hostInstRate;
935883Snate@binkert.org    Stats::Formula hostTickRate;
945883Snate@binkert.org    Stats::Value hostMemory;
955883Snate@binkert.org    Stats::Value hostSeconds;
965883Snate@binkert.org
975883Snate@binkert.org    Stats::Value simInsts;
985883Snate@binkert.org
995883Snate@binkert.org    Global();
1005883Snate@binkert.org};
1015883Snate@binkert.org
1025883Snate@binkert.orgGlobal::Global()
103695SN/A{
104695SN/A    simInsts
105707SN/A        .functor(BaseCPU::numSimulatedInstructions)
106695SN/A        .name("sim_insts")
107695SN/A        .desc("Number of instructions simulated")
108695SN/A        .precision(0)
109695SN/A        .prereq(simInsts)
110695SN/A        ;
111695SN/A
112695SN/A    simSeconds
113695SN/A        .name("sim_seconds")
114695SN/A        .desc("Number of seconds simulated")
115695SN/A        ;
116695SN/A
117707SN/A    simFreq
1187064Snate@binkert.org        .scalar(SimClock::Frequency)
119707SN/A        .name("sim_freq")
120707SN/A        .desc("Frequency of simulated ticks")
121707SN/A        ;
122707SN/A
123695SN/A    simTicks
1241020SN/A        .functor(statElapsedTicks)
125695SN/A        .name("sim_ticks")
126695SN/A        .desc("Number of ticks simulated")
127695SN/A        ;
128695SN/A
129695SN/A    hostInstRate
130695SN/A        .name("host_inst_rate")
131695SN/A        .desc("Simulator instruction rate (inst/s)")
132695SN/A        .precision(0)
133695SN/A        .prereq(simInsts)
134695SN/A        ;
135695SN/A
136695SN/A    hostMemory
137707SN/A        .functor(memUsage)
138695SN/A        .name("host_mem_usage")
139695SN/A        .desc("Number of bytes of host memory used")
140695SN/A        .prereq(hostMemory)
141695SN/A        ;
142695SN/A
143695SN/A    hostSeconds
144707SN/A        .functor(statElapsedTime)
145695SN/A        .name("host_seconds")
146695SN/A        .desc("Real time elapsed on the host")
147695SN/A        .precision(2)
148695SN/A        ;
149695SN/A
150695SN/A    hostTickRate
151695SN/A        .name("host_tick_rate")
152695SN/A        .desc("Simulator tick rate (ticks/s)")
153695SN/A        .precision(0)
154695SN/A        ;
155695SN/A
156707SN/A    simSeconds = simTicks / simFreq;
157695SN/A    hostInstRate = simInsts / hostSeconds;
158695SN/A    hostTickRate = simTicks / hostSeconds;
159695SN/A
160695SN/A    registerResetCallback(&simTicksReset);
161695SN/A}
162695SN/A
1635883Snate@binkert.orgvoid
1645883Snate@binkert.orginitSimStats()
1655883Snate@binkert.org{
1665883Snate@binkert.org    static Global global;
1675883Snate@binkert.org}
1685883Snate@binkert.org
1697822Ssteve.reinhardt@amd.comclass StatEvent : public Event
170695SN/A{
1714078Sbinkertn@umich.edu  private:
1724078Sbinkertn@umich.edu    bool dump;
1734078Sbinkertn@umich.edu    bool reset;
174695SN/A    Tick repeat;
175695SN/A
176695SN/A  public:
1777822Ssteve.reinhardt@amd.com    StatEvent(bool _dump, bool _reset, Tick _repeat)
1788581Ssteve.reinhardt@amd.com        : Event(Stat_Event_Pri, AutoDelete),
1798581Ssteve.reinhardt@amd.com          dump(_dump), reset(_reset), repeat(_repeat)
1804078Sbinkertn@umich.edu    {
1814078Sbinkertn@umich.edu    }
1824078Sbinkertn@umich.edu
1834078Sbinkertn@umich.edu    virtual void
1844078Sbinkertn@umich.edu    process()
1854078Sbinkertn@umich.edu    {
1864078Sbinkertn@umich.edu        if (dump)
1874078Sbinkertn@umich.edu            Stats::dump();
1884078Sbinkertn@umich.edu
1894078Sbinkertn@umich.edu        if (reset)
1904078Sbinkertn@umich.edu            Stats::reset();
1914078Sbinkertn@umich.edu
1925606Snate@binkert.org        if (repeat) {
1937823Ssteve.reinhardt@amd.com            Stats::schedStatEvent(dump, reset, curTick() + repeat, repeat);
1945606Snate@binkert.org        }
1954078Sbinkertn@umich.edu    }
196695SN/A};
197695SN/A
1984078Sbinkertn@umich.eduvoid
1997822Ssteve.reinhardt@amd.comschedStatEvent(bool dump, bool reset, Tick when, Tick repeat)
200695SN/A{
2017822Ssteve.reinhardt@amd.com    Event *event = new StatEvent(dump, reset, repeat);
2025606Snate@binkert.org    mainEventQueue.schedule(event, when);
203695SN/A}
204695SN/A
2057811Ssteve.reinhardt@amd.com} // namespace Stats
206