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;
118 * Check that this stat has been set up properly and is ready for
120 * @return true for success
122 virtual bool check() const = 0;
123 bool baseCheck() const;
126 * Enable the stat for use
128 virtual void enable();
131 * Prepare the stat for dumping.
133 virtual void prepare() = 0;
136 * Reset the stat to the default state.
138 virtual void reset() = 0;
141 * @return true if this stat has a value and satisfies its
142 * requirement as a prereq
144 virtual bool zero() const = 0;
147 * Visitor entry for outputing statistics data
149 virtual void visit(Visit &visitor) = 0;
152 * Checks if the first stat's name is alphabetically less than the second.
153 * This function breaks names up at periods and considers each subname
155 * @param stat1 The first stat.
156 * @param stat2 The second stat.
157 * @return stat1's name is alphabetically before stat2's
159 static bool less(Info *stat1, Info *stat2);
162 template <class Stat, class Base>
163 class InfoWrap : public Base
169 InfoWrap(Stat &stat) : s(stat) {}
171 bool check() const { return s.check(); }
172 void prepare() { s.prepare(); }
173 void reset() { s.reset(); }
175 visit(Visit &visitor)
177 visitor.visit(*static_cast<Base *>(this));
179 bool zero() const { return s.zero(); }
182 class ScalarInfoBase : public Info
185 virtual Counter value() const = 0;
186 virtual Result result() const = 0;
187 virtual Result total() const = 0;
190 template <class Stat>
191 class ScalarInfo : public InfoWrap<Stat, ScalarInfoBase>
194 ScalarInfo(Stat &stat) : InfoWrap<Stat, ScalarInfoBase>(stat) {}
196 Counter value() const { return this->s.value(); }
197 Result result() const { return this->s.result(); }
198 Result total() const { return this->s.total(); }
201 class VectorInfoBase : public Info
204 /** Names and descriptions of subfields. */
205 std::vector<std::string> subnames;
206 std::vector<std::string> subdescs;
212 virtual size_type size() const = 0;
213 virtual const VCounter &value() const = 0;
214 virtual const VResult &result() const = 0;
215 virtual Result total() const = 0;
218 template <class Stat>
219 class VectorInfo : public InfoWrap<Stat, VectorInfoBase>
222 mutable VCounter cvec;
223 mutable VResult rvec;
226 VectorInfo(Stat &stat) : InfoWrap<Stat, VectorInfoBase>(stat) {}
228 size_type size() const { return this->s.size(); }
240 this->s.result(rvec);
244 Result total() const { return this->s.total(); }
259 class DistInfoBase : public Info
262 /** Local storage for the entry values, used for printing. */
266 template <class Stat>
267 class DistInfo : public InfoWrap<Stat, DistInfoBase>
270 DistInfo(Stat &stat) : InfoWrap<Stat, DistInfoBase>(stat) {}
273 class VectorDistInfoBase : public Info
276 std::vector<DistData> data;
278 /** Names and descriptions of subfields. */
279 std::vector<std::string> subnames;
280 std::vector<std::string> subdescs;
284 /** Local storage for the entry values, used for printing. */
285 mutable VResult rvec;
288 virtual size_type size() const = 0;
291 template <class Stat>
292 class VectorDistInfo : public InfoWrap<Stat, VectorDistInfoBase>
295 VectorDistInfo(Stat &stat) : InfoWrap<Stat, VectorDistInfoBase>(stat) {}
297 size_type size() const { return this->s.size(); }
300 class Vector2dInfoBase : public Info
303 /** Names and descriptions of subfields. */
304 std::vector<std::string> subnames;
305 std::vector<std::string> subdescs;
306 std::vector<std::string> y_subnames;
311 /** Local storage for the entry values, used for printing. */
312 mutable VCounter cvec;
317 template <class Stat>
318 class Vector2dInfo : public InfoWrap<Stat, Vector2dInfoBase>
321 Vector2dInfo(Stat &stat) : InfoWrap<Stat, Vector2dInfoBase>(stat) {}
327 /** Set up an info class for this statistic */
328 void setInfo(Info *info);
329 /** Save Storage class parameters if any */
330 void setParams(const StorageParams *params);
331 /** Save Storage class parameters if any */
334 /** Grab the information class for this statistic */
336 /** Grab the information class for this statistic */
337 const Info *info() const;
341 * Reset the stat to the default state.
346 * @return true if this stat has a value and satisfies its
347 * requirement as a prereq
349 bool zero() const { return true; }
352 * Check that this stat has been set up properly and is ready for
354 * @return true for success
356 bool check() const { return true; }
359 template <class Derived, template <class> class InfoType>
360 class DataWrap : public InfoAccess
363 typedef InfoType<Derived> Info;
366 Derived &self() { return *static_cast<Derived *>(this); }
372 return safe_cast<Info *>(InfoAccess::info());
379 return safe_cast<const Info *>(InfoAccess::info());
384 * Copy constructor, copies are not allowed.
386 DataWrap(const DataWrap &stat);
391 void operator=(const DataWrap &);
396 this->setInfo(new Info(self()));
400 * Set the name and marks this stat to print at the end of simulation.
401 * @param name The new name.
402 * @return A reference to this stat.
405 name(const std::string &_name)
407 Info *info = this->info();
409 info->flags |= print;
412 const std::string &name() const { return this->info()->name; }
415 * Set the description and marks this stat to print at the end of
417 * @param desc The new description.
418 * @return A reference to this stat.
421 desc(const std::string &_desc)
423 this->info()->desc = _desc;
428 * Set the precision and marks this stat to print at the end of simulation.
429 * @param _precision The new precision
430 * @return A reference to this stat.
433 precision(int _precision)
435 this->info()->precision = _precision;
440 * Set the flags and marks this stat to print at the end of simulation.
441 * @param f The new flags.
442 * @return A reference to this stat.
445 flags(StatFlags _flags)
447 this->info()->flags |= _flags;
452 * Set the prerequisite stat and marks this stat to print at the end of
454 * @param prereq The prerequisite stat.
455 * @return A reference to this stat.
457 template <class Stat>
459 prereq(const Stat &prereq)
461 this->info()->prereq = prereq.info();
466 template <class Derived, template <class> class InfoType>
467 class DataWrapVec : public DataWrap<Derived, InfoType>
470 typedef InfoType<Derived> Info;
472 // The following functions are specific to vectors. If you use them
473 // in a non vector context, you will get a nice compiler error!
476 * Set the subfield name for the given index, and marks this stat to print
477 * at the end of simulation.
478 * @param index The subfield index.
479 * @param name The new name of the subfield.
480 * @return A reference to this stat.
483 subname(off_type index, const std::string &name)
485 Derived &self = this->self();
486 Info *info = self.info();
488 std::vector<std::string> &subn = info->subnames;
489 if (subn.size() <= index)
490 subn.resize(index + 1);
495 // The following functions are specific to 2d vectors. If you use
496 // them in a non vector context, you will get a nice compiler
497 // error because info doesn't have the right variables.
500 * Set the subfield description for the given index and marks this stat to
501 * print at the end of simulation.
502 * @param index The subfield index.
503 * @param desc The new description of the subfield
504 * @return A reference to this stat.
507 subdesc(off_type index, const std::string &desc)
509 Info *info = this->info();
511 std::vector<std::string> &subd = info->subdescs;
512 if (subd.size() <= index)
513 subd.resize(index + 1);
522 Derived &self = this->self();
523 Info *info = this->info();
525 size_t size = self.size();
526 for (off_type i = 0; i < size; ++i)
527 self.data(i)->prepare(info);
533 Derived &self = this->self();
534 Info *info = this->info();
536 size_t size = self.size();
537 for (off_type i = 0; i < size; ++i)
538 self.data(i)->reset(info);
542 template <class Derived, template <class> class InfoType>
543 class DataWrapVec2d : public DataWrapVec<Derived, InfoType>
546 typedef InfoType<Derived> Info;
549 * @warning This makes the assumption that if you're gonna subnames a 2d
550 * vector, you're subnaming across all y
553 ysubnames(const char **names)
555 Derived &self = this->self();
556 Info *info = this->info();
558 info->y_subnames.resize(self.y);
559 for (off_type i = 0; i < self.y; ++i)
560 info->y_subnames[i] = names[i];
565 ysubname(off_type index, const std::string subname)
567 Derived &self = this->self();
568 Info *info = this->info();
570 assert(index < self.y);
571 info->y_subnames.resize(self.y);
572 info->y_subnames[index] = subname.c_str();
577 //////////////////////////////////////////////////////////////////////
581 //////////////////////////////////////////////////////////////////////
584 * Templatized storage and interface for a simple scalar stat.
589 /** The statistic value. */
593 struct Params : public StorageParams {};
597 * Builds this storage element and calls the base constructor of the
605 * The the stat to the given value.
606 * @param val The new value.
608 void set(Counter val) { data = val; }
610 * Increment the stat by the given value.
611 * @param val The new value.
613 void inc(Counter val) { data += val; }
615 * Decrement the stat by the given value.
616 * @param val The new value.
618 void dec(Counter val) { data -= val; }
620 * Return the value of this stat as its base type.
621 * @return The value of this stat.
623 Counter value() const { return data; }
625 * Return the value of this stat as a result type.
626 * @return The value of this stat.
628 Result result() const { return (Result)data; }
630 * Prepare stat data for dumping or serialization
632 void prepare(Info *info) { }
634 * Reset stat value to default
636 void reset(Info *info) { data = Counter(); }
639 * @return true if zero value
641 bool zero() const { return data == Counter(); }
645 * Templatized storage and interface to a per-tick average stat. This keeps
646 * a current count and updates a total (count * ticks) when this count
647 * changes. This allows the quick calculation of a per tick count of the item
648 * being watched. This is good for keeping track of residencies in structures
649 * among other things.
654 /** The current count. */
656 /** The total count for all tick. */
657 mutable Result total;
658 /** The tick that current last changed. */
662 struct Params : public StorageParams {};
666 * Build and initializes this stat storage.
669 : current(0), total(0), last(0)
673 * Set the current count to the one provided, update the total and last
675 * @param val The new count.
680 total += current * (curTick - last);
686 * Increment the current count by the provided value, calls set.
687 * @param val The amount to increment.
689 void inc(Counter val) { set(current + val); }
692 * Deccrement the current count by the provided value, calls set.
693 * @param val The amount to decrement.
695 void dec(Counter val) { set(current - val); }
698 * Return the current count.
699 * @return The current count.
701 Counter value() const { return current; }
704 * Return the current average.
705 * @return The current average.
710 assert(last == curTick);
711 return (Result)(total + current) / (Result)(curTick + 1);
715 * @return true if zero value
717 bool zero() const { return total == 0.0; }
720 * Prepare stat data for dumping or serialization
725 total += current * (curTick - last);
730 * Reset stat value to default
742 * Implementation of a scalar stat. The type of stat is determined by the
745 template <class Derived, class Stor>
746 class ScalarBase : public DataWrap<Derived, ScalarInfo>
749 typedef Stor Storage;
750 typedef typename Stor::Params Params;
753 /** The storage of this stat. */
754 char storage[sizeof(Storage)] __attribute__ ((aligned (8)));
758 * Retrieve the storage.
759 * @param index The vector index to access.
760 * @return The storage object at the given index.
765 return reinterpret_cast<Storage *>(storage);
769 * Retrieve a const pointer to the storage.
770 * for the given index.
771 * @param index The vector index to access.
772 * @return A const pointer to the storage object at the given index.
777 return reinterpret_cast<const Storage *>(storage);
783 new (storage) Storage(this->info());
789 * Return the current value of this stat as its base type.
790 * @return The current value.
792 Counter value() const { return data()->value(); }
801 // Common operators for stats
803 * Increment the stat by 1. This calls the associated storage object inc
806 void operator++() { data()->inc(1); }
808 * Decrement the stat by 1. This calls the associated storage object dec
811 void operator--() { data()->dec(1); }
813 /** Increment the stat by 1. */
814 void operator++(int) { ++*this; }
815 /** Decrement the stat by 1. */
816 void operator--(int) { --*this; }
819 * Set the data value to the given value. This calls the associated storage
820 * object set function.
821 * @param v The new value.
823 template <typename U>
824 void operator=(const U &v) { data()->set(v); }
827 * Increment the stat by the given value. This calls the associated
828 * storage object inc function.
829 * @param v The value to add.
831 template <typename U>
832 void operator+=(const U &v) { data()->inc(v); }
835 * Decrement the stat by the given value. This calls the associated
836 * storage object dec function.
837 * @param v The value to substract.
839 template <typename U>
840 void operator-=(const U &v) { data()->dec(v); }
843 * Return the number of elements, always 1 for a scalar.
846 size_type size() const { return 1; }
848 Counter value() { return data()->value(); }
850 Result result() { return data()->result(); }
852 Result total() { return result(); }
854 bool zero() { return result() == 0.0; }
856 void reset() { data()->reset(this->info()); }
857 void prepare() { data()->prepare(this->info()); }
860 class ProxyInfo : public ScalarInfoBase
863 std::string str() const { return to_string(value()); }
864 size_type size() const { return 1; }
865 bool check() const { return true; }
868 bool zero() const { return value() == 0; }
870 void visit(Visit &visitor) { visitor.visit(*this); }
874 class ValueProxy : public ProxyInfo
880 ValueProxy(T &val) : scalar(&val) {}
881 Counter value() const { return *scalar; }
882 Result result() const { return *scalar; }
883 Result total() const { return *scalar; }
887 class FunctorProxy : public ProxyInfo
893 FunctorProxy(T &func) : functor(&func) {}
894 Counter value() const { return (*functor)(); }
895 Result result() const { return (*functor)(); }
896 Result total() const { return (*functor)(); }
899 template <class Derived>
900 class ValueBase : public DataWrap<Derived, ScalarInfo>
906 ValueBase() : proxy(NULL) { }
907 ~ValueBase() { if (proxy) delete proxy; }
913 proxy = new ValueProxy<T>(value);
922 proxy = new FunctorProxy<T>(func);
927 Counter value() { return proxy->value(); }
928 Result result() const { return proxy->result(); }
929 Result total() const { return proxy->total(); };
930 size_type size() const { return proxy->size(); }
932 std::string str() const { return proxy->str(); }
933 bool zero() const { return proxy->zero(); }
934 bool check() const { return proxy != NULL; }
939 //////////////////////////////////////////////////////////////////////
943 //////////////////////////////////////////////////////////////////////
946 * A proxy class to access the stat at a given index in a VectorBase stat.
947 * Behaves like a ScalarBase.
949 template <class Stat>
953 /** Pointer to the parent Vector. */
956 /** The index to access in the parent VectorBase. */
961 * Return the current value of this stat as its base type.
962 * @return The current value.
964 Counter value() const { return stat.data(index)->value(); }
967 * Return the current value of this statas a result type.
968 * @return The current value.
970 Result result() const { return stat.data(index)->result(); }
974 * Create and initialize this proxy, do not register it with the database.
975 * @param i The index to access.
977 ScalarProxy(Stat &s, off_type i)
983 * Create a copy of the provided ScalarProxy.
984 * @param sp The proxy to copy.
986 ScalarProxy(const ScalarProxy &sp)
987 : stat(sp.stat), index(sp.index)
991 * Set this proxy equal to the provided one.
992 * @param sp The proxy to copy.
993 * @return A reference to this proxy.
996 operator=(const ScalarProxy &sp)
1004 // Common operators for stats
1006 * Increment the stat by 1. This calls the associated storage object inc
1009 void operator++() { stat.data(index)->inc(1); }
1011 * Decrement the stat by 1. This calls the associated storage object dec
1014 void operator--() { stat.data(index)->dec(1); }
1016 /** Increment the stat by 1. */
1017 void operator++(int) { ++*this; }
1018 /** Decrement the stat by 1. */
1019 void operator--(int) { --*this; }
1022 * Set the data value to the given value. This calls the associated storage
1023 * object set function.
1024 * @param v The new value.
1026 template <typename U>
1028 operator=(const U &v)
1030 stat.data(index)->set(v);
1034 * Increment the stat by the given value. This calls the associated
1035 * storage object inc function.
1036 * @param v The value to add.
1038 template <typename U>
1040 operator+=(const U &v)
1042 stat.data(index)->inc(v);
1046 * Decrement the stat by the given value. This calls the associated
1047 * storage object dec function.
1048 * @param v The value to substract.
1050 template <typename U>
1052 operator-=(const U &v)
1054 stat.data(index)->dec(v);
1058 * Return the number of elements, always 1 for a scalar.
1061 size_type size() const { return 1; }
1067 return csprintf("%s[%d]", stat.info()->name, index);
1072 * Implementation of a vector of stats. The type of stat is determined by the
1073 * Storage class. @sa ScalarBase
1075 template <class Derived, class Stor>
1076 class VectorBase : public DataWrapVec<Derived, VectorInfo>
1079 typedef Stor Storage;
1080 typedef typename Stor::Params Params;
1083 typedef ScalarProxy<Derived> Proxy;
1084 friend class ScalarProxy<Derived>;
1085 friend class DataWrapVec<Derived, VectorInfo>;
1088 /** The storage of this stat. */
1094 * Retrieve the storage.
1095 * @param index The vector index to access.
1096 * @return The storage object at the given index.
1098 Storage *data(off_type index) { return &storage[index]; }
1101 * Retrieve a const pointer to the storage.
1102 * @param index The vector index to access.
1103 * @return A const pointer to the storage object at the given index.
1105 const Storage *data(off_type index) const { return &storage[index]; }
1110 assert(s > 0 && "size must be positive!");
1111 assert(!storage && "already initialized");
1114 char *ptr = new char[_size * sizeof(Storage)];
1115 storage = reinterpret_cast<Storage *>(ptr);
1117 for (off_type i = 0; i < _size; ++i)
1118 new (&storage[i]) Storage(this->info());
1125 value(VCounter &vec) const
1128 for (off_type i = 0; i < size(); ++i)
1129 vec[i] = data(i)->value();
1133 * Copy the values to a local vector and return a reference to it.
1134 * @return A reference to a vector of the stat values.
1137 result(VResult &vec) const
1140 for (off_type i = 0; i < size(); ++i)
1141 vec[i] = data(i)->result();
1145 * Return a total of all entries in this vector.
1146 * @return The total of all vector entries.
1152 for (off_type i = 0; i < size(); ++i)
1153 total += data(i)->result();
1158 * @return the number of elements in this vector.
1160 size_type size() const { return _size; }
1165 for (off_type i = 0; i < size(); ++i)
1166 if (data(i)->zero())
1174 return storage != NULL;
1187 for (off_type i = 0; i < _size; ++i)
1188 data(i)->~Storage();
1189 delete [] reinterpret_cast<char *>(storage);
1193 * Set this vector to have the given size.
1194 * @param size The new size.
1195 * @return A reference to this stat.
1198 init(size_type size)
1200 Derived &self = this->self();
1206 * Return a reference (ScalarProxy) to the stat at the given index.
1207 * @param index The vector index to access.
1208 * @return A reference of the stat.
1211 operator[](off_type index)
1213 assert (index >= 0 && index < size());
1214 return Proxy(this->self(), index);
1218 template <class Stat>
1227 mutable VResult vec;
1229 typename Stat::Storage *
1230 data(off_type index)
1232 assert(index < len);
1233 return stat.data(offset + index);
1236 const typename Stat::Storage *
1237 data(off_type index) const
1239 assert(index < len);
1240 return stat.data(offset + index);
1249 for (off_type i = 0; i < size(); ++i)
1250 vec[i] = data(i)->result();
1259 for (off_type i = 0; i < size(); ++i)
1260 total += data(i)->result();
1265 VectorProxy(Stat &s, off_type o, size_type l)
1266 : stat(s), offset(o), len(l)
1270 VectorProxy(const VectorProxy &sp)
1271 : stat(sp.stat), offset(sp.offset), len(sp.len)
1276 operator=(const VectorProxy &sp)
1285 operator[](off_type index)
1287 assert (index >= 0 && index < size());
1288 return ScalarProxy<Stat>(stat, offset + index);
1291 size_type size() const { return len; }
1294 template <class Derived, class Stor>
1295 class Vector2dBase : public DataWrapVec2d<Derived, Vector2dInfo>
1298 typedef Vector2dInfo<Derived> Info;
1299 typedef Stor Storage;
1300 typedef typename Stor::Params Params;
1301 typedef VectorProxy<Derived> Proxy;
1302 friend class ScalarProxy<Derived>;
1303 friend class VectorProxy<Derived>;
1304 friend class DataWrapVec<Derived, Vector2dInfo>;
1305 friend class DataWrapVec2d<Derived, Vector2dInfo>;
1314 Storage *data(off_type index) { return &storage[index]; }
1315 const Storage *data(off_type index) const { return &storage[index]; }
1327 for (off_type i = 0; i < _size; ++i)
1328 data(i)->~Storage();
1329 delete [] reinterpret_cast<char *>(storage);
1333 init(size_type _x, size_type _y)
1335 assert(_x > 0 && _y > 0 && "sizes must be positive!");
1336 assert(!storage && "already initialized");
1338 Derived &self = this->self();
1339 Info *info = this->info();
1347 char *ptr = new char[_size * sizeof(Storage)];
1348 storage = reinterpret_cast<Storage *>(ptr);
1350 for (off_type i = 0; i < _size; ++i)
1351 new (&storage[i]) Storage(info);
1358 std::string ysubname(off_type i) const { return (*this->y_subnames)[i]; }
1361 operator[](off_type index)
1363 off_type offset = index * y;
1364 assert (index >= 0 && offset + index < size());
1365 return Proxy(this->self(), offset, y);
1378 return data(0)->zero();
1380 for (off_type i = 0; i < size(); ++i)
1381 if (!data(i)->zero())
1390 Info *info = this->info();
1391 size_type size = this->size();
1393 for (off_type i = 0; i < size; ++i)
1394 data(i)->prepare(info);
1396 info->cvec.resize(size);
1397 for (off_type i = 0; i < size; ++i)
1398 info->cvec[i] = data(i)->value();
1402 * Reset stat value to default
1407 Info *info = this->info();
1408 size_type size = this->size();
1409 for (off_type i = 0; i < size; ++i)
1410 data(i)->reset(info);
1416 return storage != NULL;
1420 //////////////////////////////////////////////////////////////////////
1422 // Non formula statistics
1424 //////////////////////////////////////////////////////////////////////
1426 struct DistParams : public StorageParams
1430 /** The minimum value to track. */
1432 /** The maximum value to track. */
1434 /** The number of entries in each bucket. */
1435 Counter bucket_size;
1436 /** The number of buckets. Equal to (max-min)/bucket_size. */
1439 explicit DistParams(bool f) : fancy(f) {}
1443 * Templatized storage and interface for a distrbution stat.
1448 /** The parameters for a distribution stat. */
1449 struct Params : public DistParams
1451 Params() : DistParams(false) {}
1455 /** The minimum value to track. */
1457 /** The maximum value to track. */
1459 /** The number of entries in each bucket. */
1460 Counter bucket_size;
1461 /** The number of buckets. Equal to (max-min)/bucket_size. */
1464 /** The smallest value sampled. */
1466 /** The largest value sampled. */
1468 /** The number of values sampled less than min. */
1470 /** The number of values sampled more than max. */
1472 /** The current sum. */
1474 /** The sum of squares. */
1476 /** The number of samples. */
1478 /** Counter for each bucket. */
1482 DistStor(Info *info)
1483 : cvec(safe_cast<const Params *>(info->storageParams)->buckets)
1489 * Add a value to the distribution for the given number of times.
1490 * @param val The value to add.
1491 * @param number The number of times to add the value.
1494 sample(Counter val, int number)
1496 if (val < min_track)
1497 underflow += number;
1498 else if (val > max_track)
1502 (size_type)std::floor((val - min_track) / bucket_size);
1503 assert(index < size());
1504 cvec[index] += number;
1513 Counter sample = val * number;
1515 squares += sample * sample;
1520 * Return the number of buckets in this distribution.
1521 * @return the number of buckets.
1523 size_type size() const { return cvec.size(); }
1526 * Returns true if any calls to sample have been made.
1527 * @return True if any values have been sampled.
1532 return samples == Counter();
1536 prepare(Info *info, DistData &data)
1538 const Params *params = safe_cast<const Params *>(info->storageParams);
1540 data.min_val = (min_val == CounterLimits::max()) ? 0 : min_val;
1541 data.max_val = (max_val == CounterLimits::min()) ? 0 : max_val;
1542 data.underflow = underflow;
1543 data.overflow = overflow;
1545 int buckets = params->buckets;
1546 data.cvec.resize(buckets);
1547 for (off_type i = 0; i < buckets; ++i)
1548 data.cvec[i] = cvec[i];
1551 data.squares = squares;
1552 data.samples = samples;
1556 * Reset stat value to default
1561 const Params *params = safe_cast<const Params *>(info->storageParams);
1562 min_track = params->min;
1563 max_track = params->max;
1564 bucket_size = params->bucket_size;
1566 min_val = CounterLimits::max();
1567 max_val = CounterLimits::min();
1571 size_type size = cvec.size();
1572 for (off_type i = 0; i < size; ++i)
1573 cvec[i] = Counter();
1576 squares = Counter();
1577 samples = Counter();
1582 * Templatized storage and interface for a distribution that calculates mean
1588 struct Params : public DistParams
1590 Params() : DistParams(true) {}
1594 /** The current sum. */
1596 /** The sum of squares. */
1598 /** The number of samples. */
1603 * Create and initialize this storage.
1605 FancyStor(Info *info)
1606 : sum(Counter()), squares(Counter()), samples(Counter())
1610 * Add a value the given number of times to this running average.
1611 * Update the running sum and sum of squares, increment the number of
1612 * values seen by the given number.
1613 * @param val The value to add.
1614 * @param number The number of times to add the value.
1617 sample(Counter val, int number)
1619 Counter value = val * number;
1621 squares += value * value;
1626 * Return the number of entries in this stat, 1
1629 size_type size() const { return 1; }
1632 * Return true if no samples have been added.
1633 * @return True if no samples have been added.
1635 bool zero() const { return samples == Counter(); }
1638 prepare(Info *info, DistData &data)
1641 data.squares = squares;
1642 data.samples = samples;
1646 * Reset stat value to default
1652 squares = Counter();
1653 samples = Counter();
1658 * Templatized storage for distribution that calculates per tick mean and
1664 struct Params : public DistParams
1666 Params() : DistParams(true) {}
1670 /** Current total. */
1672 /** Current sum of squares. */
1677 * Create and initialize this storage.
1679 AvgFancy(Info *info)
1680 : sum(Counter()), squares(Counter())
1684 * Add a value to the distribution for the given number of times.
1685 * Update the running sum and sum of squares.
1686 * @param val The value to add.
1687 * @param number The number of times to add the value.
1690 sample(Counter val, int number)
1692 Counter value = val * number;
1694 squares += value * value;
1698 * Return the number of entries, in this case 1.
1701 size_type size() const { return 1; }
1704 * Return true if no samples have been added.
1705 * @return True if the sum is zero.
1707 bool zero() const { return sum == Counter(); }
1710 prepare(Info *info, DistData &data)
1713 data.squares = squares;
1714 data.samples = curTick;
1718 * Reset stat value to default
1724 squares = Counter();
1729 * Implementation of a distribution stat. The type of distribution is
1730 * determined by the Storage template. @sa ScalarBase
1732 template <class Derived, class Stor>
1733 class DistBase : public DataWrap<Derived, DistInfo>
1736 typedef DistInfo<Derived> Info;
1737 typedef Stor Storage;
1738 typedef typename Stor::Params Params;
1741 /** The storage for this stat. */
1742 char storage[sizeof(Storage)] __attribute__ ((aligned (8)));
1746 * Retrieve the storage.
1747 * @return The storage object for this stat.
1752 return reinterpret_cast<Storage *>(storage);
1756 * Retrieve a const pointer to the storage.
1757 * @return A const pointer to the storage object for this stat.
1762 return reinterpret_cast<const Storage *>(storage);
1768 new (storage) Storage(this->info());
1776 * Add a value to the distribtion n times. Calls sample on the storage
1778 * @param v The value to add.
1779 * @param n The number of times to add it, defaults to 1.
1781 template <typename U>
1782 void sample(const U &v, int n = 1) { data()->sample(v, n); }
1785 * Return the number of entries in this stat.
1786 * @return The number of entries.
1788 size_type size() const { return data()->size(); }
1790 * Return true if no samples have been added.
1791 * @return True if there haven't been any samples.
1793 bool zero() const { return data()->zero(); }
1798 Info *info = this->info();
1799 data()->prepare(info, info->data);
1803 * Reset stat value to default
1808 data()->reset(this->info());
1812 template <class Stat>
1815 template <class Derived, class Stor>
1816 class VectorDistBase : public DataWrapVec<Derived, VectorDistInfo>
1819 typedef VectorDistInfo<Derived> Info;
1820 typedef Stor Storage;
1821 typedef typename Stor::Params Params;
1822 typedef DistProxy<Derived> Proxy;
1823 friend class DistProxy<Derived>;
1824 friend class DataWrapVec<Derived, VectorDistInfo>;
1832 data(off_type index)
1834 return &storage[index];
1838 data(off_type index) const
1840 return &storage[index];
1846 assert(s > 0 && "size must be positive!");
1847 assert(!storage && "already initialized");
1850 char *ptr = new char[_size * sizeof(Storage)];
1851 storage = reinterpret_cast<Storage *>(ptr);
1853 Info *info = this->info();
1854 for (off_type i = 0; i < _size; ++i)
1855 new (&storage[i]) Storage(info);
1870 for (off_type i = 0; i < _size; ++i)
1871 data(i)->~Storage();
1872 delete [] reinterpret_cast<char *>(storage);
1875 Proxy operator[](off_type index);
1888 for (off_type i = 0; i < size(); ++i)
1889 if (!data(i)->zero())
1898 Info *info = this->info();
1899 size_type size = this->size();
1900 info->data.resize(size);
1901 for (off_type i = 0; i < size; ++i)
1902 data(i)->prepare(info, info->data[i]);
1908 return storage != NULL;
1912 template <class Stat>
1920 typename Stat::Storage *data() { return stat->data(index); }
1921 const typename Stat::Storage *data() const { return stat->data(index); }
1924 DistProxy(Stat *s, off_type i)
1928 DistProxy(const DistProxy &sp)
1929 : stat(sp.stat), index(sp.index)
1933 operator=(const DistProxy &sp)
1941 template <typename U>
1943 sample(const U &v, int n = 1)
1945 data()->sample(v, n);
1957 return data()->zero();
1961 * Proxy has no state. Nothing to reset.
1966 template <class Derived, class Stor>
1967 inline typename VectorDistBase<Derived, Stor>::Proxy
1968 VectorDistBase<Derived, Stor>::operator[](off_type index)
1970 assert (index >= 0 && index < size());
1971 typedef typename VectorDistBase<Derived, Stor>::Proxy Proxy;
1972 return Proxy(this, index);
1976 template <class Storage>
1978 VectorDistBase<Storage>::total(off_type index) const
1981 for (off_type i = 0; i < x_size(); ++i)
1982 total += data(i)->result();
1986 //////////////////////////////////////////////////////////////////////
1990 //////////////////////////////////////////////////////////////////////
1993 * Base class for formula statistic node. These nodes are used to build a tree
1994 * that represents the formula.
1996 class Node : public RefCounted
2000 * Return the number of nodes in the subtree starting at this node.
2001 * @return the number of nodes in this subtree.
2003 virtual size_type size() const = 0;
2005 * Return the result vector of this subtree.
2006 * @return The result vector of this subtree.
2008 virtual const VResult &result() const = 0;
2010 * Return the total of the result vector.
2011 * @return The total of the result vector.
2013 virtual Result total() const = 0;
2018 virtual std::string str() const = 0;
2021 /** Reference counting pointer to a function Node. */
2022 typedef RefCountingPtr<Node> NodePtr;
2024 class ScalarStatNode : public Node
2027 const ScalarInfoBase *data;
2028 mutable VResult vresult;
2031 ScalarStatNode(const ScalarInfoBase *d) : data(d), vresult(1) {}
2036 vresult[0] = data->result();
2040 Result total() const { return data->result(); };
2042 size_type size() const { return 1; }
2047 std::string str() const { return data->name; }
2050 template <class Stat>
2051 class ScalarProxyNode : public Node
2054 const ScalarProxy<Stat> proxy;
2055 mutable VResult vresult;
2058 ScalarProxyNode(const ScalarProxy<Stat> &p)
2059 : proxy(p), vresult(1)
2065 vresult[0] = proxy.result();
2072 return proxy.result();
2091 class VectorStatNode : public Node
2094 const VectorInfoBase *data;
2097 VectorStatNode(const VectorInfoBase *d) : data(d) { }
2098 const VResult &result() const { return data->result(); }
2099 Result total() const { return data->total(); };
2101 size_type size() const { return data->size(); }
2103 std::string str() const { return data->name; }
2107 class ConstNode : public Node
2113 ConstNode(T s) : vresult(1, (Result)s) {}
2114 const VResult &result() const { return vresult; }
2115 Result total() const { return vresult[0]; };
2116 size_type size() const { return 1; }
2117 std::string str() const { return to_string(vresult[0]); }
2121 class ConstVectorNode : public Node
2127 ConstVectorNode(const T &s) : vresult(s.begin(), s.end()) {}
2128 const VResult &result() const { return vresult; }
2133 size_type size = this->size();
2135 for (off_type i = 0; i < size; i++)
2140 size_type size() const { return vresult.size(); }
2144 size_type size = this->size();
2145 std::string tmp = "(";
2146 for (off_type i = 0; i < size; i++)
2147 tmp += csprintf("%s ",to_string(vresult[i]));
2157 struct OpString<std::plus<Result> >
2159 static std::string str() { return "+"; }
2163 struct OpString<std::minus<Result> >
2165 static std::string str() { return "-"; }
2169 struct OpString<std::multiplies<Result> >
2171 static std::string str() { return "*"; }
2175 struct OpString<std::divides<Result> >
2177 static std::string str() { return "/"; }
2181 struct OpString<std::modulus<Result> >
2183 static std::string str() { return "%"; }
2187 struct OpString<std::negate<Result> >
2189 static std::string str() { return "-"; }
2193 class UnaryNode : public Node
2197 mutable VResult vresult;
2200 UnaryNode(NodePtr &p) : l(p) {}
2205 const VResult &lvec = l->result();
2206 size_type size = lvec.size();
2210 vresult.resize(size);
2212 for (off_type i = 0; i < size; ++i)
2213 vresult[i] = op(lvec[i]);
2221 const VResult &vec = this->result();
2223 for (off_type i = 0; i < size(); i++)
2228 size_type size() const { return l->size(); }
2233 return OpString<Op>::str() + l->str();
2238 class BinaryNode : public Node
2243 mutable VResult vresult;
2246 BinaryNode(NodePtr &a, NodePtr &b) : l(a), r(b) {}
2252 const VResult &lvec = l->result();
2253 const VResult &rvec = r->result();
2255 assert(lvec.size() > 0 && rvec.size() > 0);
2257 if (lvec.size() == 1 && rvec.size() == 1) {
2259 vresult[0] = op(lvec[0], rvec[0]);
2260 } else if (lvec.size() == 1) {
2261 size_type size = rvec.size();
2262 vresult.resize(size);
2263 for (off_type i = 0; i < size; ++i)
2264 vresult[i] = op(lvec[0], rvec[i]);
2265 } else if (rvec.size() == 1) {
2266 size_type size = lvec.size();
2267 vresult.resize(size);
2268 for (off_type i = 0; i < size; ++i)
2269 vresult[i] = op(lvec[i], rvec[0]);
2270 } else if (rvec.size() == lvec.size()) {
2271 size_type size = rvec.size();
2272 vresult.resize(size);
2273 for (off_type i = 0; i < size; ++i)
2274 vresult[i] = op(lvec[i], rvec[i]);
2283 const VResult &vec = this->result();
2285 for (off_type i = 0; i < size(); i++)
2293 size_type ls = l->size();
2294 size_type rs = r->size();
2297 } else if (rs == 1) {
2300 assert(ls == rs && "Node vector sizes are not equal");
2308 return csprintf("(%s %s %s)", l->str(), OpString<Op>::str(), r->str());
2313 class SumNode : public Node
2317 mutable VResult vresult;
2320 SumNode(NodePtr &p) : l(p), vresult(1) {}
2325 const VResult &lvec = l->result();
2326 size_type size = lvec.size();
2332 for (off_type i = 0; i < size; ++i)
2333 vresult[0] = op(vresult[0], lvec[i]);
2341 const VResult &lvec = l->result();
2342 size_type size = lvec.size();
2345 Result vresult = 0.0;
2348 for (off_type i = 0; i < size; ++i)
2349 vresult = op(vresult, lvec[i]);
2354 size_type size() const { return 1; }
2359 return csprintf("total(%s)", l->str());
2364 //////////////////////////////////////////////////////////////////////
2366 // Visible Statistics Types
2368 //////////////////////////////////////////////////////////////////////
2370 * @defgroup VisibleStats "Statistic Types"
2371 * These are the statistics that are used in the simulator.
2376 * This is a simple scalar statistic, like a counter.
2377 * @sa Stat, ScalarBase, StatStor
2379 class Scalar : public ScalarBase<Scalar, StatStor>
2382 using ScalarBase<Scalar, StatStor>::operator=;
2386 * A stat that calculates the per tick average of a value.
2387 * @sa Stat, ScalarBase, AvgStor
2389 class Average : public ScalarBase<Average, AvgStor>
2392 using ScalarBase<Average, AvgStor>::operator=;
2395 class Value : public ValueBase<Value>
2400 * A vector of scalar stats.
2401 * @sa Stat, VectorBase, StatStor
2403 class Vector : public VectorBase<Vector, StatStor>
2408 * A vector of Average stats.
2409 * @sa Stat, VectorBase, AvgStor
2411 class AverageVector : public VectorBase<AverageVector, AvgStor>
2416 * A 2-Dimensional vecto of scalar stats.
2417 * @sa Stat, Vector2dBase, StatStor
2419 class Vector2d : public Vector2dBase<Vector2d, StatStor>
2424 * A simple distribution stat.
2425 * @sa Stat, DistBase, DistStor
2427 class Distribution : public DistBase<Distribution, DistStor>
2431 * Set the parameters of this distribution. @sa DistStor::Params
2432 * @param min The minimum value of the distribution.
2433 * @param max The maximum value of the distribution.
2434 * @param bkt The number of values in each bucket.
2435 * @return A reference to this distribution.
2438 init(Counter min, Counter max, Counter bkt)
2440 DistStor::Params *params = new DistStor::Params;
2443 params->bucket_size = bkt;
2444 params->buckets = (size_type)rint((max - min) / bkt + 1.0);
2445 this->setParams(params);
2447 return this->self();
2452 * Calculates the mean and variance of all the samples.
2453 * @sa Stat, DistBase, FancyStor
2455 class StandardDeviation : public DistBase<StandardDeviation, FancyStor>
2459 * Construct and initialize this distribution.
2468 * Calculates the per tick mean and variance of the samples.
2469 * @sa Stat, DistBase, AvgFancy
2471 class AverageDeviation : public DistBase<AverageDeviation, AvgFancy>
2475 * Construct and initialize this distribution.
2484 * A vector of distributions.
2485 * @sa Stat, VectorDistBase, DistStor
2487 class VectorDistribution : public VectorDistBase<VectorDistribution, DistStor>
2491 * Initialize storage and parameters for this distribution.
2492 * @param size The size of the vector (the number of distributions).
2493 * @param min The minimum value of the distribution.
2494 * @param max The maximum value of the distribution.
2495 * @param bkt The number of values in each bucket.
2496 * @return A reference to this distribution.
2498 VectorDistribution &
2499 init(size_type size, Counter min, Counter max, Counter bkt)
2501 DistStor::Params *params = new DistStor::Params;
2504 params->bucket_size = bkt;
2505 params->buckets = (size_type)rint((max - min) / bkt + 1.0);
2506 this->setParams(params);
2508 return this->self();
2513 * This is a vector of StandardDeviation stats.
2514 * @sa Stat, VectorDistBase, FancyStor
2516 class VectorStandardDeviation
2517 : public VectorDistBase<VectorStandardDeviation, FancyStor>
2521 * Initialize storage for this distribution.
2522 * @param size The size of the vector.
2523 * @return A reference to this distribution.
2525 VectorStandardDeviation &
2526 init(size_type size)
2529 return this->self();
2534 * This is a vector of AverageDeviation stats.
2535 * @sa Stat, VectorDistBase, AvgFancy
2537 class VectorAverageDeviation
2538 : public VectorDistBase<VectorAverageDeviation, AvgFancy>
2542 * Initialize storage for this distribution.
2543 * @param size The size of the vector.
2544 * @return A reference to this distribution.
2546 VectorAverageDeviation &
2547 init(size_type size)
2550 return this->self();
2554 class FormulaInfoBase : public VectorInfoBase
2557 virtual std::string str() const = 0;
2560 template <class Stat>
2561 class FormulaInfo : public InfoWrap<Stat, FormulaInfoBase>
2564 mutable VResult vec;
2565 mutable VCounter cvec;
2568 FormulaInfo(Stat &stat) : InfoWrap<Stat, FormulaInfoBase>(stat) {}
2570 size_type size() const { return this->s.size(); }
2575 this->s.result(vec);
2578 Result total() const { return this->s.total(); }
2579 VCounter &value() const { return cvec; }
2581 std::string str() const { return this->s.str(); }
2586 * A formula for statistics that is calculated when printed. A formula is
2587 * stored as a tree of Nodes that represent the equation to calculate.
2588 * @sa Stat, ScalarStat, VectorStat, Node, Temp
2590 class Formula : public DataWrapVec<Formula, FormulaInfo>
2593 /** The root of the tree which represents the Formula */
2599 * Create and initialize thie formula, and register it with the database.
2604 * Create a formula with the given root node, register it with the
2606 * @param r The root of the expression tree.
2611 * Set an unitialized Formula to the given root.
2612 * @param r The root of the expression tree.
2613 * @return a reference to this formula.
2615 const Formula &operator=(Temp r);
2618 * Add the given tree to the existing one.
2619 * @param r The root of the expression tree.
2620 * @return a reference to this formula.
2622 const Formula &operator+=(Temp r);
2624 * Return the result of the Fomula in a vector. If there were no Vector
2625 * components to the Formula, then the vector is size 1. If there were,
2626 * like x/y with x being a vector of size 3, then the result returned will
2627 * be x[0]/y, x[1]/y, x[2]/y, respectively.
2628 * @return The result vector.
2630 void result(VResult &vec) const;
2633 * Return the total Formula result. If there is a Vector
2634 * component to this Formula, then this is the result of the
2635 * Formula if the formula is applied after summing all the
2636 * components of the Vector. For example, if Formula is x/y where
2637 * x is size 3, then total() will return (x[1]+x[2]+x[3])/y. If
2638 * there is no Vector component, total() returns the same value as
2639 * the first entry in the VResult val() returns.
2640 * @return The total of the result vector.
2642 Result total() const;
2645 * Return the number of elements in the tree.
2647 size_type size() const;
2652 * Formulas don't need to be reset
2661 std::string str() const;
2664 class FormulaNode : public Node
2667 const Formula &formula;
2668 mutable VResult vec;
2671 FormulaNode(const Formula &f) : formula(f) {}
2673 size_type size() const { return formula.size(); }
2674 const VResult &result() const { formula.result(vec); return vec; }
2675 Result total() const { return formula.total(); }
2677 std::string str() const { return formula.str(); }
2681 * Helper class to construct formula node trees.
2687 * Pointer to a Node object.
2693 * Copy the given pointer to this class.
2694 * @param n A pointer to a Node object to copy.
2696 Temp(NodePtr n) : node(n) { }
2699 * Return the node pointer.
2700 * @return the node pointer.
2702 operator NodePtr&() { return node; }
2706 * Create a new ScalarStatNode.
2707 * @param s The ScalarStat to place in a node.
2709 Temp(const Scalar &s)
2710 : node(new ScalarStatNode(s.info()))
2714 * Create a new ScalarStatNode.
2715 * @param s The ScalarStat to place in a node.
2717 Temp(const Value &s)
2718 : node(new ScalarStatNode(s.info()))
2722 * Create a new ScalarStatNode.
2723 * @param s The ScalarStat to place in a node.
2725 Temp(const Average &s)
2726 : node(new ScalarStatNode(s.info()))
2730 * Create a new VectorStatNode.
2731 * @param s The VectorStat to place in a node.
2733 Temp(const Vector &s)
2734 : node(new VectorStatNode(s.info()))
2740 Temp(const Formula &f)
2741 : node(new FormulaNode(f))
2745 * Create a new ScalarProxyNode.
2746 * @param p The ScalarProxy to place in a node.
2748 template <class Stat>
2749 Temp(const ScalarProxy<Stat> &p)
2750 : node(new ScalarProxyNode<Stat>(p))
2754 * Create a ConstNode
2755 * @param value The value of the const node.
2757 Temp(signed char value)
2758 : node(new ConstNode<signed char>(value))
2762 * Create a ConstNode
2763 * @param value The value of the const node.
2765 Temp(unsigned char value)
2766 : node(new ConstNode<unsigned char>(value))
2770 * Create a ConstNode
2771 * @param value The value of the const node.
2773 Temp(signed short value)
2774 : node(new ConstNode<signed short>(value))
2778 * Create a ConstNode
2779 * @param value The value of the const node.
2781 Temp(unsigned short value)
2782 : node(new ConstNode<unsigned short>(value))
2786 * Create a ConstNode
2787 * @param value The value of the const node.
2789 Temp(signed int value)
2790 : node(new ConstNode<signed int>(value))
2794 * Create a ConstNode
2795 * @param value The value of the const node.
2797 Temp(unsigned int value)
2798 : node(new ConstNode<unsigned int>(value))
2802 * Create a ConstNode
2803 * @param value The value of the const node.
2805 Temp(signed long value)
2806 : node(new ConstNode<signed long>(value))
2810 * Create a ConstNode
2811 * @param value The value of the const node.
2813 Temp(unsigned long value)
2814 : node(new ConstNode<unsigned long>(value))
2818 * Create a ConstNode
2819 * @param value The value of the const node.
2821 Temp(signed long long value)
2822 : node(new ConstNode<signed long long>(value))
2826 * Create a ConstNode
2827 * @param value The value of the const node.
2829 Temp(unsigned long long value)
2830 : node(new ConstNode<unsigned long long>(value))
2834 * Create a ConstNode
2835 * @param value The value of the const node.
2838 : node(new ConstNode<float>(value))
2842 * Create a ConstNode
2843 * @param value The value of the const node.
2846 : node(new ConstNode<double>(value))
2856 operator+(Temp l, Temp r)
2858 return NodePtr(new BinaryNode<std::plus<Result> >(l, r));
2862 operator-(Temp l, Temp r)
2864 return NodePtr(new BinaryNode<std::minus<Result> >(l, r));
2868 operator*(Temp l, Temp r)
2870 return NodePtr(new BinaryNode<std::multiplies<Result> >(l, r));
2874 operator/(Temp l, Temp r)
2876 return NodePtr(new BinaryNode<std::divides<Result> >(l, r));
2882 return NodePtr(new UnaryNode<std::negate<Result> >(l));
2885 template <typename T>
2889 return NodePtr(new ConstNode<T>(val));
2892 template <typename T>
2894 constantVector(T val)
2896 return NodePtr(new ConstVectorNode<T>(val));
2902 return NodePtr(new SumNode<std::plus<Result> >(val));
2906 * Enable the statistics package. Before the statistics package is
2907 * enabled, all statistics must be created and initialized and once
2908 * the package is enabled, no more statistics can be created.
2913 * Prepare all stats for data access. This must be done before
2914 * dumping and serialization.
2919 * Dump all statistics data to the registered outputs
2924 * Reset all statistics to the base state
2928 * Register a callback that should be called whenever statistics are
2931 void registerResetCallback(Callback *cb);
2933 std::list<Info *> &statsList();
2935 /* namespace Stats */ }
2937 #endif // __BASE_STATISTICS_HH__