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 181 void 182 update() |
183 { 184 if (!subnames.empty()) { 185 int s = size(); 186 if (subnames.size() < s) 187 subnames.resize(s); 188 189 if (subdescs.size() < s) 190 subdescs.resize(s); --- 12 unchanged lines hidden (view full) --- 203 public: 204 VectorStatData(Stat &stat) : s(stat) {} 205 206 virtual bool check() const { return s.check(); } 207 virtual bool zero() const { return s.zero(); } 208 virtual void reset() { s.reset(); } 209 210 virtual size_t size() const { return s.size(); } |
211 212 virtual VCounter & 213 value() const |
214 { 215 s.value(cvec); 216 return cvec; 217 } |
218 219 virtual const VResult & 220 result() const |
221 { 222 s.result(rvec); 223 return rvec; 224 } |
225 |
226 virtual Result total() const { return s.total(); } |
227 228 virtual void 229 visit(Visit &visitor) |
230 { 231 update(); 232 s.update(this); 233 visitor.visit(*this); 234 } 235}; 236 237struct DistDataData --- 27 unchanged lines hidden (view full) --- 265 Stat &s; 266 267 public: 268 DistStatData(Stat &stat) : s(stat) {} 269 270 virtual bool check() const { return s.check(); } 271 virtual void reset() { s.reset(); } 272 virtual bool zero() const { return s.zero(); } |
273 274 virtual void 275 visit(Visit &visitor) |
276 { 277 s.update(this); 278 visitor.visit(*this); 279 } 280}; 281 282struct VectorDistData : public StatData 283{ 284 std::vector<DistDataData> data; 285 286 /** Names and descriptions of subfields. */ 287 mutable std::vector<std::string> subnames; 288 mutable std::vector<std::string> subdescs; 289 290 /** Local storage for the entry values, used for printing. */ 291 mutable VResult rvec; 292 293 virtual size_t size() const = 0; |
294 295 void 296 update() |
297 { 298 int s = size(); 299 if (subnames.size() < s) 300 subnames.resize(s); 301 302 if (subdescs.size() < s) 303 subdescs.resize(s); 304 } --- 7 unchanged lines hidden (view full) --- 312 313 public: 314 VectorDistStatData(Stat &stat) : s(stat) {} 315 316 virtual bool check() const { return s.check(); } 317 virtual void reset() { s.reset(); } 318 virtual size_t size() const { return s.size(); } 319 virtual bool zero() const { return s.zero(); } |
320 321 virtual void 322 visit(Visit &visitor) |
323 { 324 update(); 325 s.update(this); 326 visitor.visit(*this); 327 } 328}; 329 330struct Vector2dData : public StatData 331{ 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; 336 337 /** Local storage for the entry values, used for printing. */ 338 mutable VCounter cvec; 339 mutable int x; 340 mutable int y; 341 |
342 void 343 update() |
344 { 345 if (subnames.size() < x) 346 subnames.resize(x); 347 } 348}; 349 350template <class Stat> 351class Vector2dStatData : public Vector2dData 352{ 353 protected: 354 Stat &s; 355 356 public: 357 Vector2dStatData(Stat &stat) : s(stat) {} 358 359 virtual bool check() const { return s.check(); } 360 virtual void reset() { s.reset(); } 361 virtual bool zero() const { return s.zero(); } |
362 363 virtual void 364 visit(Visit &visitor) |
365 { 366 update(); 367 s.update(this); 368 visitor.visit(*this); 369 } 370}; 371 372class DataAccess --- 11 unchanged lines hidden (view full) --- 384 385template <class Parent, class Child, template <class> class Data> 386class Wrap : public Child 387{ 388 protected: 389 Parent &self() { return *reinterpret_cast<Parent *>(this); } 390 391 protected: |
392 Data 393 statData() |
394 { 395 StatData *__data = DataAccess::statData(); 396 Data<Child> *ptr = dynamic_cast<Data<Child> *>(__data); 397 assert(ptr); 398 return ptr; 399 } 400 401 public: |
402 const Data 403 statData() const |
404 { 405 const StatData *__data = DataAccess::statData(); 406 const Data<Child> *ptr = dynamic_cast<const Data<Child> *>(__data); 407 assert(ptr); 408 return ptr; 409 } 410 411 protected: 412 /** 413 * Copy constructor, copies are not allowed. 414 */ 415 Wrap(const Wrap &stat); |
416 |
417 /** 418 * Can't copy stats. 419 */ 420 void operator=(const Wrap &); 421 422 public: 423 Wrap() 424 { 425 this->map(new Data<Child>(*this)); 426 } 427 428 /** 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. 432 */ |
433 Parent & 434 name(const std::string &_name) |
435 { 436 Data<Child> *data = this->statData(); 437 data->name = _name; 438 this->setPrint(); 439 return this->self(); 440 } 441 442 /** 443 * Set the description and marks this stat to print at the end of 444 * simulation. 445 * @param desc The new description. 446 * @return A reference to this stat. 447 */ |
448 Parent & 449 desc(const std::string &_desc) |
450 { 451 this->statData()->desc = _desc; 452 return this->self(); 453 } 454 455 /** 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. 459 */ |
460 Parent & 461 precision(int _precision) |
462 { 463 this->statData()->precision = _precision; 464 return this->self(); 465 } 466 467 /** 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. 471 */ |
472 Parent & 473 flags(StatFlags _flags) |
474 { 475 this->statData()->flags |= _flags; 476 return this->self(); 477 } 478 479 /** 480 * Set the prerequisite stat and marks this stat to print at the end of 481 * simulation. 482 * @param prereq The prerequisite stat. 483 * @return A reference to this stat. 484 */ 485 template <class Stat> |
486 Parent & 487 prereq(const Stat &prereq) |
488 { 489 this->statData()->prereq = prereq.statData(); 490 return this->self(); 491 } 492}; 493 494template <class Parent, class Child, template <class Child> class Data> 495class WrapVec : public Wrap<Parent, Child, Data> --- 4 unchanged lines hidden (view full) --- 500 501 /** 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. 507 */ |
508 Parent & 509 subname(int index, const std::string &name) |
510 { 511 std::vector<std::string> &subn = this->statData()->subnames; 512 if (subn.size() <= index) 513 subn.resize(index + 1); 514 subn[index] = name; 515 return this->self(); 516 } 517 518 /** 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. 524 */ |
525 Parent & 526 subdesc(int index, const std::string &desc) |
527 { 528 std::vector<std::string> &subd = this->statData()->subdescs; 529 if (subd.size() <= index) 530 subd.resize(index + 1); 531 subd[index] = desc; 532 533 return this->self(); 534 } 535 536}; 537 538template <class Parent, class Child, template <class Child> class Data> 539class WrapVec2d : public WrapVec<Parent, Child, Data> 540{ 541 public: 542 /** 543 * @warning This makes the assumption that if you're gonna subnames a 2d 544 * vector, you're subnaming across all y 545 */ |
546 Parent & 547 ysubnames(const char **names) |
548 { 549 Data<Child> *data = this->statData(); 550 data->y_subnames.resize(this->y); 551 for (int i = 0; i < this->y; ++i) 552 data->y_subnames[i] = names[i]; 553 return this->self(); 554 } |
555 556 Parent & 557 ysubname(int index, const std::string subname) |
558 { 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(); 563 return this->self(); 564 } 565}; --- 93 unchanged lines hidden (view full) --- 659 AvgStor(Params &p) : current(0), total(0), last(0) { } 660 661 /** 662 * Set the current count to the one provided, update the total and last 663 * set values. 664 * @param val The new count. 665 * @param p The parameters for this storage. 666 */ |
667 void 668 set(Counter val, Params &p) { |
669 total += current * (curTick - last); 670 last = curTick; 671 current = val; 672 } 673 674 /** 675 * Increment the current count by the provided value, calls set. 676 * @param val The amount to increment. --- 15 unchanged lines hidden (view full) --- 692 */ 693 Counter value(const Params &p) const { return current; } 694 695 /** 696 * Return the current average. 697 * @param p The parameters for this storage. 698 * @return The current average. 699 */ |
700 Result 701 result(const Params &p) const |
702 { 703 total += current * (curTick - last); 704 last = curTick; 705 return (Result)(total + current) / (Result)(curTick + 1); 706 } 707 708 /** 709 * Reset stat value to default 710 */ |
711 void 712 reset() |
713 { 714 total = 0; 715 last = curTick; 716 } 717 718 /** 719 * @return true if zero value 720 */ --- 172 unchanged lines hidden (view full) --- 893 private: 894 ProxyData *proxy; 895 896 public: 897 ValueBase() : proxy(NULL) { } 898 ~ValueBase() { if (proxy) delete proxy; } 899 900 template <class T> |
901 void 902 scalar(T &value) |
903 { 904 proxy = new ValueProxy<T>(value); 905 setInit(); 906 } 907 908 template <class T> |
909 void 910 functor(T &func) |
911 { 912 proxy = new FunctorProxy<T>(func); 913 setInit(); 914 } 915 916 Counter value() { return proxy->value(); } 917 Result result() const { return proxy->result(); } 918 Result total() const { return proxy->total(); }; --- 58 unchanged lines hidden (view full) --- 977 : stat(sp.stat), index(sp.index) 978 {} 979 980 /** 981 * Set this proxy equal to the provided one. 982 * @param sp The proxy to copy. 983 * @return A reference to this proxy. 984 */ |
985 const ScalarProxy & 986 operator=(const ScalarProxy &sp) { |
987 stat = sp.stat; 988 index = sp.index; 989 return *this; 990 } 991 992 public: 993 // Common operators for stats 994 /** --- 13 unchanged lines hidden (view full) --- 1008 void operator--(int) { --*this; } 1009 1010 /** 1011 * Set the data value to the given value. This calls the associated storage 1012 * object set function. 1013 * @param v The new value. 1014 */ 1015 template <typename U> |
1016 void 1017 operator=(const U &v) 1018 { 1019 stat->data(index)->set(v, stat->params); 1020 } |
1021 1022 /** 1023 * Increment the stat by the given value. This calls the associated 1024 * storage object inc function. 1025 * @param v The value to add. 1026 */ 1027 template <typename U> |
1028 void 1029 operator+=(const U &v) 1030 { 1031 stat->data(index)->inc(v, stat->params); 1032 } |
1033 1034 /** 1035 * Decrement the stat by the given value. This calls the associated 1036 * storage object dec function. 1037 * @param v The value to substract. 1038 */ 1039 template <typename U> |
1040 void 1041 operator-=(const U &v) 1042 { 1043 stat->data(index)->dec(v, stat->params); 1044 } |
1045 1046 /** 1047 * Return the number of elements, always 1 for a scalar. 1048 * @return 1. 1049 */ 1050 size_t size() const { return 1; } 1051 1052 /** --- 62 unchanged lines hidden (view full) --- 1115 1116 for (int i = 0; i < _size; ++i) 1117 new (&storage[i]) Storage(params); 1118 1119 setInit(); 1120 } 1121 1122 public: |
1123 void 1124 value(VCounter &vec) const |
1125 { 1126 vec.resize(size()); 1127 for (int i = 0; i < size(); ++i) 1128 vec[i] = data(i)->value(params); 1129 } 1130 1131 /** 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. 1134 */ |
1135 void 1136 result(VResult &vec) const |
1137 { 1138 vec.resize(size()); 1139 for (int i = 0; i < size(); ++i) 1140 vec[i] = data(i)->result(params); 1141 } 1142 1143 /** 1144 * Return a total of all entries in this vector. 1145 * @return The total of all vector entries. 1146 */ |
1147 Result 1148 total() const 1149 { |
1150 Result total = 0.0; 1151 for (int i = 0; i < size(); ++i) 1152 total += data(i)->result(params); 1153 return total; 1154 } 1155 1156 /** 1157 * @return the number of elements in this vector. --- 113 unchanged lines hidden (view full) --- 1271 operator=(const VectorProxy &sp) 1272 { 1273 stat = sp.stat; 1274 offset = sp.offset; 1275 len = sp.len; 1276 return *this; 1277 } 1278 |
1279 ScalarProxy 1280 operator[](int index) |
1281 { 1282 assert (index >= 0 && index < size()); 1283 return ScalarProxy<Stat>(stat, offset + index); 1284 } 1285 1286 size_t size() const { return len; } 1287 1288 /** --- 168 unchanged lines hidden (view full) --- 1457 } 1458 1459 /** 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. 1464 */ |
1465 void 1466 sample(Counter val, int number, const Params ¶ms) |
1467 { 1468 if (val < params.min) 1469 underflow += number; 1470 else if (val > params.max) 1471 overflow += number; 1472 else { |
1473 size_t index = std::floor((val - params.min) / params.bucket_size); |
1474 assert(index < size(params)); 1475 cvec[index] += number; 1476 } 1477 1478 if (val < min_val) 1479 min_val = val; 1480 1481 if (val > max_val) --- 12 unchanged lines hidden (view full) --- 1494 */ 1495 size_t size(const Params &) const { return cvec.size(); } 1496 1497 /** 1498 * Returns true if any calls to sample have been made. 1499 * @param params The paramters of the distribution. 1500 * @return True if any values have been sampled. 1501 */ |
1502 bool 1503 zero(const Params ¶ms) const |
1504 { 1505 return samples == Counter(); 1506 } 1507 |
1508 void 1509 update(DistDataData *data, const Params ¶ms) |
1510 { 1511 data->min = params.min; 1512 data->max = params.max; 1513 data->bucket_size = params.bucket_size; 1514 data->size = params.size; 1515 1516 data->min_val = (min_val == CounterLimits::max()) ? 0 : min_val; 1517 data->max_val = (max_val == CounterLimits::min()) ? 0 : max_val; --- 6 unchanged lines hidden (view full) --- 1524 data->sum = sum; 1525 data->squares = squares; 1526 data->samples = samples; 1527 } 1528 1529 /** 1530 * Reset stat value to default 1531 */ |
1532 void 1533 reset() |
1534 { 1535 min_val = CounterLimits::max(); 1536 max_val = CounterLimits::min(); 1537 underflow = 0; 1538 overflow = 0; 1539 1540 int size = cvec.size(); 1541 for (int i = 0; i < size; ++i) --- 37 unchanged lines hidden (view full) --- 1579 /** 1580 * Add a value the given number of times to this running average. 1581 * Update the running sum and sum of squares, increment the number of 1582 * values seen by the given number. 1583 * @param val The value to add. 1584 * @param number The number of times to add the value. 1585 * @param p The parameters of this stat. 1586 */ |
1587 void 1588 sample(Counter val, int number, const Params &p) |
1589 { 1590 Counter value = val * number; 1591 sum += value; 1592 squares += value * value; 1593 samples += number; 1594 } 1595 |
1596 void 1597 update(DistDataData *data, const Params ¶ms) |
1598 { 1599 data->sum = sum; 1600 data->squares = squares; 1601 data->samples = samples; 1602 } 1603 1604 /** 1605 * Return the number of entries in this stat, 1 --- 5 unchanged lines hidden (view full) --- 1611 * Return true if no samples have been added. 1612 * @return True if no samples have been added. 1613 */ 1614 bool zero(const Params &) const { return samples == Counter(); } 1615 1616 /** 1617 * Reset stat value to default 1618 */ |
1619 void 1620 reset() |
1621 { 1622 sum = Counter(); 1623 squares = Counter(); 1624 samples = Counter(); 1625 } 1626}; 1627 1628/** --- 21 unchanged lines hidden (view full) --- 1650 1651 /** 1652 * Add a value to the distribution for the given number of times. 1653 * Update the running sum and sum of squares. 1654 * @param val The value to add. 1655 * @param number The number of times to add the value. 1656 * @param p The paramters of the distribution. 1657 */ |
1658 void 1659 sample(Counter val, int number, const Params &p) |
1660 { 1661 Counter value = val * number; 1662 sum += value; 1663 squares += value * value; 1664 } 1665 |
1666 void 1667 update(DistDataData *data, const Params ¶ms) |
1668 { 1669 data->sum = sum; 1670 data->squares = squares; 1671 data->samples = curTick; 1672 } 1673 1674 /** 1675 * Return the number of entries, in this case 1. 1676 * @return 1. 1677 */ 1678 size_t size(const Params ¶ms) const { return 1; } |
1679 |
1680 /** 1681 * Return true if no samples have been added. 1682 * @return True if the sum is zero. 1683 */ 1684 bool zero(const Params ¶ms) const { return sum == Counter(); } |
1685 |
1686 /** 1687 * Reset stat value to default 1688 */ |
1689 void 1690 reset() |
1691 { 1692 sum = Counter(); 1693 squares = Counter(); 1694 } 1695}; 1696 1697/** 1698 * Implementation of a distribution stat. The type of distribution is --- 14 unchanged lines hidden (view full) --- 1713 /** The parameters for this stat. */ 1714 Params params; 1715 1716 protected: 1717 /** 1718 * Retrieve the storage. 1719 * @return The storage object for this stat. 1720 */ |
1721 Storage * 1722 data() |
1723 { 1724 return reinterpret_cast<Storage *>(storage); 1725 } 1726 1727 /** 1728 * Retrieve a const pointer to the storage. 1729 * @return A const pointer to the storage object for this stat. 1730 */ --- 28 unchanged lines hidden (view full) --- 1759 */ 1760 size_t size() const { return data()->size(params); } 1761 /** 1762 * Return true if no samples have been added. 1763 * @return True if there haven't been any samples. 1764 */ 1765 bool zero() const { return data()->zero(params); } 1766 |
1767 void 1768 update(DistData *base) |
1769 { 1770 base->data.fancy = Storage::fancy; 1771 data()->update(&(base->data), params); 1772 } 1773 1774 /** 1775 * Reset stat value to default 1776 */ --- 134 unchanged lines hidden (view full) --- 1911 DistProxy(Stat *s, int i) 1912 : stat(s), index(i) 1913 {} 1914 1915 DistProxy(const DistProxy &sp) 1916 : stat(sp.stat), index(sp.index) 1917 {} 1918 |
1919 const DistProxy & 1920 operator=(const DistProxy &sp) |
1921 { 1922 stat = sp.stat; 1923 index = sp.index; 1924 return *this; 1925 } 1926 1927 public: 1928 template <typename U> --- 30 unchanged lines hidden (view full) --- 1959} 1960 1961#if 0 1962template <class Storage> 1963Result 1964VectorDistBase<Storage>::total(int index) const 1965{ 1966 int total = 0; |
1967 for (int i = 0; i < x_size(); ++i) |
1968 total += data(i)->result(stat->params); |
1969} 1970#endif 1971 1972////////////////////////////////////////////////////////////////////// 1973// 1974// Formula Details 1975// 1976////////////////////////////////////////////////////////////////////// --- 33 unchanged lines hidden (view full) --- 2010class ScalarStatNode : public Node 2011{ 2012 private: 2013 const ScalarData *data; 2014 mutable VResult vresult; 2015 2016 public: 2017 ScalarStatNode(const ScalarData *d) : data(d), vresult(1) {} |
2018 2019 virtual const VResult & 2020 result() const |
2021 { 2022 vresult[0] = data->result(); 2023 return vresult; 2024 } |
2025 |
2026 virtual Result total() const { return data->result(); }; 2027 2028 virtual size_t size() const { return 1; } 2029 2030 /** 2031 * 2032 */ 2033 virtual std::string str() const { return data->name; } --- 73 unchanged lines hidden (view full) --- 2107class ConstVectorNode : public Node 2108{ 2109 private: 2110 VResult vresult; 2111 2112 public: 2113 ConstVectorNode(const T &s) : vresult(s.begin(), s.end()) {} 2114 const VResult &result() const { return vresult; } |
2115 2116 virtual Result 2117 total() const |
2118 { 2119 int size = this->size(); 2120 Result tmp = 0; 2121 for (int i = 0; i < size; i++) |
2122 tmp += vresult[i]; |
2123 return tmp; 2124 } |
2125 |
2126 virtual size_t size() const { return vresult.size(); } |
2127 virtual std::string 2128 str() const |
2129 { 2130 int size = this->size(); 2131 std::string tmp = "("; 2132 for (int i = 0; i < size; i++) |
2133 tmp += csprintf("%s ",to_string(vresult[i])); |
2134 tmp += ")"; 2135 return tmp; 2136 } 2137}; 2138 2139template <class Op> 2140struct OpString; 2141 --- 38 unchanged lines hidden (view full) --- 2180{ 2181 public: 2182 NodePtr l; 2183 mutable VResult vresult; 2184 2185 public: 2186 UnaryNode(NodePtr &p) : l(p) {} 2187 |
2188 const VResult & 2189 result() const |
2190 { 2191 const VResult &lvec = l->result(); 2192 int size = lvec.size(); 2193 2194 assert(size > 0); 2195 2196 vresult.resize(size); 2197 Op op; 2198 for (int i = 0; i < size; ++i) 2199 vresult[i] = op(lvec[i]); 2200 2201 return vresult; 2202 } 2203 |
2204 Result 2205 total() const |
2206 { 2207 const VResult &vec = this->result(); 2208 Result total = 0; 2209 for (int i = 0; i < size(); i++) 2210 total += vec[i]; 2211 return total; 2212 } 2213 2214 virtual size_t size() const { return l->size(); } 2215 |
2216 virtual std::string 2217 str() const |
2218 { 2219 return OpString<Op>::str() + l->str(); 2220 } 2221}; 2222 2223template <class Op> 2224class BinaryNode : public Node 2225{ 2226 public: 2227 NodePtr l; 2228 NodePtr r; 2229 mutable VResult vresult; 2230 2231 public: 2232 BinaryNode(NodePtr &a, NodePtr &b) : l(a), r(b) {} 2233 |
2234 const VResult & 2235 result() const |
2236 { 2237 Op op; 2238 const VResult &lvec = l->result(); 2239 const VResult &rvec = r->result(); 2240 2241 assert(lvec.size() > 0 && rvec.size() > 0); 2242 2243 if (lvec.size() == 1 && rvec.size() == 1) { --- 14 unchanged lines hidden (view full) --- 2258 vresult.resize(size); 2259 for (int i = 0; i < size; ++i) 2260 vresult[i] = op(lvec[i], rvec[i]); 2261 } 2262 2263 return vresult; 2264 } 2265 |
2266 Result 2267 total() const |
2268 { 2269 const VResult &vec = this->result(); 2270 Result total = 0; 2271 for (int i = 0; i < size(); i++) 2272 total += vec[i]; 2273 return total; 2274 } 2275 |
2276 virtual size_t 2277 size() const 2278 { |
2279 int ls = l->size(); 2280 int rs = r->size(); |
2281 if (ls == 1) { |
2282 return rs; |
2283 } else if (rs == 1) { |
2284 return ls; |
2285 } else { |
2286 assert(ls == rs && "Node vector sizes are not equal"); 2287 return ls; 2288 } 2289 } 2290 |
2291 virtual std::string 2292 str() const |
2293 { 2294 return csprintf("(%s %s %s)", l->str(), OpString<Op>::str(), r->str()); 2295 } 2296}; 2297 2298template <class Op> 2299class SumNode : public Node 2300{ 2301 public: 2302 NodePtr l; 2303 mutable VResult vresult; 2304 2305 public: 2306 SumNode(NodePtr &p) : l(p), vresult(1) {} 2307 |
2308 const VResult & 2309 result() const |
2310 { 2311 const VResult &lvec = l->result(); 2312 int size = lvec.size(); 2313 assert(size > 0); 2314 2315 vresult[0] = 0.0; 2316 2317 Op op; 2318 for (int i = 0; i < size; ++i) 2319 vresult[0] = op(vresult[0], lvec[i]); 2320 2321 return vresult; 2322 } 2323 |
2324 Result 2325 total() const |
2326 { 2327 const VResult &lvec = l->result(); 2328 int size = lvec.size(); 2329 assert(size > 0); 2330 2331 Result vresult = 0.0; 2332 2333 Op op; 2334 for (int i = 0; i < size; ++i) 2335 vresult = op(vresult, lvec[i]); 2336 2337 return vresult; 2338 } 2339 2340 virtual size_t size() const { return 1; } 2341 |
2342 virtual std::string 2343 str() const |
2344 { 2345 return csprintf("total(%s)", l->str()); 2346 } 2347}; 2348 2349 2350////////////////////////////////////////////////////////////////////// 2351// --- 33 unchanged lines hidden (view full) --- 2385 2386class Value : public Wrap<Value, ValueBase, ScalarStatData> 2387{ 2388 public: 2389 /** The base implementation. */ 2390 typedef ValueBase Base; 2391 2392 template <class T> |
2393 Value & 2394 scalar(T &value) |
2395 { 2396 Base::scalar(value); 2397 return *this; 2398 } 2399 2400 template <class T> |
2401 Value & 2402 functor(T &func) |
2403 { 2404 Base::functor(func); 2405 return *this; 2406 } 2407}; 2408 2409/** 2410 * A stat that calculates the per tick average of a value. --- 12 unchanged lines hidden (view full) --- 2423 } 2424 2425 /** 2426 * Sets the stat equal to the given value. Calls the base implementation 2427 * of operator= 2428 * @param v The new value. 2429 */ 2430 template <typename U> |
2431 void 2432 operator=(const U &v) 2433 { 2434 Base::operator=(v); 2435 } |
2436}; 2437 2438/** 2439 * A vector of scalar stats. 2440 * @sa Stat, VectorBase, StatStor 2441 */ 2442template<int N = 0> 2443class Vector : public WrapVec<Vector<N>, VectorBase<StatStor>, VectorStatData> 2444{ 2445 public: 2446 /** The base implementation. */ 2447 typedef ScalarBase<StatStor> Base; 2448 2449 /** 2450 * Set this vector to have the given size. 2451 * @param size The new size. 2452 * @return A reference to this stat. 2453 */ |
2454 Vector & 2455 init(size_t size) 2456 { |
2457 this->doInit(size); 2458 return *this; 2459 } 2460}; 2461 2462/** 2463 * A vector of Average stats. 2464 * @sa Stat, VectorBase, AvgStor 2465 */ 2466template<int N = 0> 2467class AverageVector 2468 : public WrapVec<AverageVector<N>, VectorBase<AvgStor>, VectorStatData> 2469{ 2470 public: 2471 /** 2472 * Set this vector to have the given size. 2473 * @param size The new size. 2474 * @return A reference to this stat. 2475 */ |
2476 AverageVector & 2477 init(size_t size) 2478 { |
2479 this->doInit(size); 2480 return *this; 2481 } 2482}; 2483 2484/** 2485 * A 2-Dimensional vecto of scalar stats. 2486 * @sa Stat, Vector2dBase, StatStor 2487 */ 2488template<int N = 0> 2489class Vector2d 2490 : public WrapVec2d<Vector2d<N>, Vector2dBase<StatStor>, Vector2dStatData> 2491{ 2492 public: |
2493 Vector2d & 2494 init(size_t x, size_t y) 2495 { |
2496 this->doInit(x, y); 2497 return *this; 2498 } 2499}; 2500 2501/** 2502 * A simple distribution stat. 2503 * @sa Stat, DistBase, DistStor --- 11 unchanged lines hidden (view full) --- 2515 public: 2516 /** 2517 * Set the parameters of this distribution. @sa DistStor::Params 2518 * @param min The minimum value of the distribution. 2519 * @param max The maximum value of the distribution. 2520 * @param bkt The number of values in each bucket. 2521 * @return A reference to this distribution. 2522 */ |
2523 Distribution & 2524 init(Counter min, Counter max, Counter bkt) 2525 { |
2526 this->params.min = min; 2527 this->params.max = max; 2528 this->params.bucket_size = bkt; 2529 this->params.size = (int)rint((max - min) / bkt + 1.0); 2530 this->doInit(); 2531 return *this; 2532 } 2533}; --- 11 unchanged lines hidden (view full) --- 2545 typedef DistBase<DistStor> Base; 2546 /** The parameter type. */ 2547 typedef DistStor::Params Params; 2548 2549 public: 2550 /** 2551 * Construct and initialize this distribution. 2552 */ |
2553 StandardDeviation() 2554 { |
2555 this->doInit(); 2556 } 2557}; 2558 2559/** 2560 * Calculates the per tick mean and variance of the samples. 2561 * @sa Stat, DistBase, AvgFancy 2562 */ --- 37 unchanged lines hidden (view full) --- 2600 /** 2601 * Initialize storage and parameters for this distribution. 2602 * @param size The size of the vector (the number of distributions). 2603 * @param min The minimum value of the distribution. 2604 * @param max The maximum value of the distribution. 2605 * @param bkt The number of values in each bucket. 2606 * @return A reference to this distribution. 2607 */ |
2608 VectorDistribution & 2609 init(int size, Counter min, Counter max, Counter bkt) 2610 { |
2611 this->params.min = min; 2612 this->params.max = max; 2613 this->params.bucket_size = bkt; 2614 this->params.size = (int)rint((max - min) / bkt + 1.0); 2615 this->doInit(size); 2616 return *this; 2617 } 2618}; --- 15 unchanged lines hidden (view full) --- 2634 typedef DistStor::Params Params; 2635 2636 public: 2637 /** 2638 * Initialize storage for this distribution. 2639 * @param size The size of the vector. 2640 * @return A reference to this distribution. 2641 */ |
2642 VectorStandardDeviation & 2643 init(int size) 2644 { |
2645 this->doInit(size); 2646 return *this; 2647 } 2648}; 2649 2650/** 2651 * This is a vector of AverageDeviation stats. 2652 * @sa Stat, VectorDistBase, AvgFancy --- 11 unchanged lines hidden (view full) --- 2664 typedef DistStor::Params Params; 2665 2666 public: 2667 /** 2668 * Initialize storage for this distribution. 2669 * @param size The size of the vector. 2670 * @return A reference to this distribution. 2671 */ |
2672 VectorAverageDeviation & 2673 init(int size) 2674 { |
2675 this->doInit(size); 2676 return *this; 2677 } 2678}; 2679 2680/** 2681 * A formula for statistics that is calculated when printed. A formula is 2682 * stored as a tree of Nodes that represent the equation to calculate. --- 70 unchanged lines hidden (view full) --- 2753 2754 public: 2755 FormulaStatData(Stat &stat) : s(stat) {} 2756 2757 virtual bool zero() const { return s.zero(); } 2758 virtual void reset() { s.reset(); } 2759 2760 virtual size_t size() const { return s.size(); } |
2761 2762 virtual const VResult & 2763 result() const |
2764 { 2765 s.result(vec); 2766 return vec; 2767 } 2768 virtual Result total() const { return s.total(); } 2769 virtual VCounter &value() const { return cvec; } |
2770 2771 virtual void 2772 visit(Visit &visitor) |
2773 { 2774 update(); 2775 s.update(this); 2776 visitor.visit(*this); 2777 } |
2778 |
2779 virtual std::string str() const { return s.str(); } 2780}; 2781 2782class Temp; 2783class Formula 2784 : public WrapVec<Formula, 2785 FormulaBase, 2786 FormulaStatData> --- 68 unchanged lines hidden (view full) --- 2855 2856 public: 2857 /** 2858 * Create a new ScalarStatNode. 2859 * @param s The ScalarStat to place in a node. 2860 */ 2861 template <int N> 2862 Temp(const Scalar<N> &s) |
2863 : node(new ScalarStatNode(s.statData())) 2864 { } |
2865 2866 /** 2867 * Create a new ScalarStatNode. 2868 * @param s The ScalarStat to place in a node. 2869 */ 2870 Temp(const Value &s) |
2871 : node(new ScalarStatNode(s.statData())) 2872 { } |
2873 2874 /** 2875 * Create a new ScalarStatNode. 2876 * @param s The ScalarStat to place in a node. 2877 */ 2878 template <int N> 2879 Temp(const Average<N> &s) |
2880 : node(new ScalarStatNode(s.statData())) 2881 { } |
2882 2883 /** 2884 * Create a new VectorStatNode. 2885 * @param s The VectorStat to place in a node. 2886 */ 2887 template <int N> 2888 Temp(const Vector<N> &s) |
2889 : node(new VectorStatNode(s.statData())) 2890 { } |
2891 2892 /** 2893 * 2894 */ 2895 Temp(const Formula &f) |
2896 : node(new FormulaNode(f)) 2897 { } |
2898 2899 /** 2900 * Create a new ScalarProxyNode. 2901 * @param p The ScalarProxy to place in a node. 2902 */ 2903 template <class Stat> 2904 Temp(const ScalarProxy<Stat> &p) |
2905 : node(new ScalarProxyNode 2906 { } |
2907 2908 /** 2909 * Create a ConstNode 2910 * @param value The value of the const node. 2911 */ 2912 Temp(signed char value) |
2913 : node(new ConstNode 2914 { } |
2915 2916 /** 2917 * Create a ConstNode 2918 * @param value The value of the const node. 2919 */ 2920 Temp(unsigned char value) |
2921 : node(new ConstNode 2922 { } |
2923 2924 /** 2925 * Create a ConstNode 2926 * @param value The value of the const node. 2927 */ 2928 Temp(signed short value) |
2929 : node(new ConstNode 2930 { } |
2931 2932 /** 2933 * Create a ConstNode 2934 * @param value The value of the const node. 2935 */ 2936 Temp(unsigned short value) |
2937 : node(new ConstNode 2938 { } |
2939 2940 /** 2941 * Create a ConstNode 2942 * @param value The value of the const node. 2943 */ 2944 Temp(signed int value) |
2945 : node(new ConstNode 2946 { } |
2947 2948 /** 2949 * Create a ConstNode 2950 * @param value The value of the const node. 2951 */ 2952 Temp(unsigned int value) |
2953 : node(new ConstNode 2954 { } |
2955 2956 /** 2957 * Create a ConstNode 2958 * @param value The value of the const node. 2959 */ 2960 Temp(signed long value) |
2961 : node(new ConstNode 2962 { } |
2963 2964 /** 2965 * Create a ConstNode 2966 * @param value The value of the const node. 2967 */ 2968 Temp(unsigned long value) |
2969 : node(new ConstNode 2970 { } |
2971 2972 /** 2973 * Create a ConstNode 2974 * @param value The value of the const node. 2975 */ 2976 Temp(signed long long value) |
2977 : node(new ConstNode 2978 { } |
2979 2980 /** 2981 * Create a ConstNode 2982 * @param value The value of the const node. 2983 */ 2984 Temp(unsigned long long value) |
2985 : node(new ConstNode 2986 { } |
2987 2988 /** 2989 * Create a ConstNode 2990 * @param value The value of the const node. 2991 */ 2992 Temp(float value) |
2993 : node(new ConstNode 2994 { } |
2995 2996 /** 2997 * Create a ConstNode 2998 * @param value The value of the const node. 2999 */ 3000 Temp(double value) |
3001 : node(new ConstNode 3002 { } |
3003}; 3004 3005 3006/** 3007 * @} 3008 */ 3009 3010void check(); --- 57 unchanged lines hidden --- |