gem5  v21.1.0.2
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 (_info) {
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 (_info) {
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 Formula::Formula(Group *parent, const char *name, const char *desc)
141  parent, name, units::Unspecified::get(), desc)
142 
143 {
144 }
145 
146 Formula::Formula(Group *parent, const char *name, const units::Base *unit,
147  const char *desc)
148  : DataWrapVec<Formula, FormulaInfoProxy>(parent, name, unit, desc)
149 {
150 }
151 
152 Formula::Formula(Group *parent, const char *name, const char *desc,
153  const Temp &r)
155  parent, name, units::Unspecified::get(), desc)
156 {
157  *this = r;
158 }
159 
160 Formula::Formula(Group *parent, const char *name, const units::Base *unit,
161  const char *desc, const Temp &r)
162  : DataWrapVec<Formula, FormulaInfoProxy>(parent, name, unit, desc)
163 {
164  *this = r;
165 }
166 
167 const Formula &
169 {
170  assert(!root && "Can't change formulas");
171  root = r.getNodePtr();
172  setInit();
173  assert(size());
174  return *this;
175 }
176 
177 const Formula &
179 {
180  if (root)
181  root = NodePtr(new BinaryNode<std::plus<Result> >(root, r));
182  else {
183  root = r.getNodePtr();
184  setInit();
185  }
186 
187  assert(size());
188  return *this;
189 }
190 
191 const Formula &
193 {
194  assert (root);
195  root = NodePtr(new BinaryNode<std::divides<Result> >(root, r));
196 
197  assert(size());
198  return *this;
199 }
200 
201 
202 void
204 {
205  if (root)
206  vec = root->result();
207 }
208 
209 Result
211 {
212  return root ? root->total() : 0.0;
213 }
214 
215 size_type
217 {
218  if (!root)
219  return 0;
220  else
221  return root->size();
222 }
223 
224 void
226 {
227 }
228 
229 bool
231 {
232  VResult vec;
233  result(vec);
234  for (VResult::size_type i = 0; i < vec.size(); ++i)
235  if (vec[i] != 0.0)
236  return false;
237  return true;
238 }
239 
240 std::string
242 {
243  return root ? root->str() : "";
244 }
245 
248 
249 void
250 registerHandlers(Handler reset_handler, Handler dump_handler)
251 {
252  resetHandler = reset_handler;
253  dumpHandler = dump_handler;
254 }
255 
258 
259 void
261 {
263 }
264 
265 void
267 {
268  dumpQueue.process();
269 }
270 
271 void
272 registerResetCallback(const std::function<void()> &callback)
273 {
274  resetQueue.push_back(callback);
275 }
276 
277 bool _enabled = false;
278 
279 bool
281 {
282  return _enabled;
283 }
284 
285 void
287 {
288  if (_enabled)
289  fatal("Stats are already enabled");
290 
291  _enabled = true;
292 }
293 
294 void
296 {
297  if (dumpHandler)
298  dumpHandler();
299  else
300  fatal("No registered statistics::dump handler");
301 }
302 
303 void
305 {
306  if (resetHandler)
307  resetHandler();
308  else
309  fatal("No registered statistics::reset handler");
310 }
311 
312 const Info *
313 resolve(const std::string &name)
314 {
315  const auto &it = nameMap().find(name);
316  if (it != nameMap().cend()) {
317  return it->second;
318  } else {
319  return Root::root()->resolveStat(name);
320  }
321 }
322 
323 void
324 registerDumpCallback(const std::function<void()> &callback)
325 {
326  dumpQueue.push_back(callback);
327 }
328 
329 } // namespace statistics
330 
331 void
333 {
335 }
336 
337 } // namespace gem5
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:189
gem5::statistics::Formula::reset
void reset()
Formulas don't need to be reset.
Definition: statistics.cc:225
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:277
gem5::statistics::Result
double Result
All results are doubles.
Definition: types.hh:56
gem5::statistics::resetHandler
Handler resetHandler
Definition: statistics.cc:246
gem5::statistics::resolve
const Info * resolve(const std::string &name)
Definition: statistics.cc:313
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:257
gem5::statistics::InfoAccess::_info
Info * _info
Definition: statistics.hh:186
gem5::statistics::Temp
Helper class to construct formula node trees.
Definition: statistics.hh:2647
gem5::statistics::Formula
A formula for statistics that is calculated when printed.
Definition: statistics.hh:2536
std::vector< Result >
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:66
gem5::statistics::Formula::operator/=
const Formula & operator/=(Temp r)
Divide the existing tree by the given one.
Definition: statistics.cc:192
gem5::statistics::Formula::result
void result(VResult &vec) const
Return the result of the Fomula in a vector.
Definition: statistics.cc:203
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:250
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:324
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:286
gem5::statistics::FormulaInfoProxy
Definition: statistics.hh:2373
statistics.hh
gem5::statistics::reset
void reset()
Definition: statistics.cc:304
gem5::statistics::dump
void dump()
Dump all statistics data to the registered outputs.
Definition: statistics.cc:295
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:272
gem5::statistics::processDumpQueue
void processDumpQueue()
Process all the callbacks in the dump callbacks queue.
Definition: statistics.cc:266
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:2540
gem5::debugDumpStats
void debugDumpStats()
Definition: statistics.cc:332
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:2892
gem5::statistics::enabled
bool enabled()
Definition: statistics.cc:280
gem5::statistics::statsList
std::list< Info * > & statsList()
Definition: statistics.cc:62
gem5::statistics::dumpQueue
CallbackQueue dumpQueue
Definition: statistics.cc:256
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:203
gem5::statistics::Formula::str
std::string str() const
Definition: statistics.cc:241
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:260
gem5::statistics::Formula::operator=
const Formula & operator=(const Temp &r)
Set an unitialized Formula to the given root.
Definition: statistics.cc:168
gem5::statistics::MapType
std::map< const void *, Info * > MapType
Definition: statistics.hh:2920
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:1548
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::MipsISA::r
r
Definition: pra_constants.hh:98
gem5::statistics::init
const FlagsType init
This Stat is Initialized.
Definition: info.hh:56
gem5::statistics::BinaryNode
Definition: statistics.hh:1764
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:178
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::statistics::Formula::total
Result total() const
Return the total Formula result.
Definition: statistics.cc:210
gem5::statistics::DataWrapVec
Definition: statistics.hh:377
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:216
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:139
callback.hh
gem5::statistics::dumpHandler
Handler dumpHandler
Definition: statistics.cc:247
gem5::statistics::Formula::zero
bool zero() const
Definition: statistics.cc:230
gem5::statistics::Info
Definition: info.hh:80

Generated on Tue Sep 21 2021 12:24:57 for gem5 by doxygen 1.8.17