Deleted Added
sdiff udiff text old ( 5582:c2fd66e6a919 ) new ( 5598:345ef3bda3d2 )
full compact
1/*
2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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;

--- 163 unchanged lines hidden (view full) ---

172 /** Names and descriptions of subfields. */
173 mutable std::vector<std::string> subnames;
174 mutable std::vector<std::string> subdescs;
175
176 virtual size_t size() const = 0;
177 virtual const VCounter &value() const = 0;
178 virtual const VResult &result() const = 0;
179 virtual Result total() const = 0;
180 void update()
181 {
182 if (!subnames.empty()) {
183 int s = size();
184 if (subnames.size() < s)
185 subnames.resize(s);
186
187 if (subdescs.size() < s)
188 subdescs.resize(s);

--- 12 unchanged lines hidden (view full) ---

201 public:
202 VectorStatData(Stat &stat) : s(stat) {}
203
204 virtual bool check() const { return s.check(); }
205 virtual bool zero() const { return s.zero(); }
206 virtual void reset() { s.reset(); }
207
208 virtual size_t size() const { return s.size(); }
209 virtual VCounter &value() const
210 {
211 s.value(cvec);
212 return cvec;
213 }
214 virtual const VResult &result() const
215 {
216 s.result(rvec);
217 return rvec;
218 }
219 virtual Result total() const { return s.total(); }
220 virtual void visit(Visit &visitor)
221 {
222 update();
223 s.update(this);
224 visitor.visit(*this);
225 }
226};
227
228struct DistDataData

--- 27 unchanged lines hidden (view full) ---

256 Stat &s;
257
258 public:
259 DistStatData(Stat &stat) : s(stat) {}
260
261 virtual bool check() const { return s.check(); }
262 virtual void reset() { s.reset(); }
263 virtual bool zero() const { return s.zero(); }
264 virtual void visit(Visit &visitor)
265 {
266 s.update(this);
267 visitor.visit(*this);
268 }
269};
270
271struct VectorDistData : public StatData
272{
273 std::vector<DistDataData> data;
274
275 /** Names and descriptions of subfields. */
276 mutable std::vector<std::string> subnames;
277 mutable std::vector<std::string> subdescs;
278
279 /** Local storage for the entry values, used for printing. */
280 mutable VResult rvec;
281
282 virtual size_t size() const = 0;
283 void update()
284 {
285 int s = size();
286 if (subnames.size() < s)
287 subnames.resize(s);
288
289 if (subdescs.size() < s)
290 subdescs.resize(s);
291 }

--- 7 unchanged lines hidden (view full) ---

299
300 public:
301 VectorDistStatData(Stat &stat) : s(stat) {}
302
303 virtual bool check() const { return s.check(); }
304 virtual void reset() { s.reset(); }
305 virtual size_t size() const { return s.size(); }
306 virtual bool zero() const { return s.zero(); }
307 virtual void visit(Visit &visitor)
308 {
309 update();
310 s.update(this);
311 visitor.visit(*this);
312 }
313};
314
315struct Vector2dData : public StatData
316{
317 /** Names and descriptions of subfields. */
318 std::vector<std::string> subnames;
319 std::vector<std::string> subdescs;
320 std::vector<std::string> y_subnames;
321
322 /** Local storage for the entry values, used for printing. */
323 mutable VCounter cvec;
324 mutable int x;
325 mutable int y;
326
327 void update()
328 {
329 if (subnames.size() < x)
330 subnames.resize(x);
331 }
332};
333
334template <class Stat>
335class Vector2dStatData : public Vector2dData
336{
337 protected:
338 Stat &s;
339
340 public:
341 Vector2dStatData(Stat &stat) : s(stat) {}
342
343 virtual bool check() const { return s.check(); }
344 virtual void reset() { s.reset(); }
345 virtual bool zero() const { return s.zero(); }
346 virtual void visit(Visit &visitor)
347 {
348 update();
349 s.update(this);
350 visitor.visit(*this);
351 }
352};
353
354class DataAccess

--- 11 unchanged lines hidden (view full) ---

