gem5  v22.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
53 namespace gem5
54 {
55 
56 GEM5_DEPRECATED_NAMESPACE(Stats, statistics);
57 namespace statistics
58 {
59 
60 // We wrap these in a function to make sure they're built in time.
63 {
64  static std::list<Info *> the_list;
65  return the_list;
66 }
67 
68 MapType &
70 {
71  static MapType the_map;
72  return the_map;
73 }
74 
75 void
77 {
78  panic_if(statsMap().find(this) != statsMap().end() ||
79  _info != nullptr,
80  "shouldn't register stat twice!");
81 
82  // New-style stats are reachable through the hierarchy and
83  // shouldn't be added to the global lists.
84  if (parent) {
85  _info = info;
86  return;
87  }
88 
89  statsList().push_back(info);
90 
91 #ifndef NDEBUG
93 #endif
94  statsMap().insert(std::make_pair(this, info));
95  assert(result.second && "this should never fail");
96  assert(statsMap().find(this) != statsMap().end());
97 }
98 
99 void
101 {
102  info()->setStorageParams(params);
103 }
104 
105 void
107 {
108  info()->flags.set(init);
109 }
110 
111 Info *
113 {
114  if (newStyleStats()) {
115  // New-style stats
116  return _info;
117  } else {
118  // Legacy stats
119  MapType::const_iterator i = statsMap().find(this);
120  assert(i != statsMap().end());
121  return (*i).second;
122  }
123 }
124 
125 const Info *
126 InfoAccess::info() const
127 {
128  if (newStyleStats()) {
129  // New-style stats
130  return _info;
131  } else {
132  // Legacy stats
133  MapType::const_iterator i = statsMap().find(this);
134  assert(i != statsMap().end());
135  return (*i).second;
136  }
137 }
138 
139 bool
141 {
142  return _info != nullptr;
143 }
144 
145 Formula::Formula(Group *parent, const char *name, const char *desc)
147  parent, name, units::Unspecified::get(), desc)
148 
149 {
150 }
151 
152 Formula::Formula(Group *parent, const char *name, const units::Base *unit,
153  const char *desc)
154  : DataWrapVec<Formula, FormulaInfoProxy>(parent, name, unit, desc)
155 {
156 }
157 
158 Formula::Formula(Group *parent, const char *name, const char *desc,
159  const Temp &r)
161  parent, name, units::Unspecified::get(), desc)
162 {
163  *this = r;
164 }
165 
166 Formula::Formula(Group *parent, const char *name, const units::Base *unit,
167  const char *desc, const Temp &r)
168  : DataWrapVec<Formula, FormulaInfoProxy>(parent, name, unit, desc)
169 {
170  *this = r;
171 }
172 
173 const Formula &
175 {
176  assert(!root && "Can't change formulas");
177  root = r.getNodePtr();
178  setInit();
179  assert(size());
180  return *this;
181 }
182 
183 const Formula &
185 {
186  if (root)
187  root = NodePtr(new BinaryNode<std::plus<Result> >(root, r));
188  else {
189  root = r.getNodePtr();
190  setInit();
191  }
192 
193  assert(size());
194  return *this;
195 }
196 
197 const Formula &
199 {
200  assert (root);
201  root = NodePtr(new BinaryNode<std::divides<Result> >(root, r));
202 
203  assert(size());
204  return *this;
205 }
206 
207 
208 void
210 {
211  if (root)
212  vec = root->result();
213 }
214 
215 Result
217 {
218  return root ? root->total() : 0.0;
219 }
220 
221 size_type
223 {
224  if (!root)
225  return 0;
226  else
227  return root->size();
228 }
229 
230 void
232 {
233 }
234 
235 bool
237 {
238  VResult vec;
239  result(vec);
240  for (VResult::size_type i = 0; i < vec.size(); ++i)
241  if (vec[i] != 0.0)
242  return false;
243  return true;
244 }
245 
246 std::string
248 {
249  return root ? root->str() : "";
250 }
251 
254 
255 void
256 registerHandlers(Handler reset_handler, Handler dump_handler)
257 {
258  resetHandler = reset_handler;
259  dumpHandler = dump_handler;
260 }
261 
264 
265 void
267 {
269 }
270 
271 void
273 {
274  dumpQueue.process();
275 }
276 
277 void
278 registerResetCallback(const std::function<void()> &callback)
279 {
280  resetQueue.push_back(callback);
281 }
282 
283 bool _enabled = false;
284 
285 bool
287 {
288  return _enabled;
289 }
290 
291 void
293 {
294  if (_enabled)
295  fatal("Stats are already enabled");
296 
297  _enabled = true;
298 }
299 
300 void
302 {
303  if (dumpHandler)
304  dumpHandler();
305  else
306  fatal("No registered statistics::dump handler");
307 }
308 
309 void
311 {
312  if (resetHandler)
313  resetHandler();
314  else
315  fatal("No registered statistics::reset handler");
316 }
317 
318 const Info *
319 resolve(const std::string &name)
320 {
321  const auto &it = nameMap().find(name);
322  if (it != nameMap().cend()) {
323  return it->second;
324  } else {
325  return Root::root()->resolveStat(name);
326  }
327 }
328 
329 void
330 registerDumpCallback(const std::function<void()> &callback)
331 {
332  dumpQueue.push_back(callback);
333 }
334 
335 } // namespace statistics
336 
337 void
339 {
341 }
342 
343 } // namespace gem5
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:190
gem5::statistics::Formula::reset
void reset()
Formulas don't need to be reset.
Definition: statistics.cc:231
gem5::CallbackQueue
Definition: callback.hh:38
gem5::statistics::units::Base
The Base class is the parent class of all unit classes.
Definition: units.hh:122
gem5::statistics::_enabled
bool _enabled
Definition: statistics.cc:283
gem5::statistics::Result
double Result
All results are doubles.
Definition: types.hh:56
gem5::statistics::resetHandler
Handler resetHandler
Definition: statistics.cc:252
gem5::statistics::resolve
const Info * resolve(const std::string &name)
Definition: statistics.cc:319
gem5::Flags::set
void set(Type mask)
Set all flag's bits matching the given mask.
Definition: flags.hh:116
gem5::statistics::resetQueue
CallbackQueue resetQueue
Definition: statistics.cc:263
gem5::statistics::InfoAccess::_info
Info * _info
Definition: statistics.hh:186
gem5::statistics::Temp
Helper class to construct formula node trees.
Definition: statistics.hh:2650
gem5::statistics::Formula
A formula for statistics that is calculated when printed.
Definition: statistics.hh:2539
std::vector< Result >
gem5::VegaISA::r
Bitfield< 5 > r
Definition: pagetable.hh:60
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:67
gem5::statistics::Formula::operator/=
const Formula & operator/=(Temp r)
Divide the existing tree by the given one.
Definition: statistics.cc:198
gem5::statistics::Formula::result
void result(VResult &vec) const
Return the result of the Fomula in a vector.
Definition: statistics.cc:209
gem5::statistics::Group::resolveStat
const Info * resolveStat(std::string name) const
Resolve a stat by its name within this group.
Definition: group.cc:128
gem5::statistics::Info::flags
Flags flags
The formatting flags.
Definition: info.hh:92
root.hh
gem5::statistics::registerHandlers
void registerHandlers(Handler reset_handler, Handler dump_handler)
Definition: statistics.cc:256
gem5::statistics::registerDumpCallback
void registerDumpCallback(const std::function< void()> &callback)
Register a callback that should be called whenever statistics are about to be dumped.
Definition: statistics.cc:330
gem5::statistics::InfoAccess::newStyleStats
bool newStyleStats() const
Check if the info is new style stats.
Definition: statistics.cc:140
gem5::statistics::InfoAccess::info
Info * info()
Grab the information class for this statistic.
Definition: statistics.cc:112
gem5::statistics::statsMap
MapType & statsMap()
Definition: statistics.cc:69
gem5::statistics::enable
void enable()
Definition: statistics.cc:292
gem5::statistics::FormulaInfoProxy
Definition: statistics.hh:2376
statistics.hh
gem5::statistics::reset
void reset()
Definition: statistics.cc:310
gem5::statistics::dump
void dump()
Dump all statistics data to the registered outputs.
Definition: statistics.cc:301
gem5::statistics::InfoAccess::setInit
void setInit()
Save Storage class parameters if any.
Definition: statistics.cc:106
gem5::statistics::registerResetCallback
void registerResetCallback(const std::function< void()> &callback)
Register a callback that should be called whenever statistics are reset.
Definition: statistics.cc:278
gem5::statistics::processDumpQueue
void processDumpQueue()
Process all the callbacks in the dump callbacks queue.
Definition: statistics.cc:272
std::pair
STL pair class.
Definition: stl.hh:58
gem5::statistics::size_type
unsigned int size_type
Definition: types.hh:60
gem5::statistics::Formula::root
NodePtr root
The root of the tree which represents the Formula.
Definition: statistics.hh:2543
gem5::debugDumpStats
void debugDumpStats()
Definition: statistics.cc:338
gem5::GEM5_DEPRECATED_NAMESPACE
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
name
const std::string & name()
Definition: trace.cc:49
gem5::statistics::Handler
void(* Handler)()
Register reset and dump handlers.
Definition: statistics.hh:2895
gem5::statistics::enabled
bool enabled()
Definition: statistics.cc:286
gem5::statistics::statsList
std::list< Info * > & statsList()
Definition: statistics.cc:62
gem5::statistics::dumpQueue
CallbackQueue dumpQueue
Definition: statistics.cc:262
panic_if
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:204
gem5::statistics::Formula::str
std::string str() const
Definition: statistics.cc:247
gem5::statistics::nameMap
NameMapType & nameMap()
Definition: info.cc:66
gem5::statistics::StorageParams
Definition: storage.hh:49
gem5::statistics::processResetQueue
void processResetQueue()
Process all the callbacks in the reset callbacks queue.
Definition: statistics.cc:266
gem5::statistics::Formula::operator=
const Formula & operator=(const Temp &r)
Set an unitialized Formula to the given root.
Definition: statistics.cc:174
gem5::statistics::MapType
std::map< const void *, Info * > MapType
Definition: statistics.hh:2923
gem5::PowerISA::vec
Bitfield< 25 > vec
Definition: misc.hh:108
gem5::statistics::NodePtr
std::shared_ptr< Node > NodePtr
Shared pointer to a function Node.
Definition: statistics.hh:1551
logging.hh
gem5::statistics::Group
Statistics container.
Definition: group.hh:93
gem5::statistics::Info::setStorageParams
void setStorageParams(const StorageParams *const params)
Setter for the storage params.
Definition: info.cc:91
gem5::statistics::init
const FlagsType init
This Stat is Initialized.
Definition: info.hh:56
gem5::statistics::BinaryNode
Definition: statistics.hh:1767
gem5::statistics::InfoAccess::setInfo
void setInfo(Group *parent, Info *info)
Set up an info class for this statistic.
Definition: statistics.cc:76
std::list
STL list class.
Definition: stl.hh:51
gem5::statistics::Formula::operator+=
const Formula & operator+=(Temp r)
Add the given tree to the existing one.
Definition: statistics.cc:184
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::statistics::Formula::total
Result total() const
Return the total Formula result.
Definition: statistics.cc:216
gem5::statistics::DataWrapVec
Definition: statistics.hh:380
gem5::statistics::InfoAccess::setParams
void setParams(const StorageParams *params)
Save Storage class parameters if any.
Definition: statistics.cc:100
gem5::CallbackQueue::process
void process()
Definition: callback.hh:49
gem5::statistics::Formula::size
size_type size() const
Return the number of elements in the tree.
Definition: statistics.cc:222
gem5::Root::root
static Root * root()
Use this function to get a pointer to the single Root object in the simulation.
Definition: root.hh:93
gem5::statistics::Formula::Formula
Formula(Group *parent=nullptr, const char *name=nullptr, const char *desc=nullptr)
Create and initialize thie formula, and register it with the database.
Definition: statistics.cc:145
callback.hh
gem5::statistics::dumpHandler
Handler dumpHandler
Definition: statistics.cc:253
gem5::statistics::Formula::zero
bool zero() const
Definition: statistics.cc:236
gem5::statistics::Info
Definition: info.hh:80

Generated on Thu Jun 16 2022 10:41:45 for gem5 by doxygen 1.8.17