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
33 * Declaration of Statistics objects.
39 * Generalized N-dimensinal vector
43 * -- these both can use the same function that prints out a
44 * specific set of stats
45 * VectorStandardDeviation totals
48 #ifndef __BASE_STATISTICS_HH__
49 #define __BASE_STATISTICS_HH__
62 #include "base/cprintf.hh"
63 #include "base/intmath.hh"
64 #include "base/refcnt.hh"
65 #include "base/str.hh"
66 #include "base/stats/flags.hh"
67 #include "base/stats/visit.hh"
68 #include "base/stats/types.hh"
69 #include "sim/host.hh"
73 /** The current simulated tick. */
76 /* A namespace for all of the Statistics */
79 /* Contains the statistic implementation details */
80 //////////////////////////////////////////////////////////////////////
82 // Statistics Framework Base classes
84 //////////////////////////////////////////////////////////////////////
87 /** The name of the stat. */
89 /** The description of the stat. */
91 /** The formatting flags. */
93 /** The display precision. */
95 /** A pointer to a prerequisite Stat. */
96 const StatData *prereq;
98 * A unique stat ID for each stat in the simulator.
99 * Can be used externally for lookups as well as for debugging.
107 * Reset the corresponding stat to the default state.
109 virtual void reset() = 0;
112 * @return true if this stat has a value and satisfies its
113 * requirement as a prereq
115 virtual bool zero() const = 0;
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 * Visitor entry for outputing statistics data
128 virtual void visit(Visit &visitor) = 0;
131 * Checks if the first stat's name is alphabetically less than the second.
132 * This function breaks names up at periods and considers each subname
134 * @param stat1 The first stat.
135 * @param stat2 The second stat.
136 * @return stat1's name is alphabetically before stat2's
138 static bool less(StatData *stat1, StatData *stat2);
141 class ScalarData : public StatData
144 virtual Counter value() const = 0;
145 virtual Result result() const = 0;
146 virtual Result total() const = 0;
147 virtual void visit(Visit &visitor) { visitor.visit(*this); }
150 template <class Stat>
151 class ScalarStatData : public ScalarData
157 ScalarStatData(Stat &stat) : s(stat) {}
159 virtual bool check() const { return s.check(); }
160 virtual Counter value() const { return s.value(); }
161 virtual Result result() const { return s.result(); }
162 virtual Result total() const { return s.total(); }
163 virtual void reset() { s.reset(); }
164 virtual bool zero() const { return s.zero(); }
167 struct VectorData : public StatData
169 /** Names and descriptions of subfields. */
170 mutable std::vector<std::string> subnames;
171 mutable std::vector<std::string> subdescs;
173 virtual size_t size() const = 0;
174 virtual const VCounter &value() const = 0;
175 virtual const VResult &result() const = 0;
176 virtual Result total() const = 0;
179 if (!subnames.empty()) {
181 if (subnames.size() < s)
184 if (subdescs.size() < s)
190 template <class Stat>
191 class VectorStatData : public VectorData
195 mutable VCounter cvec;
196 mutable VResult rvec;
199 VectorStatData(Stat &stat) : s(stat) {}
201 virtual bool check() const { return s.check(); }
202 virtual bool zero() const { return s.zero(); }
203 virtual void reset() { s.reset(); }
205 virtual size_t size() const { return s.size(); }
206 virtual VCounter &value() const
211 virtual const VResult &result() const
216 virtual Result total() const { return s.total(); }
217 virtual void visit(Visit &visitor)
221 visitor.visit(*this);
243 struct DistData : public StatData
245 /** Local storage for the entry values, used for printing. */
249 template <class Stat>
250 class DistStatData : public DistData
256 DistStatData(Stat &stat) : s(stat) {}
258 virtual bool check() const { return s.check(); }
259 virtual void reset() { s.reset(); }
260 virtual bool zero() const { return s.zero(); }
261 virtual void visit(Visit &visitor)
264 visitor.visit(*this);
268 struct VectorDistData : public StatData
270 std::vector<DistDataData> data;
272 /** Names and descriptions of subfields. */
273 mutable std::vector<std::string> subnames;
274 mutable std::vector<std::string> subdescs;
276 /** Local storage for the entry values, used for printing. */
277 mutable VResult rvec;
279 virtual size_t size() const = 0;
283 if (subnames.size() < s)
286 if (subdescs.size() < s)
291 template <class Stat>
292 class VectorDistStatData : public VectorDistData
298 VectorDistStatData(Stat &stat) : s(stat) {}
300 virtual bool check() const { return s.check(); }
301 virtual void reset() { s.reset(); }
302 virtual size_t size() const { return s.size(); }
303 virtual bool zero() const { return s.zero(); }
304 virtual void visit(Visit &visitor)
308 visitor.visit(*this);
312 struct Vector2dData : public StatData
314 /** Names and descriptions of subfields. */
315 std::vector<std::string> subnames;
316 std::vector<std::string> subdescs;
317 std::vector<std::string> y_subnames;
319 /** Local storage for the entry values, used for printing. */
320 mutable VCounter cvec;
326 if (subnames.size() < x)
331 template <class Stat>
332 class Vector2dStatData : public Vector2dData
338 Vector2dStatData(Stat &stat) : s(stat) {}
340 virtual bool check() const { return s.check(); }
341 virtual void reset() { s.reset(); }
342 virtual bool zero() const { return s.zero(); }
343 virtual void visit(Visit &visitor)
347 visitor.visit(*this);
354 StatData *find() const;
355 void map(StatData *data);
357 StatData *statData();
358 const StatData *statData() const;
364 template <class Parent, class Child, template <class> class Data>
365 class Wrap : public Child
368 Parent &self() { return *reinterpret_cast<Parent *>(this); }
371 Data<Child> *statData()
373 StatData *__data = DataAccess::statData();
374 Data<Child> *ptr = dynamic_cast<Data<Child> *>(__data);
380 const Data<Child> *statData() const
382 const StatData *__data = DataAccess::statData();
383 const Data<Child> *ptr = dynamic_cast<const Data<Child> *>(__data);
390 * Copy constructor, copies are not allowed.
392 Wrap(const Wrap &stat);
396 void operator=(const Wrap &);
401 this->map(new Data<Child>(*this));
405 * Set the name and marks this stat to print at the end of simulation.
406 * @param name The new name.
407 * @return A reference to this stat.
409 Parent &name(const std::string &_name)
411 Data<Child> *data = this->statData();
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.
423 Parent &desc(const std::string &_desc)
425 this->statData()->desc = _desc;
430 * Set the precision and marks this stat to print at the end of simulation.
431 * @param p The new precision
432 * @return A reference to this stat.
434 Parent &precision(int _precision)
436 this->statData()->precision = _precision;
441 * Set the flags and marks this stat to print at the end of simulation.
442 * @param f The new flags.
443 * @return A reference to this stat.
445 Parent &flags(StatFlags _flags)
447 this->statData()->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>
458 Parent &prereq(const Stat &prereq)
460 this->statData()->prereq = prereq.statData();
465 template <class Parent, class Child, template <class Child> class Data>
466 class WrapVec : public Wrap<Parent, Child, Data>
469 // The following functions are specific to vectors. If you use them
470 // in a non vector context, you will get a nice compiler error!
473 * Set the subfield name for the given index, and marks this stat to print
474 * at the end of simulation.
475 * @param index The subfield index.
476 * @param name The new name of the subfield.
477 * @return A reference to this stat.
479 Parent &subname(int index, const std::string &name)
481 std::vector<std::string> &subn = this->statData()->subnames;
482 if (subn.size() <= index)
483 subn.resize(index + 1);
489 * Set the subfield description for the given index and marks this stat to
490 * print at the end of simulation.
491 * @param index The subfield index.
492 * @param desc The new description of the subfield
493 * @return A reference to this stat.
495 Parent &subdesc(int index, const std::string &desc)
497 std::vector<std::string> &subd = this->statData()->subdescs;
498 if (subd.size() <= index)
499 subd.resize(index + 1);
507 template <class Parent, class Child, template <class Child> class Data>
508 class WrapVec2d : public WrapVec<Parent, Child, Data>
512 * @warning This makes the assumption that if you're gonna subnames a 2d
513 * vector, you're subnaming across all y
515 Parent &ysubnames(const char **names)
517 Data<Child> *data = this->statData();
518 data->y_subnames.resize(this->y);
519 for (int i = 0; i < this->y; ++i)
520 data->y_subnames[i] = names[i];
523 Parent &ysubname(int index, const std::string subname)
525 Data<Child> *data = this->statData();
526 assert(index < this->y);
527 data->y_subnames.resize(this->y);
528 data->y_subnames[index] = subname.c_str();
533 //////////////////////////////////////////////////////////////////////
537 //////////////////////////////////////////////////////////////////////
540 * Templatized storage and interface for a simple scalar stat.
545 /** The paramaters for this storage type, none for a scalar. */
549 /** The statistic value. */
554 * Builds this storage element and calls the base constructor of the
557 StatStor(const Params &) : data(Counter()) {}
560 * The the stat to the given value.
561 * @param val The new value.
562 * @param p The paramters of this storage type.
564 void set(Counter val, const Params &p) { data = val; }
566 * Increment the stat by the given value.
567 * @param val The new value.
568 * @param p The paramters of this storage type.
570 void inc(Counter val, const Params &p) { data += val; }
572 * Decrement the stat by the given value.
573 * @param val The new value.
574 * @param p The paramters of this storage type.
576 void dec(Counter val, const Params &p) { data -= val; }
578 * Return the value of this stat as its base type.
579 * @param p The params of this storage type.
580 * @return The value of this stat.
582 Counter value(const Params &p) const { return data; }
584 * Return the value of this stat as a result type.
585 * @param p The parameters of this storage type.
586 * @return The value of this stat.
588 Result result(const Params &p) const { return (Result)data; }
590 * Reset stat value to default
592 void reset() { data = Counter(); }
595 * @return true if zero value
597 bool zero() const { return data == Counter(); }
601 * Templatized storage and interface to a per-tick average stat. This keeps
602 * a current count and updates a total (count * ticks) when this count
603 * changes. This allows the quick calculation of a per tick count of the item
604 * being watched. This is good for keeping track of residencies in structures
605 * among other things.
610 /** The paramaters for this storage type */
614 /** The current count. */
616 /** The total count for all tick. */
617 mutable Result total;
618 /** The tick that current last changed. */
623 * Build and initializes this stat storage.
625 AvgStor(Params &p) : current(0), total(0), last(0) { }
628 * Set the current count to the one provided, update the total and last
630 * @param val The new count.
631 * @param p The parameters for this storage.
633 void set(Counter val, Params &p) {
634 total += current * (curTick - last);
640 * Increment the current count by the provided value, calls set.
641 * @param val The amount to increment.
642 * @param p The parameters for this storage.
644 void inc(Counter val, Params &p) { set(current + val, p); }
647 * Deccrement the current count by the provided value, calls set.
648 * @param val The amount to decrement.
649 * @param p The parameters for this storage.
651 void dec(Counter val, Params &p) { set(current - val, p); }
654 * Return the current count.
655 * @param p The parameters for this storage.
656 * @return The current count.
658 Counter value(const Params &p) const { return current; }
661 * Return the current average.
662 * @param p The parameters for this storage.
663 * @return The current average.
665 Result result(const Params &p) const
667 total += current * (curTick - last);
669 return (Result)(total + current) / (Result)(curTick + 1);
673 * Reset stat value to default
682 * @return true if zero value
684 bool zero() const { return total == 0.0; }
688 * Implementation of a scalar stat. The type of stat is determined by the
691 template <class Stor>
692 class ScalarBase : public DataAccess
695 typedef Stor Storage;
697 /** Define the params of the storage class. */
698 typedef typename Storage::Params Params;
701 /** The storage of this stat. */
702 char storage[sizeof(Storage)] __attribute__ ((aligned (8)));
704 /** The parameters for this stat. */
709 * Retrieve the storage.
710 * @param index The vector index to access.
711 * @return The storage object at the given index.
716 return reinterpret_cast<Storage *>(storage);
720 * Retrieve a const pointer to the storage.
721 * for the given index.
722 * @param index The vector index to access.
723 * @return A const pointer to the storage object at the given index.
728 return reinterpret_cast<const Storage *>(storage);
734 new (storage) Storage(params);
740 * Return the current value of this stat as its base type.
741 * @return The current value.
743 Counter value() const { return data()->value(params); }
747 * Create and initialize this stat, register it with the database.
753 // Common operators for stats
755 * Increment the stat by 1. This calls the associated storage object inc
758 void operator++() { data()->inc(1, params); }
760 * Decrement the stat by 1. This calls the associated storage object dec
763 void operator--() { data()->dec(1, params); }
765 /** Increment the stat by 1. */
766 void operator++(int) { ++*this; }
767 /** Decrement the stat by 1. */
768 void operator--(int) { --*this; }
771 * Set the data value to the given value. This calls the associated storage
772 * object set function.
773 * @param v The new value.
775 template <typename U>
776 void operator=(const U &v) { data()->set(v, params); }
779 * Increment the stat by the given value. This calls the associated
780 * storage object inc function.
781 * @param v The value to add.
783 template <typename U>
784 void operator+=(const U &v) { data()->inc(v, params); }
787 * Decrement the stat by the given value. This calls the associated
788 * storage object dec function.
789 * @param v The value to substract.
791 template <typename U>
792 void operator-=(const U &v) { data()->dec(v, params); }
795 * Return the number of elements, always 1 for a scalar.
798 size_t size() const { return 1; }
800 bool check() const { return true; }
803 * Reset stat value to default
805 void reset() { data()->reset(); }
807 Counter value() { return data()->value(params); }
809 Result result() { return data()->result(params); }
811 Result total() { return result(); }
813 bool zero() { return result() == 0.0; }
817 class ProxyData : public ScalarData
820 virtual void visit(Visit &visitor) { visitor.visit(*this); }
821 virtual std::string str() const { return to_string(value()); }
822 virtual size_t size() const { return 1; }
823 virtual bool zero() const { return value() == 0; }
824 virtual bool check() const { return true; }
825 virtual void reset() { }
829 class ValueProxy : public ProxyData
835 ValueProxy(T &val) : scalar(&val) {}
836 virtual Counter value() const { return *scalar; }
837 virtual Result result() const { return *scalar; }
838 virtual Result total() const { return *scalar; }
842 class FunctorProxy : public ProxyData
848 FunctorProxy(T &func) : functor(&func) {}
849 virtual Counter value() const { return (*functor)(); }
850 virtual Result result() const { return (*functor)(); }
851 virtual Result total() const { return (*functor)(); }
854 class ValueBase : public DataAccess
860 ValueBase() : proxy(NULL) { }
861 ~ValueBase() { if (proxy) delete proxy; }
864 void scalar(T &value)
866 proxy = new ValueProxy<T>(value);
871 void functor(T &func)
873 proxy = new FunctorProxy<T>(func);
877 Counter value() { return proxy->value(); }
878 Result result() const { return proxy->result(); }
879 Result total() const { return proxy->total(); };
880 size_t size() const { return proxy->size(); }
882 std::string str() const { return proxy->str(); }
883 bool zero() const { return proxy->zero(); }
884 bool check() const { return proxy != NULL; }
888 //////////////////////////////////////////////////////////////////////
892 //////////////////////////////////////////////////////////////////////
895 * A proxy class to access the stat at a given index in a VectorBase stat.
896 * Behaves like a ScalarBase.
898 template <class Stat>
902 /** Pointer to the parent Vector. */
905 /** The index to access in the parent VectorBase. */
910 * Return the current value of this stat as its base type.
911 * @return The current value.
913 Counter value() const { return stat->data(index)->value(stat->params); }
916 * Return the current value of this statas a result type.
917 * @return The current value.
919 Result result() const { return stat->data(index)->result(stat->params); }
923 * Create and initialize this proxy, do not register it with the database.
924 * @param p The params to use.
925 * @param i The index to access.
927 ScalarProxy(Stat *s, int i)
934 * Create a copy of the provided ScalarProxy.
935 * @param sp The proxy to copy.
937 ScalarProxy(const ScalarProxy &sp)
938 : stat(sp.stat), index(sp.index)
942 * Set this proxy equal to the provided one.
943 * @param sp The proxy to copy.
944 * @return A reference to this proxy.
946 const ScalarProxy &operator=(const ScalarProxy &sp) {
953 // Common operators for stats
955 * Increment the stat by 1. This calls the associated storage object inc
958 void operator++() { stat->data(index)->inc(1, stat->params); }
960 * Decrement the stat by 1. This calls the associated storage object dec
963 void operator--() { stat->data(index)->dec(1, stat->params); }
965 /** Increment the stat by 1. */
966 void operator++(int) { ++*this; }
967 /** Decrement the stat by 1. */
968 void operator--(int) { --*this; }
971 * Set the data value to the given value. This calls the associated storage
972 * object set function.
973 * @param v The new value.
975 template <typename U>
976 void operator=(const U &v) { stat->data(index)->set(v, stat->params); }
979 * Increment the stat by the given value. This calls the associated
980 * storage object inc function.
981 * @param v The value to add.
983 template <typename U>
984 void operator+=(const U &v) { stat->data(index)->inc(v, stat->params); }
987 * Decrement the stat by the given value. This calls the associated
988 * storage object dec function.
989 * @param v The value to substract.
991 template <typename U>
992 void operator-=(const U &v) { stat->data(index)->dec(v, stat->params); }
995 * Return the number of elements, always 1 for a scalar.
998 size_t size() const { return 1; }
1001 * This stat has no state. Nothing to reset
1009 return csprintf("%s[%d]", stat->str(), index);
1015 * Implementation of a vector of stats. The type of stat is determined by the
1016 * Storage class. @sa ScalarBase
1018 template <class Stor>
1019 class VectorBase : public DataAccess
1022 typedef Stor Storage;
1024 /** Define the params of the storage class. */
1025 typedef typename Storage::Params Params;
1028 typedef ScalarProxy<VectorBase<Storage> > Proxy;
1030 friend class ScalarProxy<VectorBase<Storage> >;
1033 /** The storage of this stat. */
1037 /** The parameters for this stat. */
1042 * Retrieve the storage.
1043 * @param index The vector index to access.
1044 * @return The storage object at the given index.
1046 Storage *data(int index) { return &storage[index]; }
1049 * Retrieve a const pointer to the storage.
1050 * @param index The vector index to access.
1051 * @return A const pointer to the storage object at the given index.
1053 const Storage *data(int index) const { return &storage[index]; }
1058 assert(s > 0 && "size must be positive!");
1059 assert(!storage && "already initialized");
1062 char *ptr = new char[_size * sizeof(Storage)];
1063 storage = reinterpret_cast<Storage *>(ptr);
1065 for (int i = 0; i < _size; ++i)
1066 new (&storage[i]) Storage(params);
1072 void value(VCounter &vec) const
1075 for (int i = 0; i < size(); ++i)
1076 vec[i] = data(i)->value(params);
1080 * Copy the values to a local vector and return a reference to it.
1081 * @return A reference to a vector of the stat values.
1083 void result(VResult &vec) const
1086 for (int i = 0; i < size(); ++i)
1087 vec[i] = data(i)->result(params);
1091 * Return a total of all entries in this vector.
1092 * @return The total of all vector entries.
1094 Result total() const {
1096 for (int i = 0; i < size(); ++i)
1097 total += data(i)->result(params);
1102 * @return the number of elements in this vector.
1104 size_t size() const { return _size; }
1109 for (int i = 0; i < size(); ++i)
1110 if (data(i)->zero())
1118 return storage != NULL;
1124 for (int i = 0; i < size(); ++i)
1138 for (int i = 0; i < _size; ++i)
1139 data(i)->~Storage();
1140 delete [] reinterpret_cast<char *>(storage);
1144 * Return a reference (ScalarProxy) to the stat at the given index.
1145 * @param index The vector index to access.
1146 * @return A reference of the stat.
1149 operator[](int index)
1151 assert (index >= 0 && index < size());
1152 return Proxy(this, index);
1155 void update(StatData *data) {}
1158 template <class Stat>
1167 mutable VResult vec;
1169 typename Stat::Storage *
1172 assert(index < len);
1173 return stat->data(offset + index);
1176 const typename Stat::Storage *
1177 data(int index) const
1179 assert(index < len);
1180 return const_cast<Stat *>(stat)->data(offset + index);
1189 for (int i = 0; i < size(); ++i)
1190 vec[i] = data(i)->result(stat->params);
1199 for (int i = 0; i < size(); ++i)
1200 total += data(i)->result(stat->params);
1205 VectorProxy(Stat *s, int o, int l)
1206 : stat(s), offset(o), len(l)
1210 VectorProxy(const VectorProxy &sp)
1211 : stat(sp.stat), offset(sp.offset), len(sp.len)
1216 operator=(const VectorProxy &sp)
1224 ScalarProxy<Stat> operator[](int index)
1226 assert (index >= 0 && index < size());
1227 return ScalarProxy<Stat>(stat, offset + index);
1230 size_t size() const { return len; }
1233 * This stat has no state. Nothing to reset.
1238 template <class Stor>
1239 class Vector2dBase : public DataAccess
1242 typedef Stor Storage;
1243 typedef typename Storage::Params Params;
1244 typedef VectorProxy<Vector2dBase<Storage> > Proxy;
1245 friend class ScalarProxy<Vector2dBase<Storage> >;
1246 friend class VectorProxy<Vector2dBase<Storage> >;
1256 Storage *data(int index) { return &storage[index]; }
1257 const Storage *data(int index) const { return &storage[index]; }
1260 doInit(int _x, int _y)
1262 assert(_x > 0 && _y > 0 && "sizes must be positive!");
1263 assert(!storage && "already initialized");
1265 Vector2dData *statdata = dynamic_cast<Vector2dData *>(find());
1273 char *ptr = new char[_size * sizeof(Storage)];
1274 storage = reinterpret_cast<Storage *>(ptr);
1276 for (int i = 0; i < _size; ++i)
1277 new (&storage[i]) Storage(params);
1292 for (int i = 0; i < _size; ++i)
1293 data(i)->~Storage();
1294 delete [] reinterpret_cast<char *>(storage);
1298 update(Vector2dData *newdata)
1300 int size = this->size();
1301 newdata->cvec.resize(size);
1302 for (int i = 0; i < size; ++i)
1303 newdata->cvec[i] = data(i)->value(params);
1306 std::string ysubname(int i) const { return (*this->y_subnames)[i]; }
1309 operator[](int index)
1311 int offset = index * y;
1312 assert (index >= 0 && offset + index < size());
1313 return Proxy(this, offset, y);
1326 return data(0)->zero();
1328 for (int i = 0; i < size(); ++i)
1329 if (!data(i)->zero())
1336 * Reset stat value to default
1341 for (int i = 0; i < size(); ++i)
1348 return storage != NULL;
1352 //////////////////////////////////////////////////////////////////////
1354 // Non formula statistics
1356 //////////////////////////////////////////////////////////////////////
1359 * Templatized storage and interface for a distrbution stat.
1364 /** The parameters for a distribution stat. */
1367 /** The minimum value to track. */
1369 /** The maximum value to track. */
1371 /** The number of entries in each bucket. */
1372 Counter bucket_size;
1373 /** The number of buckets. Equal to (max-min)/bucket_size. */
1376 enum { fancy = false };
1379 /** The smallest value sampled. */
1381 /** The largest value sampled. */
1383 /** The number of values sampled less than min. */
1385 /** The number of values sampled more than max. */
1387 /** The current sum. */
1389 /** The sum of squares. */
1391 /** The number of samples. */
1393 /** Counter for each bucket. */
1397 DistStor(const Params ¶ms)
1404 * Add a value to the distribution for the given number of times.
1405 * @param val The value to add.
1406 * @param number The number of times to add the value.
1407 * @param params The paramters of the distribution.
1409 void sample(Counter val, int number, const Params ¶ms)
1411 if (val < params.min)
1412 underflow += number;
1413 else if (val > params.max)
1416 int index = (int)std::floor((val - params.min) / params.bucket_size);
1417 assert(index < size(params));
1418 cvec[index] += number;
1427 Counter sample = val * number;
1429 squares += sample * sample;
1434 * Return the number of buckets in this distribution.
1435 * @return the number of buckets.
1436 * @todo Is it faster to return the size from the parameters?
1438 size_t size(const Params &) const { return cvec.size(); }
1441 * Returns true if any calls to sample have been made.
1442 * @param params The paramters of the distribution.
1443 * @return True if any values have been sampled.
1445 bool zero(const Params ¶ms) const
1447 return samples == Counter();
1450 void update(DistDataData *data, const Params ¶ms)
1452 data->min = params.min;
1453 data->max = params.max;
1454 data->bucket_size = params.bucket_size;
1455 data->size = params.size;
1457 data->min_val = (min_val == INT_MAX) ? 0 : min_val;
1458 data->max_val = (max_val == INT_MIN) ? 0 : max_val;
1459 data->underflow = underflow;
1460 data->overflow = overflow;
1461 data->cvec.resize(params.size);
1462 for (int i = 0; i < params.size; ++i)
1463 data->cvec[i] = cvec[i];
1466 data->squares = squares;
1467 data->samples = samples;
1471 * Reset stat value to default
1480 int size = cvec.size();
1481 for (int i = 0; i < size; ++i)
1482 cvec[i] = Counter();
1485 squares = Counter();
1486 samples = Counter();
1491 * Templatized storage and interface for a distribution that calculates mean
1498 * No paramters for this storage.
1501 enum { fancy = true };
1504 /** The current sum. */
1506 /** The sum of squares. */
1508 /** The number of samples. */
1513 * Create and initialize this storage.
1515 FancyStor(const Params &)
1516 : sum(Counter()), squares(Counter()), samples(Counter())
1520 * Add a value the given number of times to this running average.
1521 * Update the running sum and sum of squares, increment the number of
1522 * values seen by the given number.
1523 * @param val The value to add.
1524 * @param number The number of times to add the value.
1525 * @param p The parameters of this stat.
1527 void sample(Counter val, int number, const Params &p)
1529 Counter value = val * number;
1531 squares += value * value;
1535 void update(DistDataData *data, const Params ¶ms)
1538 data->squares = squares;
1539 data->samples = samples;
1543 * Return the number of entries in this stat, 1
1546 size_t size(const Params &) const { return 1; }
1549 * Return true if no samples have been added.
1550 * @return True if no samples have been added.
1552 bool zero(const Params &) const { return samples == Counter(); }
1555 * Reset stat value to default
1560 squares = Counter();
1561 samples = Counter();
1566 * Templatized storage for distribution that calculates per tick mean and
1572 /** No parameters for this storage. */
1574 enum { fancy = true };
1577 /** Current total. */
1579 /** Current sum of squares. */
1584 * Create and initialize this storage.
1586 AvgFancy(const Params &) : sum(Counter()), squares(Counter()) {}
1589 * Add a value to the distribution for the given number of times.
1590 * Update the running sum and sum of squares.
1591 * @param val The value to add.
1592 * @param number The number of times to add the value.
1593 * @param p The paramters of the distribution.
1595 void sample(Counter val, int number, const Params &p)
1597 Counter value = val * number;
1599 squares += value * value;
1602 void update(DistDataData *data, const Params ¶ms)
1605 data->squares = squares;
1606 data->samples = curTick;
1610 * Return the number of entries, in this case 1.
1613 size_t size(const Params ¶ms) const { return 1; }
1615 * Return true if no samples have been added.
1616 * @return True if the sum is zero.
1618 bool zero(const Params ¶ms) const { return sum == Counter(); }
1620 * Reset stat value to default
1625 squares = Counter();
1630 * Implementation of a distribution stat. The type of distribution is
1631 * determined by the Storage template. @sa ScalarBase
1633 template <class Stor>
1634 class DistBase : public DataAccess
1637 typedef Stor Storage;
1638 /** Define the params of the storage class. */
1639 typedef typename Storage::Params Params;
1642 /** The storage for this stat. */
1643 char storage[sizeof(Storage)] __attribute__ ((aligned (8)));
1645 /** The parameters for this stat. */
1650 * Retrieve the storage.
1651 * @return The storage object for this stat.
1655 return reinterpret_cast<Storage *>(storage);
1659 * Retrieve a const pointer to the storage.
1660 * @return A const pointer to the storage object for this stat.
1665 return reinterpret_cast<const Storage *>(storage);
1671 new (storage) Storage(params);
1679 * Add a value to the distribtion n times. Calls sample on the storage
1681 * @param v The value to add.
1682 * @param n The number of times to add it, defaults to 1.
1684 template <typename U>
1685 void sample(const U &v, int n = 1) { data()->sample(v, n, params); }
1688 * Return the number of entries in this stat.
1689 * @return The number of entries.
1691 size_t size() const { return data()->size(params); }
1693 * Return true if no samples have been added.
1694 * @return True if there haven't been any samples.
1696 bool zero() const { return data()->zero(params); }
1698 void update(DistData *base)
1700 base->data.fancy = Storage::fancy;
1701 data()->update(&(base->data), params);
1705 * Reset stat value to default
1720 template <class Stat>
1723 template <class Stor>
1724 class VectorDistBase : public DataAccess
1727 typedef Stor Storage;
1728 typedef typename Storage::Params Params;
1729 typedef DistProxy<VectorDistBase<Storage> > Proxy;
1730 friend class DistProxy<VectorDistBase<Storage> >;
1741 return &storage[index];
1745 data(int index) const
1747 return &storage[index];
1753 assert(s > 0 && "size must be positive!");
1754 assert(!storage && "already initialized");
1757 char *ptr = new char[_size * sizeof(Storage)];
1758 storage = reinterpret_cast<Storage *>(ptr);
1760 for (int i = 0; i < _size; ++i)
1761 new (&storage[i]) Storage(params);
1776 for (int i = 0; i < _size; ++i)
1777 data(i)->~Storage();
1778 delete [] reinterpret_cast<char *>(storage);
1781 Proxy operator[](int index);
1794 for (int i = 0; i < size(); ++i)
1795 if (!data(i)->zero(params))
1802 * Reset stat value to default
1807 for (int i = 0; i < size(); ++i)
1814 return storage != NULL;
1818 update(VectorDistData *base)
1820 int size = this->size();
1821 base->data.resize(size);
1822 for (int i = 0; i < size; ++i) {
1823 base->data[i].fancy = Storage::fancy;
1824 data(i)->update(&(base->data[i]), params);
1829 template <class Stat>
1837 typename Stat::Storage *data() { return stat->data(index); }
1838 const typename Stat::Storage *data() const { return stat->data(index); }
1841 DistProxy(Stat *s, int i)
1845 DistProxy(const DistProxy &sp)
1846 : stat(sp.stat), index(sp.index)
1849 const DistProxy &operator=(const DistProxy &sp)
1857 template <typename U>
1859 sample(const U &v, int n = 1)
1861 data()->sample(v, n, stat->params);
1873 return data()->zero(stat->params);
1877 * Proxy has no state. Nothing to reset.
1882 template <class Storage>
1883 inline typename VectorDistBase<Storage>::Proxy
1884 VectorDistBase<Storage>::operator[](int index)
1886 assert (index >= 0 && index < size());
1887 return typename VectorDistBase<Storage>::Proxy(this, index);
1891 template <class Storage>
1893 VectorDistBase<Storage>::total(int index) const
1896 for (int i = 0; i < x_size(); ++i) {
1897 total += data(i)->result(stat->params);
1902 //////////////////////////////////////////////////////////////////////
1906 //////////////////////////////////////////////////////////////////////
1909 * Base class for formula statistic node. These nodes are used to build a tree
1910 * that represents the formula.
1912 class Node : public RefCounted
1916 * Return the number of nodes in the subtree starting at this node.
1917 * @return the number of nodes in this subtree.
1919 virtual size_t size() const = 0;
1921 * Return the result vector of this subtree.
1922 * @return The result vector of this subtree.
1924 virtual const VResult &result() const = 0;
1926 * Return the total of the result vector.
1927 * @return The total of the result vector.
1929 virtual Result total() const = 0;
1934 virtual std::string str() const = 0;
1937 /** Reference counting pointer to a function Node. */
1938 typedef RefCountingPtr<Node> NodePtr;
1940 class ScalarStatNode : public Node
1943 const ScalarData *data;
1944 mutable VResult vresult;
1947 ScalarStatNode(const ScalarData *d) : data(d), vresult(1) {}
1948 virtual const VResult &result() const
1950 vresult[0] = data->result();
1953 virtual Result total() const { return data->result(); };
1955 virtual size_t size() const { return 1; }
1960 virtual std::string str() const { return data->name; }
1963 template <class Stat>
1964 class ScalarProxyNode : public Node
1967 const ScalarProxy<Stat> proxy;
1968 mutable VResult vresult;
1971 ScalarProxyNode(const ScalarProxy<Stat> &p)
1972 : proxy(p), vresult(1)
1975 virtual const VResult &
1978 vresult[0] = proxy.result();
1985 return proxy.result();
2004 class VectorStatNode : public Node
2007 const VectorData *data;
2010 VectorStatNode(const VectorData *d) : data(d) { }
2011 virtual const VResult &result() const { return data->result(); }
2012 virtual Result total() const { return data->total(); };
2014 virtual size_t size() const { return data->size(); }
2016 virtual std::string str() const { return data->name; }
2020 class ConstNode : public Node
2026 ConstNode(T s) : vresult(1, (Result)s) {}
2027 const VResult &result() const { return vresult; }
2028 virtual Result total() const { return vresult[0]; };
2029 virtual size_t size() const { return 1; }
2030 virtual std::string str() const { return to_string(vresult[0]); }
2037 struct OpString<std::plus<Result> >
2039 static std::string str() { return "+"; }
2043 struct OpString<std::minus<Result> >
2045 static std::string str() { return "-"; }
2049 struct OpString<std::multiplies<Result> >
2051 static std::string str() { return "*"; }
2055 struct OpString<std::divides<Result> >
2057 static std::string str() { return "/"; }
2061 struct OpString<std::modulus<Result> >
2063 static std::string str() { return "%"; }
2067 struct OpString<std::negate<Result> >
2069 static std::string str() { return "-"; }
2073 class UnaryNode : public Node
2077 mutable VResult vresult;
2080 UnaryNode(NodePtr &p) : l(p) {}
2082 const VResult &result() const
2084 const VResult &lvec = l->result();
2085 int size = lvec.size();
2089 vresult.resize(size);
2091 for (int i = 0; i < size; ++i)
2092 vresult[i] = op(lvec[i]);
2097 Result total() const
2099 const VResult &vec = this->result();
2101 for (int i = 0; i < size(); i++)
2106 virtual size_t size() const { return l->size(); }
2108 virtual std::string str() const
2110 return OpString<Op>::str() + l->str();
2115 class BinaryNode : public Node
2120 mutable VResult vresult;
2123 BinaryNode(NodePtr &a, NodePtr &b) : l(a), r(b) {}
2125 const VResult &result() const
2128 const VResult &lvec = l->result();
2129 const VResult &rvec = r->result();
2131 assert(lvec.size() > 0 && rvec.size() > 0);
2133 if (lvec.size() == 1 && rvec.size() == 1) {
2135 vresult[0] = op(lvec[0], rvec[0]);
2136 } else if (lvec.size() == 1) {
2137 int size = rvec.size();
2138 vresult.resize(size);
2139 for (int i = 0; i < size; ++i)
2140 vresult[i] = op(lvec[0], rvec[i]);
2141 } else if (rvec.size() == 1) {
2142 int size = lvec.size();
2143 vresult.resize(size);
2144 for (int i = 0; i < size; ++i)
2145 vresult[i] = op(lvec[i], rvec[0]);
2146 } else if (rvec.size() == lvec.size()) {
2147 int size = rvec.size();
2148 vresult.resize(size);
2149 for (int i = 0; i < size; ++i)
2150 vresult[i] = op(lvec[i], rvec[i]);
2156 Result total() const
2158 const VResult &vec = this->result();
2160 for (int i = 0; i < size(); i++)
2165 virtual size_t size() const {
2173 assert(ls == rs && "Node vector sizes are not equal");
2178 virtual std::string str() const
2180 return csprintf("(%s %s %s)", l->str(), OpString<Op>::str(), r->str());
2185 class SumNode : public Node
2189 mutable VResult vresult;
2192 SumNode(NodePtr &p) : l(p), vresult(1) {}
2194 const VResult &result() const
2196 const VResult &lvec = l->result();
2197 int size = lvec.size();
2203 for (int i = 0; i < size; ++i)
2204 vresult[0] = op(vresult[0], lvec[i]);
2209 Result total() const
2211 const VResult &lvec = l->result();
2212 int size = lvec.size();
2215 Result vresult = 0.0;
2218 for (int i = 0; i < size; ++i)
2219 vresult = op(vresult, lvec[i]);
2224 virtual size_t size() const { return 1; }
2226 virtual std::string str() const
2228 return csprintf("total(%s)", l->str());
2233 //////////////////////////////////////////////////////////////////////
2235 // Visible Statistics Types
2237 //////////////////////////////////////////////////////////////////////
2239 * @defgroup VisibleStats "Statistic Types"
2240 * These are the statistics that are used in the simulator.
2245 * This is a simple scalar statistic, like a counter.
2246 * @sa Stat, ScalarBase, StatStor
2249 class Scalar : public Wrap<Scalar<N>, ScalarBase<StatStor>, ScalarStatData>
2252 /** The base implementation. */
2253 typedef ScalarBase<StatStor> Base;
2261 * Sets the stat equal to the given value. Calls the base implementation
2263 * @param v The new value.
2265 template <typename U>
2266 void operator=(const U &v) { Base::operator=(v); }
2269 class Value : public Wrap<Value, ValueBase, ScalarStatData>
2272 /** The base implementation. */
2273 typedef ValueBase Base;
2276 Value &scalar(T &value)
2278 Base::scalar(value);
2283 Value &functor(T &func)
2285 Base::functor(func);
2291 * A stat that calculates the per tick average of a value.
2292 * @sa Stat, ScalarBase, AvgStor
2295 class Average : public Wrap<Average<N>, ScalarBase<AvgStor>, ScalarStatData>
2298 /** The base implementation. */
2299 typedef ScalarBase<AvgStor> Base;
2307 * Sets the stat equal to the given value. Calls the base implementation
2309 * @param v The new value.
2311 template <typename U>
2312 void operator=(const U &v) { Base::operator=(v); }
2316 * A vector of scalar stats.
2317 * @sa Stat, VectorBase, StatStor
2320 class Vector : public WrapVec<Vector<N>, VectorBase<StatStor>, VectorStatData>
2323 /** The base implementation. */
2324 typedef ScalarBase<StatStor> Base;
2327 * Set this vector to have the given size.
2328 * @param size The new size.
2329 * @return A reference to this stat.
2331 Vector &init(size_t size) {
2338 * A vector of Average stats.
2339 * @sa Stat, VectorBase, AvgStor
2343 : public WrapVec<AverageVector<N>, VectorBase<AvgStor>, VectorStatData>
2347 * Set this vector to have the given size.
2348 * @param size The new size.
2349 * @return A reference to this stat.
2351 AverageVector &init(size_t size) {
2358 * A 2-Dimensional vecto of scalar stats.
2359 * @sa Stat, Vector2dBase, StatStor
2363 : public WrapVec2d<Vector2d<N>, Vector2dBase<StatStor>, Vector2dStatData>
2366 Vector2d &init(size_t x, size_t y) {
2373 * A simple distribution stat.
2374 * @sa Stat, DistBase, DistStor
2378 : public Wrap<Distribution<N>, DistBase<DistStor>, DistStatData>
2381 /** Base implementation. */
2382 typedef DistBase<DistStor> Base;
2383 /** The Parameter type. */
2384 typedef DistStor::Params Params;
2388 * Set the parameters of this distribution. @sa DistStor::Params
2389 * @param min The minimum value of the distribution.
2390 * @param max The maximum value of the distribution.
2391 * @param bkt The number of values in each bucket.
2392 * @return A reference to this distribution.
2394 Distribution &init(Counter min, Counter max, Counter bkt) {
2395 this->params.min = min;
2396 this->params.max = max;
2397 this->params.bucket_size = bkt;
2398 this->params.size = (int)rint((max - min) / bkt + 1.0);
2405 * Calculates the mean and variance of all the samples.
2406 * @sa Stat, DistBase, FancyStor
2409 class StandardDeviation
2410 : public Wrap<StandardDeviation<N>, DistBase<FancyStor>, DistStatData>
2413 /** The base implementation */
2414 typedef DistBase<DistStor> Base;
2415 /** The parameter type. */
2416 typedef DistStor::Params Params;
2420 * Construct and initialize this distribution.
2422 StandardDeviation() {
2428 * Calculates the per tick mean and variance of the samples.
2429 * @sa Stat, DistBase, AvgFancy
2432 class AverageDeviation
2433 : public Wrap<AverageDeviation<N>, DistBase<AvgFancy>, DistStatData>
2436 /** The base implementation */
2437 typedef DistBase<DistStor> Base;
2438 /** The parameter type. */
2439 typedef DistStor::Params Params;
2443 * Construct and initialize this distribution.
2452 * A vector of distributions.
2453 * @sa Stat, VectorDistBase, DistStor
2456 class VectorDistribution
2457 : public WrapVec<VectorDistribution<N>,
2458 VectorDistBase<DistStor>,
2462 /** The base implementation */
2463 typedef VectorDistBase<DistStor> Base;
2464 /** The parameter type. */
2465 typedef DistStor::Params Params;
2469 * Initialize storage and parameters for this distribution.
2470 * @param size The size of the vector (the number of distributions).
2471 * @param min The minimum value of the distribution.
2472 * @param max The maximum value of the distribution.
2473 * @param bkt The number of values in each bucket.
2474 * @return A reference to this distribution.
2476 VectorDistribution &init(int size, Counter min, Counter max, Counter bkt) {
2477 this->params.min = min;
2478 this->params.max = max;
2479 this->params.bucket_size = bkt;
2480 this->params.size = (int)rint((max - min) / bkt + 1.0);
2487 * This is a vector of StandardDeviation stats.
2488 * @sa Stat, VectorDistBase, FancyStor
2491 class VectorStandardDeviation
2492 : public WrapVec<VectorStandardDeviation<N>,
2493 VectorDistBase<FancyStor>,
2497 /** The base implementation */
2498 typedef VectorDistBase<FancyStor> Base;
2499 /** The parameter type. */
2500 typedef DistStor::Params Params;
2504 * Initialize storage for this distribution.
2505 * @param size The size of the vector.
2506 * @return A reference to this distribution.
2508 VectorStandardDeviation &init(int size) {
2515 * This is a vector of AverageDeviation stats.
2516 * @sa Stat, VectorDistBase, AvgFancy
2519 class VectorAverageDeviation
2520 : public WrapVec<VectorAverageDeviation<N>,
2521 VectorDistBase<AvgFancy>,
2525 /** The base implementation */
2526 typedef VectorDistBase<AvgFancy> Base;
2527 /** The parameter type. */
2528 typedef DistStor::Params Params;
2532 * Initialize storage for this distribution.
2533 * @param size The size of the vector.
2534 * @return A reference to this distribution.
2536 VectorAverageDeviation &init(int size) {
2543 * A formula for statistics that is calculated when printed. A formula is
2544 * stored as a tree of Nodes that represent the equation to calculate.
2545 * @sa Stat, ScalarStat, VectorStat, Node, Temp
2547 class FormulaBase : public DataAccess
2550 /** The root of the tree which represents the Formula */
2556 * Return the result of the Fomula in a vector. If there were no Vector
2557 * components to the Formula, then the vector is size 1. If there were,
2558 * like x/y with x being a vector of size 3, then the result returned will
2559 * be x[0]/y, x[1]/y, x[2]/y, respectively.
2560 * @return The result vector.
2562 void result(VResult &vec) const;
2565 * Return the total Formula result. If there is a Vector
2566 * component to this Formula, then this is the result of the
2567 * Formula if the formula is applied after summing all the
2568 * components of the Vector. For example, if Formula is x/y where
2569 * x is size 3, then total() will return (x[1]+x[2]+x[3])/y. If
2570 * there is no Vector component, total() returns the same value as
2571 * the first entry in the VResult val() returns.
2572 * @return The total of the result vector.
2574 Result total() const;
2577 * Return the number of elements in the tree.
2579 size_t size() const;
2581 bool check() const { return true; }
2584 * Formulas don't need to be reset
2596 void update(StatData *);
2598 std::string str() const;
2601 class FormulaData : public VectorData
2604 virtual std::string str() const = 0;
2605 virtual bool check() const { return true; }
2608 template <class Stat>
2609 class FormulaStatData : public FormulaData
2613 mutable VResult vec;
2614 mutable VCounter cvec;
2617 FormulaStatData(Stat &stat) : s(stat) {}
2619 virtual bool zero() const { return s.zero(); }
2620 virtual void reset() { s.reset(); }
2622 virtual size_t size() const { return s.size(); }
2623 virtual const VResult &result() const
2628 virtual Result total() const { return s.total(); }
2629 virtual VCounter &value() const { return cvec; }
2630 virtual void visit(Visit &visitor)
2634 visitor.visit(*this);
2636 virtual std::string str() const { return s.str(); }
2641 : public WrapVec<Formula,
2647 * Create and initialize thie formula, and register it with the database.
2652 * Create a formula with the given root node, register it with the
2654 * @param r The root of the expression tree.
2659 * Set an unitialized Formula to the given root.
2660 * @param r The root of the expression tree.
2661 * @return a reference to this formula.
2663 const Formula &operator=(Temp r);
2666 * Add the given tree to the existing one.
2667 * @param r The root of the expression tree.
2668 * @return a reference to this formula.
2670 const Formula &operator+=(Temp r);
2673 class FormulaNode : public Node
2676 const Formula &formula;
2677 mutable VResult vec;
2680 FormulaNode(const Formula &f) : formula(f) {}
2682 virtual size_t size() const { return formula.size(); }
2683 virtual const VResult &result() const { formula.result(vec); return vec; }
2684 virtual Result total() const { return formula.total(); }
2686 virtual std::string str() const { return formula.str(); }
2690 * Helper class to construct formula node trees.
2696 * Pointer to a Node object.
2702 * Copy the given pointer to this class.
2703 * @param n A pointer to a Node object to copy.
2705 Temp(NodePtr n) : node(n) { }
2708 * Return the node pointer.
2709 * @return the node pointer.
2711 operator NodePtr&() { return node;}
2715 * Create a new ScalarStatNode.
2716 * @param s The ScalarStat to place in a node.
2719 Temp(const Scalar<N> &s)
2720 : node(new ScalarStatNode(s.statData())) { }
2723 * Create a new ScalarStatNode.
2724 * @param s The ScalarStat to place in a node.
2726 Temp(const Value &s)
2727 : node(new ScalarStatNode(s.statData())) { }
2730 * Create a new ScalarStatNode.
2731 * @param s The ScalarStat to place in a node.
2734 Temp(const Average<N> &s)
2735 : node(new ScalarStatNode(s.statData())) { }
2738 * Create a new VectorStatNode.
2739 * @param s The VectorStat to place in a node.
2742 Temp(const Vector<N> &s)
2743 : node(new VectorStatNode(s.statData())) { }
2748 Temp(const Formula &f)
2749 : node(new FormulaNode(f)) { }
2752 * Create a new ScalarProxyNode.
2753 * @param p The ScalarProxy to place in a node.
2755 template <class Stat>
2756 Temp(const ScalarProxy<Stat> &p)
2757 : node(new ScalarProxyNode<Stat>(p)) { }
2760 * Create a ConstNode
2761 * @param value The value of the const node.
2763 Temp(signed char value)
2764 : node(new ConstNode<signed char>(value)) {}
2767 * Create a ConstNode
2768 * @param value The value of the const node.
2770 Temp(unsigned char value)
2771 : node(new ConstNode<unsigned char>(value)) {}
2774 * Create a ConstNode
2775 * @param value The value of the const node.
2777 Temp(signed short value)
2778 : 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)) {}
2788 * Create a ConstNode
2789 * @param value The value of the const node.
2791 Temp(signed int value)
2792 : node(new ConstNode<signed int>(value)) {}
2795 * Create a ConstNode
2796 * @param value The value of the const node.
2798 Temp(unsigned int value)
2799 : 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)) {}
2809 * Create a ConstNode
2810 * @param value The value of the const node.
2812 Temp(unsigned long value)
2813 : node(new ConstNode<unsigned long>(value)) {}
2816 * Create a ConstNode
2817 * @param value The value of the const node.
2819 Temp(signed long long value)
2820 : node(new ConstNode<signed long long>(value)) {}
2823 * Create a ConstNode
2824 * @param value The value of the const node.
2826 Temp(unsigned long long value)
2827 : node(new ConstNode<unsigned long long>(value)) {}
2830 * Create a ConstNode
2831 * @param value The value of the const node.
2834 : node(new ConstNode<float>(value)) {}
2837 * Create a ConstNode
2838 * @param value The value of the const node.
2841 : node(new ConstNode<double>(value)) {}
2852 void registerResetCallback(Callback *cb);
2855 operator+(Temp l, Temp r)
2857 return NodePtr(new BinaryNode<std::plus<Result> >(l, r));
2861 operator-(Temp l, Temp r)
2863 return NodePtr(new BinaryNode<std::minus<Result> >(l, r));
2867 operator*(Temp l, Temp r)
2869 return NodePtr(new BinaryNode<std::multiplies<Result> >(l, r));
2873 operator/(Temp l, Temp r)
2875 return NodePtr(new BinaryNode<std::divides<Result> >(l, r));
2881 return NodePtr(new UnaryNode<std::negate<Result> >(l));
2884 template <typename T>
2888 return NodePtr(new ConstNode<T>(val));
2894 return NodePtr(new SumNode<std::plus<Result> >(val));
2897 /* namespace Stats */ }
2899 #endif // __BASE_STATISTICS_HH__