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__
59 #include "base/cprintf.hh"
60 #include "base/intmath.hh"
61 #include "base/refcnt.hh"
62 #include "base/str.hh"
63 #include "base/stats/flags.hh"
64 #include "base/stats/visit.hh"
65 #include "base/stats/types.hh"
66 #include "sim/host.hh"
70 /** The current simulated cycle. */
73 /* A namespace for all of the Statistics */
76 /* Contains the statistic implementation details */
77 //////////////////////////////////////////////////////////////////////
79 // Statistics Framework Base classes
81 //////////////////////////////////////////////////////////////////////
84 /** The name of the stat. */
86 /** The description of the stat. */
88 /** The formatting flags. */
90 /** The display precision. */
92 /** A pointer to a prerequisite Stat. */
93 const StatData *prereq;
95 * A unique stat ID for each stat in the simulator.
96 * Can be used externally for lookups as well as for debugging.
104 * Reset the corresponding stat to the default state.
106 virtual void reset() = 0;
109 * @return true if this stat has a value and satisfies its
110 * requirement as a prereq
112 virtual bool zero() const = 0;
115 * Check that this stat has been set up properly and is ready for
117 * @return true for success
119 virtual bool check() const = 0;
120 bool baseCheck() const;
123 * Visitor entry for outputing statistics data
125 virtual void visit(Visit &visitor) = 0;
128 * Checks if the first stat's name is alphabetically less than the second.
129 * This function breaks names up at periods and considers each subname
131 * @param stat1 The first stat.
132 * @param stat2 The second stat.
133 * @return stat1's name is alphabetically before stat2's
135 static bool less(StatData *stat1, StatData *stat2);
138 class ScalarData : public StatData
141 virtual Counter value() const = 0;
142 virtual Result result() const = 0;
143 virtual Result total() const = 0;
144 virtual void visit(Visit &visitor) { visitor.visit(*this); }
147 template <class Stat>
148 class ScalarStatData : public ScalarData
154 ScalarStatData(Stat &stat) : s(stat) {}
156 virtual bool check() const { return s.check(); }
157 virtual Counter value() const { return s.value(); }
158 virtual Result result() const { return s.result(); }
159 virtual Result total() const { return s.total(); }
160 virtual void reset() { s.reset(); }
161 virtual bool zero() const { return s.zero(); }
164 struct VectorData : public StatData
166 /** Names and descriptions of subfields. */
167 mutable std::vector<std::string> subnames;
168 mutable std::vector<std::string> subdescs;
170 virtual size_t size() const = 0;
171 virtual const VCounter &value() const = 0;
172 virtual const VResult &result() const = 0;
173 virtual Result total() const = 0;
176 if (!subnames.empty()) {
178 if (subnames.size() < s)
181 if (subdescs.size() < s)
187 template <class Stat>
188 class VectorStatData : public VectorData
192 mutable VCounter cvec;
193 mutable VResult rvec;
196 VectorStatData(Stat &stat) : s(stat) {}
198 virtual bool check() const { return s.check(); }
199 virtual bool zero() const { return s.zero(); }
200 virtual void reset() { s.reset(); }
202 virtual size_t size() const { return s.size(); }
203 virtual VCounter &value() const
208 virtual const VResult &result() const
213 virtual Result total() const { return s.total(); }
214 virtual void visit(Visit &visitor)
218 visitor.visit(*this);
240 struct DistData : public StatData
242 /** Local storage for the entry values, used for printing. */
246 template <class Stat>
247 class DistStatData : public DistData
253 DistStatData(Stat &stat) : s(stat) {}
255 virtual bool check() const { return s.check(); }
256 virtual void reset() { s.reset(); }
257 virtual bool zero() const { return s.zero(); }
258 virtual void visit(Visit &visitor)
261 visitor.visit(*this);
265 struct VectorDistData : public StatData
267 std::vector<DistDataData> data;
269 /** Names and descriptions of subfields. */
270 mutable std::vector<std::string> subnames;
271 mutable std::vector<std::string> subdescs;
273 /** Local storage for the entry values, used for printing. */
274 mutable VResult rvec;
276 virtual size_t size() const = 0;
280 if (subnames.size() < s)
283 if (subdescs.size() < s)
288 template <class Stat>
289 class VectorDistStatData : public VectorDistData
295 VectorDistStatData(Stat &stat) : s(stat) {}
297 virtual bool check() const { return s.check(); }
298 virtual void reset() { s.reset(); }
299 virtual size_t size() const { return s.size(); }
300 virtual bool zero() const { return s.zero(); }
301 virtual void visit(Visit &visitor)
305 visitor.visit(*this);
309 struct Vector2dData : public StatData
311 /** Names and descriptions of subfields. */
312 std::vector<std::string> subnames;
313 std::vector<std::string> subdescs;
314 std::vector<std::string> y_subnames;
316 /** Local storage for the entry values, used for printing. */
317 mutable VCounter cvec;
323 if (subnames.size() < x)
328 template <class Stat>
329 class Vector2dStatData : public Vector2dData
335 Vector2dStatData(Stat &stat) : s(stat) {}
337 virtual bool check() const { return s.check(); }
338 virtual void reset() { s.reset(); }
339 virtual bool zero() const { return s.zero(); }
340 virtual void visit(Visit &visitor)
344 visitor.visit(*this);
351 StatData *find() const;
352 void map(StatData *data);
354 StatData *statData();
355 const StatData *statData() const;
361 template <class Parent, class Child, template <class> class Data>
362 class Wrap : public Child
365 Parent &self() { return *reinterpret_cast<Parent *>(this); }
368 Data<Child> *statData()
370 StatData *__data = DataAccess::statData();
371 Data<Child> *ptr = dynamic_cast<Data<Child> *>(__data);
377 const Data<Child> *statData() const
379 const StatData *__data = DataAccess::statData();
380 const Data<Child> *ptr = dynamic_cast<const Data<Child> *>(__data);
387 * Copy constructor, copies are not allowed.
389 Wrap(const Wrap &stat);
393 void operator=(const Wrap &);
398 map(new Data<Child>(*this));
402 * Set the name and marks this stat to print at the end of simulation.
403 * @param name The new name.
404 * @return A reference to this stat.
406 Parent &name(const std::string &_name)
408 Data<Child> *data = this->statData();
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.
420 Parent &desc(const std::string &_desc)
422 this->statData()->desc = _desc;
427 * Set the precision and marks this stat to print at the end of simulation.
428 * @param p The new precision
429 * @return A reference to this stat.
431 Parent &precision(int _precision)
433 this->statData()->precision = _precision;
438 * Set the flags and marks this stat to print at the end of simulation.
439 * @param f The new flags.
440 * @return A reference to this stat.
442 Parent &flags(StatFlags _flags)
444 this->statData()->flags |= _flags;
449 * Set the prerequisite stat and marks this stat to print at the end of
451 * @param prereq The prerequisite stat.
452 * @return A reference to this stat.
454 template <class Stat>
455 Parent &prereq(const Stat &prereq)
457 this->statData()->prereq = prereq.statData();
462 template <class Parent, class Child, template <class Child> class Data>
463 class WrapVec : public Wrap<Parent, Child, Data>
466 // The following functions are specific to vectors. If you use them
467 // in a non vector context, you will get a nice compiler error!
470 * Set the subfield name for the given index, and marks this stat to print
471 * at the end of simulation.
472 * @param index The subfield index.
473 * @param name The new name of the subfield.
474 * @return A reference to this stat.
476 Parent &subname(int index, const std::string &name)
478 std::vector<std::string> &subn = this->statData()->subnames;
479 if (subn.size() <= index)
480 subn.resize(index + 1);
486 * Set the subfield description for the given index and marks this stat to
487 * print at the end of simulation.
488 * @param index The subfield index.
489 * @param desc The new description of the subfield
490 * @return A reference to this stat.
492 Parent &subdesc(int index, const std::string &desc)
494 std::vector<std::string> &subd = this->statData()->subdescs;
495 if (subd.size() <= index)
496 subd.resize(index + 1);
504 template <class Parent, class Child, template <class Child> class Data>
505 class WrapVec2d : public WrapVec<Parent, Child, Data>
509 * @warning This makes the assumption that if you're gonna subnames a 2d
510 * vector, you're subnaming across all y
512 Parent &ysubnames(const char **names)
514 Data<Child> *data = this->statData();
515 data->y_subnames.resize(this->y);
516 for (int i = 0; i < this->y; ++i)
517 data->y_subnames[i] = names[i];
520 Parent &ysubname(int index, const std::string subname)
522 Data<Child> *data = this->statData();
523 assert(index < this->y);
524 data->y_subnames.resize(this->y);
525 data->y_subnames[index] = subname.c_str();
530 //////////////////////////////////////////////////////////////////////
534 //////////////////////////////////////////////////////////////////////
537 * Templatized storage and interface for a simple scalar stat.
542 /** The paramaters for this storage type, none for a scalar. */
546 /** The statistic value. */
551 * Builds this storage element and calls the base constructor of the
554 StatStor(const Params &) : data(Counter()) {}
557 * The the stat to the given value.
558 * @param val The new value.
559 * @param p The paramters of this storage type.
561 void set(Counter val, const Params &p) { data = val; }
563 * Increment the stat by the given value.
564 * @param val The new value.
565 * @param p The paramters of this storage type.
567 void inc(Counter val, const Params &p) { data += val; }
569 * Decrement the stat by the given value.
570 * @param val The new value.
571 * @param p The paramters of this storage type.
573 void dec(Counter val, const Params &p) { data -= val; }
575 * Return the value of this stat as its base type.
576 * @param p The params of this storage type.
577 * @return The value of this stat.
579 Counter value(const Params &p) const { return data; }
581 * Return the value of this stat as a result type.
582 * @param p The parameters of this storage type.
583 * @return The value of this stat.
585 Result result(const Params &p) const { return (Result)data; }
587 * Reset stat value to default
589 void reset() { data = Counter(); }
592 * @return true if zero value
594 bool zero() const { return data == Counter(); }
598 * Templatized storage and interface to a per-cycle average stat. This keeps
599 * a current count and updates a total (count * cycles) when this count
600 * changes. This allows the quick calculation of a per cycle count of the item
601 * being watched. This is good for keeping track of residencies in structures
602 * among other things.
607 /** The paramaters for this storage type */
611 /** The current count. */
613 /** The total count for all cycles. */
614 mutable Result total;
615 /** The cycle that current last changed. */
620 * Build and initializes this stat storage.
622 AvgStor(Params &p) : current(0), total(0), last(0) { }
625 * Set the current count to the one provided, update the total and last
627 * @param val The new count.
628 * @param p The parameters for this storage.
630 void set(Counter val, Params &p) {
631 total += current * (curTick - last);
637 * Increment the current count by the provided value, calls set.
638 * @param val The amount to increment.
639 * @param p The parameters for this storage.
641 void inc(Counter val, Params &p) { set(current + val, p); }
644 * Deccrement the current count by the provided value, calls set.
645 * @param val The amount to decrement.
646 * @param p The parameters for this storage.
648 void dec(Counter val, Params &p) { set(current - val, p); }
651 * Return the current count.
652 * @param p The parameters for this storage.
653 * @return The current count.
655 Counter value(const Params &p) const { return current; }
658 * Return the current average.
659 * @param p The parameters for this storage.
660 * @return The current average.
662 Result result(const Params &p) const
664 total += current * (curTick - last);
666 return (Result)(total + current) / (Result)(curTick + 1);
670 * Reset stat value to default
679 * @return true if zero value
681 bool zero() const { return total == 0.0; }
685 * Implementation of a scalar stat. The type of stat is determined by the
688 template <class Stor>
689 class ScalarBase : public DataAccess
692 typedef Stor Storage;
694 /** Define the params of the storage class. */
695 typedef typename Storage::Params Params;
698 /** The storage of this stat. */
699 char storage[sizeof(Storage)];
701 /** The parameters for this stat. */
706 * Retrieve the storage.
707 * @param index The vector index to access.
708 * @return The storage object at the given index.
713 return reinterpret_cast<Storage *>(storage);
717 * Retrieve a const pointer to the storage.
718 * for the given index.
719 * @param index The vector index to access.
720 * @return A const pointer to the storage object at the given index.
725 return reinterpret_cast<const Storage *>(storage);
731 new (storage) Storage(params);
737 * Return the current value of this stat as its base type.
738 * @return The current value.
740 Counter value() const { return data()->value(params); }
744 * Create and initialize this stat, register it with the database.
750 // Common operators for stats
752 * Increment the stat by 1. This calls the associated storage object inc
755 void operator++() { data()->inc(1, params); }
757 * Decrement the stat by 1. This calls the associated storage object dec
760 void operator--() { data()->dec(1, params); }
762 /** Increment the stat by 1. */
763 void operator++(int) { ++*this; }
764 /** Decrement the stat by 1. */
765 void operator--(int) { --*this; }
768 * Set the data value to the given value. This calls the associated storage
769 * object set function.
770 * @param v The new value.
772 template <typename U>
773 void operator=(const U &v) { data()->set(v, params); }
776 * Increment the stat by the given value. This calls the associated
777 * storage object inc function.
778 * @param v The value to add.
780 template <typename U>
781 void operator+=(const U &v) { data()->inc(v, params); }
784 * Decrement the stat by the given value. This calls the associated
785 * storage object dec function.
786 * @param v The value to substract.
788 template <typename U>
789 void operator-=(const U &v) { data()->dec(v, params); }
792 * Return the number of elements, always 1 for a scalar.
795 size_t size() const { return 1; }
797 bool check() const { return true; }
800 * Reset stat value to default
802 void reset() { data()->reset(); }
804 Counter value() { return data()->value(params); }
806 Result result() { return data()->result(params); }
808 Result total() { return result(); }
810 bool zero() { return result() == 0.0; }
814 class ProxyData : public ScalarData
817 virtual void visit(Visit &visitor) { visitor.visit(*this); }
818 virtual std::string str() const { return to_string(value()); }
819 virtual size_t size() const { return 1; }
820 virtual bool zero() const { return value() == 0; }
821 virtual bool check() const { return true; }
822 virtual void reset() { }
826 class ValueProxy : public ProxyData
832 ValueProxy(T &val) : scalar(&val) {}
833 virtual Counter value() const { return *scalar; }
834 virtual Result result() const { return *scalar; }
835 virtual Result total() const { return *scalar; }
839 class FunctorProxy : public ProxyData
845 FunctorProxy(T &func) : functor(&func) {}
846 virtual Counter value() const { return (*functor)(); }
847 virtual Result result() const { return (*functor)(); }
848 virtual Result total() const { return (*functor)(); }
851 class ValueBase : public DataAccess
857 ValueBase() : proxy(NULL) { }
858 ~ValueBase() { if (proxy) delete proxy; }
861 void scalar(T &value)
863 proxy = new ValueProxy<T>(value);
868 void functor(T &func)
870 proxy = new FunctorProxy<T>(func);
874 Counter value() { return proxy->value(); }
875 Result result() const { return proxy->result(); }
876 Result total() const { return proxy->total(); };
877 size_t size() const { return proxy->size(); }
879 std::string str() const { return proxy->str(); }
880 bool zero() const { return proxy->zero(); }
881 bool check() const { return proxy != NULL; }
885 //////////////////////////////////////////////////////////////////////
889 //////////////////////////////////////////////////////////////////////
892 * A proxy class to access the stat at a given index in a VectorBase stat.
893 * Behaves like a ScalarBase.
895 template <class Stat>
899 /** Pointer to the parent Vector. */
902 /** The index to access in the parent VectorBase. */
907 * Return the current value of this stat as its base type.
908 * @return The current value.
910 Counter value() const { return stat->data(index)->value(stat->params); }
913 * Return the current value of this statas a result type.
914 * @return The current value.
916 Result result() const { return stat->data(index)->result(stat->params); }
920 * Create and initialize this proxy, do not register it with the database.
921 * @param p The params to use.
922 * @param i The index to access.
924 ScalarProxy(Stat *s, int i)
931 * Create a copy of the provided ScalarProxy.
932 * @param sp The proxy to copy.
934 ScalarProxy(const ScalarProxy &sp)
935 : stat(sp.stat), index(sp.index)
939 * Set this proxy equal to the provided one.
940 * @param sp The proxy to copy.
941 * @return A reference to this proxy.
943 const ScalarProxy &operator=(const ScalarProxy &sp) {
950 // Common operators for stats
952 * Increment the stat by 1. This calls the associated storage object inc
955 void operator++() { stat->data(index)->inc(1, stat->params); }
957 * Decrement the stat by 1. This calls the associated storage object dec
960 void operator--() { stat->data(index)->dec(1, stat->params); }
962 /** Increment the stat by 1. */
963 void operator++(int) { ++*this; }
964 /** Decrement the stat by 1. */
965 void operator--(int) { --*this; }
968 * Set the data value to the given value. This calls the associated storage
969 * object set function.
970 * @param v The new value.
972 template <typename U>
973 void operator=(const U &v) { stat->data(index)->set(v, stat->params); }
976 * Increment the stat by the given value. This calls the associated
977 * storage object inc function.
978 * @param v The value to add.
980 template <typename U>
981 void operator+=(const U &v) { stat->data(index)->inc(v, stat->params); }
984 * Decrement the stat by the given value. This calls the associated
985 * storage object dec function.
986 * @param v The value to substract.
988 template <typename U>
989 void operator-=(const U &v) { stat->data(index)->dec(v, stat->params); }
992 * Return the number of elements, always 1 for a scalar.
995 size_t size() const { return 1; }
998 * This stat has no state. Nothing to reset
1006 return csprintf("%s[%d]", stat->str(), index);
1012 * Implementation of a vector of stats. The type of stat is determined by the
1013 * Storage class. @sa ScalarBase
1015 template <class Stor>
1016 class VectorBase : public DataAccess
1019 typedef Stor Storage;
1021 /** Define the params of the storage class. */
1022 typedef typename Storage::Params Params;
1025 typedef ScalarProxy<VectorBase<Storage> > Proxy;
1027 friend class ScalarProxy<VectorBase<Storage> >;
1030 /** The storage of this stat. */
1034 /** The parameters for this stat. */
1039 * Retrieve the storage.
1040 * @param index The vector index to access.
1041 * @return The storage object at the given index.
1043 Storage *data(int index) { return &storage[index]; }
1046 * Retrieve a const pointer to the storage.
1047 * @param index The vector index to access.
1048 * @return A const pointer to the storage object at the given index.
1050 const Storage *data(int index) const { return &storage[index]; }
1055 assert(s > 0 && "size must be positive!");
1056 assert(!storage && "already initialized");
1059 char *ptr = new char[_size * sizeof(Storage)];
1060 storage = reinterpret_cast<Storage *>(ptr);
1062 for (int i = 0; i < _size; ++i)
1063 new (&storage[i]) Storage(params);
1069 void value(VCounter &vec) const
1072 for (int i = 0; i < size(); ++i)
1073 vec[i] = data(i)->value(params);
1077 * Copy the values to a local vector and return a reference to it.
1078 * @return A reference to a vector of the stat values.
1080 void result(VResult &vec) const
1083 for (int i = 0; i < size(); ++i)
1084 vec[i] = data(i)->result(params);
1088 * Return a total of all entries in this vector.
1089 * @return The total of all vector entries.
1091 Result total() const {
1093 for (int i = 0; i < size(); ++i)
1094 total += data(i)->result(params);
1099 * @return the number of elements in this vector.
1101 size_t size() const { return _size; }
1106 for (int i = 0; i < size(); ++i)
1107 if (data(i)->zero())
1115 return storage != NULL;
1121 for (int i = 0; i < size(); ++i)
1135 for (int i = 0; i < _size; ++i)
1136 data(i)->~Storage();
1137 delete [] reinterpret_cast<char *>(storage);
1141 * Return a reference (ScalarProxy) to the stat at the given index.
1142 * @param index The vector index to access.
1143 * @return A reference of the stat.
1146 operator[](int index)
1148 assert (index >= 0 && index < size());
1149 return Proxy(this, index);
1152 void update(StatData *data) {}
1155 template <class Stat>
1164 mutable VResult vec;
1166 typename Stat::Storage *
1169 assert(index < len);
1170 return stat->data(offset + index);
1173 const typename Stat::Storage *
1174 data(int index) const
1176 assert(index < len);
1177 return const_cast<Stat *>(stat)->data(offset + index);
1186 for (int i = 0; i < size(); ++i)
1187 vec[i] = data(i)->result(stat->params);
1196 for (int i = 0; i < size(); ++i)
1197 total += data(i)->result(stat->params);
1202 VectorProxy(Stat *s, int o, int l)
1203 : stat(s), offset(o), len(l)
1207 VectorProxy(const VectorProxy &sp)
1208 : stat(sp.stat), offset(sp.offset), len(sp.len)
1213 operator=(const VectorProxy &sp)
1221 ScalarProxy<Stat> operator[](int index)
1223 assert (index >= 0 && index < size());
1224 return ScalarProxy<Stat>(stat, offset + index);
1227 size_t size() const { return len; }
1230 * This stat has no state. Nothing to reset.
1235 template <class Stor>
1236 class Vector2dBase : public DataAccess
1239 typedef Stor Storage;
1240 typedef typename Storage::Params Params;
1241 typedef VectorProxy<Vector2dBase<Storage> > Proxy;
1242 friend class ScalarProxy<Vector2dBase<Storage> >;
1243 friend class VectorProxy<Vector2dBase<Storage> >;
1253 Storage *data(int index) { return &storage[index]; }
1254 const Storage *data(int index) const { return &storage[index]; }
1257 doInit(int _x, int _y)
1259 assert(_x > 0 && _y > 0 && "sizes must be positive!");
1260 assert(!storage && "already initialized");
1262 Vector2dData *statdata = dynamic_cast<Vector2dData *>(find());
1270 char *ptr = new char[_size * sizeof(Storage)];
1271 storage = reinterpret_cast<Storage *>(ptr);
1273 for (int i = 0; i < _size; ++i)
1274 new (&storage[i]) Storage(params);
1289 for (int i = 0; i < _size; ++i)
1290 data(i)->~Storage();
1291 delete [] reinterpret_cast<char *>(storage);
1295 update(Vector2dData *newdata)
1297 int size = this->size();
1298 newdata->cvec.resize(size);
1299 for (int i = 0; i < size; ++i)
1300 newdata->cvec[i] = data(i)->value(params);
1303 std::string ysubname(int i) const { return (*this->y_subnames)[i]; }
1306 operator[](int index)
1308 int offset = index * y;
1309 assert (index >= 0 && offset + index < size());
1310 return Proxy(this, offset, y);
1323 return data(0)->zero();
1325 for (int i = 0; i < size(); ++i)
1326 if (!data(i)->zero())
1333 * Reset stat value to default
1338 for (int i = 0; i < size(); ++i)
1345 return storage != NULL;
1349 //////////////////////////////////////////////////////////////////////
1351 // Non formula statistics
1353 //////////////////////////////////////////////////////////////////////
1356 * Templatized storage and interface for a distrbution stat.
1361 /** The parameters for a distribution stat. */
1364 /** The minimum value to track. */
1366 /** The maximum value to track. */
1368 /** The number of entries in each bucket. */
1369 Counter bucket_size;
1370 /** The number of buckets. Equal to (max-min)/bucket_size. */
1373 enum { fancy = false };
1376 /** The smallest value sampled. */
1378 /** The largest value sampled. */
1380 /** The number of values sampled less than min. */
1382 /** The number of values sampled more than max. */
1384 /** The current sum. */
1386 /** The sum of squares. */
1388 /** The number of samples. */
1390 /** Counter for each bucket. */
1394 DistStor(const Params ¶ms)
1401 * Add a value to the distribution for the given number of times.
1402 * @param val The value to add.
1403 * @param number The number of times to add the value.
1404 * @param params The paramters of the distribution.
1406 void sample(Counter val, int number, const Params ¶ms)
1408 if (val < params.min)
1409 underflow += number;
1410 else if (val > params.max)
1413 int index = (int)floor((val - params.min) / params.bucket_size);
1414 assert(index < size(params));
1415 cvec[index] += number;
1424 Counter sample = val * number;
1426 squares += sample * sample;
1431 * Return the number of buckets in this distribution.
1432 * @return the number of buckets.
1433 * @todo Is it faster to return the size from the parameters?
1435 size_t size(const Params &) const { return cvec.size(); }
1438 * Returns true if any calls to sample have been made.
1439 * @param params The paramters of the distribution.
1440 * @return True if any values have been sampled.
1442 bool zero(const Params ¶ms) const
1444 return samples == Counter();
1447 void update(DistDataData *data, const Params ¶ms)
1449 data->min = params.min;
1450 data->max = params.max;
1451 data->bucket_size = params.bucket_size;
1452 data->size = params.size;
1454 data->min_val = (min_val == INT_MAX) ? 0 : min_val;
1455 data->max_val = (max_val == INT_MIN) ? 0 : max_val;
1456 data->underflow = underflow;
1457 data->overflow = overflow;
1458 data->cvec.resize(params.size);
1459 for (int i = 0; i < params.size; ++i)
1460 data->cvec[i] = cvec[i];
1463 data->squares = squares;
1464 data->samples = samples;
1468 * Reset stat value to default
1477 int size = cvec.size();
1478 for (int i = 0; i < size; ++i)
1479 cvec[i] = Counter();
1482 squares = Counter();
1483 samples = Counter();
1488 * Templatized storage and interface for a distribution that calculates mean
1495 * No paramters for this storage.
1498 enum { fancy = true };
1501 /** The current sum. */
1503 /** The sum of squares. */
1505 /** The number of samples. */
1510 * Create and initialize this storage.
1512 FancyStor(const Params &)
1513 : sum(Counter()), squares(Counter()), samples(Counter())
1517 * Add a value the given number of times to this running average.
1518 * Update the running sum and sum of squares, increment the number of
1519 * values seen by the given number.
1520 * @param val The value to add.
1521 * @param number The number of times to add the value.
1522 * @param p The parameters of this stat.
1524 void sample(Counter val, int number, const Params &p)
1526 Counter value = val * number;
1528 squares += value * value;
1532 void update(DistDataData *data, const Params ¶ms)
1535 data->squares = squares;
1536 data->samples = samples;
1540 * Return the number of entries in this stat, 1
1543 size_t size(const Params &) const { return 1; }
1546 * Return true if no samples have been added.
1547 * @return True if no samples have been added.
1549 bool zero(const Params &) const { return samples == Counter(); }
1552 * Reset stat value to default
1557 squares = Counter();
1558 samples = Counter();
1563 * Templatized storage for distribution that calculates per cycle mean and
1569 /** No parameters for this storage. */
1571 enum { fancy = true };
1574 /** Current total. */
1576 /** Current sum of squares. */
1581 * Create and initialize this storage.
1583 AvgFancy(const Params &) : sum(Counter()), squares(Counter()) {}
1586 * Add a value to the distribution for the given number of times.
1587 * Update the running sum and sum of squares.
1588 * @param val The value to add.
1589 * @param number The number of times to add the value.
1590 * @param p The paramters of the distribution.
1592 void sample(Counter val, int number, const Params &p)
1594 Counter value = val * number;
1596 squares += value * value;
1599 void update(DistDataData *data, const Params ¶ms)
1602 data->squares = squares;
1603 data->samples = curTick;
1607 * Return the number of entries, in this case 1.
1610 size_t size(const Params ¶ms) const { return 1; }
1612 * Return true if no samples have been added.
1613 * @return True if the sum is zero.
1615 bool zero(const Params ¶ms) const { return sum == Counter(); }
1617 * Reset stat value to default
1622 squares = Counter();
1627 * Implementation of a distribution stat. The type of distribution is
1628 * determined by the Storage template. @sa ScalarBase
1630 template <class Stor>
1631 class DistBase : public DataAccess
1634 typedef Stor Storage;
1635 /** Define the params of the storage class. */
1636 typedef typename Storage::Params Params;
1639 /** The storage for this stat. */
1640 char storage[sizeof(Storage)];
1642 /** The parameters for this stat. */
1647 * Retrieve the storage.
1648 * @return The storage object for this stat.
1652 return reinterpret_cast<Storage *>(storage);
1656 * Retrieve a const pointer to the storage.
1657 * @return A const pointer to the storage object for this stat.
1662 return reinterpret_cast<const Storage *>(storage);
1668 new (storage) Storage(params);
1676 * Add a value to the distribtion n times. Calls sample on the storage
1678 * @param v The value to add.
1679 * @param n The number of times to add it, defaults to 1.
1681 template <typename U>
1682 void sample(const U &v, int n = 1) { data()->sample(v, n, params); }
1685 * Return the number of entries in this stat.
1686 * @return The number of entries.
1688 size_t size() const { return data()->size(params); }
1690 * Return true if no samples have been added.
1691 * @return True if there haven't been any samples.
1693 bool zero() const { return data()->zero(params); }
1695 void update(DistData *base)
1697 base->data.fancy = Storage::fancy;
1698 data()->update(&(base->data), params);
1702 * Reset stat value to default
1717 template <class Stat>
1720 template <class Stor>
1721 class VectorDistBase : public DataAccess
1724 typedef Stor Storage;
1725 typedef typename Storage::Params Params;
1726 typedef DistProxy<VectorDistBase<Storage> > Proxy;
1727 friend class DistProxy<VectorDistBase<Storage> >;
1738 return &storage[index];
1742 data(int index) const
1744 return &storage[index];
1750 assert(s > 0 && "size must be positive!");
1751 assert(!storage && "already initialized");
1754 char *ptr = new char[_size * sizeof(Storage)];
1755 storage = reinterpret_cast<Storage *>(ptr);
1757 for (int i = 0; i < _size; ++i)
1758 new (&storage[i]) Storage(params);
1773 for (int i = 0; i < _size; ++i)
1774 data(i)->~Storage();
1775 delete [] reinterpret_cast<char *>(storage);
1778 Proxy operator[](int index);
1791 for (int i = 0; i < size(); ++i)
1792 if (!data(i)->zero(params))
1799 * Reset stat value to default
1804 for (int i = 0; i < size(); ++i)
1811 return storage != NULL;
1815 update(VectorDistData *base)
1817 int size = this->size();
1818 base->data.resize(size);
1819 for (int i = 0; i < size; ++i) {
1820 base->data[i].fancy = Storage::fancy;
1821 data(i)->update(&(base->data[i]), params);
1826 template <class Stat>
1834 typename Stat::Storage *data() { return stat->data(index); }
1835 const typename Stat::Storage *data() const { return stat->data(index); }
1838 DistProxy(Stat *s, int i)
1842 DistProxy(const DistProxy &sp)
1843 : stat(sp.stat), index(sp.index)
1846 const DistProxy &operator=(const DistProxy &sp)
1854 template <typename U>
1856 sample(const U &v, int n = 1)
1858 data()->sample(v, n, stat->params);
1870 return data()->zero(stat->params);
1874 * Proxy has no state. Nothing to reset.
1879 template <class Storage>
1880 inline typename VectorDistBase<Storage>::Proxy
1881 VectorDistBase<Storage>::operator[](int index)
1883 assert (index >= 0 && index < size());
1884 return typename VectorDistBase<Storage>::Proxy(this, index);
1888 template <class Storage>
1890 VectorDistBase<Storage>::total(int index) const
1893 for (int i = 0; i < x_size(); ++i) {
1894 total += data(i)->result(stat->params);
1899 //////////////////////////////////////////////////////////////////////
1903 //////////////////////////////////////////////////////////////////////
1906 * Base class for formula statistic node. These nodes are used to build a tree
1907 * that represents the formula.
1909 class Node : public RefCounted
1913 * Return the number of nodes in the subtree starting at this node.
1914 * @return the number of nodes in this subtree.
1916 virtual size_t size() const = 0;
1918 * Return the result vector of this subtree.
1919 * @return The result vector of this subtree.
1921 virtual const VResult &result() const = 0;
1923 * Return the total of the result vector.
1924 * @return The total of the result vector.
1926 virtual Result total() const = 0;
1931 virtual std::string str() const = 0;
1934 /** Reference counting pointer to a function Node. */
1935 typedef RefCountingPtr<Node> NodePtr;
1937 class ScalarStatNode : public Node
1940 const ScalarData *data;
1941 mutable VResult vresult;
1944 ScalarStatNode(const ScalarData *d) : data(d), vresult(1) {}
1945 virtual const VResult &result() const
1947 vresult[0] = data->result();
1950 virtual Result total() const { return data->result(); };
1952 virtual size_t size() const { return 1; }
1957 virtual std::string str() const { return data->name; }
1960 template <class Stat>
1961 class ScalarProxyNode : public Node
1964 const ScalarProxy<Stat> proxy;
1965 mutable VResult vresult;
1968 ScalarProxyNode(const ScalarProxy<Stat> &p)
1969 : proxy(p), vresult(1)
1972 virtual const VResult &
1975 vresult[0] = proxy.result();
1982 return proxy.result();
2001 class VectorStatNode : public Node
2004 const VectorData *data;
2007 VectorStatNode(const VectorData *d) : data(d) { }
2008 virtual const VResult &result() const { return data->result(); }
2009 virtual Result total() const { return data->total(); };
2011 virtual size_t size() const { return data->size(); }
2013 virtual std::string str() const { return data->name; }
2017 class ConstNode : public Node
2023 ConstNode(T s) : vresult(1, (Result)s) {}
2024 const VResult &result() const { return vresult; }
2025 virtual Result total() const { return vresult[0]; };
2026 virtual size_t size() const { return 1; }
2027 virtual std::string str() const { return to_string(vresult[0]); }
2034 struct OpString<std::plus<Result> >
2036 static std::string str() { return "+"; }
2040 struct OpString<std::minus<Result> >
2042 static std::string str() { return "-"; }
2046 struct OpString<std::multiplies<Result> >
2048 static std::string str() { return "*"; }
2052 struct OpString<std::divides<Result> >
2054 static std::string str() { return "/"; }
2058 struct OpString<std::modulus<Result> >
2060 static std::string str() { return "%"; }
2064 struct OpString<std::negate<Result> >
2066 static std::string str() { return "-"; }
2070 class UnaryNode : public Node
2074 mutable VResult vresult;
2077 UnaryNode(NodePtr &p) : l(p) {}
2079 const VResult &result() const
2081 const VResult &lvec = l->result();
2082 int size = lvec.size();
2086 vresult.resize(size);
2088 for (int i = 0; i < size; ++i)
2089 vresult[i] = op(lvec[i]);
2094 Result total() const {
2096 return op(l->total());
2099 virtual size_t size() const { return l->size(); }
2101 virtual std::string str() const
2103 return OpString<Op>::str() + l->str();
2108 class BinaryNode : public Node
2113 mutable VResult vresult;
2116 BinaryNode(NodePtr &a, NodePtr &b) : l(a), r(b) {}
2118 const VResult &result() const
2121 const VResult &lvec = l->result();
2122 const VResult &rvec = r->result();
2124 assert(lvec.size() > 0 && rvec.size() > 0);
2126 if (lvec.size() == 1 && rvec.size() == 1) {
2128 vresult[0] = op(lvec[0], rvec[0]);
2129 } else if (lvec.size() == 1) {
2130 int size = rvec.size();
2131 vresult.resize(size);
2132 for (int i = 0; i < size; ++i)
2133 vresult[i] = op(lvec[0], rvec[i]);
2134 } else if (rvec.size() == 1) {
2135 int size = lvec.size();
2136 vresult.resize(size);
2137 for (int i = 0; i < size; ++i)
2138 vresult[i] = op(lvec[i], rvec[0]);
2139 } else if (rvec.size() == lvec.size()) {
2140 int size = rvec.size();
2141 vresult.resize(size);
2142 for (int i = 0; i < size; ++i)
2143 vresult[i] = op(lvec[i], rvec[i]);
2149 Result total() const {
2151 return op(l->total(), r->total());
2154 virtual size_t size() const {
2162 assert(ls == rs && "Node vector sizes are not equal");
2167 virtual std::string str() const
2169 return csprintf("(%s %s %s)", l->str(), OpString<Op>::str(), r->str());
2174 class SumNode : public Node
2178 mutable VResult vresult;
2181 SumNode(NodePtr &p) : l(p), vresult(1) {}
2183 const VResult &result() const
2185 const VResult &lvec = l->result();
2186 int size = lvec.size();
2192 for (int i = 0; i < size; ++i)
2193 vresult[0] = op(vresult[0], lvec[i]);
2198 Result total() const
2200 const VResult &lvec = l->result();
2201 int size = lvec.size();
2204 Result vresult = 0.0;
2207 for (int i = 0; i < size; ++i)
2208 vresult = op(vresult, lvec[i]);
2213 virtual size_t size() const { return 1; }
2215 virtual std::string str() const
2217 return csprintf("total(%s)", l->str());
2222 //////////////////////////////////////////////////////////////////////
2224 // Visible Statistics Types
2226 //////////////////////////////////////////////////////////////////////
2228 * @defgroup VisibleStats "Statistic Types"
2229 * These are the statistics that are used in the simulator.
2234 * This is a simple scalar statistic, like a counter.
2235 * @sa Stat, ScalarBase, StatStor
2238 class Scalar : public Wrap<Scalar<N>, ScalarBase<StatStor>, ScalarStatData>
2241 /** The base implementation. */
2242 typedef ScalarBase<StatStor> Base;
2250 * Sets the stat equal to the given value. Calls the base implementation
2252 * @param v The new value.
2254 template <typename U>
2255 void operator=(const U &v) { Base::operator=(v); }
2258 class Value : public Wrap<Value, ValueBase, ScalarStatData>
2261 /** The base implementation. */
2262 typedef ValueBase Base;
2265 Value &scalar(T &value)
2267 Base::scalar(value);
2272 Value &functor(T &func)
2274 Base::functor(func);
2280 * A stat that calculates the per cycle average of a value.
2281 * @sa Stat, ScalarBase, AvgStor
2284 class Average : public Wrap<Average<N>, ScalarBase<AvgStor>, ScalarStatData>
2287 /** The base implementation. */
2288 typedef ScalarBase<AvgStor> Base;
2296 * Sets the stat equal to the given value. Calls the base implementation
2298 * @param v The new value.
2300 template <typename U>
2301 void operator=(const U &v) { Base::operator=(v); }
2305 * A vector of scalar stats.
2306 * @sa Stat, VectorBase, StatStor
2309 class Vector : public WrapVec<Vector<N>, VectorBase<StatStor>, VectorStatData>
2312 /** The base implementation. */
2313 typedef ScalarBase<StatStor> Base;
2316 * Set this vector to have the given size.
2317 * @param size The new size.
2318 * @return A reference to this stat.
2320 Vector &init(size_t size) {
2327 * A vector of Average stats.
2328 * @sa Stat, VectorBase, AvgStor
2332 : public WrapVec<AverageVector<N>, VectorBase<AvgStor>, VectorStatData>
2336 * Set this vector to have the given size.
2337 * @param size The new size.
2338 * @return A reference to this stat.
2340 AverageVector &init(size_t size) {
2347 * A 2-Dimensional vecto of scalar stats.
2348 * @sa Stat, Vector2dBase, StatStor
2352 : public WrapVec2d<Vector2d<N>, Vector2dBase<StatStor>, Vector2dStatData>
2355 Vector2d &init(size_t x, size_t y) {
2362 * A simple distribution stat.
2363 * @sa Stat, DistBase, DistStor
2367 : public Wrap<Distribution<N>, DistBase<DistStor>, DistStatData>
2370 /** Base implementation. */
2371 typedef DistBase<DistStor> Base;
2372 /** The Parameter type. */
2373 typedef DistStor::Params Params;
2377 * Set the parameters of this distribution. @sa DistStor::Params
2378 * @param min The minimum value of the distribution.
2379 * @param max The maximum value of the distribution.
2380 * @param bkt The number of values in each bucket.
2381 * @return A reference to this distribution.
2383 Distribution &init(Counter min, Counter max, Counter bkt) {
2384 this->params.min = min;
2385 this->params.max = max;
2386 this->params.bucket_size = bkt;
2387 this->params.size = (int)rint((max - min) / bkt + 1.0);
2394 * Calculates the mean and variance of all the samples.
2395 * @sa Stat, DistBase, FancyStor
2398 class StandardDeviation
2399 : public Wrap<StandardDeviation<N>, DistBase<FancyStor>, DistStatData>
2402 /** The base implementation */
2403 typedef DistBase<DistStor> Base;
2404 /** The parameter type. */
2405 typedef DistStor::Params Params;
2409 * Construct and initialize this distribution.
2411 StandardDeviation() {
2417 * Calculates the per cycle mean and variance of the samples.
2418 * @sa Stat, DistBase, AvgFancy
2421 class AverageDeviation
2422 : public Wrap<AverageDeviation<N>, DistBase<AvgFancy>, DistStatData>
2425 /** The base implementation */
2426 typedef DistBase<DistStor> Base;
2427 /** The parameter type. */
2428 typedef DistStor::Params Params;
2432 * Construct and initialize this distribution.
2441 * A vector of distributions.
2442 * @sa Stat, VectorDistBase, DistStor
2445 class VectorDistribution
2446 : public WrapVec<VectorDistribution<N>,
2447 VectorDistBase<DistStor>,
2451 /** The base implementation */
2452 typedef VectorDistBase<DistStor> Base;
2453 /** The parameter type. */
2454 typedef DistStor::Params Params;
2458 * Initialize storage and parameters for this distribution.
2459 * @param size The size of the vector (the number of distributions).
2460 * @param min The minimum value of the distribution.
2461 * @param max The maximum value of the distribution.
2462 * @param bkt The number of values in each bucket.
2463 * @return A reference to this distribution.
2465 VectorDistribution &init(int size, Counter min, Counter max, Counter bkt) {
2466 this->params.min = min;
2467 this->params.max = max;
2468 this->params.bucket_size = bkt;
2469 this->params.size = (int)rint((max - min) / bkt + 1.0);
2476 * This is a vector of StandardDeviation stats.
2477 * @sa Stat, VectorDistBase, FancyStor
2480 class VectorStandardDeviation
2481 : public WrapVec<VectorStandardDeviation<N>,
2482 VectorDistBase<FancyStor>,
2486 /** The base implementation */
2487 typedef VectorDistBase<FancyStor> Base;
2488 /** The parameter type. */
2489 typedef DistStor::Params Params;
2493 * Initialize storage for this distribution.
2494 * @param size The size of the vector.
2495 * @return A reference to this distribution.
2497 VectorStandardDeviation &init(int size) {
2504 * This is a vector of AverageDeviation stats.
2505 * @sa Stat, VectorDistBase, AvgFancy
2508 class VectorAverageDeviation
2509 : public WrapVec<VectorAverageDeviation<N>,
2510 VectorDistBase<AvgFancy>,
2514 /** The base implementation */
2515 typedef VectorDistBase<AvgFancy> Base;
2516 /** The parameter type. */
2517 typedef DistStor::Params Params;
2521 * Initialize storage for this distribution.
2522 * @param size The size of the vector.
2523 * @return A reference to this distribution.
2525 VectorAverageDeviation &init(int size) {
2532 * A formula for statistics that is calculated when printed. A formula is
2533 * stored as a tree of Nodes that represent the equation to calculate.
2534 * @sa Stat, ScalarStat, VectorStat, Node, Temp
2536 class FormulaBase : public DataAccess
2539 /** The root of the tree which represents the Formula */
2545 * Return the result of the Fomula in a vector. If there were no Vector
2546 * components to the Formula, then the vector is size 1. If there were,
2547 * like x/y with x being a vector of size 3, then the result returned will
2548 * be x[0]/y, x[1]/y, x[2]/y, respectively.
2549 * @return The result vector.
2551 void result(VResult &vec) const;
2554 * Return the total Formula result. If there is a Vector
2555 * component to this Formula, then this is the result of the
2556 * Formula if the formula is applied after summing all the
2557 * components of the Vector. For example, if Formula is x/y where
2558 * x is size 3, then total() will return (x[1]+x[2]+x[3])/y. If
2559 * there is no Vector component, total() returns the same value as
2560 * the first entry in the VResult val() returns.
2561 * @return The total of the result vector.
2563 Result total() const;
2566 * Return the number of elements in the tree.
2568 size_t size() const;
2570 bool check() const { return true; }
2573 * Formulas don't need to be reset
2585 void update(StatData *);
2587 std::string str() const;
2590 class FormulaData : public VectorData
2593 virtual std::string str() const = 0;
2594 virtual bool check() const { return true; }
2597 template <class Stat>
2598 class FormulaStatData : public FormulaData
2602 mutable VResult vec;
2603 mutable VCounter cvec;
2606 FormulaStatData(Stat &stat) : s(stat) {}
2608 virtual bool zero() const { return s.zero(); }
2609 virtual void reset() { s.reset(); }
2611 virtual size_t size() const { return s.size(); }
2612 virtual const VResult &result() const
2617 virtual Result total() const { return s.total(); }
2618 virtual VCounter &value() const { return cvec; }
2619 virtual void visit(Visit &visitor)
2623 visitor.visit(*this);
2625 virtual std::string str() const { return s.str(); }
2630 : public WrapVec<Formula,
2636 * Create and initialize thie formula, and register it with the database.
2641 * Create a formula with the given root node, register it with the
2643 * @param r The root of the expression tree.
2648 * Set an unitialized Formula to the given root.
2649 * @param r The root of the expression tree.
2650 * @return a reference to this formula.
2652 const Formula &operator=(Temp r);
2655 * Add the given tree to the existing one.
2656 * @param r The root of the expression tree.
2657 * @return a reference to this formula.
2659 const Formula &operator+=(Temp r);
2662 class FormulaNode : public Node
2665 const Formula &formula;
2666 mutable VResult vec;
2669 FormulaNode(const Formula &f) : formula(f) {}
2671 virtual size_t size() const { return formula.size(); }
2672 virtual const VResult &result() const { formula.result(vec); return vec; }
2673 virtual Result total() const { return formula.total(); }
2675 virtual std::string str() const { return formula.str(); }
2679 * Helper class to construct formula node trees.
2685 * Pointer to a Node object.
2691 * Copy the given pointer to this class.
2692 * @param n A pointer to a Node object to copy.
2694 Temp(NodePtr n) : node(n) { }
2697 * Return the node pointer.
2698 * @return the node pointer.
2700 operator NodePtr&() { return node;}
2704 * Create a new ScalarStatNode.
2705 * @param s The ScalarStat to place in a node.
2708 Temp(const Scalar<N> &s)
2709 : node(new ScalarStatNode(s.statData())) { }
2712 * Create a new ScalarStatNode.
2713 * @param s The ScalarStat to place in a node.
2715 Temp(const Value &s)
2716 : node(new ScalarStatNode(s.statData())) { }
2719 * Create a new ScalarStatNode.
2720 * @param s The ScalarStat to place in a node.
2723 Temp(const Average<N> &s)
2724 : node(new ScalarStatNode(s.statData())) { }
2727 * Create a new VectorStatNode.
2728 * @param s The VectorStat to place in a node.
2731 Temp(const Vector<N> &s)
2732 : node(new VectorStatNode(s.statData())) { }
2737 Temp(const Formula &f)
2738 : node(new FormulaNode(f)) { }
2741 * Create a new ScalarProxyNode.
2742 * @param p The ScalarProxy to place in a node.
2744 template <class Stat>
2745 Temp(const ScalarProxy<Stat> &p)
2746 : node(new ScalarProxyNode<Stat>(p)) { }
2749 * Create a ConstNode
2750 * @param value The value of the const node.
2752 Temp(signed char value)
2753 : node(new ConstNode<signed char>(value)) {}
2756 * Create a ConstNode
2757 * @param value The value of the const node.
2759 Temp(unsigned char value)
2760 : node(new ConstNode<unsigned char>(value)) {}
2763 * Create a ConstNode
2764 * @param value The value of the const node.
2766 Temp(signed short value)
2767 : node(new ConstNode<signed short>(value)) {}
2770 * Create a ConstNode
2771 * @param value The value of the const node.
2773 Temp(unsigned short value)
2774 : node(new ConstNode<unsigned short>(value)) {}
2777 * Create a ConstNode
2778 * @param value The value of the const node.
2780 Temp(signed int value)
2781 : node(new ConstNode<signed int>(value)) {}
2784 * Create a ConstNode
2785 * @param value The value of the const node.
2787 Temp(unsigned int value)
2788 : node(new ConstNode<unsigned int>(value)) {}
2791 * Create a ConstNode
2792 * @param value The value of the const node.
2794 Temp(signed long value)
2795 : node(new ConstNode<signed long>(value)) {}
2798 * Create a ConstNode
2799 * @param value The value of the const node.
2801 Temp(unsigned long value)
2802 : node(new ConstNode<unsigned long>(value)) {}
2805 * Create a ConstNode
2806 * @param value The value of the const node.
2808 Temp(signed long long value)
2809 : node(new ConstNode<signed long long>(value)) {}
2812 * Create a ConstNode
2813 * @param value The value of the const node.
2815 Temp(unsigned long long value)
2816 : node(new ConstNode<unsigned long long>(value)) {}
2819 * Create a ConstNode
2820 * @param value The value of the const node.
2823 : node(new ConstNode<float>(value)) {}
2826 * Create a ConstNode
2827 * @param value The value of the const node.
2830 : node(new ConstNode<double>(value)) {}
2840 void registerResetCallback(Callback *cb);
2843 operator+(Temp l, Temp r)
2845 return NodePtr(new BinaryNode<std::plus<Result> >(l, r));
2849 operator-(Temp l, Temp r)
2851 return NodePtr(new BinaryNode<std::minus<Result> >(l, r));
2855 operator*(Temp l, Temp r)
2857 return NodePtr(new BinaryNode<std::multiplies<Result> >(l, r));
2861 operator/(Temp l, Temp r)
2863 return NodePtr(new BinaryNode<std::divides<Result> >(l, r));
2869 return NodePtr(new UnaryNode<std::negate<Result> >(l));
2872 template <typename T>
2876 return NodePtr(new ConstNode<T>(val));
2882 return NodePtr(new SumNode<std::plus<Result> >(val));
2885 /* namespace Stats */ }
2887 #endif // __BASE_STATISTICS_HH__