366
367template <class Parent, class Child, template <class> class Data>
368class Wrap : public Child
369{
370 protected:
371 Parent &self() { return *reinterpret_cast<Parent *>(this); }
372
373 protected:
374 Data<Child> *statData()
375 {
376 StatData *__data = DataAccess::statData();
377 Data<Child> *ptr = dynamic_cast<Data<Child> *>(__data);
378 assert(ptr);
379 return ptr;
380 }
381
382 public:
383 const Data<Child> *statData() const
384 {
385 const StatData *__data = DataAccess::statData();
386 const Data<Child> *ptr = dynamic_cast<const Data<Child> *>(__data);
387 assert(ptr);
388 return ptr;
389 }
390
391 protected:
392 /**
393 * Copy constructor, copies are not allowed.
394 */
395 Wrap(const Wrap &stat);
396 /**
397 * Can't copy stats.
398 */
399 void operator=(const Wrap &);
400
401 public:
402 Wrap()
403 {
404 this->map(new Data<Child>(*this));
405 }
406
407 /**
408 * Set the name and marks this stat to print at the end of simulation.
409 * @param name The new name.
410 * @return A reference to this stat.
411 */
412 Parent &name(const std::string &_name)
413 {
414 Data<Child> *data = this->statData();
415 data->name = _name;
416 this->setPrint();
417 return this->self();
418 }
419
420 /**
421 * Set the description and marks this stat to print at the end of
422 * simulation.
423 * @param desc The new description.
424 * @return A reference to this stat.
425 */
426 Parent &desc(const std::string &_desc)
427 {
428 this->statData()->desc = _desc;
429 return this->self();
430 }
431
432 /**
433 * Set the precision and marks this stat to print at the end of simulation.
434 * @param p The new precision
435 * @return A reference to this stat.
436 */
437 Parent &precision(int _precision)
438 {
439 this->statData()->precision = _precision;
440 return this->self();
441 }
442
443 /**
444 * Set the flags and marks this stat to print at the end of simulation.
445 * @param f The new flags.
446 * @return A reference to this stat.
447 */
448 Parent &flags(StatFlags _flags)
449 {
450 this->statData()->flags |= _flags;
451 return this->self();
452 }
453
454 /**
455 * Set the prerequisite stat and marks this stat to print at the end of
456 * simulation.
457 * @param prereq The prerequisite stat.
458 * @return A reference to this stat.
459 */
460 template <class Stat>
461 Parent &prereq(const Stat &prereq)
462 {
463 this->statData()->prereq = prereq.statData();
464 return this->self();
465 }
466};
467
468template <class Parent, class Child, template <class Child> class Data>
469class WrapVec : public Wrap<Parent, Child, Data>

--- 4 unchanged lines hidden (view full) ---

474
475 /**
476 * Set the subfield name for the given index, and marks this stat to print
477 * at the end of simulation.
478 * @param index The subfield index.
479 * @param name The new name of the subfield.
480 * @return A reference to this stat.
481 */
482 Parent &subname(int index, const std::string &name)
483 {
484 std::vector<std::string> &subn = this->statData()->subnames;
485 if (subn.size() <= index)
486 subn.resize(index + 1);
487 subn[index] = name;
488 return this->self();
489 }
490
491 /**
492 * Set the subfield description for the given index and marks this stat to
493 * print at the end of simulation.
494 * @param index The subfield index.
495 * @param desc The new description of the subfield
496 * @return A reference to this stat.
497 */
498 Parent &subdesc(int index, const std::string &desc)
499 {
500 std::vector<std::string> &subd = this->statData()->subdescs;
501 if (subd.size() <= index)
502 subd.resize(index + 1);
503 subd[index] = desc;
504
505 return this->self();
506 }
507
508};
509
510template <class Parent, class Child, template <class Child> class Data>
511class WrapVec2d : public WrapVec<Parent, Child, Data>
512{
513 public:
514 /**
515 * @warning This makes the assumption that if you're gonna subnames a 2d
516 * vector, you're subnaming across all y
517 */
518 Parent &ysubnames(const char **names)
519 {
520 Data<Child> *data = this->statData();
521 data->y_subnames.resize(this->y);
522 for (int i = 0; i < this->y; ++i)
523 data->y_subnames[i] = names[i];
524 return this->self();
525 }
526 Parent &ysubname(int index, const std::string subname)
527 {
528 Data<Child> *data = this->statData();
529 assert(index < this->y);
530 data->y_subnames.resize(this->y);
531 data->y_subnames[index] = subname.c_str();
532 return this->self();
533 }
534};

--- 93 unchanged lines hidden (view full) ---

