gem5  v22.1.0.0
statistics.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Inria
3  * Copyright (c) 2019-2020 Arm Limited
4  * All rights reserved.
5  *
6  * The license below extends only to copyright in the software and shall
7  * not be construed as granting a license to any other intellectual
8  * property including but not limited to intellectual property relating
9  * to a hardware implementation of the functionality of the software
10  * licensed hereunder. You may use the software subject to the license
11  * terms below provided that you ensure that this notice is replicated
12  * unmodified and in its entirety in all distributions of the software,
13  * modified or unmodified, in source code or in binary form.
14  *
15  * Copyright (c) 2003-2005 The Regents of The University of Michigan
16  * Copyright (c) 2017, Centre National de la Recherche Scientifique
17  * All rights reserved.
18  *
19  * Redistribution and use in source and binary forms, with or without
20  * modification, are permitted provided that the following conditions are
21  * met: redistributions of source code must retain the above copyright
22  * notice, this list of conditions and the following disclaimer;
23  * redistributions in binary form must reproduce the above copyright
24  * notice, this list of conditions and the following disclaimer in the
25  * documentation and/or other materials provided with the distribution;
26  * neither the name of the copyright holders nor the names of its
27  * contributors may be used to endorse or promote products derived from
28  * this software without specific prior written permission.
29  *
30  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41  */
42 
59 #ifndef __BASE_STATISTICS_HH__
60 #define __BASE_STATISTICS_HH__
61 
62 #include <algorithm>
63 #include <cassert>
64 #ifdef __SUNPRO_CC
65 #include <math.h>
66 #endif
67 #include <cmath>
68 #include <functional>
69 #include <iosfwd>
70 #include <list>
71 #include <map>
72 #include <memory>
73 #include <string>
74 #include <vector>
75 
76 #include "base/cast.hh"
77 #include "base/compiler.hh"
78 #include "base/cprintf.hh"
79 #include "base/intmath.hh"
80 #include "base/logging.hh"
81 #include "base/stats/group.hh"
82 #include "base/stats/info.hh"
83 #include "base/stats/output.hh"
84 #include "base/stats/storage.hh"
85 #include "base/stats/types.hh"
86 #include "base/stats/units.hh"
87 #include "base/str.hh"
88 #include "base/types.hh"
89 
90 namespace gem5
91 {
92 
93 /* A namespace for all of the Statistics */
94 GEM5_DEPRECATED_NAMESPACE(Stats, statistics);
95 namespace statistics
96 {
97 
98 template <class Stat, class Base>
99 class InfoProxy : public Base
100 {
101  protected:
102  Stat &s;
103 
104  public:
105  InfoProxy(Stat &stat) : s(stat) {}
106 
107  bool check() const { return s.check(); }
108  void prepare() { s.prepare(); }
109  void reset() { s.reset(); }
110  void
111  visit(Output &visitor)
112  {
113  visitor.visit(*static_cast<Base *>(this));
114  }
115  bool zero() const { return s.zero(); }
116 };
117 
118 template <class Stat>
119 class ScalarInfoProxy : public InfoProxy<Stat, ScalarInfo>
120 {
121  public:
122  ScalarInfoProxy(Stat &stat) : InfoProxy<Stat, ScalarInfo>(stat) {}
123 
124  Counter value() const { return this->s.value(); }
125  Result result() const { return this->s.result(); }
126  Result total() const { return this->s.total(); }
127 };
128 
129 template <class Stat>
130 class VectorInfoProxy : public InfoProxy<Stat, VectorInfo>
131 {
132  protected:
133  mutable VCounter cvec;
134  mutable VResult rvec;
135 
136  public:
137  VectorInfoProxy(Stat &stat) : InfoProxy<Stat, VectorInfo>(stat) {}
138 
139  size_type size() const { return this->s.size(); }
140 
141  VCounter &
142  value() const
143  {
144  this->s.value(cvec);
145  return cvec;
146  }
147 
148  const VResult &
149  result() const
150  {
151  this->s.result(rvec);
152  return rvec;
153  }
154 
155  Result total() const { return this->s.total(); }
156 };
157 
158 template <class Stat>
159 class DistInfoProxy : public InfoProxy<Stat, DistInfo>
160 {
161  public:
162  DistInfoProxy(Stat &stat) : InfoProxy<Stat, DistInfo>(stat) {}
163 };
164 
165 template <class Stat>
166 class VectorDistInfoProxy : public InfoProxy<Stat, VectorDistInfo>
167 {
168  public:
169  VectorDistInfoProxy(Stat &stat) : InfoProxy<Stat, VectorDistInfo>(stat) {}
170 
171  size_type size() const { return this->s.size(); }
172 };
173 
174 template <class Stat>
175 class Vector2dInfoProxy : public InfoProxy<Stat, Vector2dInfo>
176 {
177  public:
178  Vector2dInfoProxy(Stat &stat) : InfoProxy<Stat, Vector2dInfo>(stat) {}
179 
180  Result total() const { return this->s.total(); }
181 };
182 
184 {
185  private:
187 
188  protected:
190  void setInfo(Group *parent, Info *info);
192  void setParams(const StorageParams *params);
194  void setInit();
195 
197  Info *info();
199  const Info *info() const;
200 
202  bool newStyleStats() const;
203 
204  public:
206  : _info(nullptr) {};
207 
211  void reset() { }
212 
217  bool zero() const { return true; }
218 
224  bool check() const { return true; }
225 };
226 
227 template <class Derived, template <class> class InfoProxyType>
228 class DataWrap : public InfoAccess
229 {
230  public:
231  typedef InfoProxyType<Derived> Info;
232 
233  protected:
234  Derived &self() { return *static_cast<Derived *>(this); }
235 
236  protected:
237  Info *
239  {
240  return safe_cast<Info *>(InfoAccess::info());
241  }
242 
243  public:
244  const Info *
245  info() const
246  {
247  return safe_cast<const Info *>(InfoAccess::info());
248  }
249 
250  public:
251  DataWrap() = delete;
252  DataWrap(const DataWrap &) = delete;
253  DataWrap &operator=(const DataWrap &) = delete;
254 
255  DataWrap(Group *parent, const char *name, const units::Base *unit,
256  const char *desc)
257  {
258  auto info = new Info(self());
259  this->setInfo(parent, info);
260 
261  if (parent)
262  parent->addStat(info);
263 
264  if (name) {
265  info->setName(name, !newStyleStats());
266  info->flags.set(display);
267  }
268 
269  info->unit = unit;
270 
271  if (desc)
272  info->desc = desc;
273 
274  // Stat that does not belong to any statistics::Group is a legacy stat
275  std::string common_message = "Legacy stat is a stat that does not "
276  "belong to any statistics::Group. Legacy stat is deprecated.";
277  if (parent == nullptr && name != nullptr)
278  warn(csprintf("`%s` is a legacy stat. %s", name, common_message));
279  else if (parent == nullptr)
280  warn_once("One of the stats is a legacy stat. " + common_message);
281  }
282 
288  Derived &
289  name(const std::string &name)
290  {
291  Info *info = this->info();
292  info->setName(name, !newStyleStats());
293  info->flags.set(display);
294  return this->self();
295  }
296  const std::string &name() const { return this->info()->name; }
297 
304  Derived &
305  setSeparator(const std::string &_sep)
306  {
307  this->info()->setSeparator(_sep);
308  return this->self();
309  }
310  const std::string &setSeparator() const
311  {
312  return this->info()->separatorString;
313  }
314 
320  Derived &
321  unit(const units::Base *_unit)
322  {
323  this->info()->unit = _unit;
324  return this->self();
325  }
326 
333  Derived &
334  desc(const std::string &_desc)
335  {
336  this->info()->desc = _desc;
337  return this->self();
338  }
339 
345  Derived &
346  precision(int _precision)
347  {
348  this->info()->precision = _precision;
349  return this->self();
350  }
351 
357  Derived &
358  flags(Flags _flags)
359  {
360  this->info()->flags.set(_flags);
361  return this->self();
362  }
363 
370  template <class Stat>
371  Derived &
372  prereq(const Stat &prereq)
373  {
374  this->info()->prereq = prereq.info();
375  return this->self();
376  }
377 };
378 
379 template <class Derived, template <class> class InfoProxyType>
380 class DataWrapVec : public DataWrap<Derived, InfoProxyType>
381 {
382  public:
383  typedef InfoProxyType<Derived> Info;
384 
385  DataWrapVec(Group *parent = nullptr, const char *name = nullptr,
387  const char *desc = nullptr)
388  : DataWrap<Derived, InfoProxyType>(parent, name, unit, desc)
389  {}
390 
391  // The following functions are specific to vectors. If you use them
392  // in a non vector context, you will get a nice compiler error!
393 
401  Derived &
402  subname(off_type index, const std::string &name)
403  {
404  Derived &self = this->self();
405  Info *info = self.info();
406 
407  std::vector<std::string> &subn = info->subnames;
408  if (subn.size() <= index)
409  subn.resize(index + 1);
410  subn[index] = name;
411  return self;
412  }
413 
414  // The following functions are specific to 2d vectors. If you use
415  // them in a non vector context, you will get a nice compiler
416  // error because info doesn't have the right variables.
417 
425  Derived &
426  subdesc(off_type index, const std::string &desc)
427  {
428  Info *info = this->info();
429 
430  std::vector<std::string> &subd = info->subdescs;
431  if (subd.size() <= index)
432  subd.resize(index + 1);
433  subd[index] = desc;
434 
435  return this->self();
436  }
437 
438  void
440  {
441  Derived &self = this->self();
442  Info *info = this->info();
443 
444  size_t size = self.size();
445  for (off_type i = 0; i < size; ++i)
446  self.data(i)->prepare(info->getStorageParams());
447  }
448 
449  void
451  {
452  Derived &self = this->self();
453  Info *info = this->info();
454 
455  size_t size = self.size();
456  for (off_type i = 0; i < size; ++i)
457  self.data(i)->reset(info->getStorageParams());
458  }
459 };
460 
461 template <class Derived, template <class> class InfoProxyType>
462 class DataWrapVec2d : public DataWrapVec<Derived, InfoProxyType>
463 {
464  public:
465  typedef InfoProxyType<Derived> Info;
466 
467  DataWrapVec2d(Group *parent, const char *name,
468  const units::Base *unit, const char *desc)
469  : DataWrapVec<Derived, InfoProxyType>(parent, name, unit, desc)
470  {
471  }
472 
477  Derived &
478  ysubnames(const char **names)
479  {
480  Derived &self = this->self();
481  Info *info = this->info();
482 
483  info->y_subnames.resize(self.y);
484  for (off_type i = 0; i < self.y; ++i)
485  info->y_subnames[i] = names[i];
486  return self;
487  }
488 
489  Derived &
490  ysubname(off_type index, const std::string &subname)
491  {
492  Derived &self = this->self();
493  Info *info = this->info();
494 
495  assert(index < self.y);
496  info->y_subnames.resize(self.y);
497  info->y_subnames[index] = subname.c_str();
498  return self;
499  }
500 
501  std::string
503  {
504  return this->info()->y_subnames[i];
505  }
506 
507 };
508 
510 //
511 // Simple Statistics
512 //
514 
519 template <class Derived, class Stor>
520 class ScalarBase : public DataWrap<Derived, ScalarInfoProxy>
521 {
522  public:
523  typedef Stor Storage;
524  typedef typename Stor::Params Params;
525 
526  protected:
528  GEM5_ALIGNED(8) char storage[sizeof(Storage)];
529 
530  protected:
536  Storage *
538  {
539  return reinterpret_cast<Storage *>(storage);
540  }
541 
548  const Storage *
549  data() const
550  {
551  return reinterpret_cast<const Storage *>(storage);
552  }
553 
554  void
556  {
557  new (storage) Storage(this->info()->getStorageParams());
558  this->setInit();
559  }
560 
561  public:
562  ScalarBase(Group *parent = nullptr, const char *name = nullptr,
564  const char *desc = nullptr)
565  : DataWrap<Derived, ScalarInfoProxy>(parent, name, unit, desc)
566  {
567  this->doInit();
568  }
569 
570  public:
571  // Common operators for stats
576  void operator++() { data()->inc(1); }
581  void operator--() { data()->dec(1); }
582 
584  void operator++(int) { ++*this; }
586  void operator--(int) { --*this; }
587 
593  template <typename U>
594  void operator=(const U &v) { data()->set(v); }
595 
601  template <typename U>
602  void operator+=(const U &v) { data()->inc(v); }
603 
609  template <typename U>
610  void operator-=(const U &v) { data()->dec(v); }
611 
616  size_type size() const { return 1; }
617 
622  Counter value() const { return data()->value(); }
623 
624  Result result() const { return data()->result(); }
625 
626  Result total() const { return result(); }
627 
628  bool zero() const { return result() == 0.0; }
629 
630  void reset() { data()->reset(this->info()->getStorageParams()); }
631  void prepare() { data()->prepare(this->info()->getStorageParams()); }
632 };
633 
634 class ProxyInfo : public ScalarInfo
635 {
636  public:
637  std::string str() const { return std::to_string(value()); }
638  size_type size() const { return 1; }
639  bool check() const { return true; }
640  void prepare() { }
641  void reset() { }
642  bool zero() const { return value() == 0; }
643 
644  void visit(Output &visitor) { visitor.visit(*this); }
645 };
646 
647 template <class T>
648 class ValueProxy : public ProxyInfo
649 {
650  private:
651  T *scalar;
652 
653  public:
655  Counter value() const { return *scalar; }
656  Result result() const { return *scalar; }
657  Result total() const { return *scalar; }
658 };
659 
660 template <class T, class Enabled=void>
661 class FunctorProxy : public ProxyInfo
662 {
663  private:
665 
666  public:
667  FunctorProxy(T &func) : functor(&func) {}
668  Counter value() const { return (*functor)(); }
669  Result result() const { return (*functor)(); }
670  Result total() const { return (*functor)(); }
671 };
672 
679 template <class T>
680 class FunctorProxy<T,
681  typename std::enable_if_t<std::is_constructible_v<std::function<Result()>,
682  const T &>>> : public ProxyInfo
683 {
684  private:
685  std::function<Result()> functor;
686 
687  public:
688  FunctorProxy(const T &func) : functor(func) {}
689  Counter value() const { return functor(); }
690  Result result() const { return functor(); }
691  Result total() const { return functor(); }
692 };
693 
698 template <class T, class V>
699 class MethodProxy : public ProxyInfo
700 {
701  private:
702  T *object;
703  typedef V (T::*MethodPointer) () const;
705 
706  public:
707  MethodProxy(T *obj, MethodPointer meth) : object(obj), method(meth) {}
708  Counter value() const { return (object->*method)(); }
709  Result result() const { return (object->*method)(); }
710  Result total() const { return (object->*method)(); }
711 };
712 
713 template <class Derived>
714 class ValueBase : public DataWrap<Derived, ScalarInfoProxy>
715 {
716  private:
718 
719  public:
720  ValueBase(Group *parent, const char *name,
721  const units::Base *unit,
722  const char *desc)
723  : DataWrap<Derived, ScalarInfoProxy>(parent, name, unit, desc),
724  proxy(NULL)
725  {
726  }
727 
728  ~ValueBase() { if (proxy) delete proxy; }
729 
730  template <class T>
731  Derived &
733  {
734  proxy = new ValueProxy<T>(value);
735  this->setInit();
736  return this->self();
737  }
738 
739  template <class T>
740  Derived &
741  functor(const T &func)
742  {
743  proxy = new FunctorProxy<T>(func);
744  this->setInit();
745  return this->self();
746  }
747 
748  template <class T>
749  Derived &
750  functor(T &func)
751  {
752  proxy = new FunctorProxy<T>(func);
753  this->setInit();
754  return this->self();
755  }
756 
764  template <class T, class V>
765  Derived &
766  method(T *obj, V (T::*method)() const)
767  {
768  proxy = new MethodProxy<T,V>(obj, method);
769  this->setInit();
770  return this->self();
771  }
772 
773  Counter value() { return proxy->value(); }
774  Result result() const { return proxy->result(); }
775  Result total() const { return proxy->total(); };
776  size_type size() const { return proxy->size(); }
777 
778  std::string str() const { return proxy->str(); }
779  bool zero() const { return proxy->zero(); }
780  bool check() const { return proxy != NULL; }
781  void prepare() { }
782  void reset() { }
783 };
784 
786 //
787 // Vector Statistics
788 //
790 
795 template <class Stat>
797 {
798  private:
800  Stat &stat;
801 
804 
805  public:
810  Counter value() const { return stat.data(index)->value(); }
811 
816  Result result() const { return stat.data(index)->result(); }
817 
818  public:
824  : stat(s), index(i)
825  {
826  }
827 
833  : stat(sp.stat), index(sp.index)
834  {}
835 
841  const ScalarProxy &
843  {
844  stat = sp.stat;
845  index = sp.index;
846  return *this;
847  }
848 
849  public:
850  // Common operators for stats
855  void operator++() { stat.data(index)->inc(1); }
860  void operator--() { stat.data(index)->dec(1); }
861 
863  void operator++(int) { ++*this; }
865  void operator--(int) { --*this; }
866 
872  template <typename U>
873  void
874  operator=(const U &v)
875  {
876  stat.data(index)->set(v);
877  }
878 
884  template <typename U>
885  void
886  operator+=(const U &v)
887  {
888  stat.data(index)->inc(v);
889  }
890 
896  template <typename U>
897  void
898  operator-=(const U &v)
899  {
900  stat.data(index)->dec(v);
901  }
902 
907  size_type size() const { return 1; }
908 
909  public:
910  std::string
911  str() const
912  {
913  return csprintf("%s[%d]", stat.info()->name, index);
914  }
915 };
916 
921 template <class Derived, class Stor>
922 class VectorBase : public DataWrapVec<Derived, VectorInfoProxy>
923 {
924  public:
925  typedef Stor Storage;
926  typedef typename Stor::Params Params;
927 
930  friend class ScalarProxy<Derived>;
931  friend class DataWrapVec<Derived, VectorInfoProxy>;
932 
933  protected:
936 
937  protected:
944 
950  const Storage *data(off_type index) const { return storage[index]; }
951 
952  void
954  {
955  fatal_if(s <= 0, "Storage size must be positive");
956  fatal_if(check(), "Stat has already been initialized");
957 
958  storage.reserve(s);
959  for (size_type i = 0; i < s; ++i)
960  storage.push_back(new Storage(this->info()->getStorageParams()));
961 
962  this->setInit();
963  }
964 
965  public:
966  void
968  {
969  vec.resize(size());
970  for (off_type i = 0; i < size(); ++i)
971  vec[i] = data(i)->value();
972  }
973 
978  void
980  {
981  vec.resize(size());
982  for (off_type i = 0; i < size(); ++i)
983  vec[i] = data(i)->result();
984  }
985 
990  Result
991  total() const
992  {
993  Result total = 0.0;
994  for (off_type i = 0; i < size(); ++i)
995  total += data(i)->result();
996  return total;
997  }
998 
1002  size_type size() const { return storage.size(); }
1003 
1004  bool
1005  zero() const
1006  {
1007  for (off_type i = 0; i < size(); ++i)
1008  if (data(i)->zero())
1009  return false;
1010  return true;
1011  }
1012 
1013  bool
1014  check() const
1015  {
1016  return size() > 0;
1017  }
1018 
1019  public:
1020  VectorBase(Group *parent, const char *name,
1021  const units::Base *unit,
1022  const char *desc)
1023  : DataWrapVec<Derived, VectorInfoProxy>(parent, name, unit, desc),
1024  storage()
1025  {}
1026 
1028  {
1029  for (auto& stor : storage) {
1030  delete stor;
1031  }
1032  }
1033 
1039  Derived &
1041  {
1042  Derived &self = this->self();
1043  self.doInit(size);
1044  return self;
1045  }
1046 
1052  Proxy
1054  {
1055  assert (index < size());
1056  return Proxy(this->self(), index);
1057  }
1058 };
1059 
1060 template <class Stat>
1062 {
1063  private:
1064  Stat &stat;
1067 
1068  private:
1069  mutable VResult vec;
1070 
1071  typename Stat::Storage *
1073  {
1074  assert(index < len);
1075  return stat.data(offset + index);
1076  }
1077 
1078  const typename Stat::Storage *
1080  {
1081  assert(index < len);
1082  return stat.data(offset + index);
1083  }
1084 
1085  public:
1086  const VResult &
1087  result() const
1088  {
1089  vec.resize(size());
1090 
1091  for (off_type i = 0; i < size(); ++i)
1092  vec[i] = data(i)->result();
1093 
1094  return vec;
1095  }
1096 
1097  Result
1098  total() const
1099  {
1100  Result total = 0.0;
1101  for (off_type i = 0; i < size(); ++i)
1102  total += data(i)->result();
1103  return total;
1104  }
1105 
1106  public:
1108  : stat(s), offset(o), len(l)
1109  {
1110  }
1111 
1113  : stat(sp.stat), offset(sp.offset), len(sp.len)
1114  {
1115  }
1116 
1117  const VectorProxy &
1119  {
1120  stat = sp.stat;
1121  offset = sp.offset;
1122  len = sp.len;
1123  return *this;
1124  }
1125 
1128  {
1129  assert (index < size());
1130  return ScalarProxy<Stat>(stat, offset + index);
1131  }
1132 
1133  size_type size() const { return len; }
1134 };
1135 
1136 template <class Derived, class Stor>
1137 class Vector2dBase : public DataWrapVec2d<Derived, Vector2dInfoProxy>
1138 {
1139  public:
1141  typedef Stor Storage;
1142  typedef typename Stor::Params Params;
1144  friend class ScalarProxy<Derived>;
1145  friend class VectorProxy<Derived>;
1146  friend class DataWrapVec<Derived, Vector2dInfoProxy>;
1147  friend class DataWrapVec2d<Derived, Vector2dInfoProxy>;
1148 
1149  protected:
1153 
1154  protected:
1156  const Storage *data(off_type index) const { return storage[index]; }
1157 
1158  public:
1159  Vector2dBase(Group *parent, const char *name,
1160  const units::Base *unit,
1161  const char *desc)
1162  : DataWrapVec2d<Derived, Vector2dInfoProxy>(parent, name, unit, desc),
1163  x(0), y(0), storage()
1164  {}
1165 
1167  {
1168  for (auto& stor : storage) {
1169  delete stor;
1170  }
1171  }
1172 
1173  Derived &
1175  {
1176  fatal_if((_x <= 0) || (_y <= 0), "Storage sizes must be positive");
1177  fatal_if(check(), "Stat has already been initialized");
1178 
1179  Derived &self = this->self();
1180  Info *info = this->info();
1181 
1182  x = _x;
1183  y = _y;
1184  info->x = _x;
1185  info->y = _y;
1186 
1187  storage.reserve(x * y);
1188  for (size_type i = 0; i < x * y; ++i)
1189  storage.push_back(new Storage(this->info()->getStorageParams()));
1190 
1191  this->setInit();
1192 
1193  return self;
1194  }
1195 
1196  Proxy
1198  {
1199  off_type offset = index * y;
1200  assert (offset + y <= size());
1201  return Proxy(this->self(), offset, y);
1202  }
1203 
1204 
1205  size_type
1206  size() const
1207  {
1208  return storage.size();
1209  }
1210 
1211  bool
1212  zero() const
1213  {
1214  return data(0)->zero();
1215  }
1216 
1221  Result
1222  total() const
1223  {
1224  Result total = 0.0;
1225  for (off_type i = 0; i < size(); ++i)
1226  total += data(i)->result();
1227  return total;
1228  }
1229 
1230  void
1232  {
1233  Info *info = this->info();
1234  size_type size = this->size();
1235 
1236  for (off_type i = 0; i < size; ++i)
1237  data(i)->prepare(info->getStorageParams());
1238 
1239  info->cvec.resize(size);
1240  for (off_type i = 0; i < size; ++i)
1241  info->cvec[i] = data(i)->value();
1242  }
1243 
1247  void
1249  {
1250  Info *info = this->info();
1251  size_type size = this->size();
1252  for (off_type i = 0; i < size; ++i)
1253  data(i)->reset(info->getStorageParams());
1254  }
1255 
1256  bool
1257  check() const
1258  {
1259  return size() > 0;
1260  }
1261 };
1262 
1264 //
1265 // Non formula statistics
1266 //
1268 
1273 template <class Derived, class Stor>
1274 class DistBase : public DataWrap<Derived, DistInfoProxy>
1275 {
1276  public:
1278  typedef Stor Storage;
1279  typedef typename Stor::Params Params;
1280 
1281  protected:
1283  GEM5_ALIGNED(8) char storage[sizeof(Storage)];
1284 
1285  protected:
1290  Storage *
1292  {
1293  return reinterpret_cast<Storage *>(storage);
1294  }
1295 
1300  const Storage *
1301  data() const
1302  {
1303  return reinterpret_cast<const Storage *>(storage);
1304  }
1305 
1306  void
1308  {
1309  new (storage) Storage(this->info()->getStorageParams());
1310  this->setInit();
1311  }
1312 
1313  public:
1314  DistBase(Group *parent, const char *name,
1315  const units::Base *unit,
1316  const char *desc)
1317  : DataWrap<Derived, DistInfoProxy>(parent, name, unit, desc)
1318  {
1319  }
1320 
1327  template <typename U>
1328  void sample(const U &v, int n = 1) { data()->sample(v, n); }
1329 
1334  size_type size() const { return data()->size(); }
1339  bool zero() const { return data()->zero(); }
1340 
1341  void
1343  {
1344  Info *info = this->info();
1345  data()->prepare(info->getStorageParams(), info->data);
1346  }
1347 
1351  void
1353  {
1354  data()->reset(this->info()->getStorageParams());
1355  }
1356 
1360  void add(DistBase &d) { data()->add(d.data()); }
1361 };
1362 
1363 template <class Stat>
1364 class DistProxy;
1365 
1366 template <class Derived, class Stor>
1367 class VectorDistBase : public DataWrapVec<Derived, VectorDistInfoProxy>
1368 {
1369  public:
1371  typedef Stor Storage;
1372  typedef typename Stor::Params Params;
1374  friend class DistProxy<Derived>;
1375  friend class DataWrapVec<Derived, VectorDistInfoProxy>;
1376 
1377  protected:
1379 
1380  protected:
1381  Storage *
1383  {
1384  return storage[index];
1385  }
1386 
1387  const Storage *
1389  {
1390  return storage[index];
1391  }
1392 
1393  void
1395  {
1396  fatal_if(s <= 0, "Storage size must be positive");
1397  fatal_if(check(), "Stat has already been initialized");
1398 
1399  storage.reserve(s);
1400  for (size_type i = 0; i < s; ++i)
1401  storage.push_back(new Storage(this->info()->getStorageParams()));
1402 
1403  this->setInit();
1404  }
1405 
1406  public:
1407  VectorDistBase(Group *parent, const char *name,
1408  const units::Base *unit,
1409  const char *desc)
1410  : DataWrapVec<Derived, VectorDistInfoProxy>(parent, name, unit, desc),
1411  storage()
1412  {}
1413 
1415  {
1416  for (auto& stor : storage) {
1417  delete stor;
1418  }
1419  }
1420 
1422  {
1423  assert(index < size());
1424  return Proxy(this->self(), index);
1425  }
1426 
1427  size_type
1428  size() const
1429  {
1430  return storage.size();
1431  }
1432 
1433  bool
1434  zero() const
1435  {
1436  for (off_type i = 0; i < size(); ++i)
1437  if (!data(i)->zero())
1438  return false;
1439  return true;
1440  }
1441 
1442  void
1444  {
1445  Info *info = this->info();
1446  size_type size = this->size();
1447  info->data.resize(size);
1448  for (off_type i = 0; i < size; ++i)
1449  data(i)->prepare(info->getStorageParams(), info->data[i]);
1450  }
1451 
1452  bool
1453  check() const
1454  {
1455  return size() > 0;
1456  }
1457 };
1458 
1459 template <class Stat>
1461 {
1462  private:
1463  Stat &stat;
1465 
1466  protected:
1467  typename Stat::Storage *data() { return stat.data(index); }
1468  const typename Stat::Storage *data() const { return stat.data(index); }
1469 
1470  public:
1472  : stat(s), index(i)
1473  {}
1474 
1476  : stat(sp.stat), index(sp.index)
1477  {}
1478 
1479  const DistProxy &
1481  {
1482  stat = sp.stat;
1483  index = sp.index;
1484  return *this;
1485  }
1486 
1487  public:
1488  template <typename U>
1489  void
1490  sample(const U &v, int n = 1)
1491  {
1492  data()->sample(v, n);
1493  }
1494 
1495  size_type
1496  size() const
1497  {
1498  return 1;
1499  }
1500 
1501  bool
1502  zero() const
1503  {
1504  return data()->zero();
1505  }
1506 
1510  void reset() { }
1511 };
1512 
1514 //
1515 // Formula Details
1516 //
1518 
1523 class Node
1524 {
1525  public:
1530  virtual size_type size() const = 0;
1535  virtual const VResult &result() const = 0;
1540  virtual Result total() const = 0;
1541 
1545  virtual std::string str() const = 0;
1546 
1547  virtual ~Node() {};
1548 };
1549 
1551 typedef std::shared_ptr<Node> NodePtr;
1552 
1553 class ScalarStatNode : public Node
1554 {
1555  private:
1557  mutable VResult vresult;
1558 
1559  public:
1561 
1562  const VResult &
1563  result() const
1564  {
1565  vresult[0] = data->result();
1566  return vresult;
1567  }
1568 
1569  Result total() const { return data->result(); };
1570 
1571  size_type size() const { return 1; }
1572 
1576  std::string str() const { return data->name; }
1577 };
1578 
1579 template <class Stat>
1580 class ScalarProxyNode : public Node
1581 {
1582  private:
1584  mutable VResult vresult;
1585 
1586  public:
1588  : proxy(p), vresult(1)
1589  { }
1590 
1591  const VResult &
1592  result() const
1593  {
1594  vresult[0] = proxy.result();
1595  return vresult;
1596  }
1597 
1598  Result
1599  total() const
1600  {
1601  return proxy.result();
1602  }
1603 
1604  size_type
1605  size() const
1606  {
1607  return 1;
1608  }
1609 
1613  std::string
1614  str() const
1615  {
1616  return proxy.str();
1617  }
1618 };
1619 
1620 class VectorStatNode : public Node
1621 {
1622  private:
1624 
1625  public:
1627  const VResult &result() const { return data->result(); }
1628  Result total() const { return data->total(); };
1629 
1630  size_type size() const { return data->size(); }
1631 
1632  std::string str() const { return data->name; }
1633 };
1634 
1635 template <class T>
1636 class ConstNode : public Node
1637 {
1638  private:
1640 
1641  public:
1642  ConstNode(T s) : vresult(1, (Result)s) {}
1643  const VResult &result() const { return vresult; }
1644  Result total() const { return vresult[0]; };
1645  size_type size() const { return 1; }
1646  std::string str() const { return std::to_string(vresult[0]); }
1647 };
1648 
1649 template <class T>
1650 class ConstVectorNode : public Node
1651 {
1652  private:
1654 
1655  public:
1656  ConstVectorNode(const T &s) : vresult(s.begin(), s.end()) {}
1657  const VResult &result() const { return vresult; }
1658 
1659  Result
1660  total() const
1661  {
1662  size_type size = this->size();
1663  Result tmp = 0;
1664  for (off_type i = 0; i < size; i++)
1665  tmp += vresult[i];
1666  return tmp;
1667  }
1668 
1669  size_type size() const { return vresult.size(); }
1670  std::string
1671  str() const
1672  {
1673  size_type size = this->size();
1674  std::string tmp = "(";
1675  for (off_type i = 0; i < size; i++)
1676  tmp += csprintf("%s ", std::to_string(vresult[i]));
1677  tmp += ")";
1678  return tmp;
1679  }
1680 };
1681 
1682 template <class Op>
1683 struct OpString;
1684 
1685 template<>
1686 struct OpString<std::plus<Result> >
1687 {
1688  static std::string str() { return "+"; }
1689 };
1690 
1691 template<>
1692 struct OpString<std::minus<Result> >
1693 {
1694  static std::string str() { return "-"; }
1695 };
1696 
1697 template<>
1698 struct OpString<std::multiplies<Result> >
1699 {
1700  static std::string str() { return "*"; }
1701 };
1702 
1703 template<>
1704 struct OpString<std::divides<Result> >
1705 {
1706  static std::string str() { return "/"; }
1707 };
1708 
1709 template<>
1710 struct OpString<std::modulus<Result> >
1711 {
1712  static std::string str() { return "%"; }
1713 };
1714 
1715 template<>
1716 struct OpString<std::negate<Result> >
1717 {
1718  static std::string str() { return "-"; }
1719 };
1720 
1721 template <class Op>
1722 class UnaryNode : public Node
1723 {
1724  public:
1726  mutable VResult vresult;
1727 
1728  public:
1730 
1731  const VResult &
1732  result() const
1733  {
1734  const VResult &lvec = l->result();
1735  size_type size = lvec.size();
1736 
1737  assert(size > 0);
1738 
1739  vresult.resize(size);
1740  Op op;
1741  for (off_type i = 0; i < size; ++i)
1742  vresult[i] = op(lvec[i]);
1743 
1744  return vresult;
1745  }
1746 
1747  Result
1748  total() const
1749  {
1750  const VResult &vec = this->result();
1751  Result total = 0.0;
1752  for (off_type i = 0; i < size(); i++)
1753  total += vec[i];
1754  return total;
1755  }
1756 
1757  size_type size() const { return l->size(); }
1758 
1759  std::string
1760  str() const
1761  {
1762  return OpString<Op>::str() + l->str();
1763  }
1764 };
1765 
1766 template <class Op>
1767 class BinaryNode : public Node
1768 {
1769  public:
1772  mutable VResult vresult;
1773 
1774  public:
1776 
1777  const VResult &
1778  result() const override
1779  {
1780  Op op;
1781  const VResult &lvec = l->result();
1782  const VResult &rvec = r->result();
1783 
1784  assert(lvec.size() > 0 && rvec.size() > 0);
1785 
1786  if (lvec.size() == 1 && rvec.size() == 1) {
1787  vresult.resize(1);
1788  vresult[0] = op(lvec[0], rvec[0]);
1789  } else if (lvec.size() == 1) {
1790  size_type size = rvec.size();
1791  vresult.resize(size);
1792  for (off_type i = 0; i < size; ++i)
1793  vresult[i] = op(lvec[0], rvec[i]);
1794  } else if (rvec.size() == 1) {
1795  size_type size = lvec.size();
1796  vresult.resize(size);
1797  for (off_type i = 0; i < size; ++i)
1798  vresult[i] = op(lvec[i], rvec[0]);
1799  } else if (rvec.size() == lvec.size()) {
1800  size_type size = rvec.size();
1801  vresult.resize(size);
1802  for (off_type i = 0; i < size; ++i)
1803  vresult[i] = op(lvec[i], rvec[i]);
1804  }
1805 
1806  return vresult;
1807  }
1808 
1809  Result
1810  total() const override
1811  {
1812  const VResult &vec = this->result();
1813  const VResult &lvec = l->result();
1814  const VResult &rvec = r->result();
1815  Result total = 0.0;
1816  Result lsum = 0.0;
1817  Result rsum = 0.0;
1818  Op op;
1819 
1820  assert(lvec.size() > 0 && rvec.size() > 0);
1821  assert(lvec.size() == rvec.size() ||
1822  lvec.size() == 1 || rvec.size() == 1);
1823 
1825  if (lvec.size() == rvec.size() && lvec.size() > 1) {
1826  for (off_type i = 0; i < size(); ++i) {
1827  lsum += lvec[i];
1828  rsum += rvec[i];
1829  }
1830  return op(lsum, rsum);
1831  }
1832 
1834  for (off_type i = 0; i < size(); ++i) {
1835  total += vec[i];
1836  }
1837 
1838  return total;
1839  }
1840 
1841  size_type
1842  size() const override
1843  {
1844  size_type ls = l->size();
1845  size_type rs = r->size();
1846  if (ls == 1) {
1847  return rs;
1848  } else if (rs == 1) {
1849  return ls;
1850  } else {
1851  assert(ls == rs && "Node vector sizes are not equal");
1852  return ls;
1853  }
1854  }
1855 
1856  std::string
1857  str() const override
1858  {
1859  return csprintf("(%s %s %s)", l->str(), OpString<Op>::str(), r->str());
1860  }
1861 };
1862 
1863 template <class Op>
1864 class SumNode : public Node
1865 {
1866  public:
1868  mutable VResult vresult;
1869 
1870  public:
1871  SumNode(NodePtr &p) : l(p), vresult(1) {}
1872 
1873  const VResult &
1874  result() const
1875  {
1876  const VResult &lvec = l->result();
1877  size_type size = lvec.size();
1878  assert(size > 0);
1879 
1880  vresult[0] = 0.0;
1881 
1882  Op op;
1883  for (off_type i = 0; i < size; ++i)
1884  vresult[0] = op(vresult[0], lvec[i]);
1885 
1886  return vresult;
1887  }
1888 
1889  Result
1890  total() const
1891  {
1892  const VResult &lvec = l->result();
1893  size_type size = lvec.size();
1894  assert(size > 0);
1895 
1896  Result result = 0.0;
1897 
1898  Op op;
1899  for (off_type i = 0; i < size; ++i)
1900  result = op(result, lvec[i]);
1901 
1902  return result;
1903  }
1904 
1905  size_type size() const { return 1; }
1906 
1907  std::string
1908  str() const
1909  {
1910  return csprintf("total(%s)", l->str());
1911  }
1912 };
1913 
1914 
1916 //
1917 // Visible Statistics Types
1918 //
1920 
1930 class Scalar : public ScalarBase<Scalar, StatStor>
1931 {
1932  public:
1934 
1935  Scalar(Group *parent = nullptr)
1937  parent, nullptr, units::Unspecified::get(), nullptr)
1938  {
1939  }
1940 
1941  Scalar(Group *parent, const char *name, const char *desc = nullptr)
1943  parent, name, units::Unspecified::get(), desc)
1944  {
1945  }
1946 
1947  Scalar(Group *parent, const char *name, const units::Base *unit,
1948  const char *desc = nullptr)
1949  : ScalarBase<Scalar, StatStor>(parent, name, unit, desc)
1950  {
1951  }
1952 };
1953 
1958 class Average : public ScalarBase<Average, AvgStor>
1959 {
1960  public:
1962 
1963  Average(Group *parent = nullptr)
1965  parent, nullptr, units::Unspecified::get(), nullptr)
1966  {
1967  }
1968 
1969  Average(Group *parent, const char *name, const char *desc = nullptr)
1971  parent, name, units::Unspecified::get(), desc)
1972  {
1973  }
1974 
1975  Average(Group *parent, const char *name, const units::Base *unit,
1976  const char *desc = nullptr)
1977  : ScalarBase<Average, AvgStor>(parent, name, unit, desc)
1978  {
1979  }
1980 };
1981 
1982 class Value : public ValueBase<Value>
1983 {
1984  public:
1985  Value(Group *parent = nullptr)
1986  : ValueBase<Value>(parent, nullptr, units::Unspecified::get(), nullptr)
1987  {
1988  }
1989 
1990  Value(Group *parent, const char *name, const char *desc = nullptr)
1991  : ValueBase<Value>(parent, name, units::Unspecified::get(), desc)
1992  {
1993  }
1994 
1995  Value(Group *parent, const char *name, const units::Base *unit,
1996  const char *desc = nullptr)
1997  : ValueBase<Value>(parent, name, unit, desc)
1998  {
1999  }
2000 };
2001 
2006 class Vector : public VectorBase<Vector, StatStor>
2007 {
2008  public:
2009  Vector(Group *parent = nullptr)
2011  parent, nullptr, units::Unspecified::get(), nullptr)
2012  {
2013  }
2014 
2015  Vector(Group *parent, const char *name, const char *desc = nullptr)
2017  parent, name, units::Unspecified::get(), desc)
2018  {
2019  }
2020 
2021  Vector(Group *parent, const char *name, const units::Base *unit,
2022  const char *desc = nullptr)
2023  : VectorBase<Vector, StatStor>(parent, name, unit, desc)
2024  {
2025  }
2026 };
2027 
2032 class AverageVector : public VectorBase<AverageVector, AvgStor>
2033 {
2034  public:
2035  AverageVector(Group *parent = nullptr)
2037  parent, nullptr, units::Unspecified::get(), nullptr)
2038  {
2039  }
2040 
2041  AverageVector(Group *parent, const char *name, const char *desc = nullptr)
2043  parent, name, units::Unspecified::get(), desc)
2044  {
2045  }
2046 
2047  AverageVector(Group *parent, const char *name, const units::Base *unit,
2048  const char *desc = nullptr)
2049  : VectorBase<AverageVector, AvgStor>(parent, name, unit, desc)
2050  {
2051  }
2052 };
2053 
2058 class Vector2d : public Vector2dBase<Vector2d, StatStor>
2059 {
2060  public:
2061  Vector2d(Group *parent = nullptr)
2063  parent, nullptr, units::Unspecified::get(), nullptr)
2064  {
2065  }
2066 
2067  Vector2d(Group *parent, const char *name, const char *desc = nullptr)
2069  parent, name, units::Unspecified::get(), desc)
2070  {
2071  }
2072 
2073  Vector2d(Group *parent, const char *name, const units::Base *unit,
2074  const char *desc = nullptr)
2075  : Vector2dBase<Vector2d, StatStor>(parent, name, unit, desc)
2076  {
2077  }
2078 };
2079 
2084 class Distribution : public DistBase<Distribution, DistStor>
2085 {
2086  public:
2087  Distribution(Group *parent = nullptr)
2089  parent, nullptr, units::Unspecified::get(), nullptr)
2090  {
2091  }
2092 
2093  Distribution(Group *parent, const char *name, const char *desc = nullptr)
2095  parent, name, units::Unspecified::get(), desc)
2096  {
2097  }
2098 
2099  Distribution(Group *parent, const char *name, const units::Base *unit,
2100  const char *desc = nullptr)
2101  : DistBase<Distribution, DistStor>(parent, name, unit, desc)
2102  {
2103  }
2104 
2112  Distribution &
2113  init(Counter min, Counter max, Counter bkt)
2114  {
2115  DistStor::Params *params = new DistStor::Params(min, max, bkt);
2116  this->setParams(params);
2117  this->doInit();
2118  return this->self();
2119  }
2120 };
2121 
2126 class Histogram : public DistBase<Histogram, HistStor>
2127 {
2128  public:
2129  Histogram(Group *parent = nullptr)
2131  parent, nullptr, units::Unspecified::get(), nullptr)
2132  {
2133  }
2134 
2135  Histogram(Group *parent, const char *name,
2136  const char *desc = nullptr)
2138  parent, name, units::Unspecified::get(), desc)
2139  {
2140  }
2141 
2142  Histogram(Group *parent, const char *name, const units::Base *unit,
2143  const char *desc = nullptr)
2144  : DistBase<Histogram, HistStor>(parent, name, unit, desc)
2145  {
2146  }
2147 
2153  Histogram &
2155  {
2156  HistStor::Params *params = new HistStor::Params(size);
2157  this->setParams(params);
2158  this->doInit();
2159  return this->self();
2160  }
2161 };
2162 
2167 class StandardDeviation : public DistBase<StandardDeviation, SampleStor>
2168 {
2169  public:
2173  StandardDeviation(Group *parent = nullptr)
2175  parent, nullptr, units::Unspecified::get(), nullptr)
2176  {
2177  SampleStor::Params *params = new SampleStor::Params;
2178  this->doInit();
2179  this->setParams(params);
2180  }
2181 
2182  StandardDeviation(Group *parent, const char *name,
2183  const char *desc = nullptr)
2185  parent, name, units::Unspecified::get(), desc)
2186  {
2187  SampleStor::Params *params = new SampleStor::Params;
2188  this->doInit();
2189  this->setParams(params);
2190  }
2191 
2192  StandardDeviation(Group *parent, const char *name, const units::Base *unit,
2193  const char *desc = nullptr)
2195  {
2196  SampleStor::Params *params = new SampleStor::Params;
2197  this->doInit();
2198  this->setParams(params);
2199  }
2200 };
2201 
2206 class AverageDeviation : public DistBase<AverageDeviation, AvgSampleStor>
2207 {
2208  public:
2212  AverageDeviation(Group *parent = nullptr)
2214  parent, nullptr, units::Unspecified::get(), nullptr)
2215  {
2217  this->doInit();
2218  this->setParams(params);
2219  }
2220 
2221  AverageDeviation(Group *parent, const char *name,
2222  const char *desc = nullptr)
2224  parent, name, units::Unspecified::get(), desc)
2225  {
2227  this->doInit();
2228  this->setParams(params);
2229  }
2230 
2231  AverageDeviation(Group *parent, const char *name, const units::Base *unit,
2232  const char *desc = nullptr)
2234  {
2236  this->doInit();
2237  this->setParams(params);
2238  }
2239 };
2240 
2245 class VectorDistribution : public VectorDistBase<VectorDistribution, DistStor>
2246 {
2247  public:
2248  VectorDistribution(Group *parent = nullptr)
2249  : VectorDistBase<VectorDistribution, DistStor>(parent, nullptr,
2250  units::Unspecified::get(), nullptr)
2251  {
2252  }
2253 
2254  VectorDistribution(Group *parent, const char *name,
2255  const char *desc = nullptr)
2257  parent, name, units::Unspecified::get(), desc)
2258  {
2259  }
2260 
2261  VectorDistribution(Group *parent, const char *name,
2262  const units::Base *unit,
2263  const char *desc = nullptr)
2265  desc)
2266  {
2267  }
2268 
2279  {
2280  DistStor::Params *params = new DistStor::Params(min, max, bkt);
2281  this->setParams(params);
2282  this->doInit(size);
2283  return this->self();
2284  }
2285 };
2286 
2292  : public VectorDistBase<VectorStandardDeviation, SampleStor>
2293 {
2294  public:
2295  VectorStandardDeviation(Group *parent = nullptr)
2297  units::Unspecified::get(), nullptr)
2298  {
2299  }
2300 
2301  VectorStandardDeviation(Group *parent, const char *name,
2302  const char *desc = nullptr)
2304  units::Unspecified::get(), desc)
2305  {
2306  }
2307 
2308  VectorStandardDeviation(Group *parent, const char *name,
2309  const units::Base *unit,
2310  const char *desc = nullptr)
2312  unit, desc)
2313  {
2314  }
2315 
2323  {
2324  SampleStor::Params *params = new SampleStor::Params;
2325  this->doInit(size);
2326  this->setParams(params);
2327  return this->self();
2328  }
2329 };
2330 
2336  : public VectorDistBase<VectorAverageDeviation, AvgSampleStor>
2337 {
2338  public:
2339  VectorAverageDeviation(Group *parent = nullptr)
2341  nullptr, units::Unspecified::get(), nullptr)
2342  {
2343  }
2344 
2345  VectorAverageDeviation(Group *parent, const char *name,
2346  const char *desc = nullptr)
2348  units::Unspecified::get(), desc)
2349  {
2350  }
2351 
2352  VectorAverageDeviation(Group *parent, const char *name,
2353  const units::Base *unit,
2354  const char *desc = nullptr)
2356  unit, desc)
2357  {
2358  }
2359 
2367  {
2369  this->doInit(size);
2370  this->setParams(params);
2371  return this->self();
2372  }
2373 };
2374 
2375 template <class Stat>
2376 class FormulaInfoProxy : public InfoProxy<Stat, FormulaInfo>
2377 {
2378  protected:
2379  mutable VResult vec;
2380  mutable VCounter cvec;
2381 
2382  public:
2383  FormulaInfoProxy(Stat &stat) : InfoProxy<Stat, FormulaInfo>(stat) {}
2384 
2385  size_type size() const { return this->s.size(); }
2386 
2387  const VResult &
2388  result() const
2389  {
2390  this->s.result(vec);
2391  return vec;
2392  }
2393  Result total() const { return this->s.total(); }
2394  VCounter &value() const { return cvec; }
2395 
2396  std::string str() const { return this->s.str(); }
2397 };
2398 
2399 template <class Stat>
2400 class SparseHistInfoProxy : public InfoProxy<Stat, SparseHistInfo>
2401 {
2402  public:
2403  SparseHistInfoProxy(Stat &stat) : InfoProxy<Stat, SparseHistInfo>(stat) {}
2404 };
2405 
2410 template <class Derived, class Stor>
2411 class SparseHistBase : public DataWrap<Derived, SparseHistInfoProxy>
2412 {
2413  public:
2415  typedef Stor Storage;
2416  typedef typename Stor::Params Params;
2417 
2418  protected:
2420  char storage[sizeof(Storage)];
2421 
2422  protected:
2427  Storage *
2429  {
2430  return reinterpret_cast<Storage *>(storage);
2431  }
2432 
2437  const Storage *
2438  data() const
2439  {
2440  return reinterpret_cast<const Storage *>(storage);
2441  }
2442 
2443  void
2445  {
2446  new (storage) Storage(this->info()->getStorageParams());
2447  this->setInit();
2448  }
2449 
2450  public:
2451  SparseHistBase(Group *parent, const char *name,
2452  const units::Base *unit,
2453  const char *desc)
2454  : DataWrap<Derived, SparseHistInfoProxy>(parent, name, unit, desc)
2455  {
2456  }
2457 
2464  template <typename U>
2465  void sample(const U &v, int n = 1) { data()->sample(v, n); }
2466 
2471  size_type size() const { return data()->size(); }
2476  bool zero() const { return data()->zero(); }
2477 
2478  void
2480  {
2481  Info *info = this->info();
2482  data()->prepare(info->getStorageParams(), info->data);
2483  }
2484 
2488  void
2490  {
2491  data()->reset(this->info()->getStorageParams());
2492  }
2493 };
2494 
2495 class SparseHistogram : public SparseHistBase<SparseHistogram, SparseHistStor>
2496 {
2497  public:
2498  SparseHistogram(Group *parent = nullptr)
2499  : SparseHistBase<SparseHistogram, SparseHistStor>(parent, nullptr,
2500  units::Unspecified::get(), nullptr)
2501  {
2502  }
2503 
2504  SparseHistogram(Group *parent, const char *name,
2505  const char *desc = nullptr)
2507  units::Unspecified::get(), desc)
2508  {
2509  }
2510 
2511  SparseHistogram(Group *parent, const char *name, const units::Base *unit,
2512  const char *desc = nullptr)
2514  desc)
2515  {
2516  }
2517 
2523  SparseHistogram &
2525  {
2527  this->setParams(params);
2528  this->doInit();
2529  return this->self();
2530  }
2531 };
2532 
2533 class Temp;
2539 class Formula : public DataWrapVec<Formula, FormulaInfoProxy>
2540 {
2541  protected:
2544  friend class Temp;
2545 
2546  public:
2550  Formula(Group *parent = nullptr, const char *name = nullptr,
2551  const char *desc = nullptr);
2552 
2553  Formula(Group *parent, const char *name, const units::Base *unit,
2554  const char *desc = nullptr);
2555 
2556  Formula(Group *parent, const char *name, const char *desc,
2557  const Temp &r);
2558 
2559  Formula(Group *parent, const char *name, const units::Base *unit,
2560  const char *desc, const Temp &r);
2561 
2567  const Formula &operator=(const Temp &r);
2568 
2569  template<typename T>
2570  const Formula &operator=(const T &v)
2571  {
2572  *this = Temp(v);
2573  return *this;
2574  }
2575 
2581  const Formula &operator+=(Temp r);
2582 
2588  const Formula &operator/=(Temp r);
2589 
2597  void result(VResult &vec) const;
2598 
2609  Result total() const;
2610 
2614  size_type size() const;
2615 
2616  void prepare() { }
2617 
2621  void reset();
2622 
2626  bool zero() const;
2627 
2628  std::string str() const;
2629 };
2630 
2631 class FormulaNode : public Node
2632 {
2633  private:
2635  mutable VResult vec;
2636 
2637  public:
2639 
2640  size_type size() const { return formula.size(); }
2641  const VResult &result() const { formula.result(vec); return vec; }
2642  Result total() const { return formula.total(); }
2643 
2644  std::string str() const { return formula.str(); }
2645 };
2646 
2650 class Temp
2651 {
2652  protected:
2657 
2658  public:
2663  Temp(const NodePtr &n) : node(n) { }
2664 
2665  Temp(NodePtr &&n) : node(std::move(n)) { }
2666 
2671  operator NodePtr&() { return node; }
2672 
2676  NodePtr getNodePtr() const { return node; }
2677 
2678  public:
2683  Temp(const Scalar &s)
2684  : node(new ScalarStatNode(s.info()))
2685  { }
2686 
2691  Temp(const Value &s)
2692  : node(new ScalarStatNode(s.info()))
2693  { }
2694 
2699  Temp(const Average &s)
2700  : node(new ScalarStatNode(s.info()))
2701  { }
2702 
2707  Temp(const Vector &s)
2708  : node(new VectorStatNode(s.info()))
2709  { }
2710 
2712  : node(new VectorStatNode(s.info()))
2713  { }
2714 
2718  Temp(const Formula &f)
2719  : node(new FormulaNode(f))
2720  { }
2721 
2726  template <class Stat>
2728  : node(new ScalarProxyNode<Stat>(p))
2729  { }
2730 
2735  Temp(signed char value)
2736  : node(new ConstNode<signed char>(value))
2737  { }
2738 
2743  Temp(unsigned char value)
2744  : node(new ConstNode<unsigned char>(value))
2745  { }
2746 
2751  Temp(signed short value)
2752  : node(new ConstNode<signed short>(value))
2753  { }
2754 
2759  Temp(unsigned short value)
2760  : node(new ConstNode<unsigned short>(value))
2761  { }
2762 
2767  Temp(signed int value)
2768  : node(new ConstNode<signed int>(value))
2769  { }
2770 
2775  Temp(unsigned int value)
2776  : node(new ConstNode<unsigned int>(value))
2777  { }
2778 
2783  Temp(signed long value)
2784  : node(new ConstNode<signed long>(value))
2785  { }
2786 
2791  Temp(unsigned long value)
2792  : node(new ConstNode<unsigned long>(value))
2793  { }
2794 
2799  Temp(signed long long value)
2800  : node(new ConstNode<signed long long>(value))
2801  { }
2802 
2807  Temp(unsigned long long value)
2808  : node(new ConstNode<unsigned long long>(value))
2809  { }
2810 
2815  Temp(float value)
2816  : node(new ConstNode<float>(value))
2817  { }
2818 
2823  Temp(double value)
2824  : node(new ConstNode<double>(value))
2825  { }
2826 };
2827 
2828 
2833 inline Temp
2835 {
2836  return Temp(std::make_shared<BinaryNode<std::plus<Result> > >(l, r));
2837 }
2838 
2839 inline Temp
2841 {
2842  return Temp(std::make_shared<BinaryNode<std::minus<Result> > >(l, r));
2843 }
2844 
2845 inline Temp
2847 {
2848  return Temp(std::make_shared<BinaryNode<std::multiplies<Result> > >(l, r));
2849 }
2850 
2851 inline Temp
2853 {
2854  return Temp(std::make_shared<BinaryNode<std::divides<Result> > >(l, r));
2855 }
2856 
2857 inline Temp
2859 {
2860  return Temp(std::make_shared<UnaryNode<std::negate<Result> > >(l));
2861 }
2862 
2863 template <typename T>
2864 inline Temp
2866 {
2867  return Temp(std::make_shared<ConstNode<T> >(val));
2868 }
2869 
2870 template <typename T>
2871 inline Temp
2873 {
2874  return Temp(std::make_shared<ConstVectorNode<T> >(val));
2875 }
2876 
2877 inline Temp
2879 {
2880  return Temp(std::make_shared<SumNode<std::plus<Result> > >(val));
2881 }
2882 
2884 void dump();
2885 void reset();
2886 void enable();
2887 bool enabled();
2888 const Info* resolve(const std::string &name);
2889 
2895 typedef void (*Handler)();
2896 
2897 void registerHandlers(Handler reset_handler, Handler dump_handler);
2898 
2903 void registerResetCallback(const std::function<void()> &callback);
2904 
2909 void registerDumpCallback(const std::function<void()> &callback);
2910 
2914 void processResetQueue();
2915 
2919 void processDumpQueue();
2920 
2922 
2923 typedef std::map<const void *, Info *> MapType;
2924 MapType &statsMap();
2925 
2926 } // namespace statistics
2927 
2928 void debugDumpStats();
2929 
2930 } // namespace gem5
2931 
2932 #endif // __BASE_STATISTICS_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
const char data[]
Calculates the per tick mean and variance of the samples.
Definition: statistics.hh:2207
AverageDeviation(Group *parent, const char *name, const units::Base *unit, const char *desc=nullptr)
Definition: statistics.hh:2231
AverageDeviation(Group *parent=nullptr)
Construct and initialize this distribution.
Definition: statistics.hh:2212
AverageDeviation(Group *parent, const char *name, const char *desc=nullptr)
Definition: statistics.hh:2221
A vector of Average stats.
Definition: statistics.hh:2033
AverageVector(Group *parent, const char *name, const char *desc=nullptr)
Definition: statistics.hh:2041
AverageVector(Group *parent=nullptr)
Definition: statistics.hh:2035
AverageVector(Group *parent, const char *name, const units::Base *unit, const char *desc=nullptr)
Definition: statistics.hh:2047
A stat that calculates the per tick average of a value.
Definition: statistics.hh:1959
Average(Group *parent, const char *name, const char *desc=nullptr)
Definition: statistics.hh:1969
Average(Group *parent=nullptr)
Definition: statistics.hh:1963
Average(Group *parent, const char *name, const units::Base *unit, const char *desc=nullptr)
Definition: statistics.hh:1975
Templatized storage for distribution that calculates per tick mean and variance.
Definition: storage.hh:639
Templatized storage and interface to a per-tick average stat.
Definition: storage.hh:128
Result total() const override
Return the total of the result vector.
Definition: statistics.hh:1810
std::string str() const override
Definition: statistics.hh:1857
size_type size() const override
Return the number of nodes in the subtree starting at this node.
Definition: statistics.hh:1842
BinaryNode(NodePtr &a, NodePtr &b)
Definition: statistics.hh:1775
const VResult & result() const override
Return the result vector of this subtree.
Definition: statistics.hh:1778
size_type size() const
Return the number of nodes in the subtree starting at this node.
Definition: statistics.hh:1645
std::string str() const
Definition: statistics.hh:1646
const VResult & result() const
Return the result vector of this subtree.
Definition: statistics.hh:1643
Result total() const
Return the total of the result vector.
Definition: statistics.hh:1644
const VResult & result() const
Return the result vector of this subtree.
Definition: statistics.hh:1657
Result total() const
Return the total of the result vector.
Definition: statistics.hh:1660
size_type size() const
Return the number of nodes in the subtree starting at this node.
Definition: statistics.hh:1669
std::string ysubname(off_type i) const
Definition: statistics.hh:502
InfoProxyType< Derived > Info
Definition: statistics.hh:465
DataWrapVec2d(Group *parent, const char *name, const units::Base *unit, const char *desc)
Definition: statistics.hh:467
Derived & ysubnames(const char **names)
Definition: statistics.hh:478
Derived & ysubname(off_type index, const std::string &subname)
Definition: statistics.hh:490
Derived & subname(off_type index, const std::string &name)
Set the subfield name for the given index, and marks this stat to print at the end of simulation.
Definition: statistics.hh:402
InfoProxyType< Derived > Info
Definition: statistics.hh:383
DataWrapVec(Group *parent=nullptr, const char *name=nullptr, const units::Base *unit=units::Unspecified::get(), const char *desc=nullptr)
Definition: statistics.hh:385
Derived & subdesc(off_type index, const std::string &desc)
Set the subfield description for the given index and marks this stat to print at the end of simulatio...
Definition: statistics.hh:426
InfoProxyType< Derived > Info
Definition: statistics.hh:231
const Info * info() const
Definition: statistics.hh:245
Derived & flags(Flags _flags)
Set the flags and marks this stat to print at the end of simulation.
Definition: statistics.hh:358
DataWrap(Group *parent, const char *name, const units::Base *unit, const char *desc)
Definition: statistics.hh:255
Derived & name(const std::string &name)
Set the name and marks this stat to print at the end of simulation.
Definition: statistics.hh:289
Derived & unit(const units::Base *_unit)
Set the unit of the stat.
Definition: statistics.hh:321
Derived & desc(const std::string &_desc)
Set the description and marks this stat to print at the end of simulation.
Definition: statistics.hh:334
const std::string & setSeparator() const
Definition: statistics.hh:310
const std::string & name() const
Definition: statistics.hh:296
DataWrap & operator=(const DataWrap &)=delete
DataWrap(const DataWrap &)=delete
Derived & prereq(const Stat &prereq)
Set the prerequisite stat and marks this stat to print at the end of simulation.
Definition: statistics.hh:372
Derived & setSeparator(const std::string &_sep)
Set the character(s) used between the name and vector number on vectors, dist, etc.
Definition: statistics.hh:305
Derived & precision(int _precision)
Set the precision and marks this stat to print at the end of simulation.
Definition: statistics.hh:346
Implementation of a distribution stat.
Definition: statistics.hh:1275
void sample(const U &v, int n=1)
Add a value to the distribtion n times.
Definition: statistics.hh:1328
DistInfoProxy< Derived > Info
Definition: statistics.hh:1277
size_type size() const
Return the number of entries in this stat.
Definition: statistics.hh:1334
void reset()
Reset stat value to default.
Definition: statistics.hh:1352
void add(DistBase &d)
Add the argument distribution to the this distribution.
Definition: statistics.hh:1360
bool zero() const
Return true if no samples have been added.
Definition: statistics.hh:1339
Storage * data()
Retrieve the storage.
Definition: statistics.hh:1291
GEM5_ALIGNED(8) char storage[sizeof(Storage)]
The storage for this stat.
DistBase(Group *parent, const char *name, const units::Base *unit, const char *desc)
Definition: statistics.hh:1314
const Storage * data() const
Retrieve a const pointer to the storage.
Definition: statistics.hh:1301
DistData data
Local storage for the entry values, used for printing.
Definition: info.hh:205
Stat::Storage * data()
Definition: statistics.hh:1467
void reset()
Proxy has no state.
Definition: statistics.hh:1510
const Stat::Storage * data() const
Definition: statistics.hh:1468
DistProxy(const DistProxy &sp)
Definition: statistics.hh:1475
DistProxy(Stat &s, off_type i)
Definition: statistics.hh:1471
void sample(const U &v, int n=1)
Definition: statistics.hh:1490
size_type size() const
Definition: statistics.hh:1496
const DistProxy & operator=(const DistProxy &sp)
Definition: statistics.hh:1480
Templatized storage and interface for a distribution stat.
Definition: storage.hh:234
A simple distribution stat.
Definition: statistics.hh:2085
Distribution(Group *parent, const char *name, const units::Base *unit, const char *desc=nullptr)
Definition: statistics.hh:2099
Distribution(Group *parent, const char *name, const char *desc=nullptr)
Definition: statistics.hh:2093
Distribution & init(Counter min, Counter max, Counter bkt)
Set the parameters of this distribution.
Definition: statistics.hh:2113
Distribution(Group *parent=nullptr)
Definition: statistics.hh:2087
const VResult & result() const
Definition: statistics.hh:2388
size_type size() const
Return the number of nodes in the subtree starting at this node.
Definition: statistics.hh:2640
FormulaNode(const Formula &f)
Definition: statistics.hh:2638
std::string str() const
Definition: statistics.hh:2644
const VResult & result() const
Return the result vector of this subtree.
Definition: statistics.hh:2641
Result total() const
Return the total of the result vector.
Definition: statistics.hh:2642
A formula for statistics that is calculated when printed.
Definition: statistics.hh:2540
const Formula & operator/=(Temp r)
Divide the existing tree by the given one.
Definition: statistics.cc:198
void reset()
Formulas don't need to be reset.
Definition: statistics.cc:231
void result(VResult &vec) const
Return the result of the Fomula in a vector.
Definition: statistics.cc:209
NodePtr root
The root of the tree which represents the Formula.
Definition: statistics.hh:2543
size_type size() const
Return the number of elements in the tree.
Definition: statistics.cc:222
std::string str() const
Definition: statistics.cc:247
const Formula & operator=(const T &v)
Definition: statistics.hh:2570
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
const Formula & operator=(const Temp &r)
Set an unitialized Formula to the given root.
Definition: statistics.cc:174
Result total() const
Return the total Formula result.
Definition: statistics.cc:216
const Formula & operator+=(Temp r)
Add the given tree to the existing one.
Definition: statistics.cc:184
Statistics container.
Definition: group.hh:94
Templatized storage and interface for a histogram stat.
Definition: storage.hh:400
A simple histogram stat.
Definition: statistics.hh:2127
Histogram(Group *parent, const char *name, const char *desc=nullptr)
Definition: statistics.hh:2135
Histogram & init(size_type size)
Set the parameters of this histogram.
Definition: statistics.hh:2154
Histogram(Group *parent, const char *name, const units::Base *unit, const char *desc=nullptr)
Definition: statistics.hh:2142
Histogram(Group *parent=nullptr)
Definition: statistics.hh:2129
void setInit()
Save Storage class parameters if any.
Definition: statistics.cc:106
bool check() const
Check that this stat has been set up properly and is ready for use.
Definition: statistics.hh:224
void setParams(const StorageParams *params)
Save Storage class parameters if any.
Definition: statistics.cc:100
Info * info()
Grab the information class for this statistic.
Definition: statistics.cc:112
bool newStyleStats() const
Check if the info is new style stats.
Definition: statistics.cc:140
void setInfo(Group *parent, Info *info)
Set up an info class for this statistic.
Definition: statistics.cc:76
void reset()
Reset the stat to the default state.
Definition: statistics.hh:211
void visit(Output &visitor)
Definition: statistics.hh:111
StorageParams const * getStorageParams() const
Getter for the storage params.
Definition: info.cc:85
std::string name
The name of the stat.
Definition: info.hh:84
A proxy similar to the FunctorProxy, but allows calling a method of a bound object,...
Definition: statistics.hh:700
V(T::* MethodPointer)() const
Definition: statistics.hh:703
MethodProxy(T *obj, MethodPointer meth)
Definition: statistics.hh:707
Base class for formula statistic node.
Definition: statistics.hh:1524
virtual std::string str() const =0
virtual Result total() const =0
Return the total of the result vector.
virtual size_type size() const =0
Return the number of nodes in the subtree starting at this node.
virtual const VResult & result() const =0
Return the result vector of this subtree.
void reset()
Reset the stat to the default state.
Definition: statistics.hh:641
size_type size() const
Definition: statistics.hh:638
void prepare()
Prepare the stat for dumping.
Definition: statistics.hh:640
std::string str() const
Definition: statistics.hh:637
bool check() const
Check that this stat has been set up properly and is ready for use.
Definition: statistics.hh:639
void visit(Output &visitor)
Visitor entry for outputing statistics data.
Definition: statistics.hh:644
Templatized storage and interface for a distribution that calculates mean and variance.
Definition: storage.hh:561
Implementation of a scalar stat.
Definition: statistics.hh:521
void operator+=(const U &v)
Increment the stat by the given value.
Definition: statistics.hh:602
void operator--(int)
Decrement the stat by 1.
Definition: statistics.hh:586
size_type size() const
Return the number of elements, always 1 for a scalar.
Definition: statistics.hh:616
GEM5_ALIGNED(8) char storage[sizeof(Storage)]
The storage of this stat.
ScalarBase(Group *parent=nullptr, const char *name=nullptr, const units::Base *unit=units::Unspecified::get(), const char *desc=nullptr)
Definition: statistics.hh:562
Counter value() const
Return the current value of this stat as its base type.
Definition: statistics.hh:622
void operator=(const U &v)
Set the data value to the given value.
Definition: statistics.hh:594
Storage * data()
Retrieve the storage.
Definition: statistics.hh:537
void operator--()
Decrement the stat by 1.
Definition: statistics.hh:581
void operator++(int)
Increment the stat by 1.
Definition: statistics.hh:584
void operator++()
Increment the stat by 1.
Definition: statistics.hh:576
void operator-=(const U &v)
Decrement the stat by the given value.
Definition: statistics.hh:610
const Storage * data() const
Retrieve a const pointer to the storage.
Definition: statistics.hh:549
virtual Result total() const =0
virtual Result result() const =0
virtual Counter value() const =0
const VResult & result() const
Return the result vector of this subtree.
Definition: statistics.hh:1592
size_type size() const
Return the number of nodes in the subtree starting at this node.
Definition: statistics.hh:1605
const ScalarProxy< Stat > proxy
Definition: statistics.hh:1583
ScalarProxyNode(const ScalarProxy< Stat > &p)
Definition: statistics.hh:1587
Result total() const
Return the total of the result vector.
Definition: statistics.hh:1599
A proxy class to access the stat at a given index in a VectorBase stat.
Definition: statistics.hh:797
void operator=(const U &v)
Set the data value to the given value.
Definition: statistics.hh:874
void operator+=(const U &v)
Increment the stat by the given value.
Definition: statistics.hh:886
std::string str() const
Definition: statistics.hh:911
const ScalarProxy & operator=(const ScalarProxy &sp)
Set this proxy equal to the provided one.
Definition: statistics.hh:842
ScalarProxy(Stat &s, off_type i)
Create and initialize this proxy, do not register it with the database.
Definition: statistics.hh:823
off_type index
The index to access in the parent VectorBase.
Definition: statistics.hh:803
ScalarProxy(const ScalarProxy &sp)
Create a copy of the provided ScalarProxy.
Definition: statistics.hh:832
Stat & stat
Pointer to the parent Vector.
Definition: statistics.hh:800
void operator--()
Decrement the stat by 1.
Definition: statistics.hh:860
void operator--(int)
Decrement the stat by 1.
Definition: statistics.hh:865
void operator-=(const U &v)
Decrement the stat by the given value.
Definition: statistics.hh:898
Result result() const
Return the current value of this statas a result type.
Definition: statistics.hh:816
void operator++(int)
Increment the stat by 1.
Definition: statistics.hh:863
Counter value() const
Return the current value of this stat as its base type.
Definition: statistics.hh:810
size_type size() const
Return the number of elements, always 1 for a scalar.
Definition: statistics.hh:907
void operator++()
Increment the stat by 1.
Definition: statistics.hh:855
size_type size() const
Return the number of nodes in the subtree starting at this node.
Definition: statistics.hh:1571
Result total() const
Return the total of the result vector.
Definition: statistics.hh:1569
const VResult & result() const
Return the result vector of this subtree.
Definition: statistics.hh:1563
ScalarStatNode(const ScalarInfo *d)
Definition: statistics.hh:1560
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:1931
Scalar(Group *parent, const char *name, const char *desc=nullptr)
Definition: statistics.hh:1941
Scalar(Group *parent, const char *name, const units::Base *unit, const char *desc=nullptr)
Definition: statistics.hh:1947
Scalar(Group *parent=nullptr)
Definition: statistics.hh:1935
Implementation of a sparse histogram stat.
Definition: statistics.hh:2412
SparseHistBase(Group *parent, const char *name, const units::Base *unit, const char *desc)
Definition: statistics.hh:2451
void sample(const U &v, int n=1)
Add a value to the distribtion n times.
Definition: statistics.hh:2465
void reset()
Reset stat value to default.
Definition: statistics.hh:2489
const Storage * data() const
Retrieve a const pointer to the storage.
Definition: statistics.hh:2438
bool zero() const
Return true if no samples have been added.
Definition: statistics.hh:2476
SparseHistInfoProxy< Derived > Info
Definition: statistics.hh:2414
size_type size() const
Return the number of entries in this stat.
Definition: statistics.hh:2471
char storage[sizeof(Storage)]
The storage for this stat.
Definition: statistics.hh:2420
Storage * data()
Retrieve the storage.
Definition: statistics.hh:2428
SparseHistData data
Local storage for the entry values, used for printing.
Definition: info.hh:255
Templatized storage and interface for a sparse histogram stat.
Definition: storage.hh:715
SparseHistogram(Group *parent, const char *name, const units::Base *unit, const char *desc=nullptr)
Definition: statistics.hh:2511
SparseHistogram(Group *parent=nullptr)
Definition: statistics.hh:2498
SparseHistogram(Group *parent, const char *name, const char *desc=nullptr)
Definition: statistics.hh:2504
SparseHistogram & init(size_type size)
Set the parameters of this histogram.
Definition: statistics.hh:2524
Calculates the mean and variance of all the samples.
Definition: statistics.hh:2168
StandardDeviation(Group *parent=nullptr)
Construct and initialize this distribution.
Definition: statistics.hh:2173
StandardDeviation(Group *parent, const char *name, const char *desc=nullptr)
Definition: statistics.hh:2182
StandardDeviation(Group *parent, const char *name, const units::Base *unit, const char *desc=nullptr)
Definition: statistics.hh:2192
Templatized storage and interface for a simple scalar stat.
Definition: storage.hh:58
size_type size() const
Return the number of nodes in the subtree starting at this node.
Definition: statistics.hh:1905
std::string str() const
Definition: statistics.hh:1908
Result total() const
Return the total of the result vector.
Definition: statistics.hh:1890
const VResult & result() const
Return the result vector of this subtree.
Definition: statistics.hh:1874
Helper class to construct formula node trees.
Definition: statistics.hh:2651
NodePtr getNodePtr() const
Makde gcc < 4.6.3 happy and explicitly get the underlying node.
Definition: statistics.hh:2676
Temp(signed long value)
Create a ConstNode.
Definition: statistics.hh:2783
Temp(const NodePtr &n)
Copy the given pointer to this class.
Definition: statistics.hh:2663
Temp(float value)
Create a ConstNode.
Definition: statistics.hh:2815
Temp(signed int value)
Create a ConstNode.
Definition: statistics.hh:2767
Temp(const Vector &s)
Create a new VectorStatNode.
Definition: statistics.hh:2707
Temp(const Scalar &s)
Create a new ScalarStatNode.
Definition: statistics.hh:2683
Temp(unsigned int value)
Create a ConstNode.
Definition: statistics.hh:2775
Temp(double value)
Create a ConstNode.
Definition: statistics.hh:2823
Temp(signed long long value)
Create a ConstNode.
Definition: statistics.hh:2799
Temp(unsigned short value)
Create a ConstNode.
Definition: statistics.hh:2759
Temp(const Average &s)
Create a new ScalarStatNode.
Definition: statistics.hh:2699
Temp(signed short value)
Create a ConstNode.
Definition: statistics.hh:2751
Temp(unsigned long long value)
Create a ConstNode.
Definition: statistics.hh:2807
Temp(signed char value)
Create a ConstNode.
Definition: statistics.hh:2735
Temp(const Formula &f)
Definition: statistics.hh:2718
Temp(unsigned long value)
Create a ConstNode.
Definition: statistics.hh:2791
Temp(unsigned char value)
Create a ConstNode.
Definition: statistics.hh:2743
Temp(const Value &s)
Create a new ScalarStatNode.
Definition: statistics.hh:2691
Temp(const ScalarProxy< Stat > &p)
Create a new ScalarProxyNode.
Definition: statistics.hh:2727
NodePtr node
Pointer to a Node object.
Definition: statistics.hh:2656
Temp(const AverageVector &s)
Definition: statistics.hh:2711
const VResult & result() const
Return the result vector of this subtree.
Definition: statistics.hh:1732
Result total() const
Return the total of the result vector.
Definition: statistics.hh:1748
std::string str() const
Definition: statistics.hh:1760
size_type size() const
Return the number of nodes in the subtree starting at this node.
Definition: statistics.hh:1757
Derived & functor(T &func)
Definition: statistics.hh:750
Derived & functor(const T &func)
Definition: statistics.hh:741
Derived & scalar(T &value)
Definition: statistics.hh:732
size_type size() const
Definition: statistics.hh:776
std::string str() const
Definition: statistics.hh:778
ValueBase(Group *parent, const char *name, const units::Base *unit, const char *desc)
Definition: statistics.hh:720
Derived & method(T *obj, V(T::*method)() const)
Extended functor that calls the specified method of the provided object.
Definition: statistics.hh:766
Value(Group *parent, const char *name, const units::Base *unit, const char *desc=nullptr)
Definition: statistics.hh:1995
Value(Group *parent=nullptr)
Definition: statistics.hh:1985
Value(Group *parent, const char *name, const char *desc=nullptr)
Definition: statistics.hh:1990
Vector2dBase(Group *parent, const char *name, const units::Base *unit, const char *desc)
Definition: statistics.hh:1159
const Storage * data(off_type index) const
Definition: statistics.hh:1156
Storage * data(off_type index)
Definition: statistics.hh:1155
Result total() const
Return a total of all entries in this vector.
Definition: statistics.hh:1222
void reset()
Reset stat value to default.
Definition: statistics.hh:1248
std::vector< Storage * > storage
Definition: statistics.hh:1152
VectorProxy< Derived > Proxy
Definition: statistics.hh:1143
Derived & init(size_type _x, size_type _y)
Definition: statistics.hh:1174
Vector2dInfoProxy< Derived > Info
Definition: statistics.hh:1140
Proxy operator[](off_type index)
Definition: statistics.hh:1197
VCounter cvec
Local storage for the entry values, used for printing.
Definition: info.hh:238
A 2-Dimensional vecto of scalar stats.
Definition: statistics.hh:2059
Vector2d(Group *parent, const char *name, const units::Base *unit, const char *desc=nullptr)
Definition: statistics.hh:2073
Vector2d(Group *parent=nullptr)
Definition: statistics.hh:2061
Vector2d(Group *parent, const char *name, const char *desc=nullptr)
Definition: statistics.hh:2067
This is a vector of AverageDeviation stats.
Definition: statistics.hh:2337
VectorAverageDeviation & init(size_type size)
Initialize storage for this distribution.
Definition: statistics.hh:2366
VectorAverageDeviation(Group *parent, const char *name, const char *desc=nullptr)
Definition: statistics.hh:2345
VectorAverageDeviation(Group *parent=nullptr)
Definition: statistics.hh:2339
VectorAverageDeviation(Group *parent, const char *name, const units::Base *unit, const char *desc=nullptr)
Definition: statistics.hh:2352
Implementation of a vector of stats.
Definition: statistics.hh:923
const Storage * data(off_type index) const
Retrieve a const pointer to the storage.
Definition: statistics.hh:950
Storage * data(off_type index)
Retrieve the storage.
Definition: statistics.hh:943
void value(VCounter &vec) const
Definition: statistics.hh:967
ScalarProxy< Derived > Proxy
Proxy type.
Definition: statistics.hh:929
std::vector< Storage * > storage
The storage of this stat.
Definition: statistics.hh:935
Derived & init(size_type size)
Set this vector to have the given size.
Definition: statistics.hh:1040
Proxy operator[](off_type index)
Return a reference (ScalarProxy) to the stat at the given index.
Definition: statistics.hh:1053
void doInit(size_type s)
Definition: statistics.hh:953
void result(VResult &vec) const
Copy the values to a local vector and return a reference to it.
Definition: statistics.hh:979
VectorBase(Group *parent, const char *name, const units::Base *unit, const char *desc)
Definition: statistics.hh:1020
Result total() const
Return a total of all entries in this vector.
Definition: statistics.hh:991
DistProxy< Derived > Proxy
Definition: statistics.hh:1373
const Storage * data(off_type index) const
Definition: statistics.hh:1388
Proxy operator[](off_type index)
Definition: statistics.hh:1421
std::vector< Storage * > storage
Definition: statistics.hh:1378
VectorDistInfoProxy< Derived > Info
Definition: statistics.hh:1370
VectorDistBase(Group *parent, const char *name, const units::Base *unit, const char *desc)
Definition: statistics.hh:1407
Storage * data(off_type index)
Definition: statistics.hh:1382
std::vector< DistData > data
Definition: info.hh:211
A vector of distributions.
Definition: statistics.hh:2246
VectorDistribution & init(size_type size, Counter min, Counter max, Counter bkt)
Initialize storage and parameters for this distribution.
Definition: statistics.hh:2278
VectorDistribution(Group *parent=nullptr)
Definition: statistics.hh:2248
VectorDistribution(Group *parent, const char *name, const units::Base *unit, const char *desc=nullptr)
Definition: statistics.hh:2261
VectorDistribution(Group *parent, const char *name, const char *desc=nullptr)
Definition: statistics.hh:2254
const VResult & result() const
Definition: statistics.hh:149
virtual Result total() const =0
virtual size_type size() const =0
virtual const VResult & result() const =0
const VectorProxy & operator=(const VectorProxy &sp)
Definition: statistics.hh:1118
VectorProxy(Stat &s, off_type o, size_type l)
Definition: statistics.hh:1107
const VResult & result() const
Definition: statistics.hh:1087
const Stat::Storage * data(off_type index) const
Definition: statistics.hh:1079
VectorProxy(const VectorProxy &sp)
Definition: statistics.hh:1112
ScalarProxy< Stat > operator[](off_type index)
Definition: statistics.hh:1127
Stat::Storage * data(off_type index)
Definition: statistics.hh:1072
This is a vector of StandardDeviation stats.
Definition: statistics.hh:2293
VectorStandardDeviation(Group *parent, const char *name, const char *desc=nullptr)
Definition: statistics.hh:2301
VectorStandardDeviation(Group *parent=nullptr)
Definition: statistics.hh:2295
VectorStandardDeviation(Group *parent, const char *name, const units::Base *unit, const char *desc=nullptr)
Definition: statistics.hh:2308
VectorStandardDeviation & init(size_type size)
Initialize storage for this distribution.
Definition: statistics.hh:2322
size_type size() const
Return the number of nodes in the subtree starting at this node.
Definition: statistics.hh:1630
VectorStatNode(const VectorInfo *d)
Definition: statistics.hh:1626
Result total() const
Return the total of the result vector.
Definition: statistics.hh:1628
const VResult & result() const
Return the result vector of this subtree.
Definition: statistics.hh:1627
A vector of scalar stats.
Definition: statistics.hh:2007
Vector(Group *parent, const char *name, const char *desc=nullptr)
Definition: statistics.hh:2015
Vector(Group *parent, const char *name, const units::Base *unit, const char *desc=nullptr)
Definition: statistics.hh:2021
Vector(Group *parent=nullptr)
Definition: statistics.hh:2009
The Base class is the parent class of all unit classes.
Definition: units.hh:123
static Unspecified * get()
Definition: units.hh:329
STL list class.
Definition: stl.hh:51
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition: logging.hh:226
void addStat(statistics::Info *info)
Register a stat with this group.
Definition: group.cc:109
#define warn(...)
Definition: logging.hh:246
#define warn_once(...)
Definition: logging.hh:250
constexpr RegId V
Definition: cc.hh:75
Bitfield< 31 > n
Definition: misc_types.hh:462
Bitfield< 7 > b
Definition: misc_types.hh:388
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 23, 0 > offset
Definition: types.hh:144
Bitfield< 9, 8 > rs
Definition: misc_types.hh:383
Bitfield< 8 > a
Definition: misc_types.hh:66
Bitfield< 0 > sp
Definition: misc_types.hh:75
Bitfield< 9 > d
Definition: misc_types.hh:64
Bitfield< 30, 0 > index
Bitfield< 25 > vec
Definition: misc.hh:113
constexpr RegId o(int index)
Definition: int.hh:147
Bitfield< 5 > r
Definition: pagetable.hh:60
Bitfield< 1 > s
Definition: pagetable.hh:64
Bitfield< 55 > l
Definition: pagetable.hh:54
Bitfield< 0 > v
Definition: pagetable.hh:65
Bitfield< 56 > f
Definition: pagetable.hh:53
Bitfield< 54 > p
Definition: pagetable.hh:70
static const char *const names[NumModes]
Definition: intmessage.hh:70
Bitfield< 4 > op
Definition: types.hh:83
Bitfield< 63 > val
Definition: misc.hh:776
unsigned int size_type
Definition: types.hh:60
void registerHandlers(Handler reset_handler, Handler dump_handler)
Definition: statistics.cc:256
Temp operator/(Temp l, Temp r)
Definition: statistics.hh:2852
std::shared_ptr< Node > NodePtr
Shared pointer to a function Node.
Definition: statistics.hh:1551
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
Temp operator-(Temp l, Temp r)
Definition: statistics.hh:2840
std::map< const void *, Info * > MapType
Definition: statistics.hh:2923
Temp constant(T val)
Definition: statistics.hh:2865
Temp constantVector(T val)
Definition: statistics.hh:2872
Temp sum(Temp val)
Definition: statistics.hh:2878
void processResetQueue()
Process all the callbacks in the reset callbacks queue.
Definition: statistics.cc:266
void(* Handler)()
Register reset and dump handlers.
Definition: statistics.hh:2895
double Counter
All counters are of 64-bit values.
Definition: types.hh:47
MapType & statsMap()
Definition: statistics.cc:69
const Info * resolve(const std::string &name)
Definition: statistics.cc:319
unsigned int off_type
Definition: types.hh:61
void registerResetCallback(const std::function< void()> &callback)
Register a callback that should be called whenever statistics are reset.
Definition: statistics.cc:278
Temp operator+(Temp l, Temp r)
Definition: statistics.hh:2834
const FlagsType display
Print this stat.
Definition: info.hh:58
std::list< Info * > & statsList()
Definition: statistics.cc:62
void processDumpQueue()
Process all the callbacks in the dump callbacks queue.
Definition: statistics.cc:272
void dump()
Dump all statistics data to the registered outputs.
Definition: statistics.cc:301
double Result
All results are doubles.
Definition: types.hh:56
Temp operator*(Temp l, Temp r)
Definition: statistics.hh:2846
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
void debugDumpStats()
Definition: statistics.cc:338
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
const std::string to_string(sc_enc enc)
Definition: sc_fxdefs.cc:60
Overload hash function for BasicBlockRange type.
Definition: misc.hh:2826
The parameters for a distribution stat.
Definition: storage.hh:263
The parameters for a distribution stat.
Definition: storage.hh:461
virtual void visit(const ScalarInfo &info)=0
The parameters for a sparse histogram stat.
Definition: storage.hh:725
const std::string & name()
Definition: trace.cc:49

Generated on Wed Dec 21 2022 10:22:29 for gem5 by doxygen 1.9.1