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__
63 #include "base/cprintf.hh"
64 #include "base/intmath.hh"
65 #include "base/refcnt.hh"
66 #include "base/str.hh"
67 #include "base/stats/flags.hh"
68 #include "base/stats/visit.hh"
69 #include "base/stats/types.hh"
70 #include "sim/host.hh"
74 /** The current simulated tick. */
77 /* A namespace for all of the Statistics */
80 typedef std::numeric_limits<Counter> CounterLimits;
82 /* Contains the statistic implementation details */
83 //////////////////////////////////////////////////////////////////////
85 // Statistics Framework Base classes
87 //////////////////////////////////////////////////////////////////////
90 /** The name of the stat. */
92 /** The description of the stat. */
94 /** The formatting flags. */
96 /** The display precision. */
98 /** A pointer to a prerequisite Stat. */
99 const StatData *prereq;
101 * A unique stat ID for each stat in the simulator.
102 * Can be used externally for lookups as well as for debugging.
110 * Reset the corresponding stat to the default state.
112 virtual void reset() = 0;
115 * @return true if this stat has a value and satisfies its
116 * requirement as a prereq
118 virtual bool zero() const = 0;
121 * Check that this stat has been set up properly and is ready for
123 * @return true for success
125 virtual bool check() const = 0;
126 bool baseCheck() const;
129 * Visitor entry for outputing statistics data
131 virtual void visit(Visit &visitor) = 0;
134 * Checks if the first stat's name is alphabetically less than the second.
135 * This function breaks names up at periods and considers each subname
137 * @param stat1 The first stat.
138 * @param stat2 The second stat.
139 * @return stat1's name is alphabetically before stat2's
141 static bool less(StatData *stat1, StatData *stat2);
144 class ScalarData : public StatData
147 virtual Counter value() const = 0;
148 virtual Result result() const = 0;
149 virtual Result total() const = 0;
150 virtual void visit(Visit &visitor) { visitor.visit(*this); }
153 template <class Stat>
154 class ScalarStatData : public ScalarData
160 ScalarStatData(Stat &stat) : s(stat) {}
162 virtual bool check() const { return s.check(); }
163 virtual Counter value() const { return s.value(); }
164 virtual Result result() const { return s.result(); }
165 virtual Result total() const { return s.total(); }
166 virtual void reset() { s.reset(); }
167 virtual bool zero() const { return s.zero(); }
170 struct VectorData : public StatData
172 /** Names and descriptions of subfields. */
173 mutable std::vector<std::string> subnames;
174 mutable std::vector<std::string> subdescs;
176 virtual size_type size() const = 0;
177 virtual const VCounter &value() const = 0;
178 virtual const VResult &result() const = 0;
179 virtual Result total() const = 0;
184 if (!subnames.empty()) {
185 size_type s = size();
186 if (subnames.size() < s)
189 if (subdescs.size() < s)
195 template <class Stat>
196 class VectorStatData : public VectorData
200 mutable VCounter cvec;
201 mutable VResult rvec;
204 VectorStatData(Stat &stat) : s(stat) {}
206 virtual bool check() const { return s.check(); }
207 virtual bool zero() const { return s.zero(); }
208 virtual void reset() { s.reset(); }
210 virtual size_type size() const { return s.size(); }
219 virtual const VResult &
226 virtual Result total() const { return s.total(); }
229 visit(Visit &visitor)
233 visitor.visit(*this);
255 struct DistData : public StatData
257 /** Local storage for the entry values, used for printing. */
261 template <class Stat>
262 class DistStatData : public DistData
268 DistStatData(Stat &stat) : s(stat) {}
270 virtual bool check() const { return s.check(); }
271 virtual void reset() { s.reset(); }
272 virtual bool zero() const { return s.zero(); }
275 visit(Visit &visitor)
278 visitor.visit(*this);
282 struct VectorDistData : public StatData
284 std::vector<DistDataData> data;
286 /** Names and descriptions of subfields. */
287 mutable std::vector<std::string> subnames;
288 mutable std::vector<std::string> subdescs;
290 /** Local storage for the entry values, used for printing. */
291 mutable VResult rvec;
293 virtual size_type size() const = 0;
298 size_type s = size();
299 if (subnames.size() < s)
302 if (subdescs.size() < s)
307 template <class Stat>
308 class VectorDistStatData : public VectorDistData
314 VectorDistStatData(Stat &stat) : s(stat) {}
316 virtual bool check() const { return s.check(); }
317 virtual void reset() { s.reset(); }
318 virtual size_type size() const { return s.size(); }
319 virtual bool zero() const { return s.zero(); }
322 visit(Visit &visitor)
326 visitor.visit(*this);
330 struct Vector2dData : public StatData
332 /** Names and descriptions of subfields. */
333 std::vector<std::string> subnames;
334 std::vector<std::string> subdescs;
335 std::vector<std::string> y_subnames;
337 /** Local storage for the entry values, used for printing. */
338 mutable VCounter cvec;
345 if (subnames.size() < x)
350 template <class Stat>
351 class Vector2dStatData : public Vector2dData
357 Vector2dStatData(Stat &stat) : s(stat) {}
359 virtual bool check() const { return s.check(); }
360 virtual void reset() { s.reset(); }
361 virtual bool zero() const { return s.zero(); }
364 visit(Visit &visitor)
368 visitor.visit(*this);
375 StatData *find() const;
376 void map(StatData *data);
378 StatData *statData();
379 const StatData *statData() const;
385 template <class Parent, class Child, template <class> class Data>
386 class Wrap : public Child
389 Parent &self() { return *reinterpret_cast<Parent *>(this); }
395 StatData *__data = DataAccess::statData();
396 Data<Child> *ptr = dynamic_cast<Data<Child> *>(__data);
405 const StatData *__data = DataAccess::statData();
406 const Data<Child> *ptr = dynamic_cast<const Data<Child> *>(__data);
413 * Copy constructor, copies are not allowed.
415 Wrap(const Wrap &stat);
420 void operator=(const Wrap &);
425 this->map(new Data<Child>(*this));
429 * Set the name and marks this stat to print at the end of simulation.
430 * @param name The new name.
431 * @return A reference to this stat.
434 name(const std::string &_name)
436 Data<Child> *data = this->statData();
443 * Set the description and marks this stat to print at the end of
445 * @param desc The new description.
446 * @return A reference to this stat.
449 desc(const std::string &_desc)
451 this->statData()->desc = _desc;
456 * Set the precision and marks this stat to print at the end of simulation.
457 * @param p The new precision
458 * @return A reference to this stat.
461 precision(int _precision)
463 this->statData()->precision = _precision;
468 * Set the flags and marks this stat to print at the end of simulation.
469 * @param f The new flags.
470 * @return A reference to this stat.
473 flags(StatFlags _flags)
475 this->statData()->flags |= _flags;
480 * Set the prerequisite stat and marks this stat to print at the end of
482 * @param prereq The prerequisite stat.
483 * @return A reference to this stat.
485 template <class Stat>
487 prereq(const Stat &prereq)
489 this->statData()->prereq = prereq.statData();
494 template <class Parent, class Child, template <class Child> class Data>
495 class WrapVec : public Wrap<Parent, Child, Data>
498 // The following functions are specific to vectors. If you use them
499 // in a non vector context, you will get a nice compiler error!
502 * Set the subfield name for the given index, and marks this stat to print
503 * at the end of simulation.
504 * @param index The subfield index.
505 * @param name The new name of the subfield.
506 * @return A reference to this stat.
509 subname(off_type index, const std::string &name)
511 std::vector<std::string> &subn = this->statData()->subnames;
512 if (subn.size() <= index)
513 subn.resize(index + 1);
519 * Set the subfield description for the given index and marks this stat to
520 * print at the end of simulation.
521 * @param index The subfield index.
522 * @param desc The new description of the subfield
523 * @return A reference to this stat.
526 subdesc(off_type index, const std::string &desc)
528 std::vector<std::string> &subd = this->statData()->subdescs;
529 if (subd.size() <= index)
530 subd.resize(index + 1);
538 template <class Parent, class Child, template <class Child> class Data>
539 class WrapVec2d : public WrapVec<Parent, Child, Data>
543 * @warning This makes the assumption that if you're gonna subnames a 2d
544 * vector, you're subnaming across all y
547 ysubnames(const char **names)
549 Data<Child> *data = this->statData();
550 data->y_subnames.resize(this->y);
551 for (off_type i = 0; i < this->y; ++i)
552 data->y_subnames[i] = names[i];
557 ysubname(off_type index, const std::string subname)
559 Data<Child> *data = this->statData();
560 assert(index < this->y);
561 data->y_subnames.resize(this->y);
562 data->y_subnames[index] = subname.c_str();
567 //////////////////////////////////////////////////////////////////////
571 //////////////////////////////////////////////////////////////////////
574 * Templatized storage and interface for a simple scalar stat.
579 /** The paramaters for this storage type, none for a scalar. */
583 /** The statistic value. */
588 * Builds this storage element and calls the base constructor of the
591 StatStor(const Params &) : data(Counter()) {}
594 * The the stat to the given value.
595 * @param val The new value.
596 * @param p The paramters of this storage type.
598 void set(Counter val, const Params &p) { data = val; }
600 * Increment the stat by the given value.
601 * @param val The new value.
602 * @param p The paramters of this storage type.
604 void inc(Counter val, const Params &p) { data += val; }
606 * Decrement the stat by the given value.
607 * @param val The new value.
608 * @param p The paramters of this storage type.
610 void dec(Counter val, const Params &p) { data -= val; }
612 * Return the value of this stat as its base type.
613 * @param p The params of this storage type.
614 * @return The value of this stat.
616 Counter value(const Params &p) const { return data; }
618 * Return the value of this stat as a result type.
619 * @param p The parameters of this storage type.
620 * @return The value of this stat.
622 Result result(const Params &p) const { return (Result)data; }
624 * Reset stat value to default
626 void reset() { data = Counter(); }
629 * @return true if zero value
631 bool zero() const { return data == Counter(); }
635 * Templatized storage and interface to a per-tick average stat. This keeps
636 * a current count and updates a total (count * ticks) when this count
637 * changes. This allows the quick calculation of a per tick count of the item
638 * being watched. This is good for keeping track of residencies in structures
639 * among other things.
644 /** The paramaters for this storage type */
648 /** The current count. */
650 /** The total count for all tick. */
651 mutable Result total;
652 /** The tick that current last changed. */
657 * Build and initializes this stat storage.
659 AvgStor(Params &p) : current(0), total(0), last(0) { }
662 * Set the current count to the one provided, update the total and last
664 * @param val The new count.
665 * @param p The parameters for this storage.
668 set(Counter val, Params &p) {
669 total += current * (curTick - last);
675 * Increment the current count by the provided value, calls set.
676 * @param val The amount to increment.
677 * @param p The parameters for this storage.
679 void inc(Counter val, Params &p) { set(current + val, p); }
682 * Deccrement the current count by the provided value, calls set.
683 * @param val The amount to decrement.
684 * @param p The parameters for this storage.
686 void dec(Counter val, Params &p) { set(current - val, p); }
689 * Return the current count.
690 * @param p The parameters for this storage.
691 * @return The current count.
693 Counter value(const Params &p) const { return current; }
696 * Return the current average.
697 * @param p The parameters for this storage.
698 * @return The current average.
701 result(const Params &p) const
703 total += current * (curTick - last);
705 return (Result)(total + current) / (Result)(curTick + 1);
709 * Reset stat value to default
719 * @return true if zero value
721 bool zero() const { return total == 0.0; }
725 * Implementation of a scalar stat. The type of stat is determined by the
728 template <class Stor>
729 class ScalarBase : public DataAccess
732 typedef Stor Storage;
734 /** Define the params of the storage class. */
735 typedef typename Storage::Params Params;
738 /** The storage of this stat. */
739 char storage[sizeof(Storage)] __attribute__ ((aligned (8)));
741 /** The parameters for this stat. */
746 * Retrieve the storage.
747 * @param index The vector index to access.
748 * @return The storage object at the given index.
753 return reinterpret_cast<Storage *>(storage);
757 * Retrieve a const pointer to the storage.
758 * for the given index.
759 * @param index The vector index to access.
760 * @return A const pointer to the storage object at the given index.
765 return reinterpret_cast<const Storage *>(storage);
771 new (storage) Storage(params);
777 * Return the current value of this stat as its base type.
778 * @return The current value.
780 Counter value() const { return data()->value(params); }
784 * Create and initialize this stat, register it with the database.
790 // Common operators for stats
792 * Increment the stat by 1. This calls the associated storage object inc
795 void operator++() { data()->inc(1, params); }
797 * Decrement the stat by 1. This calls the associated storage object dec
800 void operator--() { data()->dec(1, params); }
802 /** Increment the stat by 1. */
803 void operator++(int) { ++*this; }
804 /** Decrement the stat by 1. */
805 void operator--(int) { --*this; }
808 * Set the data value to the given value. This calls the associated storage
809 * object set function.
810 * @param v The new value.
812 template <typename U>
813 void operator=(const U &v) { data()->set(v, params); }
816 * Increment the stat by the given value. This calls the associated
817 * storage object inc function.
818 * @param v The value to add.
820 template <typename U>
821 void operator+=(const U &v) { data()->inc(v, params); }
824 * Decrement the stat by the given value. This calls the associated
825 * storage object dec function.
826 * @param v The value to substract.
828 template <typename U>
829 void operator-=(const U &v) { data()->dec(v, params); }
832 * Return the number of elements, always 1 for a scalar.
835 size_type size() const { return 1; }
837 bool check() const { return true; }
840 * Reset stat value to default
842 void reset() { data()->reset(); }
844 Counter value() { return data()->value(params); }
846 Result result() { return data()->result(params); }
848 Result total() { return result(); }
850 bool zero() { return result() == 0.0; }
854 class ProxyData : public ScalarData
857 virtual void visit(Visit &visitor) { visitor.visit(*this); }
858 virtual std::string str() const { return to_string(value()); }
859 virtual size_type size() const { return 1; }
860 virtual bool zero() const { return value() == 0; }
861 virtual bool check() const { return true; }
862 virtual void reset() { }
866 class ValueProxy : public ProxyData
872 ValueProxy(T &val) : scalar(&val) {}
873 virtual Counter value() const { return *scalar; }
874 virtual Result result() const { return *scalar; }
875 virtual Result total() const { return *scalar; }
879 class FunctorProxy : public ProxyData
885 FunctorProxy(T &func) : functor(&func) {}
886 virtual Counter value() const { return (*functor)(); }
887 virtual Result result() const { return (*functor)(); }
888 virtual Result total() const { return (*functor)(); }
891 class ValueBase : public DataAccess
897 ValueBase() : proxy(NULL) { }
898 ~ValueBase() { if (proxy) delete proxy; }
904 proxy = new ValueProxy<T>(value);
912 proxy = new FunctorProxy<T>(func);
916 Counter value() { return proxy->value(); }
917 Result result() const { return proxy->result(); }
918 Result total() const { return proxy->total(); };
919 size_type size() const { return proxy->size(); }
921 std::string str() const { return proxy->str(); }
922 bool zero() const { return proxy->zero(); }
923 bool check() const { return proxy != NULL; }
927 //////////////////////////////////////////////////////////////////////
931 //////////////////////////////////////////////////////////////////////
934 * A proxy class to access the stat at a given index in a VectorBase stat.
935 * Behaves like a ScalarBase.
937 template <class Stat>
941 /** Pointer to the parent Vector. */
944 /** The index to access in the parent VectorBase. */
949 * Return the current value of this stat as its base type.
950 * @return The current value.
952 Counter value() const { return stat->data(index)->value(stat->params); }
955 * Return the current value of this statas a result type.
956 * @return The current value.
958 Result result() const { return stat->data(index)->result(stat->params); }
962 * Create and initialize this proxy, do not register it with the database.
963 * @param p The params to use.
964 * @param i The index to access.
966 ScalarProxy(Stat *s, off_type i)
973 * Create a copy of the provided ScalarProxy.
974 * @param sp The proxy to copy.
976 ScalarProxy(const ScalarProxy &sp)
977 : stat(sp.stat), index(sp.index)
981 * Set this proxy equal to the provided one.
982 * @param sp The proxy to copy.
983 * @return A reference to this proxy.
986 operator=(const ScalarProxy &sp) {
993 // Common operators for stats
995 * Increment the stat by 1. This calls the associated storage object inc
998 void operator++() { stat->data(index)->inc(1, stat->params); }
1000 * Decrement the stat by 1. This calls the associated storage object dec
1003 void operator--() { stat->data(index)->dec(1, stat->params); }
1005 /** Increment the stat by 1. */
1006 void operator++(int) { ++*this; }
1007 /** Decrement the stat by 1. */
1008 void operator--(int) { --*this; }
1011 * Set the data value to the given value. This calls the associated storage
1012 * object set function.
1013 * @param v The new value.
1015 template <typename U>
1017 operator=(const U &v)
1019 stat->data(index)->set(v, stat->params);
1023 * Increment the stat by the given value. This calls the associated
1024 * storage object inc function.
1025 * @param v The value to add.
1027 template <typename U>
1029 operator+=(const U &v)
1031 stat->data(index)->inc(v, stat->params);
1035 * Decrement the stat by the given value. This calls the associated
1036 * storage object dec function.
1037 * @param v The value to substract.
1039 template <typename U>
1041 operator-=(const U &v)
1043 stat->data(index)->dec(v, stat->params);
1047 * Return the number of elements, always 1 for a scalar.
1050 size_type size() const { return 1; }
1053 * This stat has no state. Nothing to reset
1061 return csprintf("%s[%d]", stat->statData()->name, index);
1066 * Implementation of a vector of stats. The type of stat is determined by the
1067 * Storage class. @sa ScalarBase
1069 template <class Stor>
1070 class VectorBase : public DataAccess
1073 typedef Stor Storage;
1075 /** Define the params of the storage class. */
1076 typedef typename Storage::Params Params;
1079 typedef ScalarProxy<VectorBase<Storage> > Proxy;
1081 friend class ScalarProxy<VectorBase<Storage> >;
1084 /** The storage of this stat. */
1088 /** The parameters for this stat. */
1093 * Retrieve the storage.
1094 * @param index The vector index to access.
1095 * @return The storage object at the given index.
1097 Storage *data(off_type index) { return &storage[index]; }
1100 * Retrieve a const pointer to the storage.
1101 * @param index The vector index to access.
1102 * @return A const pointer to the storage object at the given index.
1104 const Storage *data(off_type index) const { return &storage[index]; }
1109 assert(s > 0 && "size must be positive!");
1110 assert(!storage && "already initialized");
1113 char *ptr = new char[_size * sizeof(Storage)];
1114 storage = reinterpret_cast<Storage *>(ptr);
1116 for (off_type i = 0; i < _size; ++i)
1117 new (&storage[i]) Storage(params);
1124 value(VCounter &vec) const
1127 for (off_type i = 0; i < size(); ++i)
1128 vec[i] = data(i)->value(params);
1132 * Copy the values to a local vector and return a reference to it.
1133 * @return A reference to a vector of the stat values.
1136 result(VResult &vec) const
1139 for (off_type i = 0; i < size(); ++i)
1140 vec[i] = data(i)->result(params);
1144 * Return a total of all entries in this vector.
1145 * @return The total of all vector entries.
1151 for (off_type i = 0; i < size(); ++i)
1152 total += data(i)->result(params);
1157 * @return the number of elements in this vector.
1159 size_type size() const { return _size; }
1164 for (off_type i = 0; i < size(); ++i)
1165 if (data(i)->zero())
1173 return storage != NULL;
1179 for (off_type i = 0; i < size(); ++i)
1193 for (off_type i = 0; i < _size; ++i)
1194 data(i)->~Storage();
1195 delete [] reinterpret_cast<char *>(storage);
1199 * Return a reference (ScalarProxy) to the stat at the given index.
1200 * @param index The vector index to access.
1201 * @return A reference of the stat.
1204 operator[](off_type index)
1206 assert (index >= 0 && index < size());
1207 return Proxy(this, index);
1210 void update(StatData *data) {}
1213 template <class Stat>
1222 mutable VResult vec;
1224 typename Stat::Storage *
1225 data(off_type index)
1227 assert(index < len);
1228 return stat->data(offset + index);
1231 const typename Stat::Storage *
1232 data(off_type index) const
1234 assert(index < len);
1235 return const_cast<Stat *>(stat)->data(offset + index);
1244 for (off_type i = 0; i < size(); ++i)
1245 vec[i] = data(i)->result(stat->params);
1254 for (off_type i = 0; i < size(); ++i)
1255 total += data(i)->result(stat->params);
1260 VectorProxy(Stat *s, off_type o, size_type l)
1261 : stat(s), offset(o), len(l)
1265 VectorProxy(const VectorProxy &sp)
1266 : stat(sp.stat), offset(sp.offset), len(sp.len)
1271 operator=(const VectorProxy &sp)
1280 operator[](off_type index)
1282 assert (index >= 0 && index < size());
1283 return ScalarProxy<Stat>(stat, offset + index);
1286 size_type size() const { return len; }
1289 * This stat has no state. Nothing to reset.
1294 template <class Stor>
1295 class Vector2dBase : public DataAccess
1298 typedef Stor Storage;
1299 typedef typename Storage::Params Params;
1300 typedef VectorProxy<Vector2dBase<Storage> > Proxy;
1301 friend class ScalarProxy<Vector2dBase<Storage> >;
1302 friend class VectorProxy<Vector2dBase<Storage> >;
1312 Storage *data(off_type index) { return &storage[index]; }
1313 const Storage *data(off_type index) const { return &storage[index]; }
1316 doInit(size_type _x, size_type _y)
1318 assert(_x > 0 && _y > 0 && "sizes must be positive!");
1319 assert(!storage && "already initialized");
1321 Vector2dData *statdata = dynamic_cast<Vector2dData *>(find());
1329 char *ptr = new char[_size * sizeof(Storage)];
1330 storage = reinterpret_cast<Storage *>(ptr);
1332 for (off_type i = 0; i < _size; ++i)
1333 new (&storage[i]) Storage(params);
1348 for (off_type i = 0; i < _size; ++i)
1349 data(i)->~Storage();
1350 delete [] reinterpret_cast<char *>(storage);
1354 update(Vector2dData *newdata)
1356 size_type size = this->size();
1357 newdata->cvec.resize(size);
1358 for (off_type i = 0; i < size; ++i)
1359 newdata->cvec[i] = data(i)->value(params);
1362 std::string ysubname(off_type i) const { return (*this->y_subnames)[i]; }
1365 operator[](off_type index)
1367 off_type offset = index * y;
1368 assert (index >= 0 && offset + index < size());
1369 return Proxy(this, offset, y);
1382 return data(0)->zero();
1384 for (off_type i = 0; i < size(); ++i)
1385 if (!data(i)->zero())
1392 * Reset stat value to default
1397 for (off_type i = 0; i < size(); ++i)
1404 return storage != NULL;
1408 //////////////////////////////////////////////////////////////////////
1410 // Non formula statistics
1412 //////////////////////////////////////////////////////////////////////
1415 * Templatized storage and interface for a distrbution stat.
1420 /** The parameters for a distribution stat. */
1423 /** The minimum value to track. */
1425 /** The maximum value to track. */
1427 /** The number of entries in each bucket. */
1428 Counter bucket_size;
1429 /** The number of buckets. Equal to (max-min)/bucket_size. */
1432 enum { fancy = false };
1435 /** The smallest value sampled. */
1437 /** The largest value sampled. */
1439 /** The number of values sampled less than min. */
1441 /** The number of values sampled more than max. */
1443 /** The current sum. */
1445 /** The sum of squares. */
1447 /** The number of samples. */
1449 /** Counter for each bucket. */
1453 DistStor(const Params ¶ms)
1460 * Add a value to the distribution for the given number of times.
1461 * @param val The value to add.
1462 * @param number The number of times to add the value.
1463 * @param params The paramters of the distribution.
1466 sample(Counter val, int number, const Params ¶ms)
1468 if (val < params.min)
1469 underflow += number;
1470 else if (val > params.max)
1474 (size_type)std::floor((val - params.min) / params.bucket_size);
1475 assert(index < size(params));
1476 cvec[index] += number;
1485 Counter sample = val * number;
1487 squares += sample * sample;
1492 * Return the number of buckets in this distribution.
1493 * @return the number of buckets.
1494 * @todo Is it faster to return the size from the parameters?
1496 size_type size(const Params &) const { return cvec.size(); }
1499 * Returns true if any calls to sample have been made.
1500 * @param params The paramters of the distribution.
1501 * @return True if any values have been sampled.
1504 zero(const Params ¶ms) const
1506 return samples == Counter();
1510 update(DistDataData *data, const Params ¶ms)
1512 data->min = params.min;
1513 data->max = params.max;
1514 data->bucket_size = params.bucket_size;
1515 data->size = params.size;
1517 data->min_val = (min_val == CounterLimits::max()) ? 0 : min_val;
1518 data->max_val = (max_val == CounterLimits::min()) ? 0 : max_val;
1519 data->underflow = underflow;
1520 data->overflow = overflow;
1521 data->cvec.resize(params.size);
1522 for (off_type i = 0; i < params.size; ++i)
1523 data->cvec[i] = cvec[i];
1526 data->squares = squares;
1527 data->samples = samples;
1531 * Reset stat value to default
1536 min_val = CounterLimits::max();
1537 max_val = CounterLimits::min();
1541 size_type size = cvec.size();
1542 for (off_type i = 0; i < size; ++i)
1543 cvec[i] = Counter();
1546 squares = Counter();
1547 samples = Counter();
1552 * Templatized storage and interface for a distribution that calculates mean
1559 * No paramters for this storage.
1562 enum { fancy = true };
1565 /** The current sum. */
1567 /** The sum of squares. */
1569 /** The number of samples. */
1574 * Create and initialize this storage.
1576 FancyStor(const Params &)
1577 : sum(Counter()), squares(Counter()), samples(Counter())
1581 * Add a value the given number of times to this running average.
1582 * Update the running sum and sum of squares, increment the number of
1583 * values seen by the given number.
1584 * @param val The value to add.
1585 * @param number The number of times to add the value.
1586 * @param p The parameters of this stat.
1589 sample(Counter val, int number, const Params &p)
1591 Counter value = val * number;
1593 squares += value * value;
1598 update(DistDataData *data, const Params ¶ms)
1601 data->squares = squares;
1602 data->samples = samples;
1606 * Return the number of entries in this stat, 1
1609 size_type size(const Params &) const { return 1; }
1612 * Return true if no samples have been added.
1613 * @return True if no samples have been added.
1615 bool zero(const Params &) const { return samples == Counter(); }
1618 * Reset stat value to default
1624 squares = Counter();
1625 samples = Counter();
1630 * Templatized storage for distribution that calculates per tick mean and
1636 /** No parameters for this storage. */
1638 enum { fancy = true };
1641 /** Current total. */
1643 /** Current sum of squares. */
1648 * Create and initialize this storage.
1650 AvgFancy(const Params &) : sum(Counter()), squares(Counter()) {}
1653 * Add a value to the distribution for the given number of times.
1654 * Update the running sum and sum of squares.
1655 * @param val The value to add.
1656 * @param number The number of times to add the value.
1657 * @param p The paramters of the distribution.
1660 sample(Counter val, int number, const Params &p)
1662 Counter value = val * number;
1664 squares += value * value;
1668 update(DistDataData *data, const Params ¶ms)
1671 data->squares = squares;
1672 data->samples = curTick;
1676 * Return the number of entries, in this case 1.
1679 size_type size(const Params ¶ms) const { return 1; }
1682 * Return true if no samples have been added.
1683 * @return True if the sum is zero.
1685 bool zero(const Params ¶ms) const { return sum == Counter(); }
1688 * Reset stat value to default
1694 squares = Counter();
1699 * Implementation of a distribution stat. The type of distribution is
1700 * determined by the Storage template. @sa ScalarBase
1702 template <class Stor>
1703 class DistBase : public DataAccess
1706 typedef Stor Storage;
1707 /** Define the params of the storage class. */
1708 typedef typename Storage::Params Params;
1711 /** The storage for this stat. */
1712 char storage[sizeof(Storage)] __attribute__ ((aligned (8)));
1714 /** The parameters for this stat. */
1719 * Retrieve the storage.
1720 * @return The storage object for this stat.
1725 return reinterpret_cast<Storage *>(storage);
1729 * Retrieve a const pointer to the storage.
1730 * @return A const pointer to the storage object for this stat.
1735 return reinterpret_cast<const Storage *>(storage);
1741 new (storage) Storage(params);
1749 * Add a value to the distribtion n times. Calls sample on the storage
1751 * @param v The value to add.
1752 * @param n The number of times to add it, defaults to 1.
1754 template <typename U>
1755 void sample(const U &v, int n = 1) { data()->sample(v, n, params); }
1758 * Return the number of entries in this stat.
1759 * @return The number of entries.
1761 size_type size() const { return data()->size(params); }
1763 * Return true if no samples have been added.
1764 * @return True if there haven't been any samples.
1766 bool zero() const { return data()->zero(params); }
1769 update(DistData *base)
1771 base->data.fancy = Storage::fancy;
1772 data()->update(&(base->data), params);
1776 * Reset stat value to default
1791 template <class Stat>
1794 template <class Stor>
1795 class VectorDistBase : public DataAccess
1798 typedef Stor Storage;
1799 typedef typename Storage::Params Params;
1800 typedef DistProxy<VectorDistBase<Storage> > Proxy;
1801 friend class DistProxy<VectorDistBase<Storage> >;
1810 data(off_type index)
1812 return &storage[index];
1816 data(off_type index) const
1818 return &storage[index];
1824 assert(s > 0 && "size must be positive!");
1825 assert(!storage && "already initialized");
1828 char *ptr = new char[_size * sizeof(Storage)];
1829 storage = reinterpret_cast<Storage *>(ptr);
1831 for (off_type i = 0; i < _size; ++i)
1832 new (&storage[i]) Storage(params);
1847 for (off_type i = 0; i < _size; ++i)
1848 data(i)->~Storage();
1849 delete [] reinterpret_cast<char *>(storage);
1852 Proxy operator[](off_type index);
1865 for (off_type i = 0; i < size(); ++i)
1866 if (!data(i)->zero(params))
1873 * Reset stat value to default
1878 for (off_type i = 0; i < size(); ++i)
1885 return storage != NULL;
1889 update(VectorDistData *base)
1891 size_type size = this->size();
1892 base->data.resize(size);
1893 for (off_type i = 0; i < size; ++i) {
1894 base->data[i].fancy = Storage::fancy;
1895 data(i)->update(&(base->data[i]), params);
1900 template <class Stat>
1908 typename Stat::Storage *data() { return stat->data(index); }
1909 const typename Stat::Storage *data() const { return stat->data(index); }
1912 DistProxy(Stat *s, off_type i)
1916 DistProxy(const DistProxy &sp)
1917 : stat(sp.stat), index(sp.index)
1921 operator=(const DistProxy &sp)
1929 template <typename U>
1931 sample(const U &v, int n = 1)
1933 data()->sample(v, n, stat->params);
1945 return data()->zero(stat->params);
1949 * Proxy has no state. Nothing to reset.
1954 template <class Storage>
1955 inline typename VectorDistBase<Storage>::Proxy
1956 VectorDistBase<Storage>::operator[](off_type index)
1958 assert (index >= 0 && index < size());
1959 return typename VectorDistBase<Storage>::Proxy(this, index);
1963 template <class Storage>
1965 VectorDistBase<Storage>::total(off_type index) const
1968 for (off_type i = 0; i < x_size(); ++i)
1969 total += data(i)->result(stat->params);
1973 //////////////////////////////////////////////////////////////////////
1977 //////////////////////////////////////////////////////////////////////
1980 * Base class for formula statistic node. These nodes are used to build a tree
1981 * that represents the formula.
1983 class Node : public RefCounted
1987 * Return the number of nodes in the subtree starting at this node.
1988 * @return the number of nodes in this subtree.
1990 virtual size_type size() const = 0;
1992 * Return the result vector of this subtree.
1993 * @return The result vector of this subtree.
1995 virtual const VResult &result() const = 0;
1997 * Return the total of the result vector.
1998 * @return The total of the result vector.
2000 virtual Result total() const = 0;
2005 virtual std::string str() const = 0;
2008 /** Reference counting pointer to a function Node. */
2009 typedef RefCountingPtr<Node> NodePtr;
2011 class ScalarStatNode : public Node
2014 const ScalarData *data;
2015 mutable VResult vresult;
2018 ScalarStatNode(const ScalarData *d) : data(d), vresult(1) {}
2020 virtual const VResult &
2023 vresult[0] = data->result();
2027 virtual Result total() const { return data->result(); };
2029 virtual size_type size() const { return 1; }
2034 virtual std::string str() const { return data->name; }
2037 template <class Stat>
2038 class ScalarProxyNode : public Node
2041 const ScalarProxy<Stat> proxy;
2042 mutable VResult vresult;
2045 ScalarProxyNode(const ScalarProxy<Stat> &p)
2046 : proxy(p), vresult(1)
2049 virtual const VResult &
2052 vresult[0] = proxy.result();
2059 return proxy.result();
2078 class VectorStatNode : public Node
2081 const VectorData *data;
2084 VectorStatNode(const VectorData *d) : data(d) { }
2085 virtual const VResult &result() const { return data->result(); }
2086 virtual Result total() const { return data->total(); };
2088 virtual size_type size() const { return data->size(); }
2090 virtual std::string str() const { return data->name; }
2094 class ConstNode : public Node
2100 ConstNode(T s) : vresult(1, (Result)s) {}
2101 const VResult &result() const { return vresult; }
2102 virtual Result total() const { return vresult[0]; };
2103 virtual size_type size() const { return 1; }
2104 virtual std::string str() const { return to_string(vresult[0]); }
2108 class ConstVectorNode : public Node
2114 ConstVectorNode(const T &s) : vresult(s.begin(), s.end()) {}
2115 const VResult &result() const { return vresult; }
2120 size_type size = this->size();
2122 for (off_type i = 0; i < size; i++)
2127 virtual size_type size() const { return vresult.size(); }
2131 size_type size = this->size();
2132 std::string tmp = "(";
2133 for (off_type i = 0; i < size; i++)
2134 tmp += csprintf("%s ",to_string(vresult[i]));
2144 struct OpString<std::plus<Result> >
2146 static std::string str() { return "+"; }
2150 struct OpString<std::minus<Result> >
2152 static std::string str() { return "-"; }
2156 struct OpString<std::multiplies<Result> >
2158 static std::string str() { return "*"; }
2162 struct OpString<std::divides<Result> >
2164 static std::string str() { return "/"; }
2168 struct OpString<std::modulus<Result> >
2170 static std::string str() { return "%"; }
2174 struct OpString<std::negate<Result> >
2176 static std::string str() { return "-"; }
2180 class UnaryNode : public Node
2184 mutable VResult vresult;
2187 UnaryNode(NodePtr &p) : l(p) {}
2192 const VResult &lvec = l->result();
2193 size_type size = lvec.size();
2197 vresult.resize(size);
2199 for (off_type i = 0; i < size; ++i)
2200 vresult[i] = op(lvec[i]);
2208 const VResult &vec = this->result();
2210 for (off_type i = 0; i < size(); i++)
2215 virtual size_type size() const { return l->size(); }
2220 return OpString<Op>::str() + l->str();
2225 class BinaryNode : public Node
2230 mutable VResult vresult;
2233 BinaryNode(NodePtr &a, NodePtr &b) : l(a), r(b) {}
2239 const VResult &lvec = l->result();
2240 const VResult &rvec = r->result();
2242 assert(lvec.size() > 0 && rvec.size() > 0);
2244 if (lvec.size() == 1 && rvec.size() == 1) {
2246 vresult[0] = op(lvec[0], rvec[0]);
2247 } else if (lvec.size() == 1) {
2248 size_type size = rvec.size();
2249 vresult.resize(size);
2250 for (off_type i = 0; i < size; ++i)
2251 vresult[i] = op(lvec[0], rvec[i]);
2252 } else if (rvec.size() == 1) {
2253 size_type size = lvec.size();
2254 vresult.resize(size);
2255 for (off_type i = 0; i < size; ++i)
2256 vresult[i] = op(lvec[i], rvec[0]);
2257 } else if (rvec.size() == lvec.size()) {
2258 size_type size = rvec.size();
2259 vresult.resize(size);
2260 for (off_type i = 0; i < size; ++i)
2261 vresult[i] = op(lvec[i], rvec[i]);
2270 const VResult &vec = this->result();
2272 for (off_type i = 0; i < size(); i++)
2280 size_type ls = l->size();
2281 size_type rs = r->size();
2284 } else if (rs == 1) {
2287 assert(ls == rs && "Node vector sizes are not equal");
2295 return csprintf("(%s %s %s)", l->str(), OpString<Op>::str(), r->str());
2300 class SumNode : public Node
2304 mutable VResult vresult;
2307 SumNode(NodePtr &p) : l(p), vresult(1) {}
2312 const VResult &lvec = l->result();
2313 size_type size = lvec.size();
2319 for (off_type i = 0; i < size; ++i)
2320 vresult[0] = op(vresult[0], lvec[i]);
2328 const VResult &lvec = l->result();
2329 size_type size = lvec.size();
2332 Result vresult = 0.0;
2335 for (off_type i = 0; i < size; ++i)
2336 vresult = op(vresult, lvec[i]);
2341 virtual size_type size() const { return 1; }
2346 return csprintf("total(%s)", l->str());
2351 //////////////////////////////////////////////////////////////////////
2353 // Visible Statistics Types
2355 //////////////////////////////////////////////////////////////////////
2357 * @defgroup VisibleStats "Statistic Types"
2358 * These are the statistics that are used in the simulator.
2363 * This is a simple scalar statistic, like a counter.
2364 * @sa Stat, ScalarBase, StatStor
2367 class Scalar : public Wrap<Scalar<N>, ScalarBase<StatStor>, ScalarStatData>
2370 /** The base implementation. */
2371 typedef ScalarBase<StatStor> Base;
2379 * Sets the stat equal to the given value. Calls the base implementation
2381 * @param v The new value.
2383 template <typename U>
2384 void operator=(const U &v) { Base::operator=(v); }
2387 class Value : public Wrap<Value, ValueBase, ScalarStatData>
2390 /** The base implementation. */
2391 typedef ValueBase Base;
2397 Base::scalar(value);
2405 Base::functor(func);
2411 * A stat that calculates the per tick average of a value.
2412 * @sa Stat, ScalarBase, AvgStor
2415 class Average : public Wrap<Average<N>, ScalarBase<AvgStor>, ScalarStatData>
2418 /** The base implementation. */
2419 typedef ScalarBase<AvgStor> Base;
2427 * Sets the stat equal to the given value. Calls the base implementation
2429 * @param v The new value.
2431 template <typename U>
2433 operator=(const U &v)
2440 * A vector of scalar stats.
2441 * @sa Stat, VectorBase, StatStor
2444 class Vector : public WrapVec<Vector<N>, VectorBase<StatStor>, VectorStatData>
2447 /** The base implementation. */
2448 typedef ScalarBase<StatStor> Base;
2451 * Set this vector to have the given size.
2452 * @param size The new size.
2453 * @return A reference to this stat.
2456 init(size_type size)
2464 * A vector of Average stats.
2465 * @sa Stat, VectorBase, AvgStor
2469 : public WrapVec<AverageVector<N>, VectorBase<AvgStor>, VectorStatData>
2473 * Set this vector to have the given size.
2474 * @param size The new size.
2475 * @return A reference to this stat.
2478 init(size_type size)
2486 * A 2-Dimensional vecto of scalar stats.
2487 * @sa Stat, Vector2dBase, StatStor
2491 : public WrapVec2d<Vector2d<N>, Vector2dBase<StatStor>, Vector2dStatData>
2495 init(size_type x, size_type y)
2503 * A simple distribution stat.
2504 * @sa Stat, DistBase, DistStor
2508 : public Wrap<Distribution<N>, DistBase<DistStor>, DistStatData>
2511 /** Base implementation. */
2512 typedef DistBase<DistStor> Base;
2513 /** The Parameter type. */
2514 typedef DistStor::Params Params;
2518 * Set the parameters of this distribution. @sa DistStor::Params
2519 * @param min The minimum value of the distribution.
2520 * @param max The maximum value of the distribution.
2521 * @param bkt The number of values in each bucket.
2522 * @return A reference to this distribution.
2525 init(Counter min, Counter max, Counter bkt)
2527 this->params.min = min;
2528 this->params.max = max;
2529 this->params.bucket_size = bkt;
2530 this->params.size = (size_type)rint((max - min) / bkt + 1.0);
2537 * Calculates the mean and variance of all the samples.
2538 * @sa Stat, DistBase, FancyStor
2541 class StandardDeviation
2542 : public Wrap<StandardDeviation<N>, DistBase<FancyStor>, DistStatData>
2545 /** The base implementation */
2546 typedef DistBase<DistStor> Base;
2547 /** The parameter type. */
2548 typedef DistStor::Params Params;
2552 * Construct and initialize this distribution.
2561 * Calculates the per tick mean and variance of the samples.
2562 * @sa Stat, DistBase, AvgFancy
2565 class AverageDeviation
2566 : public Wrap<AverageDeviation<N>, DistBase<AvgFancy>, DistStatData>
2569 /** The base implementation */
2570 typedef DistBase<DistStor> Base;
2571 /** The parameter type. */
2572 typedef DistStor::Params Params;
2576 * Construct and initialize this distribution.
2585 * A vector of distributions.
2586 * @sa Stat, VectorDistBase, DistStor
2589 class VectorDistribution
2590 : public WrapVec<VectorDistribution<N>,
2591 VectorDistBase<DistStor>,
2595 /** The base implementation */
2596 typedef VectorDistBase<DistStor> Base;
2597 /** The parameter type. */
2598 typedef DistStor::Params Params;
2602 * Initialize storage and parameters for this distribution.
2603 * @param size The size of the vector (the number of distributions).
2604 * @param min The minimum value of the distribution.
2605 * @param max The maximum value of the distribution.
2606 * @param bkt The number of values in each bucket.
2607 * @return A reference to this distribution.
2609 VectorDistribution &
2610 init(size_type size, Counter min, Counter max, Counter bkt)
2612 this->params.min = min;
2613 this->params.max = max;
2614 this->params.bucket_size = bkt;
2615 this->params.size = rint((max - min) / bkt + 1.0);
2622 * This is a vector of StandardDeviation stats.
2623 * @sa Stat, VectorDistBase, FancyStor
2626 class VectorStandardDeviation
2627 : public WrapVec<VectorStandardDeviation<N>,
2628 VectorDistBase<FancyStor>,
2632 /** The base implementation */
2633 typedef VectorDistBase<FancyStor> Base;
2634 /** The parameter type. */
2635 typedef DistStor::Params Params;
2639 * Initialize storage for this distribution.
2640 * @param size The size of the vector.
2641 * @return A reference to this distribution.
2643 VectorStandardDeviation &
2644 init(size_type size)
2652 * This is a vector of AverageDeviation stats.
2653 * @sa Stat, VectorDistBase, AvgFancy
2656 class VectorAverageDeviation
2657 : public WrapVec<VectorAverageDeviation<N>,
2658 VectorDistBase<AvgFancy>,
2662 /** The base implementation */
2663 typedef VectorDistBase<AvgFancy> Base;
2664 /** The parameter type. */
2665 typedef DistStor::Params Params;
2669 * Initialize storage for this distribution.
2670 * @param size The size of the vector.
2671 * @return A reference to this distribution.
2673 VectorAverageDeviation &
2674 init(size_type size)
2682 * A formula for statistics that is calculated when printed. A formula is
2683 * stored as a tree of Nodes that represent the equation to calculate.
2684 * @sa Stat, ScalarStat, VectorStat, Node, Temp
2686 class FormulaBase : public DataAccess
2689 /** The root of the tree which represents the Formula */
2695 * Return the result of the Fomula in a vector. If there were no Vector
2696 * components to the Formula, then the vector is size 1. If there were,
2697 * like x/y with x being a vector of size 3, then the result returned will
2698 * be x[0]/y, x[1]/y, x[2]/y, respectively.
2699 * @return The result vector.
2701 void result(VResult &vec) const;
2704 * Return the total Formula result. If there is a Vector
2705 * component to this Formula, then this is the result of the
2706 * Formula if the formula is applied after summing all the
2707 * components of the Vector. For example, if Formula is x/y where
2708 * x is size 3, then total() will return (x[1]+x[2]+x[3])/y. If
2709 * there is no Vector component, total() returns the same value as
2710 * the first entry in the VResult val() returns.
2711 * @return The total of the result vector.
2713 Result total() const;
2716 * Return the number of elements in the tree.
2718 size_type size() const;
2720 bool check() const { return true; }
2723 * Formulas don't need to be reset
2735 void update(StatData *);
2737 std::string str() const;
2740 class FormulaData : public VectorData
2743 virtual std::string str() const = 0;
2744 virtual bool check() const { return true; }
2747 template <class Stat>
2748 class FormulaStatData : public FormulaData
2752 mutable VResult vec;
2753 mutable VCounter cvec;
2756 FormulaStatData(Stat &stat) : s(stat) {}
2758 virtual bool zero() const { return s.zero(); }
2759 virtual void reset() { s.reset(); }
2761 virtual size_type size() const { return s.size(); }
2763 virtual const VResult &
2769 virtual Result total() const { return s.total(); }
2770 virtual VCounter &value() const { return cvec; }
2773 visit(Visit &visitor)
2777 visitor.visit(*this);
2780 virtual std::string str() const { return s.str(); }
2785 : public WrapVec<Formula,
2791 * Create and initialize thie formula, and register it with the database.
2796 * Create a formula with the given root node, register it with the
2798 * @param r The root of the expression tree.
2803 * Set an unitialized Formula to the given root.
2804 * @param r The root of the expression tree.
2805 * @return a reference to this formula.
2807 const Formula &operator=(Temp r);
2810 * Add the given tree to the existing one.
2811 * @param r The root of the expression tree.
2812 * @return a reference to this formula.
2814 const Formula &operator+=(Temp r);
2817 class FormulaNode : public Node
2820 const Formula &formula;
2821 mutable VResult vec;
2824 FormulaNode(const Formula &f) : formula(f) {}
2826 virtual size_type size() const { return formula.size(); }
2827 virtual const VResult &result() const { formula.result(vec); return vec; }
2828 virtual Result total() const { return formula.total(); }
2830 virtual std::string str() const { return formula.str(); }
2834 * Helper class to construct formula node trees.
2840 * Pointer to a Node object.
2846 * Copy the given pointer to this class.
2847 * @param n A pointer to a Node object to copy.
2849 Temp(NodePtr n) : node(n) { }
2852 * Return the node pointer.
2853 * @return the node pointer.
2855 operator NodePtr&() { return node;}
2859 * Create a new ScalarStatNode.
2860 * @param s The ScalarStat to place in a node.
2863 Temp(const Scalar<N> &s)
2864 : node(new ScalarStatNode(s.statData()))
2868 * Create a new ScalarStatNode.
2869 * @param s The ScalarStat to place in a node.
2871 Temp(const Value &s)
2872 : node(new ScalarStatNode(s.statData()))
2876 * Create a new ScalarStatNode.
2877 * @param s The ScalarStat to place in a node.
2880 Temp(const Average<N> &s)
2881 : node(new ScalarStatNode(s.statData()))
2885 * Create a new VectorStatNode.
2886 * @param s The VectorStat to place in a node.
2889 Temp(const Vector<N> &s)
2890 : node(new VectorStatNode(s.statData()))
2896 Temp(const Formula &f)
2897 : node(new FormulaNode(f))
2901 * Create a new ScalarProxyNode.
2902 * @param p The ScalarProxy to place in a node.
2904 template <class Stat>
2905 Temp(const ScalarProxy<Stat> &p)
2906 : node(new ScalarProxyNode<Stat>(p))
2910 * Create a ConstNode
2911 * @param value The value of the const node.
2913 Temp(signed char value)
2914 : node(new ConstNode<signed char>(value))
2918 * Create a ConstNode
2919 * @param value The value of the const node.
2921 Temp(unsigned char value)
2922 : node(new ConstNode<unsigned char>(value))
2926 * Create a ConstNode
2927 * @param value The value of the const node.
2929 Temp(signed short value)
2930 : node(new ConstNode<signed short>(value))
2934 * Create a ConstNode
2935 * @param value The value of the const node.
2937 Temp(unsigned short value)
2938 : node(new ConstNode<unsigned short>(value))
2942 * Create a ConstNode
2943 * @param value The value of the const node.
2945 Temp(signed int value)
2946 : node(new ConstNode<signed int>(value))
2950 * Create a ConstNode
2951 * @param value The value of the const node.
2953 Temp(unsigned int value)
2954 : node(new ConstNode<unsigned int>(value))
2958 * Create a ConstNode
2959 * @param value The value of the const node.
2961 Temp(signed long value)
2962 : node(new ConstNode<signed long>(value))
2966 * Create a ConstNode
2967 * @param value The value of the const node.
2969 Temp(unsigned long value)
2970 : node(new ConstNode<unsigned long>(value))
2974 * Create a ConstNode
2975 * @param value The value of the const node.
2977 Temp(signed long long value)
2978 : node(new ConstNode<signed long long>(value))
2982 * Create a ConstNode
2983 * @param value The value of the const node.
2985 Temp(unsigned long long value)
2986 : node(new ConstNode<unsigned long long>(value))
2990 * Create a ConstNode
2991 * @param value The value of the const node.
2994 : node(new ConstNode<float>(value))
2998 * Create a ConstNode
2999 * @param value The value of the const node.
3002 : node(new ConstNode<double>(value))
3014 void registerResetCallback(Callback *cb);
3017 operator+(Temp l, Temp r)
3019 return NodePtr(new BinaryNode<std::plus<Result> >(l, r));
3023 operator-(Temp l, Temp r)
3025 return NodePtr(new BinaryNode<std::minus<Result> >(l, r));
3029 operator*(Temp l, Temp r)
3031 return NodePtr(new BinaryNode<std::multiplies<Result> >(l, r));
3035 operator/(Temp l, Temp r)
3037 return NodePtr(new BinaryNode<std::divides<Result> >(l, r));
3043 return NodePtr(new UnaryNode<std::negate<Result> >(l));
3046 template <typename T>
3050 return NodePtr(new ConstNode<T>(val));
3053 template <typename T>
3055 constantVector(T val)
3057 return NodePtr(new ConstVectorNode<T>(val));
3063 return NodePtr(new SumNode<std::plus<Result> >(val));
3066 /* namespace Stats */ }
3068 #endif // __BASE_STATISTICS_HH__