628 AvgStor(Params &p) : current(0), total(0), last(0) { }
629
630 /**
631 * Set the current count to the one provided, update the total and last
632 * set values.
633 * @param val The new count.
634 * @param p The parameters for this storage.
635 */
636 void set(Counter val, Params &p) {
637 total += current * (curTick - last);
638 last = curTick;
639 current = val;
640 }
641
642 /**
643 * Increment the current count by the provided value, calls set.
644 * @param val The amount to increment.

--- 15 unchanged lines hidden (view full) ---

660 */
661 Counter value(const Params &p) const { return current; }
662
663 /**
664 * Return the current average.
665 * @param p The parameters for this storage.
666 * @return The current average.
667 */
668 Result result(const Params &p) const
669 {
670 total += current * (curTick - last);
671 last = curTick;
672 return (Result)(total + current) / (Result)(curTick + 1);
673 }
674
675 /**
676 * Reset stat value to default
677 */
678 void reset()
679 {
680 total = 0;
681 last = curTick;
682 }
683
684 /**
685 * @return true if zero value
686 */

--- 172 unchanged lines hidden (view full) ---

859 private:
860 ProxyData *proxy;
861
862 public:
863 ValueBase() : proxy(NULL) { }
864 ~ValueBase() { if (proxy) delete proxy; }
865
866 template <class T>
867 void scalar(T &value)
868 {
869 proxy = new ValueProxy<T>(value);
870 setInit();
871 }
872
873 template <class T>
874 void functor(T &func)
875 {
876 proxy = new FunctorProxy<T>(func);
877 setInit();
878 }
879
880 Counter value() { return proxy->value(); }
881 Result result() const { return proxy->result(); }
882 Result total() const { return proxy->total(); };

--- 58 unchanged lines hidden (view full) ---

