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; --- 12 unchanged lines hidden (view full) --- 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. 27 * 28 * Authors: Nathan Binkert |
29 */ 30 31/** @file 32 * Declaration of Statistics objects. 33 */ 34 35/** 36* @todo --- 17 unchanged lines hidden (view full) --- 54#endif 55#include <cmath> 56#include <functional> 57#include <iosfwd> 58#include <limits> 59#include <string> 60#include <vector> 61 |
62#include "base/cast.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" --- 9 unchanged lines hidden (view full) --- 80typedef std::numeric_limits<Counter> CounterLimits; 81 82/* Contains the statistic implementation details */ 83////////////////////////////////////////////////////////////////////// 84// 85// Statistics Framework Base classes 86// 87////////////////////////////////////////////////////////////////////// |
88class Info |
89{ |
90 public: |
91 /** The name of the stat. */ 92 std::string name; 93 /** The description of the stat. */ 94 std::string desc; 95 /** The formatting flags. */ 96 StatFlags flags; 97 /** The display precision. */ 98 int precision; 99 /** A pointer to a prerequisite Stat. */ |
100 const Info *prereq; |
101 /** 102 * A unique stat ID for each stat in the simulator. 103 * Can be used externally for lookups as well as for debugging. 104 */ 105 int id; 106 |
107 public: 108 Info(); 109 virtual ~Info(); |
110 111 /** 112 * Reset the corresponding stat to the default state. 113 */ 114 virtual void reset() = 0; 115 116 /** 117 * @return true if this stat has a value and satisfies its --- 17 unchanged lines hidden (view full) --- 135 /** 136 * Checks if the first stat's name is alphabetically less than the second. 137 * This function breaks names up at periods and considers each subname 138 * separately. 139 * @param stat1 The first stat. 140 * @param stat2 The second stat. 141 * @return stat1's name is alphabetically before stat2's 142 */ |
143 static bool less(Info *stat1, Info *stat2); |
144}; 145 |
146class ScalarInfoBase : public Info |
147{ 148 public: 149 virtual Counter value() const = 0; 150 virtual Result result() const = 0; 151 virtual Result total() const = 0; 152 virtual void visit(Visit &visitor) { visitor.visit(*this); } 153}; 154 155template <class Stat> |
156class ScalarInfo : public ScalarInfoBase |
157{ 158 protected: 159 Stat &s; 160 161 public: |
162 ScalarInfo(Stat &stat) : s(stat) {} |
163 164 virtual bool check() const { return s.check(); } 165 virtual Counter value() const { return s.value(); } 166 virtual Result result() const { return s.result(); } 167 virtual Result total() const { return s.total(); } 168 virtual void reset() { s.reset(); } 169 virtual bool zero() const { return s.zero(); } 170}; 171 |
172class VectorInfoBase : public Info |
173{ |
174 public: |
175 /** Names and descriptions of subfields. */ 176 mutable std::vector<std::string> subnames; 177 mutable std::vector<std::string> subdescs; 178 |
179 public: |
180 virtual size_type size() const = 0; 181 virtual const VCounter &value() const = 0; 182 virtual const VResult &result() const = 0; 183 virtual Result total() const = 0; 184 185 void 186 update() 187 { --- 4 unchanged lines hidden (view full) --- 192 193 if (subdescs.size() < s) 194 subdescs.resize(s); 195 } 196 } 197}; 198 199template <class Stat> |
200class VectorInfo : public VectorInfoBase |
201{ 202 protected: 203 Stat &s; 204 mutable VCounter cvec; 205 mutable VResult rvec; 206 207 public: |
208 VectorInfo(Stat &stat) : s(stat) {} |
209 210 virtual bool check() const { return s.check(); } 211 virtual bool zero() const { return s.zero(); } 212 virtual void reset() { s.reset(); } 213 214 virtual size_type size() const { return s.size(); } 215 216 virtual VCounter & --- 16 unchanged lines hidden (view full) --- 233 visit(Visit &visitor) 234 { 235 update(); 236 s.update(this); 237 visitor.visit(*this); 238 } 239}; 240 |
241struct DistData |
242{ 243 Counter min_val; 244 Counter max_val; 245 Counter underflow; 246 Counter overflow; 247 VCounter cvec; 248 Counter sum; 249 Counter squares; 250 Counter samples; 251 252 Counter min; 253 Counter max; 254 Counter bucket_size; 255 size_type size; 256 bool fancy; 257}; 258 |
259class DistInfoBase : public Info |
260{ |
261 public: |
262 /** Local storage for the entry values, used for printing. */ |
263 DistData data; |
264}; 265 266template <class Stat> |
267class DistInfo : public DistInfoBase |
268{ 269 protected: 270 Stat &s; 271 272 public: |
273 DistInfo(Stat &stat) : s(stat) {} |
274 275 virtual bool check() const { return s.check(); } 276 virtual void reset() { s.reset(); } 277 virtual bool zero() const { return s.zero(); } 278 279 virtual void 280 visit(Visit &visitor) 281 { 282 s.update(this); 283 visitor.visit(*this); 284 } 285}; 286 |
287class VectorDistInfoBase : public Info |
288{ |
289 public: 290 std::vector<DistData> data; |
291 292 /** Names and descriptions of subfields. */ 293 mutable std::vector<std::string> subnames; 294 mutable std::vector<std::string> subdescs; 295 |
296 protected: |
297 /** Local storage for the entry values, used for printing. */ 298 mutable VResult rvec; 299 |
300 public: |
301 virtual size_type size() const = 0; 302 303 void 304 update() 305 { 306 size_type s = size(); 307 if (subnames.size() < s) 308 subnames.resize(s); 309 310 if (subdescs.size() < s) 311 subdescs.resize(s); 312 } 313}; 314 315template <class Stat> |
316class VectorDistInfo : public VectorDistInfoBase |
317{ 318 protected: 319 Stat &s; 320 321 public: |
322 VectorDistInfo(Stat &stat) : s(stat) {} |
323 324 virtual bool check() const { return s.check(); } 325 virtual void reset() { s.reset(); } 326 virtual size_type size() const { return s.size(); } 327 virtual bool zero() const { return s.zero(); } 328 329 virtual void 330 visit(Visit &visitor) 331 { 332 update(); 333 s.update(this); 334 visitor.visit(*this); 335 } 336}; 337 |
338class Vector2dInfoBase : public Info |
339{ |
340 public: |
341 /** Names and descriptions of subfields. */ 342 std::vector<std::string> subnames; 343 std::vector<std::string> subdescs; 344 std::vector<std::string> y_subnames; 345 346 /** Local storage for the entry values, used for printing. */ 347 mutable VCounter cvec; 348 mutable size_type x; 349 mutable size_type y; 350 |
351 public: |
352 void 353 update() 354 { 355 if (subnames.size() < x) 356 subnames.resize(x); 357 } 358}; 359 360template <class Stat> |
361class Vector2dInfo : public Vector2dInfoBase |
362{ 363 protected: 364 Stat &s; 365 366 public: |
367 Vector2dInfo(Stat &stat) : s(stat) {} |
368 369 virtual bool check() const { return s.check(); } 370 virtual void reset() { s.reset(); } 371 virtual bool zero() const { return s.zero(); } 372 373 virtual void 374 visit(Visit &visitor) 375 { 376 update(); 377 s.update(this); 378 visitor.visit(*this); 379 } 380}; 381 |
382class InfoAccess |
383{ 384 protected: |
385 Info *find() const; 386 /** Set up an info class for this statistic */ 387 void setInfo(Info *info); 388 /** Save Storage class parameters if any */ |
389 void setInit(); |
390 391 Info *info(); 392 const Info *info() const; |
393}; 394 |
395template <class Parent, class Child, template <class> class Info> |
396class Wrap : public Child 397{ |
398 public: 399 typedef Parent ParentType; 400 typedef Child ChildType; 401 typedef Info<Child> InfoType; 402 |
403 protected: 404 Parent &self() { return *reinterpret_cast<Parent *>(this); } 405 406 protected: |
407 InfoType * 408 info() |
409 { |
410 return safe_cast<InfoType *>(InfoAccess::info()); |
411 } 412 413 public: |
414 const InfoType * 415 info() const |
416 { |
417 return safe_cast<const InfoType *>(InfoAccess::info()); |
418 } 419 420 protected: 421 /** 422 * Copy constructor, copies are not allowed. 423 */ 424 Wrap(const Wrap &stat); 425 426 /** 427 * Can't copy stats. 428 */ 429 void operator=(const Wrap &); 430 431 public: 432 Wrap() 433 { |
434 this->setInfo(new InfoType(*this)); |
435 } 436 437 /** 438 * Set the name and marks this stat to print at the end of simulation. 439 * @param name The new name. 440 * @return A reference to this stat. 441 */ 442 Parent & 443 name(const std::string &_name) 444 { |
445 InfoType *info = this->info(); 446 info->name = _name; 447 info->flags |= print; |
448 return this->self(); 449 } 450 451 /** 452 * Set the description and marks this stat to print at the end of 453 * simulation. 454 * @param desc The new description. 455 * @return A reference to this stat. 456 */ 457 Parent & 458 desc(const std::string &_desc) 459 { |
460 this->info()->desc = _desc; |
461 return this->self(); 462 } 463 464 /** 465 * Set the precision and marks this stat to print at the end of simulation. 466 * @param p The new precision 467 * @return A reference to this stat. 468 */ 469 Parent & 470 precision(int _precision) 471 { |
472 this->info()->precision = _precision; |
473 return this->self(); 474 } 475 476 /** 477 * Set the flags and marks this stat to print at the end of simulation. 478 * @param f The new flags. 479 * @return A reference to this stat. 480 */ 481 Parent & 482 flags(StatFlags _flags) 483 { |
484 this->info()->flags |= _flags; |
485 return this->self(); 486 } 487 488 /** 489 * Set the prerequisite stat and marks this stat to print at the end of 490 * simulation. 491 * @param prereq The prerequisite stat. 492 * @return A reference to this stat. 493 */ 494 template <class Stat> 495 Parent & 496 prereq(const Stat &prereq) 497 { |
498 this->info()->prereq = prereq.info(); |
499 return this->self(); 500 } 501}; 502 |
503template <class Parent, class Child, template <class Child> class Info> 504class WrapVec : public Wrap<Parent, Child, Info> |
505{ 506 public: |
507 typedef Parent ParentType; 508 typedef Child ChildType; 509 typedef Info<Child> InfoType; 510 511 public: |
512 // The following functions are specific to vectors. If you use them 513 // in a non vector context, you will get a nice compiler error! 514 515 /** 516 * Set the subfield name for the given index, and marks this stat to print 517 * at the end of simulation. 518 * @param index The subfield index. 519 * @param name The new name of the subfield. 520 * @return A reference to this stat. 521 */ 522 Parent & 523 subname(off_type index, const std::string &name) 524 { |
525 std::vector<std::string> &subn = this->info()->subnames; |
526 if (subn.size() <= index) 527 subn.resize(index + 1); 528 subn[index] = name; 529 return this->self(); 530 } 531 532 /** 533 * Set the subfield description for the given index and marks this stat to 534 * print at the end of simulation. 535 * @param index The subfield index. 536 * @param desc The new description of the subfield 537 * @return A reference to this stat. 538 */ 539 Parent & 540 subdesc(off_type index, const std::string &desc) 541 { |
542 std::vector<std::string> &subd = this->info()->subdescs; |
543 if (subd.size() <= index) 544 subd.resize(index + 1); 545 subd[index] = desc; 546 547 return this->self(); 548 } 549 550}; 551 |
552template <class Parent, class Child, template <class Child> class Info> 553class WrapVec2d : public WrapVec<Parent, Child, Info> |
554{ 555 public: |
556 typedef Parent ParentType; 557 typedef Child ChildType; 558 typedef Info<Child> InfoType; 559 560 public: |
561 /** 562 * @warning This makes the assumption that if you're gonna subnames a 2d 563 * vector, you're subnaming across all y 564 */ 565 Parent & 566 ysubnames(const char **names) 567 { |
568 InfoType *info = this->info(); 569 info->y_subnames.resize(this->y); |
570 for (off_type i = 0; i < this->y; ++i) |
571 info->y_subnames[i] = names[i]; |
572 return this->self(); 573 } 574 575 Parent & 576 ysubname(off_type index, const std::string subname) 577 { |
578 InfoType *info = this->info(); |
579 assert(index < this->y); |
580 info->y_subnames.resize(this->y); 581 info->y_subnames[index] = subname.c_str(); |
582 return this->self(); 583 } 584}; 585 586////////////////////////////////////////////////////////////////////// 587// 588// Simple Statistics 589// 590////////////////////////////////////////////////////////////////////// 591 592/** 593 * Templatized storage and interface for a simple scalar stat. 594 */ |
595class StatStor |
596{ 597 public: 598 /** The paramaters for this storage type, none for a scalar. */ 599 struct Params { }; 600 601 private: 602 /** The statistic value. */ 603 Counter data; --- 48 unchanged lines hidden (view full) --- 652 653/** 654 * Templatized storage and interface to a per-tick average stat. This keeps 655 * a current count and updates a total (count * ticks) when this count 656 * changes. This allows the quick calculation of a per tick count of the item 657 * being watched. This is good for keeping track of residencies in structures 658 * among other things. 659 */ |
660class AvgStor |
661{ 662 public: 663 /** The paramaters for this storage type */ 664 struct Params { }; 665 666 private: 667 /** The current count. */ 668 Counter current; --- 10 unchanged lines hidden (view full) --- 679 680 /** 681 * Set the current count to the one provided, update the total and last 682 * set values. 683 * @param val The new count. 684 * @param p The parameters for this storage. 685 */ 686 void |
687 set(Counter val, Params &p) 688 { |
689 total += current * (curTick - last); 690 last = curTick; 691 current = val; 692 } 693 694 /** 695 * Increment the current count by the provided value, calls set. 696 * @param val The amount to increment. --- 44 unchanged lines hidden (view full) --- 741 bool zero() const { return total == 0.0; } 742}; 743 744/** 745 * Implementation of a scalar stat. The type of stat is determined by the 746 * Storage template. 747 */ 748template <class Stor> |
749class ScalarBase : public InfoAccess |
750{ 751 public: 752 typedef Stor Storage; 753 754 /** Define the params of the storage class. */ 755 typedef typename Storage::Params Params; 756 757 protected: --- 108 unchanged lines hidden (view full) --- 866 Result result() { return data()->result(params); } 867 868 Result total() { return result(); } 869 870 bool zero() { return result() == 0.0; } 871 872}; 873 |
874class ProxyInfo : public ScalarInfoBase |
875{ 876 public: 877 virtual void visit(Visit &visitor) { visitor.visit(*this); } 878 virtual std::string str() const { return to_string(value()); } 879 virtual size_type size() const { return 1; } 880 virtual bool zero() const { return value() == 0; } 881 virtual bool check() const { return true; } 882 virtual void reset() { } 883}; 884 885template <class T> |
886class ValueProxy : public ProxyInfo |
887{ 888 private: 889 T *scalar; 890 891 public: 892 ValueProxy(T &val) : scalar(&val) {} 893 virtual Counter value() const { return *scalar; } 894 virtual Result result() const { return *scalar; } 895 virtual Result total() const { return *scalar; } 896}; 897 898template <class T> |
899class FunctorProxy : public ProxyInfo |
900{ 901 private: 902 T *functor; 903 904 public: 905 FunctorProxy(T &func) : functor(&func) {} 906 virtual Counter value() const { return (*functor)(); } 907 virtual Result result() const { return (*functor)(); } 908 virtual Result total() const { return (*functor)(); } 909}; 910 |
911class ValueBase : public InfoAccess |
912{ 913 private: |
914 ProxyInfo *proxy; |
915 916 public: 917 ValueBase() : proxy(NULL) { } 918 ~ValueBase() { if (proxy) delete proxy; } 919 920 template <class T> 921 void 922 scalar(T &value) --- 75 unchanged lines hidden (view full) --- 998 {} 999 1000 /** 1001 * Set this proxy equal to the provided one. 1002 * @param sp The proxy to copy. 1003 * @return A reference to this proxy. 1004 */ 1005 const ScalarProxy & |
1006 operator=(const ScalarProxy &sp) 1007 { |
1008 stat = sp.stat; 1009 index = sp.index; 1010 return *this; 1011 } 1012 1013 public: 1014 // Common operators for stats 1015 /** --- 58 unchanged lines hidden (view full) --- 1074 * This stat has no state. Nothing to reset 1075 */ 1076 void reset() { } 1077 1078 public: 1079 std::string 1080 str() const 1081 { |
1082 return csprintf("%s[%d]", stat->info()->name, index); |
1083 } 1084}; 1085 1086/** 1087 * Implementation of a vector of stats. The type of stat is determined by the 1088 * Storage class. @sa ScalarBase 1089 */ 1090template <class Stor> |
1091class VectorBase : public InfoAccess |
1092{ 1093 public: 1094 typedef Stor Storage; 1095 1096 /** Define the params of the storage class. */ 1097 typedef typename Storage::Params Params; 1098 1099 /** Proxy type */ --- 123 unchanged lines hidden (view full) --- 1223 */ 1224 Proxy 1225 operator[](off_type index) 1226 { 1227 assert (index >= 0 && index < size()); 1228 return Proxy(this, index); 1229 } 1230 |
1231 void update(Info *data) {} |
1232}; 1233 1234template <class Stat> 1235class VectorProxy 1236{ 1237 private: 1238 Stat *stat; 1239 off_type offset; --- 68 unchanged lines hidden (view full) --- 1308 1309 /** 1310 * This stat has no state. Nothing to reset. 1311 */ 1312 void reset() { } 1313}; 1314 1315template <class Stor> |
1316class Vector2dBase : public InfoAccess |
1317{ 1318 public: 1319 typedef Stor Storage; 1320 typedef typename Storage::Params Params; 1321 typedef VectorProxy<Vector2dBase<Storage> > Proxy; 1322 friend class ScalarProxy<Vector2dBase<Storage> >; 1323 friend class VectorProxy<Vector2dBase<Storage> >; 1324 --- 9 unchanged lines hidden (view full) --- 1334 const Storage *data(off_type index) const { return &storage[index]; } 1335 1336 void 1337 doInit(size_type _x, size_type _y) 1338 { 1339 assert(_x > 0 && _y > 0 && "sizes must be positive!"); 1340 assert(!storage && "already initialized"); 1341 |
1342 Vector2dInfoBase *info = dynamic_cast<Vector2dInfoBase *>(find()); |
1343 1344 x = _x; 1345 y = _y; |
1346 info->x = _x; 1347 info->y = _y; |
1348 _size = x * y; 1349 1350 char *ptr = new char[_size * sizeof(Storage)]; 1351 storage = reinterpret_cast<Storage *>(ptr); 1352 1353 for (off_type i = 0; i < _size; ++i) 1354 new (&storage[i]) Storage(params); 1355 --- 11 unchanged lines hidden (view full) --- 1367 return; 1368 1369 for (off_type i = 0; i < _size; ++i) 1370 data(i)->~Storage(); 1371 delete [] reinterpret_cast<char *>(storage); 1372 } 1373 1374 void |
1375 update(Vector2dInfoBase *newinfo) |
1376 { 1377 size_type size = this->size(); |
1378 newinfo->cvec.resize(size); |
1379 for (off_type i = 0; i < size; ++i) |
1380 newinfo->cvec[i] = data(i)->value(); |
1381 } 1382 1383 std::string ysubname(off_type i) const { return (*this->y_subnames)[i]; } 1384 1385 Proxy 1386 operator[](off_type index) 1387 { 1388 off_type offset = index * y; --- 41 unchanged lines hidden (view full) --- 1430// 1431// Non formula statistics 1432// 1433////////////////////////////////////////////////////////////////////// 1434 1435/** 1436 * Templatized storage and interface for a distrbution stat. 1437 */ |
1438class DistStor |
1439{ 1440 public: 1441 /** The parameters for a distribution stat. */ 1442 struct Params 1443 { 1444 /** The minimum value to track. */ 1445 Counter min; 1446 /** The maximum value to track. */ --- 76 unchanged lines hidden (view full) --- 1523 */ 1524 bool 1525 zero(const Params ¶ms) const 1526 { 1527 return samples == Counter(); 1528 } 1529 1530 void |
1531 update(DistData *data, const Params ¶ms) |
1532 { 1533 data->min = params.min; 1534 data->max = params.max; 1535 data->bucket_size = params.bucket_size; 1536 data->size = params.size; 1537 1538 data->min_val = (min_val == CounterLimits::max()) ? 0 : min_val; 1539 data->max_val = (max_val == CounterLimits::min()) ? 0 : max_val; --- 28 unchanged lines hidden (view full) --- 1568 samples = Counter(); 1569 } 1570}; 1571 1572/** 1573 * Templatized storage and interface for a distribution that calculates mean 1574 * and variance. 1575 */ |
1576class FancyStor |
1577{ 1578 public: 1579 /** 1580 * No paramters for this storage. 1581 */ 1582 struct Params {}; 1583 enum { fancy = true }; 1584 --- 26 unchanged lines hidden (view full) --- 1611 { 1612 Counter value = val * number; 1613 sum += value; 1614 squares += value * value; 1615 samples += number; 1616 } 1617 1618 void |
1619 update(DistData *data, const Params ¶ms) |
1620 { 1621 data->sum = sum; 1622 data->squares = squares; 1623 data->samples = samples; 1624 } 1625 1626 /** 1627 * Return the number of entries in this stat, 1 --- 18 unchanged lines hidden (view full) --- 1646 samples = Counter(); 1647 } 1648}; 1649 1650/** 1651 * Templatized storage for distribution that calculates per tick mean and 1652 * variance. 1653 */ |
1654class AvgFancy |
1655{ 1656 public: 1657 /** No parameters for this storage. */ 1658 struct Params {}; 1659 enum { fancy = true }; 1660 1661 private: 1662 /** Current total. */ --- 18 unchanged lines hidden (view full) --- 1681 sample(Counter val, int number, const Params &p) 1682 { 1683 Counter value = val * number; 1684 sum += value; 1685 squares += value * value; 1686 } 1687 1688 void |
1689 update(DistData *data, const Params ¶ms) |
1690 { 1691 data->sum = sum; 1692 data->squares = squares; 1693 data->samples = curTick; 1694 } 1695 1696 /** 1697 * Return the number of entries, in this case 1. --- 18 unchanged lines hidden (view full) --- 1716 } 1717}; 1718 1719/** 1720 * Implementation of a distribution stat. The type of distribution is 1721 * determined by the Storage template. @sa ScalarBase 1722 */ 1723template <class Stor> |
1724class DistBase : public InfoAccess |
1725{ 1726 public: 1727 typedef Stor Storage; 1728 /** Define the params of the storage class. */ 1729 typedef typename Storage::Params Params; 1730 1731 protected: 1732 /** The storage for this stat. */ --- 49 unchanged lines hidden (view full) --- 1782 size_type size() const { return data()->size(params); } 1783 /** 1784 * Return true if no samples have been added. 1785 * @return True if there haven't been any samples. 1786 */ 1787 bool zero() const { return data()->zero(params); } 1788 1789 void |
1790 update(DistInfoBase *base) |
1791 { 1792 base->data.fancy = Storage::fancy; 1793 data()->update(&(base->data), params); 1794 } 1795 1796 /** 1797 * Reset stat value to default 1798 */ --- 9 unchanged lines hidden (view full) --- 1808 return true; 1809 } 1810}; 1811 1812template <class Stat> 1813class DistProxy; 1814 1815template <class Stor> |
1816class VectorDistBase : public InfoAccess |
1817{ 1818 public: 1819 typedef Stor Storage; 1820 typedef typename Storage::Params Params; 1821 typedef DistProxy<VectorDistBase<Storage> > Proxy; 1822 friend class DistProxy<VectorDistBase<Storage> >; 1823 1824 protected: --- 77 unchanged lines hidden (view full) --- 1902 1903 bool 1904 check() 1905 { 1906 return storage != NULL; 1907 } 1908 1909 void |
1910 update(VectorDistInfoBase *base) |
1911 { 1912 size_type size = this->size(); 1913 base->data.resize(size); 1914 for (off_type i = 0; i < size; ++i) { 1915 base->data[i].fancy = Storage::fancy; 1916 data(i)->update(&(base->data[i]), params); 1917 } 1918 } --- 108 unchanged lines hidden (view full) --- 2027}; 2028 2029/** Reference counting pointer to a function Node. */ 2030typedef RefCountingPtr<Node> NodePtr; 2031 2032class ScalarStatNode : public Node 2033{ 2034 private: |
2035 const ScalarInfoBase *data; |
2036 mutable VResult vresult; 2037 2038 public: |
2039 ScalarStatNode(const ScalarInfoBase *d) : data(d), vresult(1) {} |
2040 2041 virtual const VResult & 2042 result() const 2043 { 2044 vresult[0] = data->result(); 2045 return vresult; 2046 } 2047 --- 46 unchanged lines hidden (view full) --- 2094 { 2095 return proxy.str(); 2096 } 2097}; 2098 2099class VectorStatNode : public Node 2100{ 2101 private: |
2102 const VectorInfoBase *data; |
2103 2104 public: |
2105 VectorStatNode(const VectorInfoBase *d) : data(d) { } |
2106 virtual const VResult &result() const { return data->result(); } 2107 virtual Result total() const { return data->total(); }; 2108 2109 virtual size_type size() const { return data->size(); } 2110 2111 virtual std::string str() const { return data->name; } 2112}; 2113 --- 266 unchanged lines hidden (view full) --- 2380 * @{ 2381 */ 2382 2383/** 2384 * This is a simple scalar statistic, like a counter. 2385 * @sa Stat, ScalarBase, StatStor 2386 */ 2387template<int N = 0> |
2388class Scalar : public Wrap<Scalar<N>, ScalarBase<StatStor>, ScalarInfo> |
2389{ 2390 public: 2391 /** The base implementation. */ 2392 typedef ScalarBase<StatStor> Base; 2393 2394 Scalar() 2395 { 2396 this->doInit(); 2397 } 2398 2399 /** 2400 * Sets the stat equal to the given value. Calls the base implementation 2401 * of operator= 2402 * @param v The new value. 2403 */ 2404 template <typename U> 2405 void operator=(const U &v) { Base::operator=(v); } 2406}; 2407 |
2408class Value : public Wrap<Value, ValueBase, ScalarInfo> |
2409{ 2410 public: 2411 /** The base implementation. */ 2412 typedef ValueBase Base; 2413 2414 template <class T> 2415 Value & 2416 scalar(T &value) --- 11 unchanged lines hidden (view full) --- 2428 } 2429}; 2430 2431/** 2432 * A stat that calculates the per tick average of a value. 2433 * @sa Stat, ScalarBase, AvgStor 2434 */ 2435template<int N = 0> |
2436class Average : public Wrap<Average<N>, ScalarBase<AvgStor>, ScalarInfo> |
2437{ 2438 public: 2439 /** The base implementation. */ 2440 typedef ScalarBase<AvgStor> Base; 2441 2442 Average() 2443 { 2444 this->doInit(); --- 12 unchanged lines hidden (view full) --- 2457 } 2458}; 2459 2460/** 2461 * A vector of scalar stats. 2462 * @sa Stat, VectorBase, StatStor 2463 */ 2464template<int N = 0> |
2465class Vector : public WrapVec<Vector<N>, VectorBase<StatStor>, VectorInfo> |
2466{ 2467 public: 2468 /** The base implementation. */ 2469 typedef ScalarBase<StatStor> Base; 2470 2471 /** 2472 * Set this vector to have the given size. 2473 * @param size The new size. --- 8 unchanged lines hidden (view full) --- 2482}; 2483 2484/** 2485 * A vector of Average stats. 2486 * @sa Stat, VectorBase, AvgStor 2487 */ 2488template<int N = 0> 2489class AverageVector |
2490 : public WrapVec<AverageVector<N>, VectorBase<AvgStor>, VectorInfo> |
2491{ 2492 public: 2493 /** 2494 * Set this vector to have the given size. 2495 * @param size The new size. 2496 * @return A reference to this stat. 2497 */ 2498 AverageVector & --- 5 unchanged lines hidden (view full) --- 2504}; 2505 2506/** 2507 * A 2-Dimensional vecto of scalar stats. 2508 * @sa Stat, Vector2dBase, StatStor 2509 */ 2510template<int N = 0> 2511class Vector2d |
2512 : public WrapVec2d<Vector2d<N>, Vector2dBase<StatStor>, Vector2dInfo> |
2513{ 2514 public: 2515 Vector2d & 2516 init(size_type x, size_type y) 2517 { 2518 this->doInit(x, y); 2519 return *this; 2520 } 2521}; 2522 2523/** 2524 * A simple distribution stat. 2525 * @sa Stat, DistBase, DistStor 2526 */ 2527template<int N = 0> 2528class Distribution |
2529 : public Wrap<Distribution<N>, DistBase<DistStor>, DistInfo> |
2530{ 2531 public: 2532 /** Base implementation. */ 2533 typedef DistBase<DistStor> Base; 2534 /** The Parameter type. */ 2535 typedef DistStor::Params Params; 2536 2537 public: --- 17 unchanged lines hidden (view full) --- 2555}; 2556 2557/** 2558 * Calculates the mean and variance of all the samples. 2559 * @sa Stat, DistBase, FancyStor 2560 */ 2561template<int N = 0> 2562class StandardDeviation |
2563 : public Wrap<StandardDeviation<N>, DistBase<FancyStor>, DistInfo> |
2564{ 2565 public: 2566 /** The base implementation */ 2567 typedef DistBase<DistStor> Base; 2568 /** The parameter type. */ 2569 typedef DistStor::Params Params; 2570 2571 public: --- 7 unchanged lines hidden (view full) --- 2579}; 2580 2581/** 2582 * Calculates the per tick mean and variance of the samples. 2583 * @sa Stat, DistBase, AvgFancy 2584 */ 2585template<int N = 0> 2586class AverageDeviation |
2587 : public Wrap<AverageDeviation<N>, DistBase<AvgFancy>, DistInfo> |
2588{ 2589 public: 2590 /** The base implementation */ 2591 typedef DistBase<DistStor> Base; 2592 /** The parameter type. */ 2593 typedef DistStor::Params Params; 2594 2595 public: --- 9 unchanged lines hidden (view full) --- 2605/** 2606 * A vector of distributions. 2607 * @sa Stat, VectorDistBase, DistStor 2608 */ 2609template<int N = 0> 2610class VectorDistribution 2611 : public WrapVec<VectorDistribution<N>, 2612 VectorDistBase<DistStor>, |
2613 VectorDistInfo> |
2614{ 2615 public: 2616 /** The base implementation */ 2617 typedef VectorDistBase<DistStor> Base; 2618 /** The parameter type. */ 2619 typedef DistStor::Params Params; 2620 2621 public: --- 20 unchanged lines hidden (view full) --- 2642/** 2643 * This is a vector of StandardDeviation stats. 2644 * @sa Stat, VectorDistBase, FancyStor 2645 */ 2646template<int N = 0> 2647class VectorStandardDeviation 2648 : public WrapVec<VectorStandardDeviation<N>, 2649 VectorDistBase<FancyStor>, |
2650 VectorDistInfo> |
2651{ 2652 public: 2653 /** The base implementation */ 2654 typedef VectorDistBase<FancyStor> Base; 2655 /** The parameter type. */ 2656 typedef DistStor::Params Params; 2657 2658 public: --- 13 unchanged lines hidden (view full) --- 2672/** 2673 * This is a vector of AverageDeviation stats. 2674 * @sa Stat, VectorDistBase, AvgFancy 2675 */ 2676template<int N = 0> 2677class VectorAverageDeviation 2678 : public WrapVec<VectorAverageDeviation<N>, 2679 VectorDistBase<AvgFancy>, |
2680 VectorDistInfo> |
2681{ 2682 public: 2683 /** The base implementation */ 2684 typedef VectorDistBase<AvgFancy> Base; 2685 /** The parameter type. */ 2686 typedef DistStor::Params Params; 2687 2688 public: --- 10 unchanged lines hidden (view full) --- 2699 } 2700}; 2701 2702/** 2703 * A formula for statistics that is calculated when printed. A formula is 2704 * stored as a tree of Nodes that represent the equation to calculate. 2705 * @sa Stat, ScalarStat, VectorStat, Node, Temp 2706 */ |
2707class FormulaBase : public InfoAccess |
2708{ 2709 protected: 2710 /** The root of the tree which represents the Formula */ 2711 NodePtr root; 2712 friend class Temp; 2713 2714 public: 2715 /** --- 32 unchanged lines hidden (view full) --- 2748 /** 2749 * 2750 */ 2751 bool zero() const; 2752 2753 /** 2754 * 2755 */ |
2756 void update(Info *); |
2757 2758 std::string str() const; 2759}; 2760 |
2761class FormulaInfoBase : public VectorInfoBase |
2762{ 2763 public: 2764 virtual std::string str() const = 0; 2765 virtual bool check() const { return true; } 2766}; 2767 2768template <class Stat> |
2769class FormulaInfo : public FormulaInfoBase |
2770{ 2771 protected: 2772 Stat &s; 2773 mutable VResult vec; 2774 mutable VCounter cvec; 2775 2776 public: |
2777 FormulaInfo(Stat &stat) : s(stat) {} |
2778 2779 virtual bool zero() const { return s.zero(); } 2780 virtual void reset() { s.reset(); } 2781 2782 virtual size_type size() const { return s.size(); } 2783 2784 virtual const VResult & 2785 result() const --- 14 unchanged lines hidden (view full) --- 2800 2801 virtual std::string str() const { return s.str(); } 2802}; 2803 2804class Temp; 2805class Formula 2806 : public WrapVec<Formula, 2807 FormulaBase, |
2808 FormulaInfo> |
2809{ 2810 public: 2811 /** 2812 * Create and initialize thie formula, and register it with the database. 2813 */ 2814 Formula(); 2815 2816 /** --- 60 unchanged lines hidden (view full) --- 2877 2878 public: 2879 /** 2880 * Create a new ScalarStatNode. 2881 * @param s The ScalarStat to place in a node. 2882 */ 2883 template <int N> 2884 Temp(const Scalar<N> &s) |
2885 : node(new ScalarStatNode(s.info())) |
2886 { } 2887 2888 /** 2889 * Create a new ScalarStatNode. 2890 * @param s The ScalarStat to place in a node. 2891 */ 2892 Temp(const Value &s) |
2893 : node(new ScalarStatNode(s.info())) |
2894 { } 2895 2896 /** 2897 * Create a new ScalarStatNode. 2898 * @param s The ScalarStat to place in a node. 2899 */ 2900 template <int N> 2901 Temp(const Average<N> &s) |
2902 : node(new ScalarStatNode(s.info())) |
2903 { } 2904 2905 /** 2906 * Create a new VectorStatNode. 2907 * @param s The VectorStat to place in a node. 2908 */ 2909 template <int N> 2910 Temp(const Vector<N> &s) |
2911 : node(new VectorStatNode(s.info())) |
2912 { } 2913 2914 /** 2915 * 2916 */ 2917 Temp(const Formula &f) 2918 : node(new FormulaNode(f)) 2919 { } --- 170 unchanged lines hidden --- |