gem5 v24.0.0.0
Loading...
Searching...
No Matches
statistics.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019-2020 Arm Limited
3 * All rights reserved.
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2003-2005 The Regents of The University of Michigan
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 */
40
41#include "base/statistics.hh"
42
43#include <cassert>
44#include <list>
45#include <map>
46#include <string>
47#include <utility>
48
49#include "base/callback.hh"
50#include "base/logging.hh"
51#include "sim/root.hh"
52
53namespace gem5
54{
55
56namespace statistics
57{
58
59// We wrap these in a function to make sure they're built in time.
62{
63 static std::list<Info *> the_list;
64 return the_list;
65}
66
67MapType &
69{
70 static MapType the_map;
71 return the_map;
72}
73
74void
76{
77 panic_if(statsMap().find(this) != statsMap().end() ||
78 _info != nullptr,
79 "shouldn't register stat twice!");
80
81 // New-style stats are reachable through the hierarchy and
82 // shouldn't be added to the global lists.
83 if (parent) {
84 _info = info;
85 return;
86 }
87
88 statsList().push_back(info);
89
90#ifndef NDEBUG
92#endif
93 statsMap().insert(std::make_pair(this, info));
94 assert(result.second && "this should never fail");
95 assert(statsMap().find(this) != statsMap().end());
96}
97
98void
100{
101 info()->setStorageParams(params);
102}
103
104void
106{
107 info()->flags.set(init);
108}
109
110Info *
112{
113 if (newStyleStats()) {
114 // New-style stats
115 return _info;
116 } else {
117 // Legacy stats
118 MapType::const_iterator i = statsMap().find(this);
119 assert(i != statsMap().end());
120 return (*i).second;
121 }
122}
123
124const Info *
126{
127 if (newStyleStats()) {
128 // New-style stats
129 return _info;
130 } else {
131 // Legacy stats
132 MapType::const_iterator i = statsMap().find(this);
133 assert(i != statsMap().end());
134 return (*i).second;
135 }
136}
137
138bool
140{
141 return _info != nullptr;
142}
143
144Formula::Formula(Group *parent, const char *name, const char *desc)
146 parent, name, units::Unspecified::get(), desc)
147
148{
149}
150
151Formula::Formula(Group *parent, const char *name, const units::Base *unit,
152 const char *desc)
153 : DataWrapVec<Formula, FormulaInfoProxy>(parent, name, unit, desc)
154{
155}
156
157Formula::Formula(Group *parent, const char *name, const char *desc,
158 const Temp &r)
160 parent, name, units::Unspecified::get(), desc)
161{
162 *this = r;
163}
164
165Formula::Formula(Group *parent, const char *name, const units::Base *unit,
166 const char *desc, const Temp &r)
167 : DataWrapVec<Formula, FormulaInfoProxy>(parent, name, unit, desc)
168{
169 *this = r;
170}
171
172const Formula &
174{
175 assert(!root && "Can't change formulas");
176 root = r.getNodePtr();
177 setInit();
178 assert(size());
179 return *this;
180}
181
182const Formula &
184{
185 if (root)
186 root = NodePtr(new BinaryNode<std::plus<Result> >(root, r));
187 else {
188 root = r.getNodePtr();
189 setInit();
190 }
191
192 assert(size());
193 return *this;
194}
195
196const Formula &
198{
199 assert (root);
200 root = NodePtr(new BinaryNode<std::divides<Result> >(root, r));
201
202 assert(size());
203 return *this;
204}
205
206
207void
209{
210 if (root)
211 vec = root->result();
212}
213
214Result
216{
217 return root ? root->total() : 0.0;
218}
219
222{
223 if (!root)
224 return 0;
225 else
226 return root->size();
227}
228
229void
231{
232}
233
234bool
236{
237 VResult vec;
238 result(vec);
239 for (VResult::size_type i = 0; i < vec.size(); ++i)
240 if (vec[i] != 0.0)
241 return false;
242 return true;
243}
244
245std::string
247{
248 return root ? root->str() : "";
249}
250
253
254void
255registerHandlers(Handler reset_handler, Handler dump_handler)
256{
257 resetHandler = reset_handler;
258 dumpHandler = dump_handler;
259}
260
263
264void
269
270void
275
276void
277registerResetCallback(const std::function<void()> &callback)
278{
279 resetQueue.push_back(callback);
280}
281
282bool _enabled = false;
283
284bool
286{
287 return _enabled;
288}
289
290void
292{
293 if (_enabled)
294 fatal("Stats are already enabled");
295
296 _enabled = true;
297}
298
299void
301{
302 if (dumpHandler)
303 dumpHandler();
304 else
305 fatal("No registered statistics::dump handler");
306}
307
308void
310{
311 if (resetHandler)
312 resetHandler();
313 else
314 fatal("No registered statistics::reset handler");
315}
316
317const Info *
318resolve(const std::string &name)
319{
320 const auto &it = nameMap().find(name);
321 if (it != nameMap().cend()) {
322 return it->second;
323 } else {
324 return Root::root()->resolveStat(name);
325 }
326}
327
328void
329registerDumpCallback(const std::function<void()> &callback)
330{
331 dumpQueue.push_back(callback);
332}
333
334} // namespace statistics
335
336void
341
342} // namespace gem5
static Root * root()
Use this function to get a pointer to the single Root object in the simulation.
Definition root.hh:93
A formula for statistics that is calculated when printed.
const Formula & operator/=(Temp r)
Divide the existing tree by the given one.
void reset()
Formulas don't need to be reset.
void result(VResult &vec) const
Return the result of the Fomula in a vector.
NodePtr root
The root of the tree which represents the Formula.
size_type size() const
Return the number of elements in the tree.
std::string str() const
Formula(Group *parent=nullptr, const char *name=nullptr, const char *desc=nullptr)
Create and initialize thie formula, and register it with the database.
const Formula & operator=(const Temp &r)
Set an unitialized Formula to the given root.
Result total() const
Return the total Formula result.
const Formula & operator+=(Temp r)
Add the given tree to the existing one.
Statistics container.
Definition group.hh:93
const Info * resolveStat(std::string name) const
Resolve a stat by its name within this group.
Definition group.cc:128
void setInit()
Save Storage class parameters if any.
void setParams(const StorageParams *params)
Save Storage class parameters if any.
Definition statistics.cc:99
Info * info()
Grab the information class for this statistic.
bool newStyleStats() const
Check if the info is new style stats.
void setInfo(Group *parent, Info *info)
Set up an info class for this statistic.
Definition statistics.cc:75
Flags flags
The formatting flags.
Definition info.hh:91
void setStorageParams(const StorageParams *const params)
Setter for the storage params.
Definition info.cc:90
Helper class to construct formula node trees.
The Base class is the parent class of all unit classes.
Definition units.hh:121
STL list class.
Definition stl.hh:51
STL pair class.
Definition stl.hh:58
void set(Type mask)
Set all flag's bits matching the given mask.
Definition flags.hh:116
#define fatal(...)
This implements a cprintf based fatal() function.
Definition logging.hh:200
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition logging.hh:214
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 25 > vec
Definition misc.hh:113
unsigned int size_type
Definition types.hh:59
void registerHandlers(Handler reset_handler, Handler dump_handler)
const FlagsType init
This Stat is Initialized.
Definition info.hh:55
std::shared_ptr< Node > NodePtr
Shared pointer to a function Node.
void registerDumpCallback(const std::function< void()> &callback)
Register a callback that should be called whenever statistics are about to be dumped.
NameMapType & nameMap()
Definition info.cc:65
std::map< const void *, Info * > MapType
void processResetQueue()
Process all the callbacks in the reset callbacks queue.
void(* Handler)()
Register reset and dump handlers.
MapType & statsMap()
Definition statistics.cc:68
const Info * resolve(const std::string &name)
void registerResetCallback(const std::function< void()> &callback)
Register a callback that should be called whenever statistics are reset.
CallbackQueue resetQueue
CallbackQueue dumpQueue
std::list< Info * > & statsList()
Definition statistics.cc:61
void processDumpQueue()
Process all the callbacks in the dump callbacks queue.
void dump()
Dump all statistics data to the registered outputs.
double Result
All results are doubles.
Definition types.hh:55
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
void debugDumpStats()
Declaration of Statistics objects.
const std::string & name()
Definition trace.cc:48

Generated on Tue Jun 18 2024 16:24:01 for gem5 by doxygen 1.11.0