gem5  [DEVELOP-FOR-23.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 namespace 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 
67 MapType &
69 {
70  static MapType the_map;
71  return the_map;
72 }
73 
74 void
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 
98 void
100 {
101  info()->setStorageParams(params);
102 }
103 
104 void
106 {
107  info()->flags.set(init);
108 }
109 
110 Info *
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 
124 const Info *
125 InfoAccess::info() const
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 
138 bool
140 {
141  return _info != nullptr;
142 }
143 
144 Formula::Formula(Group *parent, const char *name, const char *desc)
146  parent, name, units::Unspecified::get(), desc)
147 
148 {
149 }
150 
151 Formula::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 
157 Formula::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 
165 Formula::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 
172 const Formula &
174 {
175  assert(!root && "Can't change formulas");
176  root = r.getNodePtr();
177  setInit();
178  assert(size());
179  return *this;
180 }
181 
182 const 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 
196 const 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 
207 void
209 {
210  if (root)
211  vec = root->result();
212 }
213 
214 Result
216 {
217  return root ? root->total() : 0.0;
218 }
219 
220 size_type
222 {
223  if (!root)
224  return 0;
225  else
226  return root->size();
227 }
228 
229 void
231 {
232 }
233 
234 bool
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 
245 std::string
247 {
248  return root ? root->str() : "";
249 }
250 
253 
254 void
255 registerHandlers(Handler reset_handler, Handler dump_handler)
256 {
257  resetHandler = reset_handler;
258  dumpHandler = dump_handler;
259 }
260 
263 
264 void
266 {
268 }
269 
270 void
272 {
273  dumpQueue.process();
274 }
275 
276 void
277 registerResetCallback(const std::function<void()> &callback)
278 {
279  resetQueue.push_back(callback);
280 }
281 
282 bool _enabled = false;
283 
284 bool
286 {
287  return _enabled;
288 }
289 
290 void
292 {
293  if (_enabled)
294  fatal("Stats are already enabled");
295 
296  _enabled = true;
297 }
298 
299 void
301 {
302  if (dumpHandler)
303  dumpHandler();
304  else
305  fatal("No registered statistics::dump handler");
306 }
307 
308 void
310 {
311  if (resetHandler)
312  resetHandler();
313  else
314  fatal("No registered statistics::reset handler");
315 }
316 
317 const Info *
318 resolve(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 
328 void
329 registerDumpCallback(const std::function<void()> &callback)
330 {
331  dumpQueue.push_back(callback);
332 }
333 
334 } // namespace statistics
335 
336 void
338 {
340 }
341 
342 } // namespace gem5
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:200
gem5::statistics::Formula::reset
void reset()
Formulas don't need to be reset.
Definition: statistics.cc:230
gem5::CallbackQueue
Definition: callback.hh:38
gem5::statistics::units::Base
The Base class is the parent class of all unit classes.
Definition: units.hh:120
gem5::statistics::_enabled
bool _enabled
Definition: statistics.cc:282
gem5::statistics::Result
double Result
All results are doubles.
Definition: types.hh:55
gem5::statistics::resetHandler
Handler resetHandler
Definition: statistics.cc:251
gem5::statistics::resolve
const Info * resolve(const std::string &name)
Definition: statistics.cc:318
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:262
gem5::statistics::InfoAccess::_info
Info * _info
Definition: statistics.hh:185
gem5::statistics::Temp
Helper class to construct formula node trees.
Definition: statistics.hh:2649
gem5::statistics::Formula
A formula for statistics that is calculated when printed.
Definition: statistics.hh:2538
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:197
gem5::statistics::Formula::result
void result(VResult &vec) const
Return the result of the Fomula in a vector.
Definition: statistics.cc:208
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:91
root.hh
gem5::statistics::registerHandlers
void registerHandlers(Handler reset_handler, Handler dump_handler)
Definition: statistics.cc:255
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:329
gem5::statistics::InfoAccess::newStyleStats
bool newStyleStats() const
Check if the info is new style stats.
Definition: statistics.cc:139
gem5::statistics::InfoAccess::info
Info * info()
Grab the information class for this statistic.
Definition: statistics.cc:111
gem5::statistics::statsMap
MapType & statsMap()
Definition: statistics.cc:68
gem5::statistics::enable
void enable()
Definition: statistics.cc:291
gem5::statistics::FormulaInfoProxy
Definition: statistics.hh:2375
statistics.hh
gem5::statistics::reset
void reset()
Definition: statistics.cc:309
gem5::statistics::dump
void dump()
Dump all statistics data to the registered outputs.
Definition: statistics.cc:300
gem5::statistics::InfoAccess::setInit
void setInit()
Save Storage class parameters if any.
Definition: statistics.cc:105
gem5::statistics::registerResetCallback
void registerResetCallback(const std::function< void()> &callback)
Register a callback that should be called whenever statistics are reset.
Definition: statistics.cc:277
gem5::statistics::processDumpQueue
void processDumpQueue()
Process all the callbacks in the dump callbacks queue.
Definition: statistics.cc:271
std::pair
STL pair class.
Definition: stl.hh:58
gem5::statistics::size_type
unsigned int size_type
Definition: types.hh:59
gem5::statistics::Formula::root
NodePtr root
The root of the tree which represents the Formula.
Definition: statistics.hh:2542
gem5::debugDumpStats
void debugDumpStats()
Definition: statistics.cc:337
name
const std::string & name()
Definition: trace.cc:48
gem5::statistics::Handler
void(* Handler)()
Register reset and dump handlers.
Definition: statistics.hh:2894
gem5::statistics::enabled
bool enabled()
Definition: statistics.cc:285
gem5::statistics::statsList
std::list< Info * > & statsList()
Definition: statistics.cc:61
gem5::statistics::dumpQueue
CallbackQueue dumpQueue
Definition: statistics.cc:261
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:214
gem5::statistics::Formula::str
std::string str() const
Definition: statistics.cc:246
gem5::statistics::nameMap
NameMapType & nameMap()
Definition: info.cc:65
gem5::statistics::StorageParams
Definition: storage.hh:48
gem5::statistics::processResetQueue
void processResetQueue()
Process all the callbacks in the reset callbacks queue.
Definition: statistics.cc:265
gem5::statistics::Formula::operator=
const Formula & operator=(const Temp &r)
Set an unitialized Formula to the given root.
Definition: statistics.cc:173
gem5::statistics::MapType
std::map< const void *, Info * > MapType
Definition: statistics.hh:2922
gem5::PowerISA::vec
Bitfield< 25 > vec
Definition: misc.hh:113
gem5::statistics::NodePtr
std::shared_ptr< Node > NodePtr
Shared pointer to a function Node.
Definition: statistics.hh:1550
logging.hh
gem5::statistics::Group
Statistics container.
Definition: group.hh:92
gem5::statistics::Info::setStorageParams
void setStorageParams(const StorageParams *const params)
Setter for the storage params.
Definition: info.cc:90
gem5::statistics::init
const FlagsType init
This Stat is Initialized.
Definition: info.hh:55
gem5::statistics::BinaryNode
Definition: statistics.hh:1766
gem5::statistics::InfoAccess::setInfo
void setInfo(Group *parent, Info *info)
Set up an info class for this statistic.
Definition: statistics.cc:75
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:183
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:215
gem5::statistics::DataWrapVec
Definition: statistics.hh:379
gem5::statistics::InfoAccess::setParams
void setParams(const StorageParams *params)
Save Storage class parameters if any.
Definition: statistics.cc:99
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:221
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:144
callback.hh
gem5::statistics::dumpHandler
Handler dumpHandler
Definition: statistics.cc:252
gem5::statistics::Formula::zero
bool zero() const
Definition: statistics.cc:235
gem5::statistics::Info
Definition: info.hh:79

Generated on Sun Jul 30 2023 01:56:51 for gem5 by doxygen 1.8.17