941 : stat(sp.stat), index(sp.index)
942 {}
943
944 /**
945 * Set this proxy equal to the provided one.
946 * @param sp The proxy to copy.
947 * @return A reference to this proxy.
948 */
949 const ScalarProxy &operator=(const ScalarProxy &sp) {
950 stat = sp.stat;
951 index = sp.index;
952 return *this;
953 }
954
955 public:
956 // Common operators for stats
957 /**

--- 13 unchanged lines hidden (view full) ---

971 void operator--(int) { --*this; }
972
973 /**
974 * Set the data value to the given value. This calls the associated storage
975 * object set function.
976 * @param v The new value.
977 */
978 template <typename U>
979 void operator=(const U &v) { stat->data(index)->set(v, stat->params); }
980
981 /**
982 * Increment the stat by the given value. This calls the associated
983 * storage object inc function.
984 * @param v The value to add.
985 */
986 template <typename U>
987 void operator+=(const U &v) { stat->data(index)->inc(v, stat->params); }
988
989 /**
990 * Decrement the stat by the given value. This calls the associated
991 * storage object dec function.
992 * @param v The value to substract.
993 */
994 template <typename U>
995 void operator-=(const U &v) { stat->data(index)->dec(v, stat->params); }
996
997 /**
998 * Return the number of elements, always 1 for a scalar.
999 * @return 1.
1000 */
1001 size_t size() const { return 1; }
1002
1003 /**

--- 62 unchanged lines hidden (view full) ---

1066
1067 for (int i = 0; i < _size; ++i)
1068 new (&storage[i]) Storage(params);
1069
1070 setInit();
1071 }
1072
1073 public:
1074 void value(VCounter &vec) const
1075 {
1076 vec.resize(size());
1077 for (int i = 0; i < size(); ++i)
1078 vec[i] = data(i)->value(params);
1079 }
1080
1081 /**
1082 * Copy the values to a local vector and return a reference to it.
1083 * @return A reference to a vector of the stat values.
1084 */
1085 void result(VResult &vec) const
1086 {
1087 vec.resize(size());
1088 for (int i = 0; i < size(); ++i)
1089 vec[i] = data(i)->result(params);
1090 }
1091
1092 /**
1093 * Return a total of all entries in this vector.
1094 * @return The total of all vector entries.
1095 */
1096 Result total() const {
1097 Result total = 0.0;
1098 for (int i = 0; i < size(); ++i)
1099 total += data(i)->result(params);
1100 return total;
1101 }
1102
1103 /**
1104 * @return the number of elements in this vector.

--- 113 unchanged lines hidden (view full) ---

1218 operator=(const VectorProxy &sp)
1219 {
1220 stat = sp.stat;
1221 offset = sp.offset;
1222 len = sp.len;
1223 return *this;
1224 }
1225
1226 ScalarProxy<Stat> operator[](int index)
1227 {
1228 assert (index >= 0 && index < size());
1229 return ScalarProxy<Stat>(stat, offset + index);
1230 }
1231
1232 size_t size() const { return len; }
1233
1234 /**

--- 168 unchanged lines hidden (view full) ---

1403 }
1404
1405 /**
1406 * Add a value to the distribution for the given number of times.
1407 * @param val The value to add.
1408 * @param number The number of times to add the value.
1409 * @param params The paramters of the distribution.
1410 */
1411 void sample(Counter val, int number, const Params &params)
1412 {
1413 if (val < params.min)
1414 underflow += number;
1415 else if (val > params.max)
1416 overflow += number;
1417 else {
1418 int index = (int)std::floor((val - params.min) / params.bucket_size);
1419 assert(index < size(params));
1420 cvec[index] += number;
1421 }
1422
1423 if (val < min_val)
1424 min_val = val;
1425
1426 if (val > max_val)

--- 12 unchanged lines hidden (view full) ---

1439 */
1440 size_t size(const Params &) const { return cvec.size(); }
1441
1442 /**
1443 * Returns true if any calls to sample have been made.
1444 * @param params The paramters of the distribution.
1445 * @return True if any values have been sampled.
1446 */
1447 bool zero(const Params &params) const
1448 {
1449 return samples == Counter();
1450 }
1451
1452 void update(DistDataData *data, const Params &params)
1453 {
1454 data->min = params.min;
1455 data->max = params.max;
1456 data->bucket_size = params.bucket_size;
1457 data->size = params.size;
1458
1459 data->min_val = (min_val == CounterLimits::max()) ? 0 : min_val;
1460 data->max_val = (max_val == CounterLimits::min()) ? 0 : max_val;

--- 6 unchanged lines hidden (view full) ---

1467 data->sum = sum;
1468 data->squares = squares;
1469 data->samples = samples;
1470 }
1471
1472 /**
1473 * Reset stat value to default
1474 */
1475 void reset()
1476 {
1477 min_val = CounterLimits::max();
1478 max_val = CounterLimits::min();
1479 underflow = 0;
1480 overflow = 0;
1481
1482 int size = cvec.size();
1483 for (int i = 0; i < size; ++i)

--- 37 unchanged lines hidden (view full) ---

1521 /**
1522 * Add a value the given number of times to this running average.
1523 * Update the running sum and sum of squares, increment the number of
1524 * values seen by the given number.
1525 * @param val The value to add.
1526 * @param number The number of times to add the value.
1527 * @param p The parameters of this stat.
1528 */
1529 void sample(Counter val, int number, const Params &p)
1530 {
1531 Counter value = val * number;
1532 sum += value;
1533 squares += value * value;
1534 samples += number;
1535 }
1536
1537 void update(DistDataData *data, const Params &params)
1538 {
1539 data->sum = sum;
1540 data->squares = squares;
1541 data->samples = samples;
1542 }
1543
1544 /**
1545 * Return the number of entries in this stat, 1

--- 5 unchanged lines hidden (view full) ---

1551 * Return true if no samples have been added.
1552 * @return True if no samples have been added.
1553 */
1554 bool zero(const Params &) const { return samples == Counter(); }
1555
1556 /**
1557 * Reset stat value to default
1558 */
1559 void reset()
1560 {
1561 sum = Counter();
1562 squares = Counter();
1563 samples = Counter();
1564 }
1565};
1566
1567/**

--- 21 unchanged lines hidden (view full) ---

1589
1590 /**
1591 * Add a value to the distribution for the given number of times.
1592 * Update the running sum and sum of squares.
1593 * @param val The value to add.
1594 * @param number The number of times to add the value.
1595 * @param p The paramters of the distribution.
1596 */
1597 void sample(Counter val, int number, const Params &p)
1598 {
1599 Counter value = val * number;
1600 sum += value;
1601 squares += value * value;
1602 }
1603
1604 void update(DistDataData *data, const Params &params)
1605 {
1606 data->sum = sum;
1607 data->squares = squares;
1608 data->samples = curTick;
1609 }
1610
1611 /**
1612 * Return the number of entries, in this case 1.
1613 * @return 1.
1614 */
1615 size_t size(const Params &params) const { return 1; }
1616 /**
1617 * Return true if no samples have been added.
1618 * @return True if the sum is zero.
1619 */
1620 bool zero(const Params &params) const { return sum == Counter(); }
1621 /**
1622 * Reset stat value to default
1623 */
1624 void reset()
1625 {
1626 sum = Counter();
1627 squares = Counter();
1628 }
1629};
1630
1631/**
1632 * Implementation of a distribution stat. The type of distribution is

--- 14 unchanged lines hidden (view full) ---

1647 /** The parameters for this stat. */
1648 Params params;
1649
1650 protected:
1651 /**
1652 * Retrieve the storage.
1653 * @return The storage object for this stat.
1654 */
1655 Storage *data()
1656 {
1657 return reinterpret_cast<Storage *>(storage);
1658 }
1659
1660 /**
1661 * Retrieve a const pointer to the storage.
1662 * @return A const pointer to the storage object for this stat.
1663 */

