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
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//////////////////////////////////////////////////////////////////////
88struct StatData
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. */
99 const StatData *prereq;
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
106 StatData();
107 virtual ~StatData();
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 */
141 static bool less(StatData *stat1, StatData *stat2);
143 static bool less(Info *stat1, Info *stat2);
144};
145
144class ScalarData : public StatData
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>
154class ScalarStatData : public ScalarData
156class ScalarInfo : public ScalarInfoBase
157{
158 protected:
159 Stat &s;
160
161 public:
160 ScalarStatData(Stat &stat) : s(stat) {}
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
170struct VectorData : public StatData
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>
196class VectorStatData : public VectorData
200class VectorInfo : public VectorInfoBase
201{
202 protected:
203 Stat &s;
204 mutable VCounter cvec;
205 mutable VResult rvec;
206
207 public:
204 VectorStatData(Stat &stat) : s(stat) {}
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
237struct DistDataData
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
255struct DistData : public StatData
259class DistInfoBase : public Info
260{
261 public:
262 /** Local storage for the entry values, used for printing. */
258 DistDataData data;
263 DistData data;
264};
265
266template <class Stat>
262class DistStatData : public DistData
267class DistInfo : public DistInfoBase
268{
269 protected:
270 Stat &s;
271
272 public:
268 DistStatData(Stat &stat) : s(stat) {}
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
282struct VectorDistData : public StatData
287class VectorDistInfoBase : public Info
288{
284 std::vector<DistDataData> data;
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>
308class VectorDistStatData : public VectorDistData
316class VectorDistInfo : public VectorDistInfoBase
317{
318 protected:
319 Stat &s;
320
321 public:
314 VectorDistStatData(Stat &stat) : s(stat) {}
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
330struct Vector2dData : public StatData
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>
351class Vector2dStatData : public Vector2dData
361class Vector2dInfo : public Vector2dInfoBase
362{
363 protected:
364 Stat &s;
365
366 public:
357 Vector2dStatData(Stat &stat) : s(stat) {}
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
372class DataAccess
382class InfoAccess
383{
384 protected:
375 StatData *find() const;
376 void map(StatData *data);
377
378 StatData *statData();
379 const StatData *statData() const;
380
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();
382 void setPrint();
390
391 Info *info();
392 const Info *info() const;
393};
394
385template <class Parent, class Child, template <class> class Data>
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:
392 Data<Child> *
393 statData()
407 InfoType *
408 info()
409 {
395 StatData *__data = DataAccess::statData();
396 Data<Child> *ptr = dynamic_cast<Data<Child> *>(__data);
397 assert(ptr);
398 return ptr;
410 return safe_cast<InfoType *>(InfoAccess::info());
411 }
412
413 public:
402 const Data<Child> *
403 statData() const
414 const InfoType *
415 info() const
416 {
405 const StatData *__data = DataAccess::statData();
406 const Data<Child> *ptr = dynamic_cast<const Data<Child> *>(__data);
407 assert(ptr);
408 return ptr;
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 {
425 this->map(new Data<Child>(*this));
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 {
436 Data<Child> *data = this->statData();
437 data->name = _name;
438 this->setPrint();
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 {
451 this->statData()->desc = _desc;
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 {
463 this->statData()->precision = _precision;
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 {
475 this->statData()->flags |= _flags;
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 {
489 this->statData()->prereq = prereq.statData();
498 this->info()->prereq = prereq.info();
499 return this->self();
500 }
501};
502
494template <class Parent, class Child, template <class Child> class Data>
495class WrapVec : public Wrap<Parent, Child, Data>
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 {
511 std::vector<std::string> &subn = this->statData()->subnames;
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 {
528 std::vector<std::string> &subd = this->statData()->subdescs;
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
538template <class Parent, class Child, template <class Child> class Data>
539class WrapVec2d : public WrapVec<Parent, Child, Data>
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 {
549 Data<Child> *data = this->statData();
550 data->y_subnames.resize(this->y);
568 InfoType *info = this->info();
569 info->y_subnames.resize(this->y);
570 for (off_type i = 0; i < this->y; ++i)
552 data->y_subnames[i] = names[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 {
559 Data<Child> *data = this->statData();
578 InfoType *info = this->info();
579 assert(index < this->y);
561 data->y_subnames.resize(this->y);
562 data->y_subnames[index] = subname.c_str();
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 */
576struct StatStor
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 */
641struct AvgStor
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
668 set(Counter val, Params &p) {
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>
729class ScalarBase : public DataAccess
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
854class ProxyData : public ScalarData
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>
866class ValueProxy : public ProxyData
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>
879class FunctorProxy : public ProxyData
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
891class ValueBase : public DataAccess
911class ValueBase : public InfoAccess
912{
913 private:
894 ProxyData *proxy;
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 &
986 operator=(const ScalarProxy &sp) {
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 {
1061 return csprintf("%s[%d]", stat->statData()->name, index);
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>
1070class VectorBase : public DataAccess
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
1210 void update(StatData *data) {}
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>
1295class Vector2dBase : public DataAccess
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
1321 Vector2dData *statdata = dynamic_cast<Vector2dData *>(find());
1342 Vector2dInfoBase *info = dynamic_cast<Vector2dInfoBase *>(find());
1343
1344 x = _x;
1345 y = _y;
1325 statdata->x = _x;
1326 statdata->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
1354 update(Vector2dData *newdata)
1375 update(Vector2dInfoBase *newinfo)
1376 {
1377 size_type size = this->size();
1357 newdata->cvec.resize(size);
1378 newinfo->cvec.resize(size);
1379 for (off_type i = 0; i < size; ++i)
1359 newdata->cvec[i] = data(i)->value(params);
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 */
1417struct DistStor
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 &params) const
1526 {
1527 return samples == Counter();
1528 }
1529
1530 void
1510 update(DistDataData *data, const Params &params)
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 */
1555struct FancyStor
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
1598 update(DistDataData *data, const Params &params)
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 */
1633struct AvgFancy
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
1668 update(DistDataData *data, const Params &params)
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>
1703class DistBase : public DataAccess
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
1769 update(DistData *base)
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>
1795class VectorDistBase : public DataAccess
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
1889 update(VectorDistData *base)
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:
2014 const ScalarData *data;
2035 const ScalarInfoBase *data;
2036 mutable VResult vresult;
2037
2038 public:
2018 ScalarStatNode(const ScalarData *d) : data(d), vresult(1) {}
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:
2081 const VectorData *data;
2102 const VectorInfoBase *data;
2103
2104 public:
2084 VectorStatNode(const VectorData *d) : data(d) { }
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>
2367class Scalar : public Wrap<Scalar<N>, ScalarBase<StatStor>, ScalarStatData>
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
2387class Value : public Wrap<Value, ValueBase, ScalarStatData>
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>
2415class Average : public Wrap<Average<N>, ScalarBase<AvgStor>, ScalarStatData>
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>
2444class Vector : public WrapVec<Vector<N>, VectorBase<StatStor>, VectorStatData>
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
2469 : public WrapVec<AverageVector<N>, VectorBase<AvgStor>, VectorStatData>
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
2491 : public WrapVec2d<Vector2d<N>, Vector2dBase<StatStor>, Vector2dStatData>
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
2508 : public Wrap<Distribution<N>, DistBase<DistStor>, DistStatData>
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
2542 : public Wrap<StandardDeviation<N>, DistBase<FancyStor>, DistStatData>
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
2566 : public Wrap<AverageDeviation<N>, DistBase<AvgFancy>, DistStatData>
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>,
2592 VectorDistStatData>
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>,
2629 VectorDistStatData>
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>,
2659 VectorDistStatData>
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 */
2686class FormulaBase : public DataAccess
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 */
2735 void update(StatData *);
2756 void update(Info *);
2757
2758 std::string str() const;
2759};
2760
2740class FormulaData : public VectorData
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>
2748class FormulaStatData : public FormulaData
2769class FormulaInfo : public FormulaInfoBase
2770{
2771 protected:
2772 Stat &s;
2773 mutable VResult vec;
2774 mutable VCounter cvec;
2775
2776 public:
2756 FormulaStatData(Stat &stat) : s(stat) {}
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,
2787 FormulaStatData>
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)
2864 : node(new ScalarStatNode(s.statData()))
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)
2872 : node(new ScalarStatNode(s.statData()))
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)
2881 : node(new ScalarStatNode(s.statData()))
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)
2890 : node(new VectorStatNode(s.statData()))
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 ---