2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Nathan Binkert
32 * Declaration of Statistics objects.
38 * Generalized N-dimensinal vector
42 * -- these both can use the same function that prints out a
43 * specific set of stats
44 * VectorStandardDeviation totals
47 #ifndef __BASE_STATISTICS_HH__
48 #define __BASE_STATISTICS_HH__
62 #include "base/cast.hh"
63 #include "base/cprintf.hh"
64 #include "base/intmath.hh"
65 #include "base/refcnt.hh"
66 #include "base/str.hh"
67 #include "base/stats/flags.hh"
68 #include "base/stats/visit.hh"
69 #include "base/stats/types.hh"
70 #include "sim/host.hh"
74 /** The current simulated tick. */
77 /* A namespace for all of the Statistics */
82 virtual ~StorageParams();
85 //////////////////////////////////////////////////////////////////////
87 // Statistics Framework Base classes
89 //////////////////////////////////////////////////////////////////////
93 /** The name of the stat. */
95 /** The description of the stat. */
97 /** The formatting flags. */
99 /** The display precision. */
101 /** A pointer to a prerequisite Stat. */
104 * A unique stat ID for each stat in the simulator.
105 * Can be used externally for lookups as well as for debugging.
111 const StorageParams *storageParams;
117 /** Set the name of this statistic */
118 void setName(const std::string &name);
121 * Check that this stat has been set up properly and is ready for
123 * @return true for success
125 virtual bool check() const = 0;
126 bool baseCheck() const;
129 * Enable the stat for use
131 virtual void enable();
134 * Prepare the stat for dumping.
136 virtual void prepare() = 0;
139 * Reset the stat to the default state.
141 virtual void reset() = 0;
144 * @return true if this stat has a value and satisfies its
145 * requirement as a prereq
147 virtual bool zero() const = 0;
150 * Visitor entry for outputing statistics data
152 virtual void visit(Visit &visitor) = 0;
155 * Checks if the first stat's name is alphabetically less than the second.
156 * This function breaks names up at periods and considers each subname
158 * @param stat1 The first stat.
159 * @param stat2 The second stat.
160 * @return stat1's name is alphabetically before stat2's
162 static bool less(Info *stat1, Info *stat2);
165 template <class Stat, class Base>
166 class InfoWrap : public Base
172 InfoWrap(Stat &stat) : s(stat) {}
174 bool check() const { return s.check(); }
175 void prepare() { s.prepare(); }
176 void reset() { s.reset(); }
178 visit(Visit &visitor)
180 visitor.visit(*static_cast<Base *>(this));
182 bool zero() const { return s.zero(); }
185 class ScalarInfoBase : public Info
188 virtual Counter value() const = 0;
189 virtual Result result() const = 0;
190 virtual Result total() const = 0;
193 template <class Stat>
194 class ScalarInfo : public InfoWrap<Stat, ScalarInfoBase>
197 ScalarInfo(Stat &stat) : InfoWrap<Stat, ScalarInfoBase>(stat) {}
199 Counter value() const { return this->s.value(); }
200 Result result() const { return this->s.result(); }
201 Result total() const { return this->s.total(); }
204 class VectorInfoBase : public Info
207 /** Names and descriptions of subfields. */
208 std::vector<std::string> subnames;
209 std::vector<std::string> subdescs;
215 virtual size_type size() const = 0;
216 virtual const VCounter &value() const = 0;
217 virtual const VResult &result() const = 0;
218 virtual Result total() const = 0;
221 template <class Stat>
222 class VectorInfo : public InfoWrap<Stat, VectorInfoBase>
225 mutable VCounter cvec;
226 mutable VResult rvec;
229 VectorInfo(Stat &stat) : InfoWrap<Stat, VectorInfoBase>(stat) {}
231 size_type size() const { return this->s.size(); }
243 this->s.result(rvec);
247 Result total() const { return this->s.total(); }
262 class DistInfoBase : public Info
265 /** Local storage for the entry values, used for printing. */
269 template <class Stat>
270 class DistInfo : public InfoWrap<Stat, DistInfoBase>
273 DistInfo(Stat &stat) : InfoWrap<Stat, DistInfoBase>(stat) {}
276 class VectorDistInfoBase : public Info
279 std::vector<DistData> data;
281 /** Names and descriptions of subfields. */
282 std::vector<std::string> subnames;
283 std::vector<std::string> subdescs;
287 /** Local storage for the entry values, used for printing. */
288 mutable VResult rvec;
291 virtual size_type size() const = 0;
294 template <class Stat>
295 class VectorDistInfo : public InfoWrap<Stat, VectorDistInfoBase>
298 VectorDistInfo(Stat &stat) : InfoWrap<Stat, VectorDistInfoBase>(stat) {}
300 size_type size() const { return this->s.size(); }
303 class Vector2dInfoBase : public Info
306 /** Names and descriptions of subfields. */
307 std::vector<std::string> subnames;
308 std::vector<std::string> subdescs;
309 std::vector<std::string> y_subnames;
314 /** Local storage for the entry values, used for printing. */
315 mutable VCounter cvec;
320 template <class Stat>
321 class Vector2dInfo : public InfoWrap<Stat, Vector2dInfoBase>
324 Vector2dInfo(Stat &stat) : InfoWrap<Stat, Vector2dInfoBase>(stat) {}
330 /** Set up an info class for this statistic */
331 void setInfo(Info *info);
332 /** Save Storage class parameters if any */
333 void setParams(const StorageParams *params);
334 /** Save Storage class parameters if any */
337 /** Grab the information class for this statistic */
339 /** Grab the information class for this statistic */
340 const Info *info() const;
344 * Reset the stat to the default state.
349 * @return true if this stat has a value and satisfies its
350 * requirement as a prereq
352 bool zero() const { return true; }
355 * Check that this stat has been set up properly and is ready for
357 * @return true for success
359 bool check() const { return true; }
362 template <class Derived, template <class> class InfoType>
363 class DataWrap : public InfoAccess
366 typedef InfoType<Derived> Info;
369 Derived &self() { return *static_cast<Derived *>(this); }
375 return safe_cast<Info *>(InfoAccess::info());
382 return safe_cast<const Info *>(InfoAccess::info());
387 * Copy constructor, copies are not allowed.
389 DataWrap(const DataWrap &stat);
394 void operator=(const DataWrap &);
399 this->setInfo(new Info(self()));
403 * Set the name and marks this stat to print at the end of simulation.
404 * @param name The new name.
405 * @return A reference to this stat.
408 name(const std::string &name)
410 Info *info = this->info();
412 info->flags |= print;
415 const std::string &name() const { return this->info()->name; }
418 * Set the description and marks this stat to print at the end of
420 * @param desc The new description.
421 * @return A reference to this stat.
424 desc(const std::string &_desc)
426 this->info()->desc = _desc;
431 * Set the precision and marks this stat to print at the end of simulation.
432 * @param _precision The new precision
433 * @return A reference to this stat.
436 precision(int _precision)
438 this->info()->precision = _precision;
443 * Set the flags and marks this stat to print at the end of simulation.
444 * @param f The new flags.
445 * @return A reference to this stat.
448 flags(StatFlags _flags)
450 this->info()->flags |= _flags;
455 * Set the prerequisite stat and marks this stat to print at the end of
457 * @param prereq The prerequisite stat.
458 * @return A reference to this stat.
460 template <class Stat>
462 prereq(const Stat &prereq)
464 this->info()->prereq = prereq.info();
469 template <class Derived, template <class> class InfoType>
470 class DataWrapVec : public DataWrap<Derived, InfoType>
473 typedef InfoType<Derived> Info;
475 // The following functions are specific to vectors. If you use them
476 // in a non vector context, you will get a nice compiler error!
479 * Set the subfield name for the given index, and marks this stat to print
480 * at the end of simulation.
481 * @param index The subfield index.
482 * @param name The new name of the subfield.
483 * @return A reference to this stat.
486 subname(off_type index, const std::string &name)
488 Derived &self = this->self();
489 Info *info = self.info();
491 std::vector<std::string> &subn = info->subnames;
492 if (subn.size() <= index)
493 subn.resize(index + 1);
498 // The following functions are specific to 2d vectors. If you use
499 // them in a non vector context, you will get a nice compiler
500 // error because info doesn't have the right variables.
503 * Set the subfield description for the given index and marks this stat to
504 * print at the end of simulation.
505 * @param index The subfield index.
506 * @param desc The new description of the subfield
507 * @return A reference to this stat.
510 subdesc(off_type index, const std::string &desc)
512 Info *info = this->info();
514 std::vector<std::string> &subd = info->subdescs;
515 if (subd.size() <= index)
516 subd.resize(index + 1);
525 Derived &self = this->self();
526 Info *info = this->info();
528 size_t size = self.size();
529 for (off_type i = 0; i < size; ++i)
530 self.data(i)->prepare(info);
536 Derived &self = this->self();
537 Info *info = this->info();
539 size_t size = self.size();
540 for (off_type i = 0; i < size; ++i)
541 self.data(i)->reset(info);
545 template <class Derived, template <class> class InfoType>
546 class DataWrapVec2d : public DataWrapVec<Derived, InfoType>
549 typedef InfoType<Derived> Info;
552 * @warning This makes the assumption that if you're gonna subnames a 2d
553 * vector, you're subnaming across all y
556 ysubnames(const char **names)
558 Derived &self = this->self();
559 Info *info = this->info();
561 info->y_subnames.resize(self.y);
562 for (off_type i = 0; i < self.y; ++i)
563 info->y_subnames[i] = names[i];
568 ysubname(off_type index, const std::string subname)
570 Derived &self = this->self();
571 Info *info = this->info();
573 assert(index < self.y);
574 info->y_subnames.resize(self.y);
575 info->y_subnames[index] = subname.c_str();
580 //////////////////////////////////////////////////////////////////////
584 //////////////////////////////////////////////////////////////////////
587 * Templatized storage and interface for a simple scalar stat.
592 /** The statistic value. */
596 struct Params : public StorageParams {};
600 * Builds this storage element and calls the base constructor of the
608 * The the stat to the given value.
609 * @param val The new value.
611 void set(Counter val) { data = val; }
613 * Increment the stat by the given value.
614 * @param val The new value.
616 void inc(Counter val) { data += val; }
618 * Decrement the stat by the given value.
619 * @param val The new value.
621 void dec(Counter val) { data -= val; }
623 * Return the value of this stat as its base type.
624 * @return The value of this stat.
626 Counter value() const { return data; }
628 * Return the value of this stat as a result type.
629 * @return The value of this stat.
631 Result result() const { return (Result)data; }
633 * Prepare stat data for dumping or serialization
635 void prepare(Info *info) { }
637 * Reset stat value to default
639 void reset(Info *info) { data = Counter(); }
642 * @return true if zero value
644 bool zero() const { return data == Counter(); }
648 * Templatized storage and interface to a per-tick average stat. This keeps
649 * a current count and updates a total (count * ticks) when this count
650 * changes. This allows the quick calculation of a per tick count of the item
651 * being watched. This is good for keeping track of residencies in structures
652 * among other things.
657 /** The current count. */
659 /** The total count for all tick. */
660 mutable Result total;
661 /** The tick that current last changed. */
665 struct Params : public StorageParams {};
669 * Build and initializes this stat storage.
672 : current(0), total(0), last(0)
676 * Set the current count to the one provided, update the total and last
678 * @param val The new count.
683 total += current * (curTick - last);
689 * Increment the current count by the provided value, calls set.
690 * @param val The amount to increment.
692 void inc(Counter val) { set(current + val); }
695 * Deccrement the current count by the provided value, calls set.
696 * @param val The amount to decrement.
698 void dec(Counter val) { set(current - val); }
701 * Return the current count.
702 * @return The current count.
704 Counter value() const { return current; }
707 * Return the current average.
708 * @return The current average.
713 assert(last == curTick);
714 return (Result)(total + current) / (Result)(curTick + 1);
718 * @return true if zero value
720 bool zero() const { return total == 0.0; }
723 * Prepare stat data for dumping or serialization
728 total += current * (curTick - last);
733 * Reset stat value to default
745 * Implementation of a scalar stat. The type of stat is determined by the
748 template <class Derived, class Stor>
749 class ScalarBase : public DataWrap<Derived, ScalarInfo>
752 typedef Stor Storage;
753 typedef typename Stor::Params Params;
756 /** The storage of this stat. */
757 char storage[sizeof(Storage)] __attribute__ ((aligned (8)));
761 * Retrieve the storage.
762 * @param index The vector index to access.
763 * @return The storage object at the given index.
768 return reinterpret_cast<Storage *>(storage);
772 * Retrieve a const pointer to the storage.
773 * for the given index.
774 * @param index The vector index to access.
775 * @return A const pointer to the storage object at the given index.
780 return reinterpret_cast<const Storage *>(storage);
786 new (storage) Storage(this->info());
792 * Return the current value of this stat as its base type.
793 * @return The current value.
795 Counter value() const { return data()->value(); }
804 // Common operators for stats
806 * Increment the stat by 1. This calls the associated storage object inc
809 void operator++() { data()->inc(1); }
811 * Decrement the stat by 1. This calls the associated storage object dec
814 void operator--() { data()->dec(1); }
816 /** Increment the stat by 1. */
817 void operator++(int) { ++*this; }
818 /** Decrement the stat by 1. */
819 void operator--(int) { --*this; }
822 * Set the data value to the given value. This calls the associated storage
823 * object set function.
824 * @param v The new value.
826 template <typename U>
827 void operator=(const U &v) { data()->set(v); }
830 * Increment the stat by the given value. This calls the associated
831 * storage object inc function.
832 * @param v The value to add.
834 template <typename U>
835 void operator+=(const U &v) { data()->inc(v); }
838 * Decrement the stat by the given value. This calls the associated
839 * storage object dec function.
840 * @param v The value to substract.
842 template <typename U>
843 void operator-=(const U &v) { data()->dec(v); }
846 * Return the number of elements, always 1 for a scalar.
849 size_type size() const { return 1; }
851 Counter value() { return data()->value(); }
853 Result result() { return data()->result(); }
855 Result total() { return result(); }
857 bool zero() { return result() == 0.0; }
859 void reset() { data()->reset(this->info()); }
860 void prepare() { data()->prepare(this->info()); }
863 class ProxyInfo : public ScalarInfoBase
866 std::string str() const { return to_string(value()); }
867 size_type size() const { return 1; }
868 bool check() const { return true; }
871 bool zero() const { return value() == 0; }
873 void visit(Visit &visitor) { visitor.visit(*this); }
877 class ValueProxy : public ProxyInfo
883 ValueProxy(T &val) : scalar(&val) {}
884 Counter value() const { return *scalar; }
885 Result result() const { return *scalar; }
886 Result total() const { return *scalar; }
890 class FunctorProxy : public ProxyInfo
896 FunctorProxy(T &func) : functor(&func) {}
897 Counter value() const { return (*functor)(); }
898 Result result() const { return (*functor)(); }
899 Result total() const { return (*functor)(); }
902 template <class Derived>
903 class ValueBase : public DataWrap<Derived, ScalarInfo>
909 ValueBase() : proxy(NULL) { }
910 ~ValueBase() { if (proxy) delete proxy; }
916 proxy = new ValueProxy<T>(value);
925 proxy = new FunctorProxy<T>(func);
930 Counter value() { return proxy->value(); }
931 Result result() const { return proxy->result(); }
932 Result total() const { return proxy->total(); };
933 size_type size() const { return proxy->size(); }
935 std::string str() const { return proxy->str(); }
936 bool zero() const { return proxy->zero(); }
937 bool check() const { return proxy != NULL; }
942 //////////////////////////////////////////////////////////////////////
946 //////////////////////////////////////////////////////////////////////
949 * A proxy class to access the stat at a given index in a VectorBase stat.
950 * Behaves like a ScalarBase.
952 template <class Stat>
956 /** Pointer to the parent Vector. */
959 /** The index to access in the parent VectorBase. */
964 * Return the current value of this stat as its base type.
965 * @return The current value.
967 Counter value() const { return stat.data(index)->value(); }
970 * Return the current value of this statas a result type.
971 * @return The current value.
973 Result result() const { return stat.data(index)->result(); }
977 * Create and initialize this proxy, do not register it with the database.
978 * @param i The index to access.
980 ScalarProxy(Stat &s, off_type i)
986 * Create a copy of the provided ScalarProxy.
987 * @param sp The proxy to copy.
989 ScalarProxy(const ScalarProxy &sp)
990 : stat(sp.stat), index(sp.index)
994 * Set this proxy equal to the provided one.
995 * @param sp The proxy to copy.
996 * @return A reference to this proxy.
999 operator=(const ScalarProxy &sp)
1007 // Common operators for stats
1009 * Increment the stat by 1. This calls the associated storage object inc
1012 void operator++() { stat.data(index)->inc(1); }
1014 * Decrement the stat by 1. This calls the associated storage object dec
1017 void operator--() { stat.data(index)->dec(1); }
1019 /** Increment the stat by 1. */
1020 void operator++(int) { ++*this; }
1021 /** Decrement the stat by 1. */
1022 void operator--(int) { --*this; }
1025 * Set the data value to the given value. This calls the associated storage
1026 * object set function.
1027 * @param v The new value.
1029 template <typename U>
1031 operator=(const U &v)
1033 stat.data(index)->set(v);
1037 * Increment the stat by the given value. This calls the associated
1038 * storage object inc function.
1039 * @param v The value to add.
1041 template <typename U>
1043 operator+=(const U &v)
1045 stat.data(index)->inc(v);
1049 * Decrement the stat by the given value. This calls the associated
1050 * storage object dec function.
1051 * @param v The value to substract.
1053 template <typename U>
1055 operator-=(const U &v)
1057 stat.data(index)->dec(v);
1061 * Return the number of elements, always 1 for a scalar.
1064 size_type size() const { return 1; }
1070 return csprintf("%s[%d]", stat.info()->name, index);
1075 * Implementation of a vector of stats. The type of stat is determined by the
1076 * Storage class. @sa ScalarBase
1078 template <class Derived, class Stor>
1079 class VectorBase : public DataWrapVec<Derived, VectorInfo>
1082 typedef Stor Storage;
1083 typedef typename Stor::Params Params;
1086 typedef ScalarProxy<Derived> Proxy;
1087 friend class ScalarProxy<Derived>;
1088 friend class DataWrapVec<Derived, VectorInfo>;
1091 /** The storage of this stat. */
1097 * Retrieve the storage.
1098 * @param index The vector index to access.
1099 * @return The storage object at the given index.
1101 Storage *data(off_type index) { return &storage[index]; }
1104 * Retrieve a const pointer to the storage.
1105 * @param index The vector index to access.
1106 * @return A const pointer to the storage object at the given index.
1108 const Storage *data(off_type index) const { return &storage[index]; }
1113 assert(s > 0 && "size must be positive!");
1114 assert(!storage && "already initialized");
1117 char *ptr = new char[_size * sizeof(Storage)];
1118 storage = reinterpret_cast<Storage *>(ptr);
1120 for (off_type i = 0; i < _size; ++i)
1121 new (&storage[i]) Storage(this->info());
1128 value(VCounter &vec) const
1131 for (off_type i = 0; i < size(); ++i)
1132 vec[i] = data(i)->value();
1136 * Copy the values to a local vector and return a reference to it.
1137 * @return A reference to a vector of the stat values.
1140 result(VResult &vec) const
1143 for (off_type i = 0; i < size(); ++i)
1144 vec[i] = data(i)->result();
1148 * Return a total of all entries in this vector.
1149 * @return The total of all vector entries.
1155 for (off_type i = 0; i < size(); ++i)
1156 total += data(i)->result();
1161 * @return the number of elements in this vector.
1163 size_type size() const { return _size; }
1168 for (off_type i = 0; i < size(); ++i)
1169 if (data(i)->zero())
1177 return storage != NULL;
1190 for (off_type i = 0; i < _size; ++i)
1191 data(i)->~Storage();
1192 delete [] reinterpret_cast<char *>(storage);
1196 * Set this vector to have the given size.
1197 * @param size The new size.
1198 * @return A reference to this stat.
1201 init(size_type size)
1203 Derived &self = this->self();
1209 * Return a reference (ScalarProxy) to the stat at the given index.
1210 * @param index The vector index to access.
1211 * @return A reference of the stat.
1214 operator[](off_type index)
1216 assert (index >= 0 && index < size());
1217 return Proxy(this->self(), index);
1221 template <class Stat>
1230 mutable VResult vec;
1232 typename Stat::Storage *
1233 data(off_type index)
1235 assert(index < len);
1236 return stat.data(offset + index);
1239 const typename Stat::Storage *
1240 data(off_type index) const
1242 assert(index < len);
1243 return stat.data(offset + index);
1252 for (off_type i = 0; i < size(); ++i)
1253 vec[i] = data(i)->result();
1262 for (off_type i = 0; i < size(); ++i)
1263 total += data(i)->result();
1268 VectorProxy(Stat &s, off_type o, size_type l)
1269 : stat(s), offset(o), len(l)
1273 VectorProxy(const VectorProxy &sp)
1274 : stat(sp.stat), offset(sp.offset), len(sp.len)
1279 operator=(const VectorProxy &sp)
1288 operator[](off_type index)
1290 assert (index >= 0 && index < size());
1291 return ScalarProxy<Stat>(stat, offset + index);
1294 size_type size() const { return len; }
1297 template <class Derived, class Stor>
1298 class Vector2dBase : public DataWrapVec2d<Derived, Vector2dInfo>
1301 typedef Vector2dInfo<Derived> Info;
1302 typedef Stor Storage;
1303 typedef typename Stor::Params Params;
1304 typedef VectorProxy<Derived> Proxy;
1305 friend class ScalarProxy<Derived>;
1306 friend class VectorProxy<Derived>;
1307 friend class DataWrapVec<Derived, Vector2dInfo>;
1308 friend class DataWrapVec2d<Derived, Vector2dInfo>;
1317 Storage *data(off_type index) { return &storage[index]; }
1318 const Storage *data(off_type index) const { return &storage[index]; }
1330 for (off_type i = 0; i < _size; ++i)
1331 data(i)->~Storage();
1332 delete [] reinterpret_cast<char *>(storage);
1336 init(size_type _x, size_type _y)
1338 assert(_x > 0 && _y > 0 && "sizes must be positive!");
1339 assert(!storage && "already initialized");
1341 Derived &self = this->self();
1342 Info *info = this->info();
1350 char *ptr = new char[_size * sizeof(Storage)];
1351 storage = reinterpret_cast<Storage *>(ptr);
1353 for (off_type i = 0; i < _size; ++i)
1354 new (&storage[i]) Storage(info);
1361 std::string ysubname(off_type i) const { return (*this->y_subnames)[i]; }
1364 operator[](off_type index)
1366 off_type offset = index * y;
1367 assert (index >= 0 && offset + index < size());
1368 return Proxy(this->self(), offset, y);
1381 return data(0)->zero();
1383 for (off_type i = 0; i < size(); ++i)
1384 if (!data(i)->zero())
1393 Info *info = this->info();
1394 size_type size = this->size();
1396 for (off_type i = 0; i < size; ++i)
1397 data(i)->prepare(info);
1399 info->cvec.resize(size);
1400 for (off_type i = 0; i < size; ++i)
1401 info->cvec[i] = data(i)->value();
1405 * Reset stat value to default
1410 Info *info = this->info();
1411 size_type size = this->size();
1412 for (off_type i = 0; i < size; ++i)
1413 data(i)->reset(info);
1419 return storage != NULL;
1423 //////////////////////////////////////////////////////////////////////
1425 // Non formula statistics
1427 //////////////////////////////////////////////////////////////////////
1429 struct DistParams : public StorageParams
1433 /** The minimum value to track. */
1435 /** The maximum value to track. */
1437 /** The number of entries in each bucket. */
1438 Counter bucket_size;
1439 /** The number of buckets. Equal to (max-min)/bucket_size. */
1442 explicit DistParams(bool f) : fancy(f) {}
1446 * Templatized storage and interface for a distrbution stat.
1451 /** The parameters for a distribution stat. */
1452 struct Params : public DistParams
1454 Params() : DistParams(false) {}
1458 /** The minimum value to track. */
1460 /** The maximum value to track. */
1462 /** The number of entries in each bucket. */
1463 Counter bucket_size;
1464 /** The number of buckets. Equal to (max-min)/bucket_size. */
1467 /** The smallest value sampled. */
1469 /** The largest value sampled. */
1471 /** The number of values sampled less than min. */
1473 /** The number of values sampled more than max. */
1475 /** The current sum. */
1477 /** The sum of squares. */
1479 /** The number of samples. */
1481 /** Counter for each bucket. */
1485 DistStor(Info *info)
1486 : cvec(safe_cast<const Params *>(info->storageParams)->buckets)
1492 * Add a value to the distribution for the given number of times.
1493 * @param val The value to add.
1494 * @param number The number of times to add the value.
1497 sample(Counter val, int number)
1499 if (val < min_track)
1500 underflow += number;
1501 else if (val > max_track)
1505 (size_type)std::floor((val - min_track) / bucket_size);
1506 assert(index < size());
1507 cvec[index] += number;
1516 Counter sample = val * number;
1518 squares += sample * sample;
1523 * Return the number of buckets in this distribution.
1524 * @return the number of buckets.
1526 size_type size() const { return cvec.size(); }
1529 * Returns true if any calls to sample have been made.
1530 * @return True if any values have been sampled.
1535 return samples == Counter();
1539 prepare(Info *info, DistData &data)
1541 const Params *params = safe_cast<const Params *>(info->storageParams);
1543 data.min_val = (min_val == CounterLimits::max()) ? 0 : min_val;
1544 data.max_val = (max_val == CounterLimits::min()) ? 0 : max_val;
1545 data.underflow = underflow;
1546 data.overflow = overflow;
1548 int buckets = params->buckets;
1549 data.cvec.resize(buckets);
1550 for (off_type i = 0; i < buckets; ++i)
1551 data.cvec[i] = cvec[i];
1554 data.squares = squares;
1555 data.samples = samples;
1559 * Reset stat value to default
1564 const Params *params = safe_cast<const Params *>(info->storageParams);
1565 min_track = params->min;
1566 max_track = params->max;
1567 bucket_size = params->bucket_size;
1569 min_val = CounterLimits::max();
1570 max_val = CounterLimits::min();
1574 size_type size = cvec.size();
1575 for (off_type i = 0; i < size; ++i)
1576 cvec[i] = Counter();
1579 squares = Counter();
1580 samples = Counter();
1585 * Templatized storage and interface for a distribution that calculates mean
1591 struct Params : public DistParams
1593 Params() : DistParams(true) {}
1597 /** The current sum. */
1599 /** The sum of squares. */
1601 /** The number of samples. */
1606 * Create and initialize this storage.
1608 FancyStor(Info *info)
1609 : sum(Counter()), squares(Counter()), samples(Counter())
1613 * Add a value the given number of times to this running average.
1614 * Update the running sum and sum of squares, increment the number of
1615 * values seen by the given number.
1616 * @param val The value to add.
1617 * @param number The number of times to add the value.
1620 sample(Counter val, int number)
1622 Counter value = val * number;
1624 squares += value * value;
1629 * Return the number of entries in this stat, 1
1632 size_type size() const { return 1; }
1635 * Return true if no samples have been added.
1636 * @return True if no samples have been added.
1638 bool zero() const { return samples == Counter(); }
1641 prepare(Info *info, DistData &data)
1644 data.squares = squares;
1645 data.samples = samples;
1649 * Reset stat value to default
1655 squares = Counter();
1656 samples = Counter();
1661 * Templatized storage for distribution that calculates per tick mean and
1667 struct Params : public DistParams
1669 Params() : DistParams(true) {}
1673 /** Current total. */
1675 /** Current sum of squares. */
1680 * Create and initialize this storage.
1682 AvgFancy(Info *info)
1683 : sum(Counter()), squares(Counter())
1687 * Add a value to the distribution for the given number of times.
1688 * Update the running sum and sum of squares.
1689 * @param val The value to add.
1690 * @param number The number of times to add the value.
1693 sample(Counter val, int number)
1695 Counter value = val * number;
1697 squares += value * value;
1701 * Return the number of entries, in this case 1.
1704 size_type size() const { return 1; }
1707 * Return true if no samples have been added.
1708 * @return True if the sum is zero.
1710 bool zero() const { return sum == Counter(); }
1713 prepare(Info *info, DistData &data)
1716 data.squares = squares;
1717 data.samples = curTick;
1721 * Reset stat value to default
1727 squares = Counter();
1732 * Implementation of a distribution stat. The type of distribution is
1733 * determined by the Storage template. @sa ScalarBase
1735 template <class Derived, class Stor>
1736 class DistBase : public DataWrap<Derived, DistInfo>
1739 typedef DistInfo<Derived> Info;
1740 typedef Stor Storage;
1741 typedef typename Stor::Params Params;
1744 /** The storage for this stat. */
1745 char storage[sizeof(Storage)] __attribute__ ((aligned (8)));
1749 * Retrieve the storage.
1750 * @return The storage object for this stat.
1755 return reinterpret_cast<Storage *>(storage);
1759 * Retrieve a const pointer to the storage.
1760 * @return A const pointer to the storage object for this stat.
1765 return reinterpret_cast<const Storage *>(storage);
1771 new (storage) Storage(this->info());
1779 * Add a value to the distribtion n times. Calls sample on the storage
1781 * @param v The value to add.
1782 * @param n The number of times to add it, defaults to 1.
1784 template <typename U>
1785 void sample(const U &v, int n = 1) { data()->sample(v, n); }
1788 * Return the number of entries in this stat.
1789 * @return The number of entries.
1791 size_type size() const { return data()->size(); }
1793 * Return true if no samples have been added.
1794 * @return True if there haven't been any samples.
1796 bool zero() const { return data()->zero(); }
1801 Info *info = this->info();
1802 data()->prepare(info, info->data);
1806 * Reset stat value to default
1811 data()->reset(this->info());
1815 template <class Stat>
1818 template <class Derived, class Stor>
1819 class VectorDistBase : public DataWrapVec<Derived, VectorDistInfo>
1822 typedef VectorDistInfo<Derived> Info;
1823 typedef Stor Storage;
1824 typedef typename Stor::Params Params;
1825 typedef DistProxy<Derived> Proxy;
1826 friend class DistProxy<Derived>;
1827 friend class DataWrapVec<Derived, VectorDistInfo>;
1835 data(off_type index)
1837 return &storage[index];
1841 data(off_type index) const
1843 return &storage[index];
1849 assert(s > 0 && "size must be positive!");
1850 assert(!storage && "already initialized");
1853 char *ptr = new char[_size * sizeof(Storage)];
1854 storage = reinterpret_cast<Storage *>(ptr);
1856 Info *info = this->info();
1857 for (off_type i = 0; i < _size; ++i)
1858 new (&storage[i]) Storage(info);
1873 for (off_type i = 0; i < _size; ++i)
1874 data(i)->~Storage();
1875 delete [] reinterpret_cast<char *>(storage);
1878 Proxy operator[](off_type index);
1891 for (off_type i = 0; i < size(); ++i)
1892 if (!data(i)->zero())
1901 Info *info = this->info();
1902 size_type size = this->size();
1903 info->data.resize(size);
1904 for (off_type i = 0; i < size; ++i)
1905 data(i)->prepare(info, info->data[i]);
1911 return storage != NULL;
1915 template <class Stat>
1923 typename Stat::Storage *data() { return stat->data(index); }
1924 const typename Stat::Storage *data() const { return stat->data(index); }
1927 DistProxy(Stat *s, off_type i)
1931 DistProxy(const DistProxy &sp)
1932 : stat(sp.stat), index(sp.index)
1936 operator=(const DistProxy &sp)
1944 template <typename U>
1946 sample(const U &v, int n = 1)
1948 data()->sample(v, n);
1960 return data()->zero();
1964 * Proxy has no state. Nothing to reset.
1969 template <class Derived, class Stor>
1970 inline typename VectorDistBase<Derived, Stor>::Proxy
1971 VectorDistBase<Derived, Stor>::operator[](off_type index)
1973 assert (index >= 0 && index < size());
1974 typedef typename VectorDistBase<Derived, Stor>::Proxy Proxy;
1975 return Proxy(this, index);
1979 template <class Storage>
1981 VectorDistBase<Storage>::total(off_type index) const
1984 for (off_type i = 0; i < x_size(); ++i)
1985 total += data(i)->result();
1989 //////////////////////////////////////////////////////////////////////
1993 //////////////////////////////////////////////////////////////////////
1996 * Base class for formula statistic node. These nodes are used to build a tree
1997 * that represents the formula.
1999 class Node : public RefCounted
2003 * Return the number of nodes in the subtree starting at this node.
2004 * @return the number of nodes in this subtree.
2006 virtual size_type size() const = 0;
2008 * Return the result vector of this subtree.
2009 * @return The result vector of this subtree.
2011 virtual const VResult &result() const = 0;
2013 * Return the total of the result vector.
2014 * @return The total of the result vector.
2016 virtual Result total() const = 0;
2021 virtual std::string str() const = 0;
2024 /** Reference counting pointer to a function Node. */
2025 typedef RefCountingPtr<Node> NodePtr;
2027 class ScalarStatNode : public Node
2030 const ScalarInfoBase *data;
2031 mutable VResult vresult;
2034 ScalarStatNode(const ScalarInfoBase *d) : data(d), vresult(1) {}
2039 vresult[0] = data->result();
2043 Result total() const { return data->result(); };
2045 size_type size() const { return 1; }
2050 std::string str() const { return data->name; }
2053 template <class Stat>
2054 class ScalarProxyNode : public Node
2057 const ScalarProxy<Stat> proxy;
2058 mutable VResult vresult;
2061 ScalarProxyNode(const ScalarProxy<Stat> &p)
2062 : proxy(p), vresult(1)
2068 vresult[0] = proxy.result();
2075 return proxy.result();
2094 class VectorStatNode : public Node
2097 const VectorInfoBase *data;
2100 VectorStatNode(const VectorInfoBase *d) : data(d) { }
2101 const VResult &result() const { return data->result(); }
2102 Result total() const { return data->total(); };
2104 size_type size() const { return data->size(); }
2106 std::string str() const { return data->name; }
2110 class ConstNode : public Node
2116 ConstNode(T s) : vresult(1, (Result)s) {}
2117 const VResult &result() const { return vresult; }
2118 Result total() const { return vresult[0]; };
2119 size_type size() const { return 1; }
2120 std::string str() const { return to_string(vresult[0]); }
2124 class ConstVectorNode : public Node
2130 ConstVectorNode(const T &s) : vresult(s.begin(), s.end()) {}
2131 const VResult &result() const { return vresult; }
2136 size_type size = this->size();
2138 for (off_type i = 0; i < size; i++)
2143 size_type size() const { return vresult.size(); }
2147 size_type size = this->size();
2148 std::string tmp = "(";
2149 for (off_type i = 0; i < size; i++)
2150 tmp += csprintf("%s ",to_string(vresult[i]));
2160 struct OpString<std::plus<Result> >
2162 static std::string str() { return "+"; }
2166 struct OpString<std::minus<Result> >
2168 static std::string str() { return "-"; }
2172 struct OpString<std::multiplies<Result> >
2174 static std::string str() { return "*"; }
2178 struct OpString<std::divides<Result> >
2180 static std::string str() { return "/"; }
2184 struct OpString<std::modulus<Result> >
2186 static std::string str() { return "%"; }
2190 struct OpString<std::negate<Result> >
2192 static std::string str() { return "-"; }
2196 class UnaryNode : public Node
2200 mutable VResult vresult;
2203 UnaryNode(NodePtr &p) : l(p) {}
2208 const VResult &lvec = l->result();
2209 size_type size = lvec.size();
2213 vresult.resize(size);
2215 for (off_type i = 0; i < size; ++i)
2216 vresult[i] = op(lvec[i]);
2224 const VResult &vec = this->result();
2226 for (off_type i = 0; i < size(); i++)
2231 size_type size() const { return l->size(); }
2236 return OpString<Op>::str() + l->str();
2241 class BinaryNode : public Node
2246 mutable VResult vresult;
2249 BinaryNode(NodePtr &a, NodePtr &b) : l(a), r(b) {}
2255 const VResult &lvec = l->result();
2256 const VResult &rvec = r->result();
2258 assert(lvec.size() > 0 && rvec.size() > 0);
2260 if (lvec.size() == 1 && rvec.size() == 1) {
2262 vresult[0] = op(lvec[0], rvec[0]);
2263 } else if (lvec.size() == 1) {
2264 size_type size = rvec.size();
2265 vresult.resize(size);
2266 for (off_type i = 0; i < size; ++i)
2267 vresult[i] = op(lvec[0], rvec[i]);
2268 } else if (rvec.size() == 1) {
2269 size_type size = lvec.size();
2270 vresult.resize(size);
2271 for (off_type i = 0; i < size; ++i)
2272 vresult[i] = op(lvec[i], rvec[0]);
2273 } else if (rvec.size() == lvec.size()) {
2274 size_type size = rvec.size();
2275 vresult.resize(size);
2276 for (off_type i = 0; i < size; ++i)
2277 vresult[i] = op(lvec[i], rvec[i]);
2286 const VResult &vec = this->result();
2288 for (off_type i = 0; i < size(); i++)
2296 size_type ls = l->size();
2297 size_type rs = r->size();
2300 } else if (rs == 1) {
2303 assert(ls == rs && "Node vector sizes are not equal");
2311 return csprintf("(%s %s %s)", l->str(), OpString<Op>::str(), r->str());
2316 class SumNode : public Node
2320 mutable VResult vresult;
2323 SumNode(NodePtr &p) : l(p), vresult(1) {}
2328 const VResult &lvec = l->result();
2329 size_type size = lvec.size();
2335 for (off_type i = 0; i < size; ++i)
2336 vresult[0] = op(vresult[0], lvec[i]);
2344 const VResult &lvec = l->result();
2345 size_type size = lvec.size();
2348 Result vresult = 0.0;
2351 for (off_type i = 0; i < size; ++i)
2352 vresult = op(vresult, lvec[i]);
2357 size_type size() const { return 1; }
2362 return csprintf("total(%s)", l->str());
2367 //////////////////////////////////////////////////////////////////////
2369 // Visible Statistics Types
2371 //////////////////////////////////////////////////////////////////////
2373 * @defgroup VisibleStats "Statistic Types"
2374 * These are the statistics that are used in the simulator.
2379 * This is a simple scalar statistic, like a counter.
2380 * @sa Stat, ScalarBase, StatStor
2382 class Scalar : public ScalarBase<Scalar, StatStor>
2385 using ScalarBase<Scalar, StatStor>::operator=;
2389 * A stat that calculates the per tick average of a value.
2390 * @sa Stat, ScalarBase, AvgStor
2392 class Average : public ScalarBase<Average, AvgStor>
2395 using ScalarBase<Average, AvgStor>::operator=;
2398 class Value : public ValueBase<Value>
2403 * A vector of scalar stats.
2404 * @sa Stat, VectorBase, StatStor
2406 class Vector : public VectorBase<Vector, StatStor>
2411 * A vector of Average stats.
2412 * @sa Stat, VectorBase, AvgStor
2414 class AverageVector : public VectorBase<AverageVector, AvgStor>
2419 * A 2-Dimensional vecto of scalar stats.
2420 * @sa Stat, Vector2dBase, StatStor
2422 class Vector2d : public Vector2dBase<Vector2d, StatStor>
2427 * A simple distribution stat.
2428 * @sa Stat, DistBase, DistStor
2430 class Distribution : public DistBase<Distribution, DistStor>
2434 * Set the parameters of this distribution. @sa DistStor::Params
2435 * @param min The minimum value of the distribution.
2436 * @param max The maximum value of the distribution.
2437 * @param bkt The number of values in each bucket.
2438 * @return A reference to this distribution.
2441 init(Counter min, Counter max, Counter bkt)
2443 DistStor::Params *params = new DistStor::Params;
2446 params->bucket_size = bkt;
2447 params->buckets = (size_type)rint((max - min) / bkt + 1.0);
2448 this->setParams(params);
2450 return this->self();
2455 * Calculates the mean and variance of all the samples.
2456 * @sa Stat, DistBase, FancyStor
2458 class StandardDeviation : public DistBase<StandardDeviation, FancyStor>
2462 * Construct and initialize this distribution.
2471 * Calculates the per tick mean and variance of the samples.
2472 * @sa Stat, DistBase, AvgFancy
2474 class AverageDeviation : public DistBase<AverageDeviation, AvgFancy>
2478 * Construct and initialize this distribution.
2487 * A vector of distributions.
2488 * @sa Stat, VectorDistBase, DistStor
2490 class VectorDistribution : public VectorDistBase<VectorDistribution, DistStor>
2494 * Initialize storage and parameters for this distribution.
2495 * @param size The size of the vector (the number of distributions).
2496 * @param min The minimum value of the distribution.
2497 * @param max The maximum value of the distribution.
2498 * @param bkt The number of values in each bucket.
2499 * @return A reference to this distribution.
2501 VectorDistribution &
2502 init(size_type size, Counter min, Counter max, Counter bkt)
2504 DistStor::Params *params = new DistStor::Params;
2507 params->bucket_size = bkt;
2508 params->buckets = (size_type)rint((max - min) / bkt + 1.0);
2509 this->setParams(params);
2511 return this->self();
2516 * This is a vector of StandardDeviation stats.
2517 * @sa Stat, VectorDistBase, FancyStor
2519 class VectorStandardDeviation
2520 : public VectorDistBase<VectorStandardDeviation, FancyStor>
2524 * Initialize storage for this distribution.
2525 * @param size The size of the vector.
2526 * @return A reference to this distribution.
2528 VectorStandardDeviation &
2529 init(size_type size)
2532 return this->self();
2537 * This is a vector of AverageDeviation stats.
2538 * @sa Stat, VectorDistBase, AvgFancy
2540 class VectorAverageDeviation
2541 : public VectorDistBase<VectorAverageDeviation, AvgFancy>
2545 * Initialize storage for this distribution.
2546 * @param size The size of the vector.
2547 * @return A reference to this distribution.
2549 VectorAverageDeviation &
2550 init(size_type size)
2553 return this->self();
2557 class FormulaInfoBase : public VectorInfoBase
2560 virtual std::string str() const = 0;
2563 template <class Stat>
2564 class FormulaInfo : public InfoWrap<Stat, FormulaInfoBase>
2567 mutable VResult vec;
2568 mutable VCounter cvec;
2571 FormulaInfo(Stat &stat) : InfoWrap<Stat, FormulaInfoBase>(stat) {}
2573 size_type size() const { return this->s.size(); }
2578 this->s.result(vec);
2581 Result total() const { return this->s.total(); }
2582 VCounter &value() const { return cvec; }
2584 std::string str() const { return this->s.str(); }
2589 * A formula for statistics that is calculated when printed. A formula is
2590 * stored as a tree of Nodes that represent the equation to calculate.
2591 * @sa Stat, ScalarStat, VectorStat, Node, Temp
2593 class Formula : public DataWrapVec<Formula, FormulaInfo>
2596 /** The root of the tree which represents the Formula */
2602 * Create and initialize thie formula, and register it with the database.
2607 * Create a formula with the given root node, register it with the
2609 * @param r The root of the expression tree.
2614 * Set an unitialized Formula to the given root.
2615 * @param r The root of the expression tree.
2616 * @return a reference to this formula.
2618 const Formula &operator=(Temp r);
2621 * Add the given tree to the existing one.
2622 * @param r The root of the expression tree.
2623 * @return a reference to this formula.
2625 const Formula &operator+=(Temp r);
2627 * Return the result of the Fomula in a vector. If there were no Vector
2628 * components to the Formula, then the vector is size 1. If there were,
2629 * like x/y with x being a vector of size 3, then the result returned will
2630 * be x[0]/y, x[1]/y, x[2]/y, respectively.
2631 * @return The result vector.
2633 void result(VResult &vec) const;
2636 * Return the total Formula result. If there is a Vector
2637 * component to this Formula, then this is the result of the
2638 * Formula if the formula is applied after summing all the
2639 * components of the Vector. For example, if Formula is x/y where
2640 * x is size 3, then total() will return (x[1]+x[2]+x[3])/y. If
2641 * there is no Vector component, total() returns the same value as
2642 * the first entry in the VResult val() returns.
2643 * @return The total of the result vector.
2645 Result total() const;
2648 * Return the number of elements in the tree.
2650 size_type size() const;
2655 * Formulas don't need to be reset
2664 std::string str() const;
2667 class FormulaNode : public Node
2670 const Formula &formula;
2671 mutable VResult vec;
2674 FormulaNode(const Formula &f) : formula(f) {}
2676 size_type size() const { return formula.size(); }
2677 const VResult &result() const { formula.result(vec); return vec; }
2678 Result total() const { return formula.total(); }
2680 std::string str() const { return formula.str(); }
2684 * Helper class to construct formula node trees.
2690 * Pointer to a Node object.
2696 * Copy the given pointer to this class.
2697 * @param n A pointer to a Node object to copy.
2699 Temp(NodePtr n) : node(n) { }
2702 * Return the node pointer.
2703 * @return the node pointer.
2705 operator NodePtr&() { return node; }
2709 * Create a new ScalarStatNode.
2710 * @param s The ScalarStat to place in a node.
2712 Temp(const Scalar &s)
2713 : node(new ScalarStatNode(s.info()))
2717 * Create a new ScalarStatNode.
2718 * @param s The ScalarStat to place in a node.
2720 Temp(const Value &s)
2721 : node(new ScalarStatNode(s.info()))
2725 * Create a new ScalarStatNode.
2726 * @param s The ScalarStat to place in a node.
2728 Temp(const Average &s)
2729 : node(new ScalarStatNode(s.info()))
2733 * Create a new VectorStatNode.
2734 * @param s The VectorStat to place in a node.
2736 Temp(const Vector &s)
2737 : node(new VectorStatNode(s.info()))
2743 Temp(const Formula &f)
2744 : node(new FormulaNode(f))
2748 * Create a new ScalarProxyNode.
2749 * @param p The ScalarProxy to place in a node.
2751 template <class Stat>
2752 Temp(const ScalarProxy<Stat> &p)
2753 : node(new ScalarProxyNode<Stat>(p))
2757 * Create a ConstNode
2758 * @param value The value of the const node.
2760 Temp(signed char value)
2761 : node(new ConstNode<signed char>(value))
2765 * Create a ConstNode
2766 * @param value The value of the const node.
2768 Temp(unsigned char value)
2769 : node(new ConstNode<unsigned char>(value))
2773 * Create a ConstNode
2774 * @param value The value of the const node.
2776 Temp(signed short value)
2777 : node(new ConstNode<signed short>(value))
2781 * Create a ConstNode
2782 * @param value The value of the const node.
2784 Temp(unsigned short value)
2785 : node(new ConstNode<unsigned short>(value))
2789 * Create a ConstNode
2790 * @param value The value of the const node.
2792 Temp(signed int value)
2793 : node(new ConstNode<signed int>(value))
2797 * Create a ConstNode
2798 * @param value The value of the const node.
2800 Temp(unsigned int value)
2801 : node(new ConstNode<unsigned int>(value))
2805 * Create a ConstNode
2806 * @param value The value of the const node.
2808 Temp(signed long value)
2809 : node(new ConstNode<signed long>(value))
2813 * Create a ConstNode
2814 * @param value The value of the const node.
2816 Temp(unsigned long value)
2817 : node(new ConstNode<unsigned long>(value))
2821 * Create a ConstNode
2822 * @param value The value of the const node.
2824 Temp(signed long long value)
2825 : node(new ConstNode<signed long long>(value))
2829 * Create a ConstNode
2830 * @param value The value of the const node.
2832 Temp(unsigned long long value)
2833 : node(new ConstNode<unsigned long long>(value))
2837 * Create a ConstNode
2838 * @param value The value of the const node.
2841 : node(new ConstNode<float>(value))
2845 * Create a ConstNode
2846 * @param value The value of the const node.
2849 : node(new ConstNode<double>(value))
2859 operator+(Temp l, Temp r)
2861 return NodePtr(new BinaryNode<std::plus<Result> >(l, r));
2865 operator-(Temp l, Temp r)
2867 return NodePtr(new BinaryNode<std::minus<Result> >(l, r));
2871 operator*(Temp l, Temp r)
2873 return NodePtr(new BinaryNode<std::multiplies<Result> >(l, r));
2877 operator/(Temp l, Temp r)
2879 return NodePtr(new BinaryNode<std::divides<Result> >(l, r));
2885 return NodePtr(new UnaryNode<std::negate<Result> >(l));
2888 template <typename T>
2892 return NodePtr(new ConstNode<T>(val));
2895 template <typename T>
2897 constantVector(T val)
2899 return NodePtr(new ConstVectorNode<T>(val));
2905 return NodePtr(new SumNode<std::plus<Result> >(val));
2909 * Enable the statistics package. Before the statistics package is
2910 * enabled, all statistics must be created and initialized and once
2911 * the package is enabled, no more statistics can be created.
2916 * Prepare all stats for data access. This must be done before
2917 * dumping and serialization.
2922 * Dump all statistics data to the registered outputs
2927 * Reset all statistics to the base state
2931 * Register a callback that should be called whenever statistics are
2934 void registerResetCallback(Callback *cb);
2936 std::list<Info *> &statsList();
2938 /* namespace Stats */ }
2940 #endif // __BASE_STATISTICS_HH__