--- 28 unchanged lines hidden (view full) ---

1692 */
1693 size_t size() const { return data()->size(params); }
1694 /**
1695 * Return true if no samples have been added.
1696 * @return True if there haven't been any samples.
1697 */
1698 bool zero() const { return data()->zero(params); }
1699
1700 void update(DistData *base)
1701 {
1702 base->data.fancy = Storage::fancy;
1703 data()->update(&(base->data), params);
1704 }
1705
1706 /**
1707 * Reset stat value to default
1708 */

--- 134 unchanged lines hidden (view full) ---

1843 DistProxy(Stat *s, int i)
1844 : stat(s), index(i)
1845 {}
1846
1847 DistProxy(const DistProxy &sp)
1848 : stat(sp.stat), index(sp.index)
1849 {}
1850
1851 const DistProxy &operator=(const DistProxy &sp)
1852 {
1853 stat = sp.stat;
1854 index = sp.index;
1855 return *this;
1856 }
1857
1858 public:
1859 template <typename U>

--- 30 unchanged lines hidden (view full) ---

1890}
1891
1892#if 0
1893template <class Storage>
1894Result
1895VectorDistBase<Storage>::total(int index) const
1896{
1897 int total = 0;
1898 for (int i = 0; i < x_size(); ++i) {
1899 total += data(i)->result(stat->params);
1900 }
1901}
1902#endif
1903
1904//////////////////////////////////////////////////////////////////////
1905//
1906// Formula Details
1907//
1908//////////////////////////////////////////////////////////////////////

--- 33 unchanged lines hidden (view full) ---

