Deleted Added
sdiff udiff text old ( 5599:5bad83cddb8c ) new ( 5886:12431dc9a30a )
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;

--- 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 * Erik Hallnor
30 */
31
32/** @file
33 * Declaration of Statistics objects.
34 */
35
36/**
37* @todo

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

55#endif
56#include <cmath>
57#include <functional>
58#include <iosfwd>
59#include <limits>
60#include <string>
61#include <vector>
62
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//////////////////////////////////////////////////////////////////////
88struct StatData
89{
90 /** The name of the stat. */
91 std::string name;
92 /** The description of the stat. */
93 std::string desc;
94 /** The formatting flags. */
95 StatFlags flags;
96 /** The display precision. */
97 int precision;
98 /** A pointer to a prerequisite Stat. */
99 const StatData *prereq;
100 /**
101 * A unique stat ID for each stat in the simulator.
102 * Can be used externally for lookups as well as for debugging.
103 */
104 int id;
105
106 StatData();
107 virtual ~StatData();
108
109 /**
110 * Reset the corresponding stat to the default state.
111 */
112 virtual void reset() = 0;
113
114 /**
115 * @return true if this stat has a value and satisfies its

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

133 /**
134 * Checks if the first stat's name is alphabetically less than the second.
135 * This function breaks names up at periods and considers each subname
136 * separately.
137 * @param stat1 The first stat.
138 * @param stat2 The second stat.
139 * @return stat1's name is alphabetically before stat2's
140 */
141 static bool less(StatData *stat1, StatData *stat2);
142};
143
144class ScalarData : public StatData
145{
146 public:
147 virtual Counter value() const = 0;
148 virtual Result result() const = 0;
149 virtual Result total() const = 0;
150 virtual void visit(Visit &visitor) { visitor.visit(*this); }
151};
152
153template <class Stat>
154class ScalarStatData : public ScalarData
155{
156 protected:
157 Stat &s;
158
159 public:
160 ScalarStatData(Stat &stat) : s(stat) {}
161
162 virtual bool check() const { return s.check(); }
163 virtual Counter value() const { return s.value(); }
164 virtual Result result() const { return s.result(); }
165 virtual Result total() const { return s.total(); }
166 virtual void reset() { s.reset(); }
167 virtual bool zero() const { return s.zero(); }
168};
169
170struct VectorData : public StatData
171{
172 /** Names and descriptions of subfields. */
173 mutable std::vector<std::string> subnames;
174 mutable std::vector<std::string> subdescs;
175
176 virtual size_type size() const = 0;
177 virtual const VCounter &value() const = 0;
178 virtual const VResult &result() const = 0;
179 virtual Result total() const = 0;
180
181 void
182 update()
183 {

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

188
189 if (subdescs.size() < s)
190 subdescs.resize(s);
191 }
192 }
193};
194
195template <class Stat>
196class VectorStatData : public VectorData
197{
198 protected:
199 Stat &s;
200 mutable VCounter cvec;
201 mutable VResult rvec;
202
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_type size() const { return s.size(); }
211
212 virtual VCounter &

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

229 visit(Visit &visitor)
230 {
231 update();
232 s.update(this);
233 visitor.visit(*this);
234 }
235};
236
237struct DistDataData
238{
239 Counter min_val;
240 Counter max_val;
241 Counter underflow;
242 Counter overflow;
243 VCounter cvec;
244 Counter sum;
245 Counter squares;
246 Counter samples;
247
248 Counter min;
249 Counter max;
250 Counter bucket_size;
251 size_type size;
252 bool fancy;
253};
254
255struct DistData : public StatData
256{
257 /** Local storage for the entry values, used for printing. */
258 DistDataData data;
259};
260
261template <class Stat>
262class DistStatData : public DistData
263{
264 protected:
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_type size() const = 0;
294
295 void
296 update()
297 {
298 size_type s = size();
299 if (subnames.size() < s)
300 subnames.resize(s);
301
302 if (subdescs.size() < s)
303 subdescs.resize(s);
304 }
305};
306
307template <class Stat>
308class VectorDistStatData : public VectorDistData
309{
310 protected:
311 Stat &s;
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_type 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 size_type x;
340 mutable size_type 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
373{
374 protected:
375 StatData *find() const;
376 void map(StatData *data);
377
378 StatData *statData();
379 const StatData *statData() const;
380
381 void setInit();
382 void setPrint();
383};
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<Child> *
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<Child> *
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>
496{
497 public:
498 // The following functions are specific to vectors. If you use them
499 // in a non vector context, you will get a nice compiler error!
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(off_type 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(off_type 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 (off_type i = 0; i < this->y; ++i)
552 data->y_subnames[i] = names[i];
553 return this->self();
554 }
555
556 Parent &
557 ysubname(off_type 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};
566
567//////////////////////////////////////////////////////////////////////
568//
569// Simple Statistics
570//
571//////////////////////////////////////////////////////////////////////
572
573/**
574 * Templatized storage and interface for a simple scalar stat.
575 */
576struct StatStor
577{
578 public:
579 /** The paramaters for this storage type, none for a scalar. */
580 struct Params { };
581
582 private:
583 /** The statistic value. */
584 Counter data;

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

633
634/**
635 * Templatized storage and interface to a per-tick average stat. This keeps
636 * a current count and updates a total (count * ticks) when this count
637 * changes. This allows the quick calculation of a per tick count of the item
638 * being watched. This is good for keeping track of residencies in structures
639 * among other things.
640 */
641struct AvgStor
642{
643 public:
644 /** The paramaters for this storage type */
645 struct Params { };
646
647 private:
648 /** The current count. */
649 Counter current;

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

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.

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

721 bool zero() const { return total == 0.0; }
722};
723
724/**
725 * Implementation of a scalar stat. The type of stat is determined by the
726 * Storage template.
727 */
728template <class Stor>
729class ScalarBase : public DataAccess
730{
731 public:
732 typedef Stor Storage;
733
734 /** Define the params of the storage class. */
735 typedef typename Storage::Params Params;
736
737 protected:

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

846 Result result() { return data()->result(params); }
847
848 Result total() { return result(); }
849
850 bool zero() { return result() == 0.0; }
851
852};
853
854class ProxyData : public ScalarData
855{
856 public:
857 virtual void visit(Visit &visitor) { visitor.visit(*this); }
858 virtual std::string str() const { return to_string(value()); }
859 virtual size_type size() const { return 1; }
860 virtual bool zero() const { return value() == 0; }
861 virtual bool check() const { return true; }
862 virtual void reset() { }
863};
864
865template <class T>
866class ValueProxy : public ProxyData
867{
868 private:
869 T *scalar;
870
871 public:
872 ValueProxy(T &val) : scalar(&val) {}
873 virtual Counter value() const { return *scalar; }
874 virtual Result result() const { return *scalar; }
875 virtual Result total() const { return *scalar; }
876};
877
878template <class T>
879class FunctorProxy : public ProxyData
880{
881 private:
882 T *functor;
883
884 public:
885 FunctorProxy(T &func) : functor(&func) {}
886 virtual Counter value() const { return (*functor)(); }
887 virtual Result result() const { return (*functor)(); }
888 virtual Result total() const { return (*functor)(); }
889};
890
891class ValueBase : public DataAccess
892{
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)

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

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 /**

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

1053 * This stat has no state. Nothing to reset
1054 */
1055 void reset() { }
1056
1057 public:
1058 std::string
1059 str() const
1060 {
1061 return csprintf("%s[%d]", stat->statData()->name, index);
1062 }
1063};
1064
1065/**
1066 * Implementation of a vector of stats. The type of stat is determined by the
1067 * Storage class. @sa ScalarBase
1068 */
1069template <class Stor>
1070class VectorBase : public DataAccess
1071{
1072 public:
1073 typedef Stor Storage;
1074
1075 /** Define the params of the storage class. */
1076 typedef typename Storage::Params Params;
1077
1078 /** Proxy type */

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

1202 */
1203 Proxy
1204 operator[](off_type index)
1205 {
1206 assert (index >= 0 && index < size());
1207 return Proxy(this, index);
1208 }
1209
1210 void update(StatData *data) {}
1211};
1212
1213template <class Stat>
1214class VectorProxy
1215{
1216 private:
1217 Stat *stat;
1218 off_type offset;

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

1287
1288 /**
1289 * This stat has no state. Nothing to reset.
1290 */
1291 void reset() { }
1292};
1293
1294template <class Stor>
1295class Vector2dBase : public DataAccess
1296{
1297 public:
1298 typedef Stor Storage;
1299 typedef typename Storage::Params Params;
1300 typedef VectorProxy<Vector2dBase<Storage> > Proxy;
1301 friend class ScalarProxy<Vector2dBase<Storage> >;
1302 friend class VectorProxy<Vector2dBase<Storage> >;
1303

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

1313 const Storage *data(off_type index) const { return &storage[index]; }
1314
1315 void
1316 doInit(size_type _x, size_type _y)
1317 {
1318 assert(_x > 0 && _y > 0 && "sizes must be positive!");
1319 assert(!storage && "already initialized");
1320
1321 Vector2dData *statdata = dynamic_cast<Vector2dData *>(find());
1322
1323 x = _x;
1324 y = _y;
1325 statdata->x = _x;
1326 statdata->y = _y;
1327 _size = x * y;
1328
1329 char *ptr = new char[_size * sizeof(Storage)];
1330 storage = reinterpret_cast<Storage *>(ptr);
1331
1332 for (off_type i = 0; i < _size; ++i)
1333 new (&storage[i]) Storage(params);
1334

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

1346 return;
1347
1348 for (off_type i = 0; i < _size; ++i)
1349 data(i)->~Storage();
1350 delete [] reinterpret_cast<char *>(storage);
1351 }
1352
1353 void
1354 update(Vector2dData *newdata)
1355 {
1356 size_type size = this->size();
1357 newdata->cvec.resize(size);
1358 for (off_type i = 0; i < size; ++i)
1359 newdata->cvec[i] = data(i)->value(params);
1360 }
1361
1362 std::string ysubname(off_type i) const { return (*this->y_subnames)[i]; }
1363
1364 Proxy
1365 operator[](off_type index)
1366 {
1367 off_type offset = index * y;

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

1409//
1410// Non formula statistics
1411//
1412//////////////////////////////////////////////////////////////////////
1413
1414/**
1415 * Templatized storage and interface for a distrbution stat.
1416 */
1417struct DistStor
1418{
1419 public:
1420 /** The parameters for a distribution stat. */
1421 struct Params
1422 {
1423 /** The minimum value to track. */
1424 Counter min;
1425 /** The maximum value to track. */

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

1502 */
1503 bool
1504 zero(const Params &params) const
1505 {
1506 return samples == Counter();
1507 }
1508
1509 void
1510 update(DistDataData *data, const Params &params)
1511 {
1512 data->min = params.min;
1513 data->max = params.max;
1514 data->bucket_size = params.bucket_size;
1515 data->size = params.size;
1516
1517 data->min_val = (min_val == CounterLimits::max()) ? 0 : min_val;
1518 data->max_val = (max_val == CounterLimits::min()) ? 0 : max_val;

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

1547 samples = Counter();
1548 }
1549};
1550
1551/**
1552 * Templatized storage and interface for a distribution that calculates mean
1553 * and variance.
1554 */
1555struct FancyStor
1556{
1557 public:
1558 /**
1559 * No paramters for this storage.
1560 */
1561 struct Params {};
1562 enum { fancy = true };
1563

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

1590 {
1591 Counter value = val * number;
1592 sum += value;
1593 squares += value * value;
1594 samples += number;
1595 }
1596
1597 void
1598 update(DistDataData *data, const Params &params)
1599 {
1600 data->sum = sum;
1601 data->squares = squares;
1602 data->samples = samples;
1603 }
1604
1605 /**
1606 * Return the number of entries in this stat, 1

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

1625 samples = Counter();
1626 }
1627};
1628
1629/**
1630 * Templatized storage for distribution that calculates per tick mean and
1631 * variance.
1632 */
1633struct AvgFancy
1634{
1635 public:
1636 /** No parameters for this storage. */
1637 struct Params {};
1638 enum { fancy = true };
1639
1640 private:
1641 /** Current total. */

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

1660 sample(Counter val, int number, const Params &p)
1661 {
1662 Counter value = val * number;
1663 sum += value;
1664 squares += value * value;
1665 }
1666
1667 void
1668 update(DistDataData *data, const Params &params)
1669 {
1670 data->sum = sum;
1671 data->squares = squares;
1672 data->samples = curTick;
1673 }
1674
1675 /**
1676 * Return the number of entries, in this case 1.

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

1695 }
1696};
1697
1698/**
1699 * Implementation of a distribution stat. The type of distribution is
1700 * determined by the Storage template. @sa ScalarBase
1701 */
1702template <class Stor>
1703class DistBase : public DataAccess
1704{
1705 public:
1706 typedef Stor Storage;
1707 /** Define the params of the storage class. */
1708 typedef typename Storage::Params Params;
1709
1710 protected:
1711 /** The storage for this stat. */

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

1761 size_type size() const { return data()->size(params); }
1762 /**
1763 * Return true if no samples have been added.
1764 * @return True if there haven't been any samples.
1765 */
1766 bool zero() const { return data()->zero(params); }
1767
1768 void
1769 update(DistData *base)
1770 {
1771 base->data.fancy = Storage::fancy;
1772 data()->update(&(base->data), params);
1773 }
1774
1775 /**
1776 * Reset stat value to default
1777 */

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

1787 return true;
1788 }
1789};
1790
1791template <class Stat>
1792class DistProxy;
1793
1794template <class Stor>
1795class VectorDistBase : public DataAccess
1796{
1797 public:
1798 typedef Stor Storage;
1799 typedef typename Storage::Params Params;
1800 typedef DistProxy<VectorDistBase<Storage> > Proxy;
1801 friend class DistProxy<VectorDistBase<Storage> >;
1802
1803 protected:

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

1881
1882 bool
1883 check()
1884 {
1885 return storage != NULL;
1886 }
1887
1888 void
1889 update(VectorDistData *base)
1890 {
1891 size_type size = this->size();
1892 base->data.resize(size);
1893 for (off_type i = 0; i < size; ++i) {
1894 base->data[i].fancy = Storage::fancy;
1895 data(i)->update(&(base->data[i]), params);
1896 }
1897 }

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

2006};
2007
2008/** Reference counting pointer to a function Node. */
2009typedef RefCountingPtr<Node> NodePtr;
2010
2011class ScalarStatNode : public Node
2012{
2013 private:
2014 const ScalarData *data;
2015 mutable VResult vresult;
2016
2017 public:
2018 ScalarStatNode(const ScalarData *d) : data(d), vresult(1) {}
2019
2020 virtual const VResult &
2021 result() const
2022 {
2023 vresult[0] = data->result();
2024 return vresult;
2025 }
2026

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

2073 {
2074 return proxy.str();
2075 }
2076};
2077
2078class VectorStatNode : public Node
2079{
2080 private:
2081 const VectorData *data;
2082
2083 public:
2084 VectorStatNode(const VectorData *d) : data(d) { }
2085 virtual const VResult &result() const { return data->result(); }
2086 virtual Result total() const { return data->total(); };
2087
2088 virtual size_type size() const { return data->size(); }
2089
2090 virtual std::string str() const { return data->name; }
2091};
2092

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

2359 * @{
2360 */
2361
2362/**
2363 * This is a simple scalar statistic, like a counter.
2364 * @sa Stat, ScalarBase, StatStor
2365 */
2366template<int N = 0>
2367class Scalar : public Wrap<Scalar<N>, ScalarBase<StatStor>, ScalarStatData>
2368{
2369 public:
2370 /** The base implementation. */
2371 typedef ScalarBase<StatStor> Base;
2372
2373 Scalar()
2374 {
2375 this->doInit();
2376 }
2377
2378 /**
2379 * Sets the stat equal to the given value. Calls the base implementation
2380 * of operator=
2381 * @param v The new value.
2382 */
2383 template <typename U>
2384 void operator=(const U &v) { Base::operator=(v); }
2385};
2386
2387class Value : public Wrap<Value, ValueBase, ScalarStatData>
2388{
2389 public:
2390 /** The base implementation. */
2391 typedef ValueBase Base;
2392
2393 template <class T>
2394 Value &
2395 scalar(T &value)

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

2407 }
2408};
2409
2410/**
2411 * A stat that calculates the per tick average of a value.
2412 * @sa Stat, ScalarBase, AvgStor
2413 */
2414template<int N = 0>
2415class Average : public Wrap<Average<N>, ScalarBase<AvgStor>, ScalarStatData>
2416{
2417 public:
2418 /** The base implementation. */
2419 typedef ScalarBase<AvgStor> Base;
2420
2421 Average()
2422 {
2423 this->doInit();

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

2436 }
2437};
2438
2439/**
2440 * A vector of scalar stats.
2441 * @sa Stat, VectorBase, StatStor
2442 */
2443template<int N = 0>
2444class Vector : public WrapVec<Vector<N>, VectorBase<StatStor>, VectorStatData>
2445{
2446 public:
2447 /** The base implementation. */
2448 typedef ScalarBase<StatStor> Base;
2449
2450 /**
2451 * Set this vector to have the given size.
2452 * @param size The new size.

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

2461};
2462
2463/**
2464 * A vector of Average stats.
2465 * @sa Stat, VectorBase, AvgStor
2466 */
2467template<int N = 0>
2468class AverageVector
2469 : public WrapVec<AverageVector<N>, VectorBase<AvgStor>, VectorStatData>
2470{
2471 public:
2472 /**
2473 * Set this vector to have the given size.
2474 * @param size The new size.
2475 * @return A reference to this stat.
2476 */
2477 AverageVector &

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

2483};
2484
2485/**
2486 * A 2-Dimensional vecto of scalar stats.
2487 * @sa Stat, Vector2dBase, StatStor
2488 */
2489template<int N = 0>
2490class Vector2d
2491 : public WrapVec2d<Vector2d<N>, Vector2dBase<StatStor>, Vector2dStatData>
2492{
2493 public:
2494 Vector2d &
2495 init(size_type x, size_type y)
2496 {
2497 this->doInit(x, y);
2498 return *this;
2499 }
2500};
2501
2502/**
2503 * A simple distribution stat.
2504 * @sa Stat, DistBase, DistStor
2505 */
2506template<int N = 0>
2507class Distribution
2508 : public Wrap<Distribution<N>, DistBase<DistStor>, DistStatData>
2509{
2510 public:
2511 /** Base implementation. */
2512 typedef DistBase<DistStor> Base;
2513 /** The Parameter type. */
2514 typedef DistStor::Params Params;
2515
2516 public:

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

2534};
2535
2536/**
2537 * Calculates the mean and variance of all the samples.
2538 * @sa Stat, DistBase, FancyStor
2539 */
2540template<int N = 0>
2541class StandardDeviation
2542 : public Wrap<StandardDeviation<N>, DistBase<FancyStor>, DistStatData>
2543{
2544 public:
2545 /** The base implementation */
2546 typedef DistBase<DistStor> Base;
2547 /** The parameter type. */
2548 typedef DistStor::Params Params;
2549
2550 public:

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

2558};
2559
2560/**
2561 * Calculates the per tick mean and variance of the samples.
2562 * @sa Stat, DistBase, AvgFancy
2563 */
2564template<int N = 0>
2565class AverageDeviation
2566 : public Wrap<AverageDeviation<N>, DistBase<AvgFancy>, DistStatData>
2567{
2568 public:
2569 /** The base implementation */
2570 typedef DistBase<DistStor> Base;
2571 /** The parameter type. */
2572 typedef DistStor::Params Params;
2573
2574 public:

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

2584/**
2585 * A vector of distributions.
2586 * @sa Stat, VectorDistBase, DistStor
2587 */
2588template<int N = 0>
2589class VectorDistribution
2590 : public WrapVec<VectorDistribution<N>,
2591 VectorDistBase<DistStor>,
2592 VectorDistStatData>
2593{
2594 public:
2595 /** The base implementation */
2596 typedef VectorDistBase<DistStor> Base;
2597 /** The parameter type. */
2598 typedef DistStor::Params Params;
2599
2600 public:

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

2621/**
2622 * This is a vector of StandardDeviation stats.
2623 * @sa Stat, VectorDistBase, FancyStor
2624 */
2625template<int N = 0>
2626class VectorStandardDeviation
2627 : public WrapVec<VectorStandardDeviation<N>,
2628 VectorDistBase<FancyStor>,
2629 VectorDistStatData>
2630{
2631 public:
2632 /** The base implementation */
2633 typedef VectorDistBase<FancyStor> Base;
2634 /** The parameter type. */
2635 typedef DistStor::Params Params;
2636
2637 public:

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

2651/**
2652 * This is a vector of AverageDeviation stats.
2653 * @sa Stat, VectorDistBase, AvgFancy
2654 */
2655template<int N = 0>
2656class VectorAverageDeviation
2657 : public WrapVec<VectorAverageDeviation<N>,
2658 VectorDistBase<AvgFancy>,
2659 VectorDistStatData>
2660{
2661 public:
2662 /** The base implementation */
2663 typedef VectorDistBase<AvgFancy> Base;
2664 /** The parameter type. */
2665 typedef DistStor::Params Params;
2666
2667 public:

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

2678 }
2679};
2680
2681/**
2682 * A formula for statistics that is calculated when printed. A formula is
2683 * stored as a tree of Nodes that represent the equation to calculate.
2684 * @sa Stat, ScalarStat, VectorStat, Node, Temp
2685 */
2686class FormulaBase : public DataAccess
2687{
2688 protected:
2689 /** The root of the tree which represents the Formula */
2690 NodePtr root;
2691 friend class Temp;
2692
2693 public:
2694 /**

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

2727 /**
2728 *
2729 */
2730 bool zero() const;
2731
2732 /**
2733 *
2734 */
2735 void update(StatData *);
2736
2737 std::string str() const;
2738};
2739
2740class FormulaData : public VectorData
2741{
2742 public:
2743 virtual std::string str() const = 0;
2744 virtual bool check() const { return true; }
2745};
2746
2747template <class Stat>
2748class FormulaStatData : public FormulaData
2749{
2750 protected:
2751 Stat &s;
2752 mutable VResult vec;
2753 mutable VCounter cvec;
2754
2755 public:
2756 FormulaStatData(Stat &stat) : s(stat) {}
2757
2758 virtual bool zero() const { return s.zero(); }
2759 virtual void reset() { s.reset(); }
2760
2761 virtual size_type size() const { return s.size(); }
2762
2763 virtual const VResult &
2764 result() const

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

2779
2780 virtual std::string str() const { return s.str(); }
2781};
2782
2783class Temp;
2784class Formula
2785 : public WrapVec<Formula,
2786 FormulaBase,
2787 FormulaStatData>
2788{
2789 public:
2790 /**
2791 * Create and initialize thie formula, and register it with the database.
2792 */
2793 Formula();
2794
2795 /**

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

2856
2857 public:
2858 /**
2859 * Create a new ScalarStatNode.
2860 * @param s The ScalarStat to place in a node.
2861 */
2862 template <int N>
2863 Temp(const Scalar<N> &s)
2864 : node(new ScalarStatNode(s.statData()))
2865 { }
2866
2867 /**
2868 * Create a new ScalarStatNode.
2869 * @param s The ScalarStat to place in a node.
2870 */
2871 Temp(const Value &s)
2872 : node(new ScalarStatNode(s.statData()))
2873 { }
2874
2875 /**
2876 * Create a new ScalarStatNode.
2877 * @param s The ScalarStat to place in a node.
2878 */
2879 template <int N>
2880 Temp(const Average<N> &s)
2881 : node(new ScalarStatNode(s.statData()))
2882 { }
2883
2884 /**
2885 * Create a new VectorStatNode.
2886 * @param s The VectorStat to place in a node.
2887 */
2888 template <int N>
2889 Temp(const Vector<N> &s)
2890 : node(new VectorStatNode(s.statData()))
2891 { }
2892
2893 /**
2894 *
2895 */
2896 Temp(const Formula &f)
2897 : node(new FormulaNode(f))
2898 { }

--- 170 unchanged lines hidden ---