gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
statistics.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003-2005 The Regents of The University of Michigan
3  * Copyright (c) 2017, Centre National de la Recherche Scientifique
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met: redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer;
10  * redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution;
13  * neither the name of the copyright holders nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Authors: Nathan Binkert
30  * Pierre-Yves Peneau
31  */
32 
49 #ifndef __BASE_STATISTICS_HH__
50 #define __BASE_STATISTICS_HH__
51 
52 #include <algorithm>
53 #include <cassert>
54 #ifdef __SUNPRO_CC
55 #include <math.h>
56 #endif
57 #include <cmath>
58 #include <functional>
59 #include <iosfwd>
60 #include <list>
61 #include <map>
62 #include <memory>
63 #include <string>
64 #include <vector>
65 
66 #include "base/stats/info.hh"
67 #include "base/stats/output.hh"
68 #include "base/stats/types.hh"
69 #include "base/cast.hh"
70 #include "base/cprintf.hh"
71 #include "base/intmath.hh"
72 #include "base/str.hh"
73 #include "base/types.hh"
74 
75 class Callback;
76 
78 extern Tick curTick();
79 
80 /* A namespace for all of the Statistics */
81 namespace Stats {
82 
83 template <class Stat, class Base>
84 class InfoProxy : public Base
85 {
86  protected:
87  Stat &s;
88 
89  public:
90  InfoProxy(Stat &stat) : s(stat) {}
91 
92  bool check() const { return s.check(); }
93  void prepare() { s.prepare(); }
94  void reset() { s.reset(); }
95  void
96  visit(Output &visitor)
97  {
98  visitor.visit(*static_cast<Base *>(this));
99  }
100  bool zero() const { return s.zero(); }
101 };
102 
103 template <class Stat>
104 class ScalarInfoProxy : public InfoProxy<Stat, ScalarInfo>
105 {
106  public:
107  ScalarInfoProxy(Stat &stat) : InfoProxy<Stat, ScalarInfo>(stat) {}
108 
109  Counter value() const { return this->s.value(); }
110  Result result() const { return this->s.result(); }
111  Result total() const { return this->s.total(); }
112 };
113 
114 template <class Stat>
115 class VectorInfoProxy : public InfoProxy<Stat, VectorInfo>
116 {
117  protected:
118  mutable VCounter cvec;
119  mutable VResult rvec;
120 
121  public:
122  VectorInfoProxy(Stat &stat) : InfoProxy<Stat, VectorInfo>(stat) {}
123 
124  size_type size() const { return this->s.size(); }
125 
126  VCounter &
127  value() const
128  {
129  this->s.value(cvec);
130  return cvec;
131  }
132 
133  const VResult &
134  result() const
135  {
136  this->s.result(rvec);
137  return rvec;
138  }
139 
140  Result total() const { return this->s.total(); }
141 };
142 
143 template <class Stat>
144 class DistInfoProxy : public InfoProxy<Stat, DistInfo>
145 {
146  public:
147  DistInfoProxy(Stat &stat) : InfoProxy<Stat, DistInfo>(stat) {}
148 };
149 
150 template <class Stat>
151 class VectorDistInfoProxy : public InfoProxy<Stat, VectorDistInfo>
152 {
153  public:
154  VectorDistInfoProxy(Stat &stat) : InfoProxy<Stat, VectorDistInfo>(stat) {}
155 
156  size_type size() const { return this->s.size(); }
157 };
158 
159 template <class Stat>
160 class Vector2dInfoProxy : public InfoProxy<Stat, Vector2dInfo>
161 {
162  public:
163  Vector2dInfoProxy(Stat &stat) : InfoProxy<Stat, Vector2dInfo>(stat) {}
164 
165  Result total() const { return this->s.total(); }
166 };
167 
169 {
170  virtual ~StorageParams();
171 };
172 
174 {
175  protected:
177  void setInfo(Info *info);
179  void setParams(const StorageParams *params);
181  void setInit();
182 
184  Info *info();
186  const Info *info() const;
187 
188  public:
192  void reset() { }
193 
198  bool zero() const { return true; }
199 
205  bool check() const { return true; }
206 };
207 
208 template <class Derived, template <class> class InfoProxyType>
209 class DataWrap : public InfoAccess
210 {
211  public:
212  typedef InfoProxyType<Derived> Info;
213 
214  protected:
215  Derived &self() { return *static_cast<Derived *>(this); }
216 
217  protected:
218  Info *
220  {
221  return safe_cast<Info *>(InfoAccess::info());
222  }
223 
224  public:
225  const Info *
226  info() const
227  {
228  return safe_cast<const Info *>(InfoAccess::info());
229  }
230 
231  protected:
235  DataWrap(const DataWrap &stat) {}
236 
240  void operator=(const DataWrap &) {}
241 
242  public:
244  {
245  this->setInfo(new Info(self()));
246  }
247 
253  Derived &
254  name(const std::string &name)
255  {
256  Info *info = this->info();
257  info->setName(name);
258  info->flags.set(display);
259  return this->self();
260  }
261  const std::string &name() const { return this->info()->name; }
262 
269  Derived &
270  setSeparator(const std::string &_sep)
271  {
272  this->info()->setSeparator(_sep);
273  return this->self();
274  }
275  const std::string &setSeparator() const
276  {
277  return this->info()->separatorString;
278  }
279 
286  Derived &
287  desc(const std::string &_desc)
288  {
289  this->info()->desc = _desc;
290  return this->self();
291  }
292 
298  Derived &
299  precision(int _precision)
300  {
301  this->info()->precision = _precision;
302  return this->self();
303  }
304 
310  Derived &
311  flags(Flags _flags)
312  {
313  this->info()->flags.set(_flags);
314  return this->self();
315  }
316 
323  template <class Stat>
324  Derived &
325  prereq(const Stat &prereq)
326  {
327  this->info()->prereq = prereq.info();
328  return this->self();
329  }
330 };
331 
332 template <class Derived, template <class> class InfoProxyType>
333 class DataWrapVec : public DataWrap<Derived, InfoProxyType>
334 {
335  public:
336  typedef InfoProxyType<Derived> Info;
337 
339  {}
340 
342  {}
343 
344  void operator=(const DataWrapVec &)
345  {}
346 
347  // The following functions are specific to vectors. If you use them
348  // in a non vector context, you will get a nice compiler error!
349 
357  Derived &
358  subname(off_type index, const std::string &name)
359  {
360  Derived &self = this->self();
361  Info *info = self.info();
362 
363  std::vector<std::string> &subn = info->subnames;
364  if (subn.size() <= index)
365  subn.resize(index + 1);
366  subn[index] = name;
367  return self;
368  }
369 
370  // The following functions are specific to 2d vectors. If you use
371  // them in a non vector context, you will get a nice compiler
372  // error because info doesn't have the right variables.
373 
381  Derived &
382  subdesc(off_type index, const std::string &desc)
383  {
384  Info *info = this->info();
385 
386  std::vector<std::string> &subd = info->subdescs;
387  if (subd.size() <= index)
388  subd.resize(index + 1);
389  subd[index] = desc;
390 
391  return this->self();
392  }
393 
394  void
396  {
397  Derived &self = this->self();
398  Info *info = this->info();
399 
400  size_t size = self.size();
401  for (off_type i = 0; i < size; ++i)
402  self.data(i)->prepare(info);
403  }
404 
405  void
407  {
408  Derived &self = this->self();
409  Info *info = this->info();
410 
411  size_t size = self.size();
412  for (off_type i = 0; i < size; ++i)
413  self.data(i)->reset(info);
414  }
415 };
416 
417 template <class Derived, template <class> class InfoProxyType>
418 class DataWrapVec2d : public DataWrapVec<Derived, InfoProxyType>
419 {
420  public:
421  typedef InfoProxyType<Derived> Info;
422 
427  Derived &
428  ysubnames(const char **names)
429  {
430  Derived &self = this->self();
431  Info *info = this->info();
432 
433  info->y_subnames.resize(self.y);
434  for (off_type i = 0; i < self.y; ++i)
435  info->y_subnames[i] = names[i];
436  return self;
437  }
438 
439  Derived &
440  ysubname(off_type index, const std::string &subname)
441  {
442  Derived &self = this->self();
443  Info *info = this->info();
444 
445  assert(index < self.y);
446  info->y_subnames.resize(self.y);
447  info->y_subnames[index] = subname.c_str();
448  return self;
449  }
450 
451  std::string
453  {
454  return this->info()->y_subnames[i];
455  }
456 
457 };
458 
460 //
461 // Simple Statistics
462 //
464 
468 class StatStor
469 {
470  private:
473 
474  public:
475  struct Params : public StorageParams {};
476 
477  public:
482  StatStor(Info *info)
483  : data(Counter())
484  { }
485 
490  void set(Counter val) { data = val; }
495  void inc(Counter val) { data += val; }
500  void dec(Counter val) { data -= val; }
505  Counter value() const { return data; }
510  Result result() const { return (Result)data; }
514  void prepare(Info *info) { }
518  void reset(Info *info) { data = Counter(); }
519 
523  bool zero() const { return data == Counter(); }
524 };
525 
533 class AvgStor
534 {
535  private:
541  mutable Result total;
543  mutable Tick last;
544 
545  public:
546  struct Params : public StorageParams {};
547 
548  public:
552  AvgStor(Info *info)
553  : current(0), lastReset(0), total(0), last(0)
554  { }
555 
561  void
563  {
564  total += current * (curTick() - last);
565  last = curTick();
566  current = val;
567  }
568 
573  void inc(Counter val) { set(current + val); }
574 
579  void dec(Counter val) { set(current - val); }
580 
585  Counter value() const { return current; }
586 
591  Result
592  result() const
593  {
594  assert(last == curTick());
595  return (Result)(total + current) / (Result)(curTick() - lastReset + 1);
596  }
597 
601  bool zero() const { return total == 0.0; }
602 
606  void
607  prepare(Info *info)
608  {
609  total += current * (curTick() - last);
610  last = curTick();
611  }
612 
616  void
617  reset(Info *info)
618  {
619  total = 0.0;
620  last = curTick();
621  lastReset = curTick();
622  }
623 
624 };
625 
630 template <class Derived, class Stor>
631 class ScalarBase : public DataWrap<Derived, ScalarInfoProxy>
632 {
633  public:
634  typedef Stor Storage;
635  typedef typename Stor::Params Params;
636 
637  protected:
639  char storage[sizeof(Storage)] __attribute__ ((aligned (8)));
640 
641  protected:
647  Storage *
649  {
650  return reinterpret_cast<Storage *>(storage);
651  }
652 
659  const Storage *
660  data() const
661  {
662  return reinterpret_cast<const Storage *>(storage);
663  }
664 
665  void
667  {
668  new (storage) Storage(this->info());
669  this->setInit();
670  }
671 
672  public:
677  Counter value() const { return data()->value(); }
678 
679  public:
681  {
682  this->doInit();
683  }
684 
685  public:
686  // Common operators for stats
691  void operator++() { data()->inc(1); }
696  void operator--() { data()->dec(1); }
697 
699  void operator++(int) { ++*this; }
701  void operator--(int) { --*this; }
702 
708  template <typename U>
709  void operator=(const U &v) { data()->set(v); }
710 
716  template <typename U>
717  void operator+=(const U &v) { data()->inc(v); }
718 
724  template <typename U>
725  void operator-=(const U &v) { data()->dec(v); }
726 
731  size_type size() const { return 1; }
732 
733  Counter value() { return data()->value(); }
734 
735  Result result() { return data()->result(); }
736 
737  Result total() { return result(); }
738 
739  bool zero() { return result() == 0.0; }
740 
741  void reset() { data()->reset(this->info()); }
742  void prepare() { data()->prepare(this->info()); }
743 };
744 
745 class ProxyInfo : public ScalarInfo
746 {
747  public:
748  std::string str() const { return std::to_string(value()); }
749  size_type size() const { return 1; }
750  bool check() const { return true; }
751  void prepare() { }
752  void reset() { }
753  bool zero() const { return value() == 0; }
754 
755  void visit(Output &visitor) { visitor.visit(*this); }
756 };
757 
758 template <class T>
759 class ValueProxy : public ProxyInfo
760 {
761  private:
762  T *scalar;
763 
764  public:
765  ValueProxy(T &val) : scalar(&val) {}
766  Counter value() const { return *scalar; }
767  Result result() const { return *scalar; }
768  Result total() const { return *scalar; }
769 };
770 
771 template <class T>
772 class FunctorProxy : public ProxyInfo
773 {
774  private:
776 
777  public:
778  FunctorProxy(T &func) : functor(&func) {}
779  Counter value() const { return (*functor)(); }
780  Result result() const { return (*functor)(); }
781  Result total() const { return (*functor)(); }
782 };
783 
788 template <class T, class V>
789 class MethodProxy : public ProxyInfo
790 {
791  private:
792  T *object;
793  typedef V (T::*MethodPointer) () const;
795 
796  public:
797  MethodProxy(T *obj, MethodPointer meth) : object(obj), method(meth) {}
798  Counter value() const { return (object->*method)(); }
799  Result result() const { return (object->*method)(); }
800  Result total() const { return (object->*method)(); }
801 };
802 
803 template <class Derived>
804 class ValueBase : public DataWrap<Derived, ScalarInfoProxy>
805 {
806  private:
808 
809  public:
810  ValueBase() : proxy(NULL) { }
811  ~ValueBase() { if (proxy) delete proxy; }
812 
813  template <class T>
814  Derived &
816  {
817  proxy = new ValueProxy<T>(value);
818  this->setInit();
819  return this->self();
820  }
821 
822  template <class T>
823  Derived &
824  functor(T &func)
825  {
826  proxy = new FunctorProxy<T>(func);
827  this->setInit();
828  return this->self();
829  }
830 
838  template <class T, class V>
839  Derived &
840  method(T *obj, V (T::*method)() const)
841  {
842  proxy = new MethodProxy<T,V>(obj, method);
843  this->setInit();
844  return this->self();
845  }
846 
847  Counter value() { return proxy->value(); }
848  Result result() const { return proxy->result(); }
849  Result total() const { return proxy->total(); };
850  size_type size() const { return proxy->size(); }
851 
852  std::string str() const { return proxy->str(); }
853  bool zero() const { return proxy->zero(); }
854  bool check() const { return proxy != NULL; }
855  void prepare() { }
856  void reset() { }
857 };
858 
860 //
861 // Vector Statistics
862 //
864 
869 template <class Stat>
871 {
872  private:
874  Stat &stat;
875 
878 
879  public:
884  Counter value() const { return stat.data(index)->value(); }
885 
890  Result result() const { return stat.data(index)->result(); }
891 
892  public:
898  : stat(s), index(i)
899  {
900  }
901 
907  : stat(sp.stat), index(sp.index)
908  {}
909 
915  const ScalarProxy &
917  {
918  stat = sp.stat;
919  index = sp.index;
920  return *this;
921  }
922 
923  public:
924  // Common operators for stats
929  void operator++() { stat.data(index)->inc(1); }
934  void operator--() { stat.data(index)->dec(1); }
935 
937  void operator++(int) { ++*this; }
939  void operator--(int) { --*this; }
940 
946  template <typename U>
947  void
948  operator=(const U &v)
949  {
950  stat.data(index)->set(v);
951  }
952 
958  template <typename U>
959  void
960  operator+=(const U &v)
961  {
962  stat.data(index)->inc(v);
963  }
964 
970  template <typename U>
971  void
972  operator-=(const U &v)
973  {
974  stat.data(index)->dec(v);
975  }
976 
981  size_type size() const { return 1; }
982 
983  public:
984  std::string
985  str() const
986  {
987  return csprintf("%s[%d]", stat.info()->name, index);
988  }
989 };
990 
995 template <class Derived, class Stor>
996 class VectorBase : public DataWrapVec<Derived, VectorInfoProxy>
997 {
998  public:
999  typedef Stor Storage;
1000  typedef typename Stor::Params Params;
1001 
1004  friend class ScalarProxy<Derived>;
1005  friend class DataWrapVec<Derived, VectorInfoProxy>;
1006 
1007  protected:
1011 
1012  protected:
1019 
1025  const Storage *data(off_type index) const { return &storage[index]; }
1026 
1027  void
1029  {
1030  assert(s > 0 && "size must be positive!");
1031  assert(!storage && "already initialized");
1032  _size = s;
1033 
1034  char *ptr = new char[_size * sizeof(Storage)];
1035  storage = reinterpret_cast<Storage *>(ptr);
1036 
1037  for (off_type i = 0; i < _size; ++i)
1038  new (&storage[i]) Storage(this->info());
1039 
1040  this->setInit();
1041  }
1042 
1043  public:
1044  void
1045  value(VCounter &vec) const
1046  {
1047  vec.resize(size());
1048  for (off_type i = 0; i < size(); ++i)
1049  vec[i] = data(i)->value();
1050  }
1051 
1056  void
1057  result(VResult &vec) const
1058  {
1059  vec.resize(size());
1060  for (off_type i = 0; i < size(); ++i)
1061  vec[i] = data(i)->result();
1062  }
1063 
1068  Result
1069  total() const
1070  {
1071  Result total = 0.0;
1072  for (off_type i = 0; i < size(); ++i)
1073  total += data(i)->result();
1074  return total;
1075  }
1076 
1080  size_type size() const { return _size; }
1081 
1082  bool
1083  zero() const
1084  {
1085  for (off_type i = 0; i < size(); ++i)
1086  if (data(i)->zero())
1087  return false;
1088  return true;
1089  }
1090 
1091  bool
1092  check() const
1093  {
1094  return storage != NULL;
1095  }
1096 
1097  public:
1099  : storage(nullptr), _size(0)
1100  {}
1101 
1103  {
1104  if (!storage)
1105  return;
1106 
1107  for (off_type i = 0; i < _size; ++i)
1108  data(i)->~Storage();
1109  delete [] reinterpret_cast<char *>(storage);
1110  }
1111 
1117  Derived &
1119  {
1120  Derived &self = this->self();
1121  self.doInit(size);
1122  return self;
1123  }
1124 
1130  Proxy
1132  {
1133  assert (index >= 0 && index < size());
1134  return Proxy(this->self(), index);
1135  }
1136 };
1137 
1138 template <class Stat>
1140 {
1141  private:
1142  Stat &stat;
1145 
1146  private:
1147  mutable VResult vec;
1148 
1149  typename Stat::Storage *
1151  {
1152  assert(index < len);
1153  return stat.data(offset + index);
1154  }
1155 
1156  const typename Stat::Storage *
1158  {
1159  assert(index < len);
1160  return stat.data(offset + index);
1161  }
1162 
1163  public:
1164  const VResult &
1165  result() const
1166  {
1167  vec.resize(size());
1168 
1169  for (off_type i = 0; i < size(); ++i)
1170  vec[i] = data(i)->result();
1171 
1172  return vec;
1173  }
1174 
1175  Result
1176  total() const
1177  {
1178  Result total = 0.0;
1179  for (off_type i = 0; i < size(); ++i)
1180  total += data(i)->result();
1181  return total;
1182  }
1183 
1184  public:
1186  : stat(s), offset(o), len(l)
1187  {
1188  }
1189 
1191  : stat(sp.stat), offset(sp.offset), len(sp.len)
1192  {
1193  }
1194 
1195  const VectorProxy &
1197  {
1198  stat = sp.stat;
1199  offset = sp.offset;
1200  len = sp.len;
1201  return *this;
1202  }
1203 
1206  {
1207  assert (index >= 0 && index < size());
1208  return ScalarProxy<Stat>(stat, offset + index);
1209  }
1210 
1211  size_type size() const { return len; }
1212 };
1213 
1214 template <class Derived, class Stor>
1215 class Vector2dBase : public DataWrapVec2d<Derived, Vector2dInfoProxy>
1216 {
1217  public:
1219  typedef Stor Storage;
1220  typedef typename Stor::Params Params;
1222  friend class ScalarProxy<Derived>;
1223  friend class VectorProxy<Derived>;
1224  friend class DataWrapVec<Derived, Vector2dInfoProxy>;
1225  friend class DataWrapVec2d<Derived, Vector2dInfoProxy>;
1226 
1227  protected:
1232 
1233  protected:
1235  const Storage *data(off_type index) const { return &storage[index]; }
1236 
1237  public:
1239  : x(0), y(0), _size(0), storage(nullptr)
1240  {}
1241 
1243  {
1244  if (!storage)
1245  return;
1246 
1247  for (off_type i = 0; i < _size; ++i)
1248  data(i)->~Storage();
1249  delete [] reinterpret_cast<char *>(storage);
1250  }
1251 
1252  Derived &
1254  {
1255  assert(_x > 0 && _y > 0 && "sizes must be positive!");
1256  assert(!storage && "already initialized");
1257 
1258  Derived &self = this->self();
1259  Info *info = this->info();
1260 
1261  x = _x;
1262  y = _y;
1263  info->x = _x;
1264  info->y = _y;
1265  _size = x * y;
1266 
1267  char *ptr = new char[_size * sizeof(Storage)];
1268  storage = reinterpret_cast<Storage *>(ptr);
1269 
1270  for (off_type i = 0; i < _size; ++i)
1271  new (&storage[i]) Storage(info);
1272 
1273  this->setInit();
1274 
1275  return self;
1276  }
1277 
1278  Proxy
1280  {
1281  off_type offset = index * y;
1282  assert (index >= 0 && offset + y <= size());
1283  return Proxy(this->self(), offset, y);
1284  }
1285 
1286 
1287  size_type
1288  size() const
1289  {
1290  return _size;
1291  }
1292 
1293  bool
1294  zero() const
1295  {
1296  return data(0)->zero();
1297 #if 0
1298  for (off_type i = 0; i < size(); ++i)
1299  if (!data(i)->zero())
1300  return false;
1301  return true;
1302 #endif
1303  }
1304 
1309  Result
1310  total() const
1311  {
1312  Result total = 0.0;
1313  for (off_type i = 0; i < size(); ++i)
1314  total += data(i)->result();
1315  return total;
1316  }
1317 
1318  void
1320  {
1321  Info *info = this->info();
1322  size_type size = this->size();
1323 
1324  for (off_type i = 0; i < size; ++i)
1325  data(i)->prepare(info);
1326 
1327  info->cvec.resize(size);
1328  for (off_type i = 0; i < size; ++i)
1329  info->cvec[i] = data(i)->value();
1330  }
1331 
1335  void
1337  {
1338  Info *info = this->info();
1339  size_type size = this->size();
1340  for (off_type i = 0; i < size; ++i)
1341  data(i)->reset(info);
1342  }
1343 
1344  bool
1345  check() const
1346  {
1347  return storage != NULL;
1348  }
1349 };
1350 
1352 //
1353 // Non formula statistics
1354 //
1356 
1357 struct DistParams : public StorageParams
1358 {
1361 };
1362 
1367 {
1368  public:
1370  struct Params : public DistParams
1371  {
1380 
1382  buckets(0) {}
1383  };
1384 
1385  private:
1392 
1409 
1410  public:
1412  : cvec(safe_cast<const Params *>(info->storageParams)->buckets)
1413  {
1414  reset(info);
1415  }
1416 
1422  void
1423  sample(Counter val, int number)
1424  {
1425  if (val < min_track)
1426  underflow += number;
1427  else if (val > max_track)
1428  overflow += number;
1429  else {
1430  size_type index =
1431  (size_type)std::floor((val - min_track) / bucket_size);
1432  assert(index < size());
1433  cvec[index] += number;
1434  }
1435 
1436  if (val < min_val)
1437  min_val = val;
1438 
1439  if (val > max_val)
1440  max_val = val;
1441 
1442  sum += val * number;
1443  squares += val * val * number;
1444  samples += number;
1445  }
1446 
1451  size_type size() const { return cvec.size(); }
1452 
1457  bool
1458  zero() const
1459  {
1460  return samples == Counter();
1461  }
1462 
1463  void
1465  {
1466  const Params *params = safe_cast<const Params *>(info->storageParams);
1467 
1468  assert(params->type == Dist);
1469  data.type = params->type;
1470  data.min = params->min;
1471  data.max = params->max;
1472  data.bucket_size = params->bucket_size;
1473 
1474  data.min_val = (min_val == CounterLimits::max()) ? 0 : min_val;
1475  data.max_val = (max_val == CounterLimits::min()) ? 0 : max_val;
1476  data.underflow = underflow;
1477  data.overflow = overflow;
1478 
1479  data.cvec.resize(params->buckets);
1480  for (off_type i = 0; i < params->buckets; ++i)
1481  data.cvec[i] = cvec[i];
1482 
1483  data.sum = sum;
1484  data.squares = squares;
1485  data.samples = samples;
1486  }
1487 
1491  void
1492  reset(Info *info)
1493  {
1494  const Params *params = safe_cast<const Params *>(info->storageParams);
1495  min_track = params->min;
1496  max_track = params->max;
1497  bucket_size = params->bucket_size;
1498 
1499  min_val = CounterLimits::max();
1500  max_val = CounterLimits::min();
1501  underflow = Counter();
1502  overflow = Counter();
1503 
1504  size_type size = cvec.size();
1505  for (off_type i = 0; i < size; ++i)
1506  cvec[i] = Counter();
1507 
1508  sum = Counter();
1509  squares = Counter();
1510  samples = Counter();
1511  }
1512 };
1513 
1518 {
1519  public:
1521  struct Params : public DistParams
1522  {
1525 
1527  };
1528 
1529  private:
1536 
1547 
1548  public:
1550  : cvec(safe_cast<const Params *>(info->storageParams)->buckets)
1551  {
1552  reset(info);
1553  }
1554 
1555  void grow_up();
1556  void grow_out();
1557  void grow_convert();
1558  void add(HistStor *);
1559 
1565  void
1566  sample(Counter val, int number)
1567  {
1568  assert(min_bucket < max_bucket);
1569  if (val < min_bucket) {
1570  if (min_bucket == 0)
1571  grow_convert();
1572 
1573  while (val < min_bucket)
1574  grow_out();
1575  } else if (val >= max_bucket + bucket_size) {
1576  if (min_bucket == 0) {
1577  while (val >= max_bucket + bucket_size)
1578  grow_up();
1579  } else {
1580  while (val >= max_bucket + bucket_size)
1581  grow_out();
1582  }
1583  }
1584 
1585  size_type index =
1586  (int64_t)std::floor((val - min_bucket) / bucket_size);
1587 
1588  assert(index < size());
1589  cvec[index] += number;
1590 
1591  sum += val * number;
1592  squares += val * val * number;
1593  logs += log(val) * number;
1594  samples += number;
1595  }
1596 
1601  size_type size() const { return cvec.size(); }
1602 
1607  bool
1608  zero() const
1609  {
1610  return samples == Counter();
1611  }
1612 
1613  void
1615  {
1616  const Params *params = safe_cast<const Params *>(info->storageParams);
1617 
1618  assert(params->type == Hist);
1619  data.type = params->type;
1620  data.min = min_bucket;
1621  data.max = max_bucket + bucket_size - 1;
1622  data.bucket_size = bucket_size;
1623 
1624  data.min_val = min_bucket;
1625  data.max_val = max_bucket;
1626 
1627  int buckets = params->buckets;
1628  data.cvec.resize(buckets);
1629  for (off_type i = 0; i < buckets; ++i)
1630  data.cvec[i] = cvec[i];
1631 
1632  data.sum = sum;
1633  data.logs = logs;
1634  data.squares = squares;
1635  data.samples = samples;
1636  }
1637 
1641  void
1642  reset(Info *info)
1643  {
1644  const Params *params = safe_cast<const Params *>(info->storageParams);
1645  min_bucket = 0;
1646  max_bucket = params->buckets - 1;
1647  bucket_size = 1;
1648 
1649  size_type size = cvec.size();
1650  for (off_type i = 0; i < size; ++i)
1651  cvec[i] = Counter();
1652 
1653  sum = Counter();
1654  squares = Counter();
1655  samples = Counter();
1656  logs = Counter();
1657  }
1658 };
1659 
1665 {
1666  public:
1667  struct Params : public DistParams
1668  {
1670  };
1671 
1672  private:
1679 
1680  public:
1685  : sum(Counter()), squares(Counter()), samples(Counter())
1686  { }
1687 
1695  void
1696  sample(Counter val, int number)
1697  {
1698  Counter value = val * number;
1699  sum += value;
1700  squares += value * value;
1701  samples += number;
1702  }
1703 
1708  size_type size() const { return 1; }
1709 
1714  bool zero() const { return samples == Counter(); }
1715 
1716  void
1718  {
1719  const Params *params = safe_cast<const Params *>(info->storageParams);
1720 
1721  assert(params->type == Deviation);
1722  data.type = params->type;
1723  data.sum = sum;
1724  data.squares = squares;
1725  data.samples = samples;
1726  }
1727 
1731  void
1732  reset(Info *info)
1733  {
1734  sum = Counter();
1735  squares = Counter();
1736  samples = Counter();
1737  }
1738 };
1739 
1745 {
1746  public:
1747  struct Params : public DistParams
1748  {
1750  };
1751 
1752  private:
1757 
1758  public:
1763  : sum(Counter()), squares(Counter())
1764  {}
1765 
1772  void
1773  sample(Counter val, int number)
1774  {
1775  Counter value = val * number;
1776  sum += value;
1777  squares += value * value;
1778  }
1779 
1784  size_type size() const { return 1; }
1785 
1790  bool zero() const { return sum == Counter(); }
1791 
1792  void
1794  {
1795  const Params *params = safe_cast<const Params *>(info->storageParams);
1796 
1797  assert(params->type == Deviation);
1798  data.type = params->type;
1799  data.sum = sum;
1800  data.squares = squares;
1801  data.samples = curTick();
1802  }
1803 
1807  void
1808  reset(Info *info)
1809  {
1810  sum = Counter();
1811  squares = Counter();
1812  }
1813 };
1814 
1819 template <class Derived, class Stor>
1820 class DistBase : public DataWrap<Derived, DistInfoProxy>
1821 {
1822  public:
1824  typedef Stor Storage;
1825  typedef typename Stor::Params Params;
1826 
1827  protected:
1829  char storage[sizeof(Storage)] __attribute__ ((aligned (8)));
1830 
1831  protected:
1836  Storage *
1838  {
1839  return reinterpret_cast<Storage *>(storage);
1840  }
1841 
1846  const Storage *
1847  data() const
1848  {
1849  return reinterpret_cast<const Storage *>(storage);
1850  }
1851 
1852  void
1854  {
1855  new (storage) Storage(this->info());
1856  this->setInit();
1857  }
1858 
1859  public:
1860  DistBase() { }
1861 
1868  template <typename U>
1869  void sample(const U &v, int n = 1) { data()->sample(v, n); }
1870 
1875  size_type size() const { return data()->size(); }
1880  bool zero() const { return data()->zero(); }
1881 
1882  void
1884  {
1885  Info *info = this->info();
1886  data()->prepare(info, info->data);
1887  }
1888 
1892  void
1894  {
1895  data()->reset(this->info());
1896  }
1897 
1901  void add(DistBase &d) { data()->add(d.data()); }
1902 
1903 };
1904 
1905 template <class Stat>
1907 
1908 template <class Derived, class Stor>
1909 class VectorDistBase : public DataWrapVec<Derived, VectorDistInfoProxy>
1910 {
1911  public:
1913  typedef Stor Storage;
1914  typedef typename Stor::Params Params;
1916  friend class DistProxy<Derived>;
1917  friend class DataWrapVec<Derived, VectorDistInfoProxy>;
1918 
1919  protected:
1922 
1923  protected:
1924  Storage *
1926  {
1927  return &storage[index];
1928  }
1929 
1930  const Storage *
1932  {
1933  return &storage[index];
1934  }
1935 
1936  void
1938  {
1939  assert(s > 0 && "size must be positive!");
1940  assert(!storage && "already initialized");
1941  _size = s;
1942 
1943  char *ptr = new char[_size * sizeof(Storage)];
1944  storage = reinterpret_cast<Storage *>(ptr);
1945 
1946  Info *info = this->info();
1947  for (off_type i = 0; i < _size; ++i)
1948  new (&storage[i]) Storage(info);
1949 
1950  this->setInit();
1951  }
1952 
1953  public:
1955  : storage(NULL)
1956  {}
1957 
1959  {
1960  if (!storage)
1961  return ;
1962 
1963  for (off_type i = 0; i < _size; ++i)
1964  data(i)->~Storage();
1965  delete [] reinterpret_cast<char *>(storage);
1966  }
1967 
1969  {
1970  assert(index >= 0 && index < size());
1971  return Proxy(this->self(), index);
1972  }
1973 
1974  size_type
1975  size() const
1976  {
1977  return _size;
1978  }
1979 
1980  bool
1981  zero() const
1982  {
1983  for (off_type i = 0; i < size(); ++i)
1984  if (!data(i)->zero())
1985  return false;
1986  return true;
1987  }
1988 
1989  void
1991  {
1992  Info *info = this->info();
1993  size_type size = this->size();
1994  info->data.resize(size);
1995  for (off_type i = 0; i < size; ++i)
1996  data(i)->prepare(info, info->data[i]);
1997  }
1998 
1999  bool
2000  check() const
2001  {
2002  return storage != NULL;
2003  }
2004 };
2005 
2006 template <class Stat>
2007 class DistProxy
2008 {
2009  private:
2010  Stat &stat;
2012 
2013  protected:
2014  typename Stat::Storage *data() { return stat.data(index); }
2015  const typename Stat::Storage *data() const { return stat.data(index); }
2016 
2017  public:
2019  : stat(s), index(i)
2020  {}
2021 
2023  : stat(sp.stat), index(sp.index)
2024  {}
2025 
2026  const DistProxy &
2028  {
2029  stat = sp.stat;
2030  index = sp.index;
2031  return *this;
2032  }
2033 
2034  public:
2035  template <typename U>
2036  void
2037  sample(const U &v, int n = 1)
2038  {
2039  data()->sample(v, n);
2040  }
2041 
2042  size_type
2043  size() const
2044  {
2045  return 1;
2046  }
2047 
2048  bool
2049  zero() const
2050  {
2051  return data()->zero();
2052  }
2053 
2057  void reset() { }
2058 };
2059 
2061 //
2062 // Formula Details
2063 //
2065 
2070 class Node
2071 {
2072  public:
2077  virtual size_type size() const = 0;
2082  virtual const VResult &result() const = 0;
2087  virtual Result total() const = 0;
2088 
2092  virtual std::string str() const = 0;
2093 };
2094 
2096 typedef std::shared_ptr<Node> NodePtr;
2097 
2098 class ScalarStatNode : public Node
2099 {
2100  private:
2102  mutable VResult vresult;
2103 
2104  public:
2106 
2107  const VResult &
2108  result() const
2109  {
2110  vresult[0] = data->result();
2111  return vresult;
2112  }
2113 
2114  Result total() const { return data->result(); };
2115 
2116  size_type size() const { return 1; }
2117 
2121  std::string str() const { return data->name; }
2122 };
2123 
2124 template <class Stat>
2125 class ScalarProxyNode : public Node
2126 {
2127  private:
2129  mutable VResult vresult;
2130 
2131  public:
2133  : proxy(p), vresult(1)
2134  { }
2135 
2136  const VResult &
2137  result() const
2138  {
2139  vresult[0] = proxy.result();
2140  return vresult;
2141  }
2142 
2143  Result
2144  total() const
2145  {
2146  return proxy.result();
2147  }
2148 
2149  size_type
2150  size() const
2151  {
2152  return 1;
2153  }
2154 
2158  std::string
2159  str() const
2160  {
2161  return proxy.str();
2162  }
2163 };
2164 
2165 class VectorStatNode : public Node
2166 {
2167  private:
2169 
2170  public:
2171  VectorStatNode(const VectorInfo *d) : data(d) { }
2172  const VResult &result() const { return data->result(); }
2173  Result total() const { return data->total(); };
2174 
2175  size_type size() const { return data->size(); }
2176 
2177  std::string str() const { return data->name; }
2178 };
2179 
2180 template <class T>
2181 class ConstNode : public Node
2182 {
2183  private:
2185 
2186  public:
2187  ConstNode(T s) : vresult(1, (Result)s) {}
2188  const VResult &result() const { return vresult; }
2189  Result total() const { return vresult[0]; };
2190  size_type size() const { return 1; }
2191  std::string str() const { return std::to_string(vresult[0]); }
2192 };
2193 
2194 template <class T>
2195 class ConstVectorNode : public Node
2196 {
2197  private:
2199 
2200  public:
2201  ConstVectorNode(const T &s) : vresult(s.begin(), s.end()) {}
2202  const VResult &result() const { return vresult; }
2203 
2204  Result
2205  total() const
2206  {
2207  size_type size = this->size();
2208  Result tmp = 0;
2209  for (off_type i = 0; i < size; i++)
2210  tmp += vresult[i];
2211  return tmp;
2212  }
2213 
2214  size_type size() const { return vresult.size(); }
2215  std::string
2216  str() const
2217  {
2218  size_type size = this->size();
2219  std::string tmp = "(";
2220  for (off_type i = 0; i < size; i++)
2221  tmp += csprintf("%s ", std::to_string(vresult[i]));
2222  tmp += ")";
2223  return tmp;
2224  }
2225 };
2226 
2227 template <class Op>
2228 struct OpString;
2229 
2230 template<>
2231 struct OpString<std::plus<Result> >
2232 {
2233  static std::string str() { return "+"; }
2234 };
2235 
2236 template<>
2237 struct OpString<std::minus<Result> >
2238 {
2239  static std::string str() { return "-"; }
2240 };
2241 
2242 template<>
2243 struct OpString<std::multiplies<Result> >
2244 {
2245  static std::string str() { return "*"; }
2246 };
2247 
2248 template<>
2249 struct OpString<std::divides<Result> >
2250 {
2251  static std::string str() { return "/"; }
2252 };
2253 
2254 template<>
2255 struct OpString<std::modulus<Result> >
2256 {
2257  static std::string str() { return "%"; }
2258 };
2259 
2260 template<>
2261 struct OpString<std::negate<Result> >
2262 {
2263  static std::string str() { return "-"; }
2264 };
2265 
2266 template <class Op>
2267 class UnaryNode : public Node
2268 {
2269  public:
2271  mutable VResult vresult;
2272 
2273  public:
2274  UnaryNode(NodePtr &p) : l(p) {}
2275 
2276  const VResult &
2277  result() const
2278  {
2279  const VResult &lvec = l->result();
2280  size_type size = lvec.size();
2281 
2282  assert(size > 0);
2283 
2284  vresult.resize(size);
2285  Op op;
2286  for (off_type i = 0; i < size; ++i)
2287  vresult[i] = op(lvec[i]);
2288 
2289  return vresult;
2290  }
2291 
2292  Result
2293  total() const
2294  {
2295  const VResult &vec = this->result();
2296  Result total = 0.0;
2297  for (off_type i = 0; i < size(); i++)
2298  total += vec[i];
2299  return total;
2300  }
2301 
2302  size_type size() const { return l->size(); }
2303 
2304  std::string
2305  str() const
2306  {
2307  return OpString<Op>::str() + l->str();
2308  }
2309 };
2310 
2311 template <class Op>
2312 class BinaryNode : public Node
2313 {
2314  public:
2317  mutable VResult vresult;
2318 
2319  public:
2320  BinaryNode(NodePtr &a, NodePtr &b) : l(a), r(b) {}
2321 
2322  const VResult &
2323  result() const
2324  {
2325  Op op;
2326  const VResult &lvec = l->result();
2327  const VResult &rvec = r->result();
2328 
2329  assert(lvec.size() > 0 && rvec.size() > 0);
2330 
2331  if (lvec.size() == 1 && rvec.size() == 1) {
2332  vresult.resize(1);
2333  vresult[0] = op(lvec[0], rvec[0]);
2334  } else if (lvec.size() == 1) {
2335  size_type size = rvec.size();
2336  vresult.resize(size);
2337  for (off_type i = 0; i < size; ++i)
2338  vresult[i] = op(lvec[0], rvec[i]);
2339  } else if (rvec.size() == 1) {
2340  size_type size = lvec.size();
2341  vresult.resize(size);
2342  for (off_type i = 0; i < size; ++i)
2343  vresult[i] = op(lvec[i], rvec[0]);
2344  } else if (rvec.size() == lvec.size()) {
2345  size_type size = rvec.size();
2346  vresult.resize(size);
2347  for (off_type i = 0; i < size; ++i)
2348  vresult[i] = op(lvec[i], rvec[i]);
2349  }
2350 
2351  return vresult;
2352  }
2353 
2354  Result
2355  total() const
2356  {
2357  const VResult &vec = this->result();
2358  const VResult &lvec = l->result();
2359  const VResult &rvec = r->result();
2360  Result total = 0.0;
2361  Result lsum = 0.0;
2362  Result rsum = 0.0;
2363  Op op;
2364 
2365  assert(lvec.size() > 0 && rvec.size() > 0);
2366  assert(lvec.size() == rvec.size() ||
2367  lvec.size() == 1 || rvec.size() == 1);
2368 
2370  if (lvec.size() == rvec.size() && lvec.size() > 1) {
2371  for (off_type i = 0; i < size(); ++i) {
2372  lsum += lvec[i];
2373  rsum += rvec[i];
2374  }
2375  return op(lsum, rsum);
2376  }
2377 
2379  for (off_type i = 0; i < size(); ++i) {
2380  total += vec[i];
2381  }
2382 
2383  return total;
2384  }
2385 
2386  size_type
2387  size() const
2388  {
2389  size_type ls = l->size();
2390  size_type rs = r->size();
2391  if (ls == 1) {
2392  return rs;
2393  } else if (rs == 1) {
2394  return ls;
2395  } else {
2396  assert(ls == rs && "Node vector sizes are not equal");
2397  return ls;
2398  }
2399  }
2400 
2401  std::string
2402  str() const
2403  {
2404  return csprintf("(%s %s %s)", l->str(), OpString<Op>::str(), r->str());
2405  }
2406 };
2407 
2408 template <class Op>
2409 class SumNode : public Node
2410 {
2411  public:
2413  mutable VResult vresult;
2414 
2415  public:
2416  SumNode(NodePtr &p) : l(p), vresult(1) {}
2417 
2418  const VResult &
2419  result() const
2420  {
2421  const VResult &lvec = l->result();
2422  size_type size = lvec.size();
2423  assert(size > 0);
2424 
2425  vresult[0] = 0.0;
2426 
2427  Op op;
2428  for (off_type i = 0; i < size; ++i)
2429  vresult[0] = op(vresult[0], lvec[i]);
2430 
2431  return vresult;
2432  }
2433 
2434  Result
2435  total() const
2436  {
2437  const VResult &lvec = l->result();
2438  size_type size = lvec.size();
2439  assert(size > 0);
2440 
2441  Result result = 0.0;
2442 
2443  Op op;
2444  for (off_type i = 0; i < size; ++i)
2445  result = op(result, lvec[i]);
2446 
2447  return result;
2448  }
2449 
2450  size_type size() const { return 1; }
2451 
2452  std::string
2453  str() const
2454  {
2455  return csprintf("total(%s)", l->str());
2456  }
2457 };
2458 
2459 
2461 //
2462 // Visible Statistics Types
2463 //
2465 
2475 class Scalar : public ScalarBase<Scalar, StatStor>
2476 {
2477  public:
2479 };
2480 
2485 class Average : public ScalarBase<Average, AvgStor>
2486 {
2487  public:
2489 };
2490 
2491 class Value : public ValueBase<Value>
2492 {
2493 };
2494 
2499 class Vector : public VectorBase<Vector, StatStor>
2500 {
2501 };
2502 
2507 class AverageVector : public VectorBase<AverageVector, AvgStor>
2508 {
2509 };
2510 
2515 class Vector2d : public Vector2dBase<Vector2d, StatStor>
2516 {
2517 };
2518 
2523 class Distribution : public DistBase<Distribution, DistStor>
2524 {
2525  public:
2533  Distribution &
2534  init(Counter min, Counter max, Counter bkt)
2535  {
2536  DistStor::Params *params = new DistStor::Params;
2537  params->min = min;
2538  params->max = max;
2539  params->bucket_size = bkt;
2540  params->buckets = (size_type)ceil((max - min + 1.0) / bkt);
2541  this->setParams(params);
2542  this->doInit();
2543  return this->self();
2544  }
2545 };
2546 
2551 class Histogram : public DistBase<Histogram, HistStor>
2552 {
2553  public:
2559  Histogram &
2561  {
2562  HistStor::Params *params = new HistStor::Params;
2563  params->buckets = size;
2564  this->setParams(params);
2565  this->doInit();
2566  return this->self();
2567  }
2568 };
2569 
2574 class StandardDeviation : public DistBase<StandardDeviation, SampleStor>
2575 {
2576  public:
2581  {
2582  SampleStor::Params *params = new SampleStor::Params;
2583  this->doInit();
2584  this->setParams(params);
2585  }
2586 };
2587 
2592 class AverageDeviation : public DistBase<AverageDeviation, AvgSampleStor>
2593 {
2594  public:
2599  {
2601  this->doInit();
2602  this->setParams(params);
2603  }
2604 };
2605 
2610 class VectorDistribution : public VectorDistBase<VectorDistribution, DistStor>
2611 {
2612  public:
2623  {
2624  DistStor::Params *params = new DistStor::Params;
2625  params->min = min;
2626  params->max = max;
2627  params->bucket_size = bkt;
2628  params->buckets = (size_type)ceil((max - min + 1.0) / bkt);
2629  this->setParams(params);
2630  this->doInit(size);
2631  return this->self();
2632  }
2633 };
2634 
2640  : public VectorDistBase<VectorStandardDeviation, SampleStor>
2641 {
2642  public:
2650  {
2651  SampleStor::Params *params = new SampleStor::Params;
2652  this->doInit(size);
2653  this->setParams(params);
2654  return this->self();
2655  }
2656 };
2657 
2663  : public VectorDistBase<VectorAverageDeviation, AvgSampleStor>
2664 {
2665  public:
2673  {
2675  this->doInit(size);
2676  this->setParams(params);
2677  return this->self();
2678  }
2679 };
2680 
2681 template <class Stat>
2682 class FormulaInfoProxy : public InfoProxy<Stat, FormulaInfo>
2683 {
2684  protected:
2685  mutable VResult vec;
2686  mutable VCounter cvec;
2687 
2688  public:
2689  FormulaInfoProxy(Stat &stat) : InfoProxy<Stat, FormulaInfo>(stat) {}
2690 
2691  size_type size() const { return this->s.size(); }
2692 
2693  const VResult &
2694  result() const
2695  {
2696  this->s.result(vec);
2697  return vec;
2698  }
2699  Result total() const { return this->s.total(); }
2700  VCounter &value() const { return cvec; }
2701 
2702  std::string str() const { return this->s.str(); }
2703 };
2704 
2705 template <class Stat>
2706 class SparseHistInfoProxy : public InfoProxy<Stat, SparseHistInfo>
2707 {
2708  public:
2709  SparseHistInfoProxy(Stat &stat) : InfoProxy<Stat, SparseHistInfo>(stat) {}
2710 };
2711 
2716 template <class Derived, class Stor>
2717 class SparseHistBase : public DataWrap<Derived, SparseHistInfoProxy>
2718 {
2719  public:
2721  typedef Stor Storage;
2722  typedef typename Stor::Params Params;
2723 
2724  protected:
2726  char storage[sizeof(Storage)];
2727 
2728  protected:
2733  Storage *
2735  {
2736  return reinterpret_cast<Storage *>(storage);
2737  }
2738 
2743  const Storage *
2744  data() const
2745  {
2746  return reinterpret_cast<const Storage *>(storage);
2747  }
2748 
2749  void
2751  {
2752  new (storage) Storage(this->info());
2753  this->setInit();
2754  }
2755 
2756  public:
2758 
2765  template <typename U>
2766  void sample(const U &v, int n = 1) { data()->sample(v, n); }
2767 
2772  size_type size() const { return data()->size(); }
2777  bool zero() const { return data()->zero(); }
2778 
2779  void
2781  {
2782  Info *info = this->info();
2783  data()->prepare(info, info->data);
2784  }
2785 
2789  void
2791  {
2792  data()->reset(this->info());
2793  }
2794 };
2795 
2800 {
2801  public:
2803  struct Params : public DistParams
2804  {
2806  };
2807 
2808  private:
2813 
2814  public:
2816  {
2817  reset(info);
2818  }
2819 
2825  void
2826  sample(Counter val, int number)
2827  {
2828  cmap[val] += number;
2829  samples += number;
2830  }
2831 
2836  size_type size() const { return cmap.size(); }
2837 
2842  bool
2843  zero() const
2844  {
2845  return samples == Counter();
2846  }
2847 
2848  void
2850  {
2851  MCounter::iterator it;
2852  data.cmap.clear();
2853  for (it = cmap.begin(); it != cmap.end(); it++) {
2854  data.cmap[(*it).first] = (*it).second;
2855  }
2856 
2857  data.samples = samples;
2858  }
2859 
2863  void
2864  reset(Info *info)
2865  {
2866  cmap.clear();
2867  samples = 0;
2868  }
2869 };
2870 
2871 class SparseHistogram : public SparseHistBase<SparseHistogram, SparseHistStor>
2872 {
2873  public:
2879  SparseHistogram &
2881  {
2883  this->setParams(params);
2884  this->doInit();
2885  return this->self();
2886  }
2887 };
2888 
2889 class Temp;
2895 class Formula : public DataWrapVec<Formula, FormulaInfoProxy>
2896 {
2897  protected:
2900  friend class Temp;
2901 
2902  public:
2906  Formula();
2907 
2913  Formula(Temp r);
2914 
2920  const Formula &operator=(Temp r);
2921 
2927  const Formula &operator+=(Temp r);
2928 
2934  const Formula &operator/=(Temp r);
2935 
2943  void result(VResult &vec) const;
2944 
2955  Result total() const;
2956 
2960  size_type size() const;
2961 
2962  void prepare() { }
2963 
2967  void reset();
2968 
2972  bool zero() const;
2973 
2974  std::string str() const;
2975 };
2976 
2977 class FormulaNode : public Node
2978 {
2979  private:
2981  mutable VResult vec;
2982 
2983  public:
2984  FormulaNode(const Formula &f) : formula(f) {}
2985 
2986  size_type size() const { return formula.size(); }
2987  const VResult &result() const { formula.result(vec); return vec; }
2988  Result total() const { return formula.total(); }
2989 
2990  std::string str() const { return formula.str(); }
2991 };
2992 
2996 class Temp
2997 {
2998  protected:
3003 
3004  public:
3009  Temp(const NodePtr &n) : node(n) { }
3010 
3011  Temp(NodePtr &&n) : node(std::move(n)) { }
3012 
3017  operator NodePtr&() { return node; }
3018 
3022  NodePtr getNodePtr() const { return node; }
3023 
3024  public:
3029  Temp(const Scalar &s)
3030  : node(new ScalarStatNode(s.info()))
3031  { }
3032 
3037  Temp(const Value &s)
3038  : node(new ScalarStatNode(s.info()))
3039  { }
3040 
3045  Temp(const Average &s)
3046  : node(new ScalarStatNode(s.info()))
3047  { }
3048 
3053  Temp(const Vector &s)
3054  : node(new VectorStatNode(s.info()))
3055  { }
3056 
3058  : node(new VectorStatNode(s.info()))
3059  { }
3060 
3064  Temp(const Formula &f)
3065  : node(new FormulaNode(f))
3066  { }
3067 
3072  template <class Stat>
3074  : node(new ScalarProxyNode<Stat>(p))
3075  { }
3076 
3081  Temp(signed char value)
3082  : node(new ConstNode<signed char>(value))
3083  { }
3084 
3089  Temp(unsigned char value)
3090  : node(new ConstNode<unsigned char>(value))
3091  { }
3092 
3097  Temp(signed short value)
3098  : node(new ConstNode<signed short>(value))
3099  { }
3100 
3105  Temp(unsigned short value)
3106  : node(new ConstNode<unsigned short>(value))
3107  { }
3108 
3113  Temp(signed int value)
3114  : node(new ConstNode<signed int>(value))
3115  { }
3116 
3121  Temp(unsigned int value)
3122  : node(new ConstNode<unsigned int>(value))
3123  { }
3124 
3129  Temp(signed long value)
3130  : node(new ConstNode<signed long>(value))
3131  { }
3132 
3137  Temp(unsigned long value)
3138  : node(new ConstNode<unsigned long>(value))
3139  { }
3140 
3145  Temp(signed long long value)
3146  : node(new ConstNode<signed long long>(value))
3147  { }
3148 
3153  Temp(unsigned long long value)
3154  : node(new ConstNode<unsigned long long>(value))
3155  { }
3156 
3161  Temp(float value)
3162  : node(new ConstNode<float>(value))
3163  { }
3164 
3169  Temp(double value)
3170  : node(new ConstNode<double>(value))
3171  { }
3172 };
3173 
3174 
3179 inline Temp
3181 {
3182  return Temp(std::make_shared<BinaryNode<std::plus<Result> > >(l, r));
3183 }
3184 
3185 inline Temp
3187 {
3188  return Temp(std::make_shared<BinaryNode<std::minus<Result> > >(l, r));
3189 }
3190 
3191 inline Temp
3193 {
3194  return Temp(std::make_shared<BinaryNode<std::multiplies<Result> > >(l, r));
3195 }
3196 
3197 inline Temp
3199 {
3200  return Temp(std::make_shared<BinaryNode<std::divides<Result> > >(l, r));
3201 }
3202 
3203 inline Temp
3205 {
3206  return Temp(std::make_shared<UnaryNode<std::negate<Result> > >(l));
3207 }
3208 
3209 template <typename T>
3210 inline Temp
3212 {
3213  return Temp(std::make_shared<ConstNode<T> >(val));
3214 }
3215 
3216 template <typename T>
3217 inline Temp
3219 {
3220  return Temp(std::make_shared<ConstVectorNode<T> >(val));
3221 }
3222 
3223 inline Temp
3225 {
3226  return Temp(std::make_shared<SumNode<std::plus<Result> > >(val));
3227 }
3228 
3230 void dump();
3231 void reset();
3232 void enable();
3233 bool enabled();
3234 
3240 typedef void (*Handler)();
3241 
3242 void registerHandlers(Handler reset_handler, Handler dump_handler);
3243 
3249 
3254 void registerDumpCallback(Callback *cb);
3255 
3259 void processResetQueue();
3260 
3264 void processDumpQueue();
3265 
3267 
3268 typedef std::map<const void *, Info *> MapType;
3269 MapType &statsMap();
3270 
3271 typedef std::map<std::string, Info *> NameMapType;
3272 NameMapType &nameMap();
3273 
3274 bool validateStatName(const std::string &name);
3275 
3276 } // namespace Stats
3277 
3278 void debugDumpStats();
3279 
3280 #endif // __BASE_STATISTICS_HH__
const Storage * data() const
Retrieve a const pointer to the storage.
Definition: statistics.hh:660
Result total() const
Definition: statistics.hh:140
ProxyInfo * proxy
Definition: statistics.hh:807
Counter value() const
Return the current value of this stat as its base type.
Definition: statistics.hh:677
double Result
All results are doubles.
Definition: types.hh:52
Storage * data(off_type index)
Retrieve the storage.
Definition: statistics.hh:1018
std::map< Counter, int > MCounter
map of counters
Definition: types.hh:47
DistProxy(const DistProxy &sp)
Definition: statistics.hh:2022
Result total() const
Definition: statistics.hh:800
bool zero() const
Definition: statistics.hh:1294
std::string str() const
Definition: statistics.hh:2177
UnaryNode(NodePtr &p)
Definition: statistics.hh:2274
size_type size() const
Definition: statistics.hh:1080
DistProxy< Derived > Proxy
Definition: statistics.hh:1915
Storage * storage
The storage of this stat.
Definition: statistics.hh:1009
Templatized storage and interface for a sparse histogram stat.
Definition: statistics.hh:2799
const Formula & operator=(Temp r)
Set an unitialized Formula to the given root.
Definition: statistics.cc:391
std::string str() const
Definition: statistics.hh:985
size_type size() const
Return the number of nodes in the subtree starting at this node.
Definition: statistics.hh:2214
Counter samples
The number of samples.
Definition: statistics.hh:1544
std::string name
The name of the stat.
Definition: info.hh:73
Bitfield< 30, 0 > index
Temp(unsigned long long value)
Create a ConstNode.
Definition: statistics.hh:3153
void sample(const U &v, int n=1)
Definition: statistics.hh:2037
StandardDeviation()
Construct and initialize this distribution.
Definition: statistics.hh:2580
Result total() const
Definition: statistics.hh:768
Derived & method(T *obj, V(T::*method)() const)
Extended functor that calls the specified method of the provided object.
Definition: statistics.hh:840
bool zero() const
Definition: statistics.hh:1981
Counter value() const
Return the value of this stat as its base type.
Definition: statistics.hh:505
Stor::Params Params
Definition: statistics.hh:635
Derived & init(size_type _x, size_type _y)
Definition: statistics.hh:1253
Bitfield< 28 > v
Definition: miscregs.hh:1366
void processDumpQueue()
Process all the callbacks in the dump callbacks queue.
Definition: statistics.cc:488
Result total() const
Return a total of all entries in this vector.
Definition: statistics.hh:1069
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:358
const VectorProxy & operator=(const VectorProxy &sp)
Definition: statistics.hh:1196
Counter sum
The current sum.
Definition: statistics.hh:1674
virtual Result total() const =0
Return the total of the result vector.
Result total() const
Definition: statistics.hh:1176
bool zero() const
Definition: statistics.cc:452
std::vector< std::string > subdescs
Definition: info.hh:206
bool zero() const
Return true if no samples have been added.
Definition: statistics.hh:1790
void setParams(const StorageParams *params)
Save Storage class parameters if any.
Definition: statistics.cc:86
const std::string & name() const
Definition: statistics.hh:261
Generic callback class.
Definition: callback.hh:41
The parameters for a distribution stat.
Definition: statistics.hh:1357
const std::string & name()
Definition: trace.cc:49
const Storage * data(off_type index) const
Retrieve a const pointer to the storage.
Definition: statistics.hh:1025
void operator++()
Increment the stat by 1.
Definition: statistics.hh:691
Base class for formula statistic node.
Definition: statistics.hh:2070
Counter bucket_size
The number of entries in each bucket.
Definition: statistics.hh:1377
void reset(Info *info)
Reset stat value to default.
Definition: statistics.hh:1642
AverageDeviation()
Construct and initialize this distribution.
Definition: statistics.hh:2598
Bitfield< 7 > i
Definition: miscregs.hh:1378
A stat that calculates the per tick average of a value.
Definition: statistics.hh:2485
MethodProxy(T *obj, MethodPointer meth)
Definition: statistics.hh:797
VCounter & value() const
Definition: statistics.hh:2700
SampleStor(Info *info)
Create and initialize this storage.
Definition: statistics.hh:1684
size_type size() const
Definition: statistics.hh:1288
const VResult & result() const
Definition: statistics.hh:134
Counter min
The minimum value to track.
Definition: statistics.hh:1373
const Formula & operator/=(Temp r)
Divide the existing tree by the given one.
Definition: statistics.cc:415
void doInit(size_type s)
Definition: statistics.hh:1028
Counter min_val
The smallest value sampled.
Definition: statistics.hh:1394
VCounter & value() const
Definition: statistics.hh:127
VectorProxy(const VectorProxy &sp)
Definition: statistics.hh:1190
Temp(signed int value)
Create a ConstNode.
Definition: statistics.hh:3113
Counter current
The current count.
Definition: statistics.hh:537
void operator--(int)
Decrement the stat by 1.
Definition: statistics.hh:939
Temp(const AverageVector &s)
Definition: statistics.hh:3057
char storage[sizeof(Storage)] __attribute__((aligned(8)))
The storage of this stat.
virtual ~StorageParams()
Definition: statistics.cc:113
Storage * data(off_type index)
Definition: statistics.hh:1925
const VResult & result() const
Return the result vector of this subtree.
Definition: statistics.hh:2108
Counter max_bucket
The maximum value to track.
Definition: statistics.hh:1533
Temp(unsigned char value)
Create a ConstNode.
Definition: statistics.hh:3089
Result total() const
Return the total Formula result.
Definition: statistics.cc:432
virtual size_type size() const =0
Result result() const
Return the value of this stat as a result type.
Definition: statistics.hh:510
Counter overflow
The number of values sampled more than max.
Definition: statistics.hh:1400
void operator+=(const U &v)
Increment the stat by the given value.
Definition: statistics.hh:717
Result result() const
Definition: statistics.hh:110
std::string str() const
Definition: statistics.hh:2305
VCounter cvec
Counter for each bucket.
Definition: statistics.hh:1546
const VResult & result() const
Return the result vector of this subtree.
Definition: statistics.hh:2188
const DistType type
Definition: statistics.hh:1359
Bitfield< 8 > a
Definition: miscregs.hh:1377
InfoProxyType< Derived > Info
Definition: statistics.hh:212
size_type buckets
The number of buckets.
Definition: statistics.hh:1524
Proxy operator[](off_type index)
Definition: statistics.hh:1968
void inc(Counter val)
Increment the current count by the provided value, calls set.
Definition: statistics.hh:573
Counter min_val
Definition: info.hh:181
Implementation of a distribution stat.
Definition: statistics.hh:1820
virtual size_type size() const =0
Return the number of nodes in the subtree starting at this node.
VectorInfoProxy(Stat &stat)
Definition: statistics.hh:122
void operator--()
Decrement the stat by 1.
Definition: statistics.hh:696
VectorAverageDeviation & init(size_type size)
Initialize storage for this distribution.
Definition: statistics.hh:2672
virtual Result total() const =0
size_type size() const
Definition: statistics.hh:749
DistType type
Definition: info.hh:176
void prepare(Info *info, DistData &data)
Definition: statistics.hh:1793
Temp operator/(Temp l, Temp r)
Definition: statistics.hh:3198
ScalarProxy< Derived > Proxy
Proxy type.
Definition: statistics.hh:1003
virtual std::string str() const =0
const Info * info() const
Definition: statistics.hh:226
Bitfield< 0 > sp
Definition: miscregs.hh:1386
size_type size() const
Return the number of nodes in the subtree starting at this node.
Definition: statistics.hh:2175
void result(VResult &vec) const
Copy the values to a local vector and return a reference to it.
Definition: statistics.hh:1057
std::string str() const
Definition: statistics.hh:2453
Counter samples
Counter for number of samples.
Definition: statistics.hh:2810
void(* Handler)()
Register reset and dump handlers.
Definition: statistics.hh:3240
const VResult & result() const
Return the result vector of this subtree.
Definition: statistics.hh:2202
void reset()
Definition: statistics.cc:526
Result total
The total count for all tick.
Definition: statistics.hh:541
std::string str() const
Definition: statistics.hh:748
Counter min_track
The minimum value to track.
Definition: statistics.hh:1387
Templatized storage and interface for a simple scalar stat.
Definition: statistics.hh:468
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:382
const VResult & result() const
Return the result vector of this subtree.
Definition: statistics.hh:2987
bool zero() const
Definition: statistics.hh:2049
char storage[sizeof(Storage)] __attribute__((aligned(8)))
The storage for this stat.
A vector of scalar stats.
Definition: statistics.hh:2499
Bitfield< 23, 0 > offset
Definition: types.hh:149
Histogram & init(size_type size)
Set the parameters of this histogram.
Definition: statistics.hh:2560
MethodPointer method
Definition: statistics.hh:794
V(T::* MethodPointer)() const
Definition: statistics.hh:793
size_type buckets
The number of buckets.
Definition: statistics.hh:1379
VectorDistribution & init(size_type size, Counter min, Counter max, Counter bkt)
Initialize storage and parameters for this distribution.
Definition: statistics.hh:2622
list< Info * > & statsList()
Definition: statistics.cc:56
A vector of distributions.
Definition: statistics.hh:2610
Counter squares
Current sum of squares.
Definition: statistics.hh:1756
MCounter cmap
Counter for each bucket.
Definition: statistics.hh:2812
std::vector< std::string > y_subnames
Definition: info.hh:223
virtual Result result() const =0
Counter logs
The sum of logarithm of each sample, used to compute geometric mean.
Definition: statistics.hh:1540
Storage * data()
Retrieve the storage.
Definition: statistics.hh:1837
Temp(signed char value)
Create a ConstNode.
Definition: statistics.hh:3081
void add(HistStor *)
Definition: statistics.cc:359
size_type size() const
Return the number of nodes in the subtree starting at this node.
Definition: statistics.hh:2387
Result total() const
Definition: statistics.hh:165
const Storage * data(off_type index) const
Definition: statistics.hh:1235
Counter max
Definition: info.hh:178
Counter value() const
Definition: statistics.hh:798
bool zero() const
Returns true if any calls to sample have been made.
Definition: statistics.hh:2843
void operator--(int)
Decrement the stat by 1.
Definition: statistics.hh:701
Counter value() const
Definition: statistics.hh:109
ScalarProxy(Stat &s, off_type i)
Create and initialize this proxy, do not register it with the database.
Definition: statistics.hh:897
The parameters for a distribution stat.
Definition: statistics.hh:1521
Counter squares
The sum of squares.
Definition: statistics.hh:1542
Derived & scalar(T &value)
Definition: statistics.hh:815
void operator++()
Increment the stat by 1.
Definition: statistics.hh:929
Derived & flags(Flags _flags)
Set the flags and marks this stat to print at the end of simulation.
Definition: statistics.hh:311
Counter min_bucket
The minimum value to track.
Definition: statistics.hh:1531
unsigned int size_type
Definition: types.hh:56
const Formula & formula
Definition: statistics.hh:2980
const Formula & operator+=(Temp r)
Add the given tree to the existing one.
Definition: statistics.cc:401
Proxy operator[](off_type index)
Return a reference (ScalarProxy) to the stat at the given index.
Definition: statistics.hh:1131
Result total() const
Definition: statistics.hh:111
Counter overflow
Definition: info.hh:184
Result total() const
Return the total of the result vector.
Definition: statistics.hh:2144
VectorDistInfoProxy< Derived > Info
Definition: statistics.hh:1912
virtual void visit(const ScalarInfo &info)=0
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2475
This is a vector of AverageDeviation stats.
Definition: statistics.hh:2662
bool zero() const
Returns true if any calls to sample have been made.
Definition: statistics.hh:1458
Derived & init(size_type size)
Set this vector to have the given size.
Definition: statistics.hh:1118
VectorStatNode(const VectorInfo *d)
Definition: statistics.hh:2171
Calculates the mean and variance of all the samples.
Definition: statistics.hh:2574
void doInit(size_type s)
Definition: statistics.hh:1937
Bitfield< 63 > val
Definition: misc.hh:770
size_type size() const
Return the number of entries in this stat.
Definition: statistics.hh:2772
Bitfield< 31 > n
Definition: miscregs.hh:1636
size_type size() const
Return the number of entries in this stat.
Definition: statistics.hh:1875
const char data[]
Definition: circlebuf.cc:43
bool zero() const
Definition: statistics.hh:1083
Bitfield< 6 > f
Definition: miscregs.hh:1379
double Counter
All counters are of 64-bit values.
Definition: types.hh:43
void sample(Counter val, int number)
Add a value to the distribution for the given number of times.
Definition: statistics.hh:1773
virtual const VResult & result() const =0
Return the result vector of this subtree.
size_type size() const
Definition: statistics.hh:850
const Storage * data() const
Retrieve a const pointer to the storage.
Definition: statistics.hh:1847
size_type size() const
Return the number of nodes in the subtree starting at this node.
Definition: statistics.hh:2150
ScalarProxy(const ScalarProxy &sp)
Create a copy of the provided ScalarProxy.
Definition: statistics.hh:906
void result(VResult &vec) const
Return the result of the Fomula in a vector.
Definition: statistics.cc:425
Temp(signed long long value)
Create a ConstNode.
Definition: statistics.hh:3145
Data structure of sparse histogram.
Definition: info.hh:243
DistParams(DistType t)
Definition: statistics.hh:1360
void value(VCounter &vec) const
Definition: statistics.hh:1045
Bitfield< 7 > b
Definition: miscregs.hh:1564
const VResult & result() const
Definition: statistics.hh:2694
void visit(Output &visitor)
Visitor entry for outputing statistics data.
Definition: statistics.hh:755
Result total() const
Return the total of the result vector.
Definition: statistics.hh:2293
void operator++(int)
Increment the stat by 1.
Definition: statistics.hh:699
Formula()
Create and initialize thie formula, and register it with the database.
Definition: statistics.cc:379
void prepare(Info *info, DistData &data)
Definition: statistics.hh:1464
size_type size() const
Definition: statistics.hh:2043
bool zero() const
Returns true if any calls to sample have been made.
Definition: statistics.hh:1608
Counter samples
The number of samples.
Definition: statistics.hh:1406
Result result() const
Definition: statistics.hh:848
HistStor(Info *info)
Definition: statistics.hh:1549
size_type size() const
Definition: statistics.hh:1211
void enable()
Definition: statistics.cc:508
const VResult & result() const
Return the result vector of this subtree.
Definition: statistics.hh:2323
Tick curTick()
The current simulated tick.
Definition: core.hh:47
Counter max
The maximum value to track.
Definition: statistics.hh:1375
Temp(const ScalarProxy< Stat > &p)
Create a new ScalarProxyNode.
Definition: statistics.hh:3073
void prepare(Info *info, DistData &data)
Definition: statistics.hh:1717
Counter squares
The sum of squares.
Definition: statistics.hh:1676
VCounter cvec
Counter for each bucket.
Definition: statistics.hh:1408
virtual const VResult & result() const =0
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
void operator=(const U &v)
Set the data value to the given value.
Definition: statistics.hh:709
VCounter cvec
Local storage for the entry values, used for printing.
Definition: info.hh:229
bool check() const
Definition: statistics.hh:854
Bitfield< 4 > s
Definition: miscregs.hh:1738
const DistProxy & operator=(const DistProxy &sp)
Definition: statistics.hh:2027
Derived & setSeparator(const std::string &_sep)
Set the character(s) used between the name and vector number on vectors, dist, etc.
Definition: statistics.hh:270
Temp operator-(Temp l, Temp r)
Definition: statistics.hh:3186
FormulaInfoProxy(Stat &stat)
Definition: statistics.hh:2689
void reset()
Proxy has no state.
Definition: statistics.hh:2057
Temp(const Average &s)
Create a new ScalarStatNode.
Definition: statistics.hh:3045
bool zero() const
Definition: statistics.hh:198
Counter min
Definition: info.hh:177
Result result() const
Return the current average.
Definition: statistics.hh:592
Tick last
The tick that current last changed.
Definition: statistics.hh:543
BinaryNode(NodePtr &a, NodePtr &b)
Definition: statistics.hh:2320
Result result() const
Return the current value of this statas a result type.
Definition: statistics.hh:890
Templatized storage and interface for a histogram stat.
Definition: statistics.hh:1517
Stor::Params Params
Definition: statistics.hh:1220
void reset()
Formulas don't need to be reset.
Definition: statistics.cc:447
std::string str() const
Definition: statistics.hh:2990
size_type size() const
Return the number of nodes in the subtree starting at this node.
Definition: statistics.hh:2116
Counter sum
The current sum.
Definition: statistics.hh:1538
bool zero() const
Definition: statistics.hh:753
Proxy operator[](off_type index)
Definition: statistics.hh:1279
uint64_t Tick
Tick count type.
Definition: types.hh:63
Result total() const
Definition: statistics.hh:849
Counter squares
The sum of squares.
Definition: statistics.hh:1404
const Stat::Storage * data() const
Definition: statistics.hh:2015
Counter underflow
Definition: info.hh:183
A simple distribution stat.
Definition: statistics.hh:2523
std::shared_ptr< Node > NodePtr
Shared pointer to a function Node.
Definition: statistics.hh:2096
Implementation of a scalar stat.
Definition: statistics.hh:631
virtual Result total() const =0
void grow_convert()
Definition: statistics.cc:315
FormulaNode(const Formula &f)
Definition: statistics.hh:2984
void reset()
Reset the stat to the default state.
Definition: statistics.hh:752
The parameters for a distribution stat.
Definition: statistics.hh:1370
bool check() const
Definition: statistics.hh:2000
Flags flags
The formatting flags.
Definition: info.hh:79
void dec(Counter val)
Decrement the stat by the given value.
Definition: statistics.hh:500
Derived & prereq(const Stat &prereq)
Set the prerequisite stat and marks this stat to print at the end of simulation.
Definition: statistics.hh:325
void set(Counter val)
Set the current count to the one provided, update the total and last set values.
Definition: statistics.hh:562
void reset(Info *info)
Reset stat value to default.
Definition: statistics.hh:518
ScalarStatNode(const ScalarInfo *d)
Definition: statistics.hh:2105
ScalarProxy< Stat > operator[](off_type index)
Definition: statistics.hh:1205
Bitfield< 9 > d
Definition: miscregs.hh:1375
void registerResetCallback(Callback *cb)
Register a callback that should be called whenever statistics are reset.
Definition: statistics.cc:494
Counter value() const
Return the current count.
Definition: statistics.hh:585
VectorDistInfoProxy(Stat &stat)
Definition: statistics.hh:154
ScalarInfoProxy(Stat &stat)
Definition: statistics.hh:107
void reset()
Reset the stat to the default state.
Definition: statistics.hh:192
InfoProxyType< Derived > Info
Definition: statistics.hh:421
DistType
Definition: info.hh:172
Counter value() const
Definition: statistics.hh:779
void reset(Info *info)
Reset stat value to default.
Definition: statistics.hh:617
size_type size() const
Return the number of buckets in this distribution.
Definition: statistics.hh:1601
Counter bucket_size
The number of entries in each bucket.
Definition: statistics.hh:1391
A simple histogram stat.
Definition: statistics.hh:2551
StatStor(Info *info)
Builds this storage element and calls the base constructor of the datatype.
Definition: statistics.hh:482
Temp constant(T val)
Definition: statistics.hh:3211
const VResult & result() const
Return the result vector of this subtree.
Definition: statistics.hh:2137
void setName(const std::string &name)
Set the name of this statistic.
Definition: statistics.cc:172
Temp(const NodePtr &n)
Copy the given pointer to this class.
Definition: statistics.hh:3009
virtual Counter value() const =0
Temp(signed short value)
Create a ConstNode.
Definition: statistics.hh:3097
size_type size() const
Return the number of buckets in this distribution.
Definition: statistics.hh:2836
ScalarProxyNode(const ScalarProxy< Stat > &p)
Definition: statistics.hh:2132
std::string str() const
Definition: statistics.hh:2216
size_type size() const
Definition: statistics.hh:1975
Storage * data()
Retrieve the storage.
Definition: statistics.hh:2734
void prepare(Info *info)
Prepare stat data for dumping or serialization.
Definition: statistics.hh:607
AvgStor(Info *info)
Build and initializes this stat storage.
Definition: statistics.hh:552
Counter sum
Current total.
Definition: statistics.hh:1754
void operator-=(const U &v)
Decrement the stat by the given value.
Definition: statistics.hh:725
Distribution & init(Counter min, Counter max, Counter bkt)
Set the parameters of this distribution.
Definition: statistics.hh:2534
Implementation of a sparse histogram stat.
Definition: statistics.hh:2717
Result result() const
Definition: statistics.hh:780
DataWrap(const DataWrap &stat)
Copy constructor, copies are not allowed.
Definition: statistics.hh:235
bool zero() const
Definition: statistics.hh:853
bool zero() const
Definition: statistics.hh:601
STL list class.
Definition: stl.hh:54
std::vector< DistData > data
Definition: info.hh:202
const FlagsType display
Print this stat.
Definition: info.hh:47
void operator=(const DataWrapVec &)
Definition: statistics.hh:344
Calculates the per tick mean and variance of the samples.
Definition: statistics.hh:2592
const std::string & setSeparator() const
Definition: statistics.hh:275
size_type size() const
Definition: statistics.hh:124
void sample(Counter val, int number)
Add a value to the distribution for the given number of times.
Definition: statistics.hh:1423
Result total() const
Return the total of the result vector.
Definition: statistics.hh:2988
unsigned int off_type
Definition: types.hh:57
Temp(const Value &s)
Create a new ScalarStatNode.
Definition: statistics.hh:3037
size_type size() const
Return the number of nodes in the subtree starting at this node.
Definition: statistics.hh:2986
Temp(float value)
Create a ConstNode.
Definition: statistics.hh:3161
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
std::string ysubname(off_type i) const
Definition: statistics.hh:452
Temp(unsigned int value)
Create a ConstNode.
Definition: statistics.hh:3121
const Storage * data(off_type index) const
Definition: statistics.hh:1931
std::map< const void *, Info * > MapType
Definition: statistics.hh:3268
bool zero() const
Return true if no samples have been added.
Definition: statistics.hh:1714
Derived & precision(int _precision)
Set the precision and marks this stat to print at the end of simulation.
Definition: statistics.hh:299
size_type x
Definition: info.hh:225
void dec(Counter val)
Deccrement the current count by the provided value, calls set.
Definition: statistics.hh:579
T safe_cast(U ptr)
Definition: cast.hh:61
Counter bucket_size
The number of entries in each bucket.
Definition: statistics.hh:1535
Result total() const
Return a total of all entries in this vector.
Definition: statistics.hh:1310
Counter logs
Definition: info.hh:188
Temp operator+(Temp l, Temp r)
Definition: statistics.hh:3180
Templatized storage and interface to a per-tick average stat.
Definition: statistics.hh:533
Helper class to construct formula node trees.
Definition: statistics.hh:2996
void operator=(const DataWrap &)
Can't copy stats.
Definition: statistics.hh:240
bool enabled()
Definition: statistics.cc:502
void reset()
Reset stat value to default.
Definition: statistics.hh:1893
Temp(signed long value)
Create a ConstNode.
Definition: statistics.hh:3129
const VResult & result() const
Return the result vector of this subtree.
Definition: statistics.hh:2419
SparseHistInfoProxy< Derived > Info
Definition: statistics.hh:2720
bool check() const
Check that this stat has been set up properly and is ready for use.
Definition: statistics.hh:750
NameMapType & nameMap()
Definition: statistics.cc:118
Counter max_track
The maximum value to track.
Definition: statistics.hh:1389
void registerDumpCallback(Callback *cb)
Register a callback that should be called whenever statistics are about to be dumped.
Definition: statistics.cc:535
Result result() const
Definition: statistics.hh:799
Templatized storage and interface for a distribution stat.
Definition: statistics.hh:1366
size_type size() const
Definition: statistics.hh:2691
DistStor(Info *info)
Definition: statistics.hh:1411
void debugDumpStats()
Definition: statistics.cc:543
Counter max_val
The largest value sampled.
Definition: statistics.hh:1396
A formula for statistics that is calculated when printed.
Definition: statistics.hh:2895
Counter samples
Definition: info.hh:189
Result total() const
Return the total of the result vector.
Definition: statistics.hh:2205
Tick lastReset
The tick of the last reset.
Definition: statistics.hh:539
void sample(Counter val, int number)
Add a value to the distribution for the given number of times.
Definition: statistics.hh:2826
Derived & name(const std::string &name)
Set the name and marks this stat to print at the end of simulation.
Definition: statistics.hh:254
Temp sum(Temp val)
Definition: statistics.hh:3224
Templatized storage for distribution that calculates per tick mean and variance.
Definition: statistics.hh:1744
bool zero() const
Return true if no samples have been added.
Definition: statistics.hh:1880
void reset(Info *info)
Reset stat value to default.
Definition: statistics.hh:1492
void sample(Counter val, int number)
Add a value the given number of times to this running average.
Definition: statistics.hh:1696
SumNode(NodePtr &p)
Definition: statistics.hh:2416
size_type size() const
Return the number of elements in the tree.
Definition: statistics.cc:438
bool check() const
Definition: statistics.hh:92
void setInit()
Save Storage class parameters if any.
Definition: statistics.cc:92
void prepare()
Prepare the stat for dumping.
Definition: statistics.hh:751
InfoProxy(Stat &stat)
Definition: statistics.hh:90
int size()
Definition: pagetable.hh:146
const VResult & result() const
Return the result vector of this subtree.
Definition: statistics.hh:2172
Temp constantVector(T val)
Definition: statistics.hh:3218
size_type size() const
Return the number of buckets in this distribution.
Definition: statistics.hh:1451
Result total() const
Return the total of the result vector.
Definition: statistics.hh:2173
VCounter cvec
Definition: info.hh:185
bool zero() const
Return true if no samples have been added.
Definition: statistics.hh:2777
The parameters for a sparse histogram stat.
Definition: statistics.hh:2803
const VResult & result() const
Return the result vector of this subtree.
Definition: statistics.hh:2277
const VResult & result() const
Definition: statistics.hh:1165
size_type size() const
Return the number of nodes in the subtree starting at this node.
Definition: statistics.hh:2450
Counter underflow
The number of values sampled less than min.
Definition: statistics.hh:1398
size_type y
Definition: info.hh:226
void processResetQueue()
Process all the callbacks in the reset callbacks queue.
Definition: statistics.cc:482
Storage * data()
Retrieve the storage.
Definition: statistics.hh:648
Result total() const
Return the total of the result vector.
Definition: statistics.hh:2114
void setInfo(Info *info)
Set up an info class for this statistic.
Definition: statistics.cc:70
NodePtr getNodePtr() const
Makde gcc < 4.6.3 happy and explicitly get the underlying node.
Definition: statistics.hh:3022
Stor::Params Params
Definition: statistics.hh:1825
const StorageParams * storageParams
Definition: info.hh:92
const ScalarProxy & operator=(const ScalarProxy &sp)
Set this proxy equal to the provided one.
Definition: statistics.hh:916
bool check() const
Definition: statistics.hh:1092
Counter squares
Definition: info.hh:187
Result total() const
Return the total of the result vector.
Definition: statistics.hh:2355
void operator-=(const U &v)
Decrement the stat by the given value.
Definition: statistics.hh:972
void add(DistBase &d)
Add the argument distribution to the this distribution.
Definition: statistics.hh:1901
SparseHistData data
Local storage for the entry values, used for printing.
Definition: info.hh:254
void prepare(Info *info, SparseHistData &data)
Definition: statistics.hh:2849
Derived & ysubname(off_type index, const std::string &subname)
Definition: statistics.hh:440
Temp(const Scalar &s)
Create a new ScalarStatNode.
Definition: statistics.hh:3029
Vector2dInfoProxy< Derived > Info
Definition: statistics.hh:1218
bool validateStatName(const string &name)
Definition: statistics.cc:141
Counter data
The statistic value.
Definition: statistics.hh:472
void sample(Counter val, int number)
Add a value to the distribution for the given number of times.
Definition: statistics.hh:1566
Counter max_val
Definition: info.hh:182
Counter value() const
Return the current value of this stat as its base type.
Definition: statistics.hh:884
size_type size() const
Definition: statistics.hh:156
Counter sum
Definition: info.hh:186
DistInfoProxy(Stat &stat)
Definition: statistics.hh:147
SparseHistogram & init(size_type size)
Set the parameters of this histogram.
Definition: statistics.hh:2880
Result total() const
Return the total of the result vector.
Definition: statistics.hh:2435
Counter bucket_size
Definition: info.hh:179
const Storage * data() const
Retrieve a const pointer to the storage.
Definition: statistics.hh:2744
SparseHistStor(Info *info)
Definition: statistics.hh:2815
Temp operator*(Temp l, Temp r)
Definition: statistics.hh:3192
off_type index
The index to access in the parent VectorBase.
Definition: statistics.hh:877
std::string str() const
Definition: statistics.hh:2159
std::string str() const
Definition: statistics.hh:852
VectorProxy< Derived > Proxy
Definition: statistics.hh:1221
DataWrapVec(const DataWrapVec &ref)
Definition: statistics.hh:341
A vector of Average stats.
Definition: statistics.hh:2507
VectorProxy(Stat &s, off_type o, size_type l)
Definition: statistics.hh:1185
void reset()
Reset stat value to default.
Definition: statistics.hh:1336
ConstVectorNode(const T &s)
Definition: statistics.hh:2201
std::string str() const
Definition: statistics.hh:2402
std::string str() const
Definition: statistics.hh:2191
NodePtr root
The root of the tree which represents the Formula.
Definition: statistics.hh:2899
size_type size() const
Return the number of elements, always 1 for a scalar.
Definition: statistics.hh:981
std::string str() const
Definition: statistics.hh:2121
Stat::Storage * data(off_type index)
Definition: statistics.hh:1150
void inc(Counter val)
Increment the stat by the given value.
Definition: statistics.hh:495
std::string str() const
Definition: statistics.cc:463
void reset(Info *info)
Reset stat value to default.
Definition: statistics.hh:1732
Temp(unsigned short value)
Create a ConstNode.
Definition: statistics.hh:3105
void sample(const U &v, int n=1)
Add a value to the distribtion n times.
Definition: statistics.hh:2766
Derived & desc(const std::string &_desc)
Set the description and marks this stat to print at the end of simulation.
Definition: statistics.hh:287
void prepare(Info *info, DistData &data)
Definition: statistics.hh:1614
Result result() const
Definition: statistics.hh:767
void operator--()
Decrement the stat by 1.
Definition: statistics.hh:934
const ScalarProxy< Stat > proxy
Definition: statistics.hh:2128
void operator=(const U &v)
Set the data value to the given value.
Definition: statistics.hh:948
void dump()
Dump all statistics data to the registered outputs.
Definition: statistics.cc:517
Vector2dInfoProxy(Stat &stat)
Definition: statistics.hh:163
size_type size() const
Return the number of entries, in this case 1.
Definition: statistics.hh:1784
A 2-Dimensional vecto of scalar stats.
Definition: statistics.hh:2515
Counter value()
Definition: statistics.hh:847
Bitfield< 5 > t
Definition: miscregs.hh:1382
std::map< std::string, Info * > NameMapType
Definition: statistics.hh:3271
size_type size() const
Return the number of entries in this stat, 1.
Definition: statistics.hh:1708
Bitfield< 4 > op
Definition: types.hh:80
bool check() const
Check that this stat has been set up properly and is ready for use.
Definition: statistics.hh:205
Storage * data(off_type index)
Definition: statistics.hh:1234
DistInfoProxy< Derived > Info
Definition: statistics.hh:1823
VectorStandardDeviation & init(size_type size)
Initialize storage for this distribution.
Definition: statistics.hh:2649
void reset(Info *info)
Reset stat value to default.
Definition: statistics.hh:2864
InfoProxyType< Derived > Info
Definition: statistics.hh:336
size_type size() const
Return the number of elements, always 1 for a scalar.
Definition: statistics.hh:731
This is a vector of StandardDeviation stats.
Definition: statistics.hh:2639
Derived & ysubnames(const char **names)
Definition: statistics.hh:428
Result total() const
Definition: statistics.hh:781
Temp(double value)
Create a ConstNode.
Definition: statistics.hh:3169
void registerHandlers(Handler reset_handler, Handler dump_handler)
Definition: statistics.cc:472
const ScalarInfo * data
Definition: statistics.hh:2101
std::string str() const
Definition: statistics.hh:2702
Temp(unsigned long value)
Create a ConstNode.
Definition: statistics.hh:3137
Bitfield< 0 > p
Bitfield< 9, 8 > rs
Definition: miscregs.hh:1560
size_type size() const
Return the number of nodes in the subtree starting at this node.
Definition: statistics.hh:2190
NodePtr node
Pointer to a Node object.
Definition: statistics.hh:3002
void prepare(Info *info)
Prepare stat data for dumping or serialization.
Definition: statistics.hh:514
Result total() const
Definition: statistics.hh:2699
Derived & functor(T &func)
Definition: statistics.hh:824
void visit(Output &visitor)
Definition: statistics.hh:96
Info * info()
Grab the information class for this statistic.
Definition: statistics.cc:98
void operator++(int)
Increment the stat by 1.
Definition: statistics.hh:937
void set(Type flags)
Definition: flags.hh:70
Bitfield< 5 > l
A proxy similar to the FunctorProxy, but allows calling a method of a bound object, instead of a global free-standing function.
Definition: statistics.hh:789
Counter samples
The number of samples.
Definition: statistics.hh:1678
const VectorInfo * data
Definition: statistics.hh:2168
char storage[sizeof(Storage)]
The storage for this stat.
Definition: statistics.hh:2726
Temp(const Formula &f)
Definition: statistics.hh:3064
Temp(const Vector &s)
Create a new VectorStatNode.
Definition: statistics.hh:3053
Counter sum
The current sum.
Definition: statistics.hh:1402
Implementation of a vector of stats.
Definition: statistics.hh:996
void operator+=(const U &v)
Increment the stat by the given value.
Definition: statistics.hh:960
DistData data
Local storage for the entry values, used for printing.
Definition: info.hh:196
void set(Counter val)
The the stat to the given value.
Definition: statistics.hh:490
Counter value() const
Definition: statistics.hh:766
void sample(const U &v, int n=1)
Add a value to the distribtion n times.
Definition: statistics.hh:1869
Stor::Params Params
Definition: statistics.hh:1000
size_type size() const
Return the number of nodes in the subtree starting at this node.
Definition: statistics.hh:2302
Stat::Storage * data()
Definition: statistics.hh:2014
std::vector< std::string > subnames
Names and descriptions of subfields.
Definition: info.hh:205
Result total() const
Return the total of the result vector.
Definition: statistics.hh:2189
bool check() const
Definition: statistics.hh:1345
void reset()
Reset stat value to default.
Definition: statistics.hh:2790
Templatized storage and interface for a distribution that calculates mean and variance.
Definition: statistics.hh:1664
const Stat::Storage * data(off_type index) const
Definition: statistics.hh:1157
bool zero() const
Definition: statistics.hh:523
DistProxy(Stat &s, off_type i)
Definition: statistics.hh:2018
Stat & stat
Pointer to the parent Vector.
Definition: statistics.hh:874
MapType & statsMap()
Definition: statistics.cc:63
A proxy class to access the stat at a given index in a VectorBase stat.
Definition: statistics.hh:870
bool zero() const
Definition: statistics.hh:100
AvgSampleStor(Info *info)
Create and initialize this storage.
Definition: statistics.hh:1762
void reset(Info *info)
Reset stat value to default.
Definition: statistics.hh:1808
Temp(NodePtr &&n)
Definition: statistics.hh:3011

Generated on Fri Jun 9 2017 13:03:41 for gem5 by doxygen 1.8.6