1942class ScalarStatNode : public Node
1943{
1944 private:
1945 const ScalarData *data;
1946 mutable VResult vresult;
1947
1948 public:
1949 ScalarStatNode(const ScalarData *d) : data(d), vresult(1) {}
1950 virtual const VResult &result() const
1951 {
1952 vresult[0] = data->result();
1953 return vresult;
1954 }
1955 virtual Result total() const { return data->result(); };
1956
1957 virtual size_t size() const { return 1; }
1958
1959 /**
1960 *
1961 */
1962 virtual std::string str() const { return data->name; }

--- 73 unchanged lines hidden (view full) ---

2036class ConstVectorNode : public Node
2037{
2038 private:
2039 VResult vresult;
2040
2041 public:
2042 ConstVectorNode(const T &s) : vresult(s.begin(), s.end()) {}
2043 const VResult &result() const { return vresult; }
2044 virtual Result total() const
2045 {
2046 int size = this->size();
2047 Result tmp = 0;
2048 for (int i = 0; i < size; i++)
2049 {
2050 tmp += vresult[i];
2051 }
2052 return tmp;
2053 }
2054 virtual size_t size() const { return vresult.size(); }
2055 virtual std::string str() const
2056 {
2057 int size = this->size();
2058 std::string tmp = "(";
2059 for (int i = 0; i < size; i++)
2060 {
2061 tmp += csprintf("%s ",to_string(vresult[i]));
2062 }
2063 tmp += ")";
2064 return tmp;
2065 }
2066};
2067
2068template <class Op>
2069struct OpString;
2070

--- 38 unchanged lines hidden (view full) ---

2109{
2110 public:
2111 NodePtr l;
2112 mutable VResult vresult;
2113
2114 public:
2115 UnaryNode(NodePtr &p) : l(p) {}
2116
2117 const VResult &result() const
2118 {
2119 const VResult &lvec = l->result();
2120 int size = lvec.size();
2121
2122 assert(size > 0);
2123
2124 vresult.resize(size);
2125 Op op;
2126 for (int i = 0; i < size; ++i)
2127 vresult[i] = op(lvec[i]);
2128
2129 return vresult;
2130 }
2131
2132 Result total() const
2133 {
2134 const VResult &vec = this->result();
2135 Result total = 0;
2136 for (int i = 0; i < size(); i++)
2137 total += vec[i];
2138 return total;
2139 }
2140
2141 virtual size_t size() const { return l->size(); }
2142
2143 virtual std::string str() const
2144 {
2145 return OpString<Op>::str() + l->str();
2146 }
2147};
2148
2149template <class Op>
2150class BinaryNode : public Node
2151{
2152 public:
2153 NodePtr l;
2154 NodePtr r;
2155 mutable VResult vresult;
2156
2157 public:
2158 BinaryNode(NodePtr &a, NodePtr &b) : l(a), r(b) {}
2159
2160 const VResult &result() const
2161 {
2162 Op op;
2163 const VResult &lvec = l->result();
2164 const VResult &rvec = r->result();
2165
2166 assert(lvec.size() > 0 && rvec.size() > 0);
2167
2168 if (lvec.size() == 1 && rvec.size() == 1) {

--- 14 unchanged lines hidden (view full) ---

2183 vresult.resize(size);
2184 for (int i = 0; i < size; ++i)
2185 vresult[i] = op(lvec[i], rvec[i]);
2186 }
2187
2188 return vresult;
2189 }
2190
2191 Result total() const
2192 {
2193 const VResult &vec = this->result();
2194 Result total = 0;
2195 for (int i = 0; i < size(); i++)
2196 total += vec[i];
2197 return total;
2198 }
2199
2200 virtual size_t size() const {
2201 int ls = l->size();
2202 int rs = r->size();
2203 if (ls == 1)
2204 return rs;
2205 else if (rs == 1)
2206 return ls;
2207 else {
2208 assert(ls == rs && "Node vector sizes are not equal");
2209 return ls;
2210 }
2211 }
2212
2213 virtual std::string str() const
2214 {
2215 return csprintf("(%s %s %s)", l->str(), OpString<Op>::str(), r->str());
2216 }
2217};
2218
2219template <class Op>
2220class SumNode : public Node
2221{
2222 public:
2223 NodePtr l;
2224 mutable VResult vresult;
2225
2226 public:
2227 SumNode(NodePtr &p) : l(p), vresult(1) {}
2228
2229 const VResult &result() const
2230 {
2231 const VResult &lvec = l->result();
2232 int size = lvec.size();
2233 assert(size > 0);
2234
2235 vresult[0] = 0.0;
2236
2237 Op op;
2238 for (int i = 0; i < size; ++i)
2239 vresult[0] = op(vresult[0], lvec[i]);
2240
2241 return vresult;
2242 }
2243
2244 Result total() const
2245 {
2246 const VResult &lvec = l->result();
2247 int size = lvec.size();
2248 assert(size > 0);
2249
2250 Result vresult = 0.0;
2251
2252 Op op;
2253 for (int i = 0; i < size; ++i)
2254 vresult = op(vresult, lvec[i]);
2255
2256 return vresult;
2257 }
2258
2259 virtual size_t size() const { return 1; }
2260
2261 virtual std::string str() const
2262 {
2263 return csprintf("total(%s)", l->str());
2264 }
2265};
2266
2267
2268//////////////////////////////////////////////////////////////////////
2269//

--- 33 unchanged lines hidden (view full) ---

2303
2304class Value : public Wrap<Value, ValueBase, ScalarStatData>
2305{
2306 public:
2307 /** The base implementation. */
2308 typedef ValueBase Base;
2309
2310 template <class T>
2311 Value &scalar(T &value)
2312 {
2313 Base::scalar(value);
2314 return *this;
2315 }
2316
2317 template <class T>
2318 Value &functor(T &func)
2319 {
2320 Base::functor(func);
2321 return *this;
2322 }
2323};
2324
2325/**
2326 * A stat that calculates the per tick average of a value.

--- 12 unchanged lines hidden (view full) ---

2339 }
2340
2341 /**
2342 * Sets the stat equal to the given value. Calls the base implementation
2343 * of operator=
2344 * @param v The new value.
2345 */
2346 template <typename U>
2347 void operator=(const U &v) { Base::operator=(v); }
2348};
2349
2350/**
2351 * A vector of scalar stats.
2352 * @sa Stat, VectorBase, StatStor
2353 */
2354template<int N = 0>
2355class Vector : public WrapVec<Vector<N>, VectorBase<StatStor>, VectorStatData>
2356{
2357 public:
2358 /** The base implementation. */
2359 typedef ScalarBase<StatStor> Base;
2360
2361 /**
2362 * Set this vector to have the given size.
2363 * @param size The new size.
2364 * @return A reference to this stat.
2365 */
2366 Vector &init(size_t size) {
2367 this->doInit(size);
2368 return *this;
2369 }
2370};
2371
2372/**
2373 * A vector of Average stats.
2374 * @sa Stat, VectorBase, AvgStor
2375 */
2376template<int N = 0>
2377class AverageVector
2378 : public WrapVec<AverageVector<N>, VectorBase<AvgStor>, VectorStatData>
2379{
2380 public:
2381 /**
2382 * Set this vector to have the given size.
2383 * @param size The new size.
2384 * @return A reference to this stat.
2385 */
2386 AverageVector &init(size_t size) {
2387 this->doInit(size);
2388 return *this;
2389 }
2390};
2391
2392/**
2393 * A 2-Dimensional vecto of scalar stats.
2394 * @sa Stat, Vector2dBase, StatStor
2395 */
2396template<int N = 0>
2397class Vector2d
2398 : public WrapVec2d<Vector2d<N>, Vector2dBase<StatStor>, Vector2dStatData>
2399{
2400 public:
2401 Vector2d &init(size_t x, size_t y) {
2402 this->doInit(x, y);
2403 return *this;
2404 }
2405};
2406
2407/**
2408 * A simple distribution stat.
2409 * @sa Stat, DistBase, DistStor

--- 11 unchanged lines hidden (view full) ---

2421 public:
2422 /**
2423 * Set the parameters of this distribution. @sa DistStor::Params
2424 * @param min The minimum value of the distribution.
2425 * @param max The maximum value of the distribution.
2426 * @param bkt The number of values in each bucket.
2427 * @return A reference to this distribution.
2428 */
2429 Distribution &init(Counter min, Counter max, Counter bkt) {
2430 this->params.min = min;
2431 this->params.max = max;
2432 this->params.bucket_size = bkt;
2433 this->params.size = (int)rint((max - min) / bkt + 1.0);
2434 this->doInit();
2435 return *this;
2436 }
2437};

--- 11 unchanged lines hidden (view full) ---

2449 typedef DistBase<DistStor> Base;
2450 /** The parameter type. */
2451 typedef DistStor::Params Params;
2452
2453 public:
2454 /**
2455 * Construct and initialize this distribution.
2456 */
2457 StandardDeviation() {
2458 this->doInit();
2459 }
2460};
2461
2462/**
2463 * Calculates the per tick mean and variance of the samples.
2464 * @sa Stat, DistBase, AvgFancy
2465 */

--- 37 unchanged lines hidden (view full) ---

2503 /**
2504 * Initialize storage and parameters for this distribution.
2505 * @param size The size of the vector (the number of distributions).
2506 * @param min The minimum value of the distribution.
2507 * @param max The maximum value of the distribution.
2508 * @param bkt The number of values in each bucket.
2509 * @return A reference to this distribution.
2510 */
2511 VectorDistribution &init(int size, Counter min, Counter max, Counter bkt) {
2512 this->params.min = min;
2513 this->params.max = max;
2514 this->params.bucket_size = bkt;
2515 this->params.size = (int)rint((max - min) / bkt + 1.0);
2516 this->doInit(size);
2517 return *this;
2518 }
2519};

--- 15 unchanged lines hidden (view full) ---

2535 typedef DistStor::Params Params;
2536
2537 public:
2538 /**
2539 * Initialize storage for this distribution.
2540 * @param size The size of the vector.
2541 * @return A reference to this distribution.
2542 */
2543 VectorStandardDeviation &init(int size) {
2544 this->doInit(size);
2545 return *this;
2546 }
2547};
2548
2549/**
2550 * This is a vector of AverageDeviation stats.
2551 * @sa Stat, VectorDistBase, AvgFancy

--- 11 unchanged lines hidden (view full) ---

2563 typedef DistStor::Params Params;
2564
2565 public:
2566 /**
2567 * Initialize storage for this distribution.
2568 * @param size The size of the vector.
2569 * @return A reference to this distribution.
2570 */
2571 VectorAverageDeviation &init(int size) {
2572 this->doInit(size);
2573 return *this;
2574 }
2575};
2576
2577/**
2578 * A formula for statistics that is calculated when printed. A formula is
2579 * stored as a tree of Nodes that represent the equation to calculate.

--- 70 unchanged lines hidden (view full) ---

2650
2651 public:
2652 FormulaStatData(Stat &stat) : s(stat) {}
2653
2654 virtual bool zero() const { return s.zero(); }
2655 virtual void reset() { s.reset(); }
2656
2657 virtual size_t size() const { return s.size(); }
2658 virtual const VResult &result() const
2659 {
2660 s.result(vec);
2661 return vec;
2662 }
2663 virtual Result total() const { return s.total(); }
2664 virtual VCounter &value() const { return cvec; }
2665 virtual void visit(Visit &visitor)
2666 {
2667 update();
2668 s.update(this);
2669 visitor.visit(*this);
2670 }
2671 virtual std::string str() const { return s.str(); }
2672};
2673
2674class Temp;
2675class Formula
2676 : public WrapVec<Formula,
2677 FormulaBase,
2678 FormulaStatData>

--- 68 unchanged lines hidden (view full) ---

2747
2748 public:
2749 /**
2750 * Create a new ScalarStatNode.
2751 * @param s The ScalarStat to place in a node.
2752 */
2753 template <int N>
2754 Temp(const Scalar<N> &s)
2755 : node(new ScalarStatNode(s.statData())) { }
2756
2757 /**
2758 * Create a new ScalarStatNode.
2759 * @param s The ScalarStat to place in a node.
2760 */
2761 Temp(const Value &s)
2762 : node(new ScalarStatNode(s.statData())) { }
2763
2764 /**
2765 * Create a new ScalarStatNode.
2766 * @param s The ScalarStat to place in a node.
2767 */
2768 template <int N>
2769 Temp(const Average<N> &s)
2770 : node(new ScalarStatNode(s.statData())) { }
2771
2772 /**
2773 * Create a new VectorStatNode.
2774 * @param s The VectorStat to place in a node.
2775 */
2776 template <int N>
2777 Temp(const Vector<N> &s)
2778 : node(new VectorStatNode(s.statData())) { }
2779
2780 /**
2781 *
2782 */
2783 Temp(const Formula &f)
2784 : node(new FormulaNode(f)) { }
2785
2786 /**
2787 * Create a new ScalarProxyNode.
2788 * @param p The ScalarProxy to place in a node.
2789 */
2790 template <class Stat>
2791 Temp(const ScalarProxy<Stat> &p)
2792 : node(new ScalarProxyNode<Stat>(p)) { }
2793
2794 /**
2795 * Create a ConstNode
2796 * @param value The value of the const node.
2797 */
2798 Temp(signed char value)
2799 : node(new ConstNode<signed char>(value)) {}
2800
2801 /**
2802 * Create a ConstNode
2803 * @param value The value of the const node.
2804 */
2805 Temp(unsigned char value)
2806 : node(new ConstNode<unsigned char>(value)) {}
2807
2808 /**
2809 * Create a ConstNode
2810 * @param value The value of the const node.
2811 */
2812 Temp(signed short value)
2813 : node(new ConstNode<signed short>(value)) {}
2814
2815 /**
2816 * Create a ConstNode
2817 * @param value The value of the const node.
2818 */
2819 Temp(unsigned short value)
2820 : node(new ConstNode<unsigned short>(value)) {}
2821
2822 /**
2823 * Create a ConstNode
2824 * @param value The value of the const node.
2825 */
2826 Temp(signed int value)
2827 : node(new ConstNode<signed int>(value)) {}
2828
2829 /**
2830 * Create a ConstNode
2831 * @param value The value of the const node.
2832 */
2833 Temp(unsigned int value)
2834 : node(new ConstNode<unsigned int>(value)) {}
2835
2836 /**
2837 * Create a ConstNode
2838 * @param value The value of the const node.
2839 */
2840 Temp(signed long value)
2841 : node(new ConstNode<signed long>(value)) {}
2842
2843 /**
2844 * Create a ConstNode
2845 * @param value The value of the const node.
2846 */
2847 Temp(unsigned long value)
2848 : node(new ConstNode<unsigned long>(value)) {}
2849
2850 /**
2851 * Create a ConstNode
2852 * @param value The value of the const node.
2853 */
2854 Temp(signed long long value)
2855 : node(new ConstNode<signed long long>(value)) {}
2856
2857 /**
2858 * Create a ConstNode
2859 * @param value The value of the const node.
2860 */
2861 Temp(unsigned long long value)
2862 : node(new ConstNode<unsigned long long>(value)) {}
2863
2864 /**
2865 * Create a ConstNode
2866 * @param value The value of the const node.
2867 */
2868 Temp(float value)
2869 : node(new ConstNode<float>(value)) {}
2870
2871 /**
2872 * Create a ConstNode
2873 * @param value The value of the const node.
2874 */
2875 Temp(double value)
2876 : node(new ConstNode<double>(value)) {}
2877};
2878
2879
2880/**
2881 * @}
2882 */
2883
2884void check();

--- 57 unchanged lines hidden ---