statistics.hh (2665:a124942bacb8) statistics.hh (2716:b9114064d77a)
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;

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

55#include <iosfwd>
56#include <string>
57#include <vector>
58
59#include "base/cprintf.hh"
60#include "base/intmath.hh"
61#include "base/refcnt.hh"
62#include "base/str.hh"
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;

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

55#include <iosfwd>
56#include <string>
57#include <vector>
58
59#include "base/cprintf.hh"
60#include "base/intmath.hh"
61#include "base/refcnt.hh"
62#include "base/str.hh"
63#include "base/stats/bin.hh"
64#include "base/stats/flags.hh"
65#include "base/stats/visit.hh"
66#include "base/stats/types.hh"
63#include "base/stats/flags.hh"
64#include "base/stats/visit.hh"
65#include "base/stats/types.hh"
67#include "config/stats_binning.hh"
68#include "sim/host.hh"
69
70class Callback;
71
72/** The current simulated cycle. */
73extern Tick curTick;
74
75/* A namespace for all of the Statistics */

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

98 * Can be used externally for lookups as well as for debugging.
99 */
100 int id;
101
102 StatData();
103 virtual ~StatData();
104
105 /**
66#include "sim/host.hh"
67
68class Callback;
69
70/** The current simulated cycle. */
71extern Tick curTick;
72
73/* A namespace for all of the Statistics */

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

96 * Can be used externally for lookups as well as for debugging.
97 */
98 int id;
99
100 StatData();
101 virtual ~StatData();
102
103 /**
106 * @return true if the stat is binned.
107 */
108 virtual bool binned() const = 0;
109
110 /**
111 * Reset the corresponding stat to the default state.
112 */
113 virtual void reset() = 0;
114
115 /**
116 * @return true if this stat has a value and satisfies its
117 * requirement as a prereq
118 */

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

155class ScalarStatData : public ScalarData
156{
157 protected:
158 Stat &s;
159
160 public:
161 ScalarStatData(Stat &stat) : s(stat) {}
162
104 * Reset the corresponding stat to the default state.
105 */
106 virtual void reset() = 0;
107
108 /**
109 * @return true if this stat has a value and satisfies its
110 * requirement as a prereq
111 */

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

148class ScalarStatData : public ScalarData
149{
150 protected:
151 Stat &s;
152
153 public:
154 ScalarStatData(Stat &stat) : s(stat) {}
155
163 virtual bool binned() const { return s.binned(); }
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

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

198 protected:
199 Stat &s;
200 mutable VCounter cvec;
201 mutable VResult rvec;
202
203 public:
204 VectorStatData(Stat &stat) : s(stat) {}
205
156 virtual bool check() const { return s.check(); }
157 virtual Counter value() const { return s.value(); }
158 virtual Result result() const { return s.result(); }
159 virtual Result total() const { return s.total(); }
160 virtual void reset() { s.reset(); }
161 virtual bool zero() const { return s.zero(); }
162};
163

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

190 protected:
191 Stat &s;
192 mutable VCounter cvec;
193 mutable VResult rvec;
194
195 public:
196 VectorStatData(Stat &stat) : s(stat) {}
197
206 virtual bool binned() const { return s.binned(); }
207 virtual bool check() const { return s.check(); }
208 virtual bool zero() const { return s.zero(); }
209 virtual void reset() { s.reset(); }
210
211 virtual size_t size() const { return s.size(); }
212 virtual VCounter &value() const
213 {
214 s.value(cvec);

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

256class DistStatData : public DistData
257{
258 protected:
259 Stat &s;
260
261 public:
262 DistStatData(Stat &stat) : s(stat) {}
263
198 virtual bool check() const { return s.check(); }
199 virtual bool zero() const { return s.zero(); }
200 virtual void reset() { s.reset(); }
201
202 virtual size_t size() const { return s.size(); }
203 virtual VCounter &value() const
204 {
205 s.value(cvec);

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

247class DistStatData : public DistData
248{
249 protected:
250 Stat &s;
251
252 public:
253 DistStatData(Stat &stat) : s(stat) {}
254
264 virtual bool binned() const { return s.binned(); }
265 virtual bool check() const { return s.check(); }
266 virtual void reset() { s.reset(); }
267 virtual bool zero() const { return s.zero(); }
268 virtual void visit(Visit &visitor)
269 {
270 s.update(this);
271 visitor.visit(*this);
272 }

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

295 }
296};
297
298template <class Stat>
299class VectorDistStatData : public VectorDistData
300{
301 protected:
302 Stat &s;
255 virtual bool check() const { return s.check(); }
256 virtual void reset() { s.reset(); }
257 virtual bool zero() const { return s.zero(); }
258 virtual void visit(Visit &visitor)
259 {
260 s.update(this);
261 visitor.visit(*this);
262 }

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

285 }
286};
287
288template <class Stat>
289class VectorDistStatData : public VectorDistData
290{
291 protected:
292 Stat &s;
303 typedef typename Stat::bin_t bin_t;
304
305 public:
306 VectorDistStatData(Stat &stat) : s(stat) {}
307
293
294 public:
295 VectorDistStatData(Stat &stat) : s(stat) {}
296
308 virtual bool binned() const { return bin_t::binned; }
309 virtual bool check() const { return s.check(); }
310 virtual void reset() { s.reset(); }
311 virtual size_t size() const { return s.size(); }
312 virtual bool zero() const { return s.zero(); }
313 virtual void visit(Visit &visitor)
314 {
315 update();
316 s.update(this);

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

337 }
338};
339
340template <class Stat>
341class Vector2dStatData : public Vector2dData
342{
343 protected:
344 Stat &s;
297 virtual bool check() const { return s.check(); }
298 virtual void reset() { s.reset(); }
299 virtual size_t size() const { return s.size(); }
300 virtual bool zero() const { return s.zero(); }
301 virtual void visit(Visit &visitor)
302 {
303 update();
304 s.update(this);

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

325 }
326};
327
328template <class Stat>
329class Vector2dStatData : public Vector2dData
330{
331 protected:
332 Stat &s;
345 typedef typename Stat::bin_t bin_t;
346
347 public:
348 Vector2dStatData(Stat &stat) : s(stat) {}
349
333
334 public:
335 Vector2dStatData(Stat &stat) : s(stat) {}
336
350 virtual bool binned() const { return bin_t::binned; }
351 virtual bool check() const { return s.check(); }
352 virtual void reset() { s.reset(); }
353 virtual bool zero() const { return s.zero(); }
354 virtual void visit(Visit &visitor)
355 {
356 update();
357 s.update(this);
358 visitor.visit(*this);
359 }
360};
361
337 virtual bool check() const { return s.check(); }
338 virtual void reset() { s.reset(); }
339 virtual bool zero() const { return s.zero(); }
340 virtual void visit(Visit &visitor)
341 {
342 update();
343 s.update(this);
344 visitor.visit(*this);
345 }
346};
347
362
363class DataAccess
364{
365 protected:
366 StatData *find() const;
367 void map(StatData *data);
368
369 StatData *statData();
370 const StatData *statData() const;

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

610};
611
612/**
613 * Templatized storage and interface to a per-cycle average stat. This keeps
614 * a current count and updates a total (count * cycles) when this count
615 * changes. This allows the quick calculation of a per cycle count of the item
616 * being watched. This is good for keeping track of residencies in structures
617 * among other things.
348class DataAccess
349{
350 protected:
351 StatData *find() const;
352 void map(StatData *data);
353
354 StatData *statData();
355 const StatData *statData() const;

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

595};
596
597/**
598 * Templatized storage and interface to a per-cycle average stat. This keeps
599 * a current count and updates a total (count * cycles) when this count
600 * changes. This allows the quick calculation of a per cycle count of the item
601 * being watched. This is good for keeping track of residencies in structures
602 * among other things.
618 * @todo add lateny to the stat and fix binning.
619 */
620struct AvgStor
621{
622 public:
623 /** The paramaters for this storage type */
603 */
604struct AvgStor
605{
606 public:
607 /** The paramaters for this storage type */
624 struct Params
625 {
626 /**
627 * The current count. We stash this here because the current
628 * value is not a binned value.
629 */
630 Counter current;
631 };
608 struct Params { };
632
633 private:
609
610 private:
611 /** The current count. */
612 Counter current;
634 /** The total count for all cycles. */
635 mutable Result total;
636 /** The cycle that current last changed. */
637 mutable Tick last;
638
639 public:
640 /**
641 * Build and initializes this stat storage.
642 */
613 /** The total count for all cycles. */
614 mutable Result total;
615 /** The cycle that current last changed. */
616 mutable Tick last;
617
618 public:
619 /**
620 * Build and initializes this stat storage.
621 */
643 AvgStor(Params &p) : total(0), last(0) { p.current = Counter(); }
622 AvgStor(Params &p) : current(0), total(0), last(0) { }
644
645 /**
646 * Set the current count to the one provided, update the total and last
647 * set values.
648 * @param val The new count.
649 * @param p The parameters for this storage.
650 */
651 void set(Counter val, Params &p) {
623
624 /**
625 * Set the current count to the one provided, update the total and last
626 * set values.
627 * @param val The new count.
628 * @param p The parameters for this storage.
629 */
630 void set(Counter val, Params &p) {
652 total += p.current * (curTick - last);
631 total += current * (curTick - last);
653 last = curTick;
632 last = curTick;
654 p.current = val;
633 current = val;
655 }
656
657 /**
658 * Increment the current count by the provided value, calls set.
659 * @param val The amount to increment.
660 * @param p The parameters for this storage.
661 */
634 }
635
636 /**
637 * Increment the current count by the provided value, calls set.
638 * @param val The amount to increment.
639 * @param p The parameters for this storage.
640 */
662 void inc(Counter val, Params &p) { set(p.current + val, p); }
641 void inc(Counter val, Params &p) { set(current + val, p); }
663
664 /**
665 * Deccrement the current count by the provided value, calls set.
666 * @param val The amount to decrement.
667 * @param p The parameters for this storage.
668 */
642
643 /**
644 * Deccrement the current count by the provided value, calls set.
645 * @param val The amount to decrement.
646 * @param p The parameters for this storage.
647 */
669 void dec(Counter val, Params &p) { set(p.current - val, p); }
648 void dec(Counter val, Params &p) { set(current - val, p); }
670
671 /**
672 * Return the current count.
673 * @param p The parameters for this storage.
674 * @return The current count.
675 */
649
650 /**
651 * Return the current count.
652 * @param p The parameters for this storage.
653 * @return The current count.
654 */
676 Counter value(const Params &p) const { return p.current; }
655 Counter value(const Params &p) const { return current; }
677
678 /**
679 * Return the current average.
680 * @param p The parameters for this storage.
681 * @return The current average.
682 */
683 Result result(const Params &p) const
684 {
656
657 /**
658 * Return the current average.
659 * @param p The parameters for this storage.
660 * @return The current average.
661 */
662 Result result(const Params &p) const
663 {
685 total += p.current * (curTick - last);
664 total += current * (curTick - last);
686 last = curTick;
665 last = curTick;
687 return (Result)(total + p.current) / (Result)(curTick + 1);
666 return (Result)(total + current) / (Result)(curTick + 1);
688 }
689
690 /**
691 * Reset stat value to default
692 */
693 void reset()
694 {
695 total = 0;
696 last = curTick;
697 }
698
699 /**
700 * @return true if zero value
701 */
702 bool zero() const { return total == 0.0; }
703};
704
705/**
706 * Implementation of a scalar stat. The type of stat is determined by the
667 }
668
669 /**
670 * Reset stat value to default
671 */
672 void reset()
673 {
674 total = 0;
675 last = curTick;
676 }
677
678 /**
679 * @return true if zero value
680 */
681 bool zero() const { return total == 0.0; }
682};
683
684/**
685 * Implementation of a scalar stat. The type of stat is determined by the
707 * Storage template. The storage for this stat is held within the Bin class.
708 * This allows for breaking down statistics across multiple bins easily.
686 * Storage template.
709 */
687 */
710template <class Storage, class Bin>
688template
711class ScalarBase : public DataAccess
712{
713 public:
689class ScalarBase : public DataAccess
690{
691 public:
692 typedef Stor Storage;
693
714 /** Define the params of the storage class. */
694 /** Define the params of the storage class. */
715 typedef typename Storage::Params params_t;
716 /** Define the bin type. */
717 typedef typename Bin::template Bin<Storage> bin_t;
695 typedef typename Storage::Params Params;
718
719 protected:
696
697 protected:
720 /** The bin of this stat. */
721 bin_t bin;
698 /** The storage of this stat. */
699 char storage[sizeof(Storage)];
700
722 /** The parameters for this stat. */
701 /** The parameters for this stat. */
723 params_t params;
702 Params params;
724
725 protected:
726 /**
703
704 protected:
705 /**
727 * Retrieve the storage from the bin.
728 * @return The storage object for this stat.
706 * Retrieve the storage.
707 * @param index The vector index to access.
708 * @return The storage object at the given index.
729 */
709 */
730 Storage *data() { return bin.data(params); }
710 Storage *
711 data()
712 {
713 return reinterpret_cast<Storage *>(storage);
714 }
715
731 /**
716 /**
732 * Retrieve a const pointer to the storage from the bin.
733 * @return A const pointer to the storage object for this stat.
717 * Retrieve a const pointer to the storage.
718 * for the given index.
719 * @param index The vector index to access.
720 * @return A const pointer to the storage object at the given index.
734 */
721 */
735 const Storage *data() const
722 const Storage *
723 data() const
736 {
724 {
737 bin_t *_bin = const_cast<bin_t *>(&bin);
738 params_t *_params = const_cast<params_t *>(&params);
739 return _bin->data(*_params);
725 return reinterpret_cast<const Storage *>(storage);
740 }
741
726 }
727
728 void
729 doInit()
730 {
731 new (storage) Storage(params);
732 setInit();
733 }
734
742 public:
743 /**
744 * Return the current value of this stat as its base type.
745 * @return The current value.
746 */
747 Counter value() const { return data()->value(params); }
748
749 public:
750 /**
751 * Create and initialize this stat, register it with the database.
752 */
753 ScalarBase()
735 public:
736 /**
737 * Return the current value of this stat as its base type.
738 * @return The current value.
739 */
740 Counter value() const { return data()->value(params); }
741
742 public:
743 /**
744 * Create and initialize this stat, register it with the database.
745 */
746 ScalarBase()
754 {
755 bin.init(params);
756 }
747 { }
757
758 public:
759 // Common operators for stats
760 /**
761 * Increment the stat by 1. This calls the associated storage object inc
762 * function.
763 */
764 void operator++() { data()->inc(1, params); }

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

797 template <typename U>
798 void operator-=(const U &v) { data()->dec(v, params); }
799
800 /**
801 * Return the number of elements, always 1 for a scalar.
802 * @return 1.
803 */
804 size_t size() const { return 1; }
748
749 public:
750 // Common operators for stats
751 /**
752 * Increment the stat by 1. This calls the associated storage object inc
753 * function.
754 */
755 void operator++() { data()->inc(1, params); }

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

788 template <typename U>
789 void operator-=(const U &v) { data()->dec(v, params); }
790
791 /**
792 * Return the number of elements, always 1 for a scalar.
793 * @return 1.
794 */
795 size_t size() const { return 1; }
805 /**
806 * Return true if stat is binned.
807 *@return True is stat is binned.
808 */
809 bool binned() const { return bin_t::binned; }
810
796
811 bool check() const { return bin.initialized(); }
797 bool check() const { return true; }
812
813 /**
814 * Reset stat value to default
815 */
798
799 /**
800 * Reset stat value to default
801 */
816 void reset() { bin.reset(); }
802 void reset() { data()->reset(); }
817
818 Counter value() { return data()->value(params); }
819
820 Result result() { return data()->result(params); }
821
822 Result total() { return result(); }
823
824 bool zero() { return result() == 0.0; }
825
826};
827
828class ProxyData : public ScalarData
829{
830 public:
831 virtual void visit(Visit &visitor) { visitor.visit(*this); }
803
804 Counter value() { return data()->value(params); }
805
806 Result result() { return data()->result(params); }
807
808 Result total() { return result(); }
809
810 bool zero() { return result() == 0.0; }
811
812};
813
814class ProxyData : public ScalarData
815{
816 public:
817 virtual void visit(Visit &visitor) { visitor.visit(*this); }
832 virtual bool binned() const { return false; }
833 virtual std::string str() const { return to_string(value()); }
834 virtual size_t size() const { return 1; }
835 virtual bool zero() const { return value() == 0; }
836 virtual bool check() const { return true; }
837 virtual void reset() { }
838};
839
840template <class T>

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

886 setInit();
887 }
888
889 Counter value() { return proxy->value(); }
890 Result result() const { return proxy->result(); }
891 Result total() const { return proxy->total(); };
892 size_t size() const { return proxy->size(); }
893
818 virtual std::string str() const { return to_string(value()); }
819 virtual size_t size() const { return 1; }
820 virtual bool zero() const { return value() == 0; }
821 virtual bool check() const { return true; }
822 virtual void reset() { }
823};
824
825template <class T>

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

871 setInit();
872 }
873
874 Counter value() { return proxy->value(); }
875 Result result() const { return proxy->result(); }
876 Result total() const { return proxy->total(); };
877 size_t size() const { return proxy->size(); }
878
894 bool binned() const { return proxy->binned(); }
895 std::string str() const { return proxy->str(); }
896 bool zero() const { return proxy->zero(); }
897 bool check() const { return proxy != NULL; }
898 void reset() { }
899};
900
901//////////////////////////////////////////////////////////////////////
902//
903// Vector Statistics
904//
905//////////////////////////////////////////////////////////////////////
879 std::string str() const { return proxy->str(); }
880 bool zero() const { return proxy->zero(); }
881 bool check() const { return proxy != NULL; }
882 void reset() { }
883};
884
885//////////////////////////////////////////////////////////////////////
886//
887// Vector Statistics
888//
889//////////////////////////////////////////////////////////////////////
906template <class Storage, class Bin>
907class ScalarProxy;
908
909/**
890
891/**
910 * Implementation of a vector of stats. The type of stat is determined by the
911 * Storage class. @sa ScalarBase
912 */
913template <class Storage, class Bin>
914class VectorBase : public DataAccess
915{
916 public:
917 /** Define the params of the storage class. */
918 typedef typename Storage::Params params_t;
919 /** Define the bin type. */
920 typedef typename Bin::template VectorBin<Storage> bin_t;
921
922 protected:
923 /** The bin of this stat. */
924 bin_t bin;
925 /** The parameters for this stat. */
926 params_t params;
927
928 protected:
929 /**
930 * Retrieve the storage from the bin for the given index.
931 * @param index The vector index to access.
932 * @return The storage object at the given index.
933 */
934 Storage *data(int index) { return bin.data(index, params); }
935 /**
936 * Retrieve a const pointer to the storage from the bin
937 * for the given index.
938 * @param index The vector index to access.
939 * @return A const pointer to the storage object at the given index.
940 */
941 const Storage *data(int index) const
942 {
943 bin_t *_bin = const_cast<bin_t *>(&bin);
944 params_t *_params = const_cast<params_t *>(&params);
945 return _bin->data(index, *_params);
946 }
947
948 public:
949 void value(VCounter &vec) const
950 {
951 vec.resize(size());
952 for (int i = 0; i < size(); ++i)
953 vec[i] = data(i)->value(params);
954 }
955
956 /**
957 * Copy the values to a local vector and return a reference to it.
958 * @return A reference to a vector of the stat values.
959 */
960 void result(VResult &vec) const
961 {
962 vec.resize(size());
963 for (int i = 0; i < size(); ++i)
964 vec[i] = data(i)->result(params);
965 }
966
967 /**
968 * @return True is stat is binned.
969 */
970 bool binned() const { return bin_t::binned; }
971
972 /**
973 * Return a total of all entries in this vector.
974 * @return The total of all vector entries.
975 */
976 Result total() const {
977 Result total = 0.0;
978 for (int i = 0; i < size(); ++i)
979 total += data(i)->result(params);
980 return total;
981 }
982
983 /**
984 * @return the number of elements in this vector.
985 */
986 size_t size() const { return bin.size(); }
987
988 bool zero() const
989 {
990 for (int i = 0; i < size(); ++i)
991 if (data(i)->zero())
992 return true;
993 return false;
994 }
995
996 bool check() const { return bin.initialized(); }
997 void reset() { bin.reset(); }
998
999 public:
1000 VectorBase() {}
1001
1002 /** Friend this class with the associated scalar proxy. */
1003 friend class ScalarProxy<Storage, Bin>;
1004
1005 /**
1006 * Return a reference (ScalarProxy) to the stat at the given index.
1007 * @param index The vector index to access.
1008 * @return A reference of the stat.
1009 */
1010 ScalarProxy<Storage, Bin> operator[](int index);
1011
1012 void update(StatData *data) {}
1013};
1014
1015const StatData * getStatData(const void *stat);
1016
1017/**
1018 * A proxy class to access the stat at a given index in a VectorBase stat.
1019 * Behaves like a ScalarBase.
1020 */
892 * A proxy class to access the stat at a given index in a VectorBase stat.
893 * Behaves like a ScalarBase.
894 */
1021template <class Storage, class Bin>
895template <class Stat>
1022class ScalarProxy
1023{
896class ScalarProxy
897{
1024 public:
1025 /** Define the params of the storage class. */
1026 typedef typename Storage::Params params_t;
1027 /** Define the bin type. */
1028 typedef typename Bin::template VectorBin<Storage> bin_t;
1029
1030 private:
898 private:
1031 /** Pointer to the bin in the parent VectorBase. */
1032 bin_t *bin;
1033 /** Pointer to the params in the parent VectorBase. */
1034 params_t *params;
899 /** Pointer to the parent Vector. */
900 Stat *stat;
901
1035 /** The index to access in the parent VectorBase. */
1036 int index;
902 /** The index to access in the parent VectorBase. */
903 int index;
1037 /** Keep a pointer to the original stat so was can get data */
1038 void *stat;
1039
904
1040 protected:
1041 /**
1042 * Retrieve the storage from the bin.
1043 * @return The storage from the bin for this stat.
1044 */
1045 Storage *data() { return bin->data(index, *params); }
1046 /**
1047 * Retrieve a const pointer to the storage from the bin.
1048 * @return A const pointer to the storage for this stat.
1049 */
1050 const Storage *data() const
1051 {
1052 bin_t *_bin = const_cast<bin_t *>(bin);
1053 params_t *_params = const_cast<params_t *>(params);
1054 return _bin->data(index, *_params);
1055 }
1056
1057 public:
1058 /**
1059 * Return the current value of this stat as its base type.
1060 * @return The current value.
1061 */
905 public:
906 /**
907 * Return the current value of this stat as its base type.
908 * @return The current value.
909 */
1062 Counter value() const { return data()->value(*params); }
910 Counter value() const { return stat->data(index)->value(stat->params); }
1063
1064 /**
1065 * Return the current value of this statas a result type.
1066 * @return The current value.
1067 */
911
912 /**
913 * Return the current value of this statas a result type.
914 * @return The current value.
915 */
1068 Result result() const { return data()->result(*params); }
916 Result result() const { return stat->data(index)->result(stat->params); }
1069
1070 public:
1071 /**
1072 * Create and initialize this proxy, do not register it with the database.
917
918 public:
919 /**
920 * Create and initialize this proxy, do not register it with the database.
1073 * @param b The bin to use.
1074 * @param p The params to use.
1075 * @param i The index to access.
1076 */
921 * @param p The params to use.
922 * @param i The index to access.
923 */
1077 ScalarProxy(bin_t &b, params_t &p, int i, void *s)
1078 : bin(&b), params(&p), index(i), stat(s) {}
924 ScalarProxy(Stat *s, int i)
925 : stat(s), index(i)
926 {
927 assert(stat);
928 }
929
1079 /**
1080 * Create a copy of the provided ScalarProxy.
1081 * @param sp The proxy to copy.
1082 */
1083 ScalarProxy(const ScalarProxy &sp)
930 /**
931 * Create a copy of the provided ScalarProxy.
932 * @param sp The proxy to copy.
933 */
934 ScalarProxy(const ScalarProxy &sp)
1084 : bin(sp.bin), params(sp.params), index(sp.index), stat(sp.stat) {}
935 : stat(sp.stat), index(sp.index)
936 {}
937
1085 /**
1086 * Set this proxy equal to the provided one.
1087 * @param sp The proxy to copy.
1088 * @return A reference to this proxy.
1089 */
1090 const ScalarProxy &operator=(const ScalarProxy &sp) {
938 /**
939 * Set this proxy equal to the provided one.
940 * @param sp The proxy to copy.
941 * @return A reference to this proxy.
942 */
943 const ScalarProxy &operator=(const ScalarProxy &sp) {
1091 bin = sp.bin;
1092 params = sp.params;
1093 index = sp.index;
1094 stat = sp.stat;
944 stat = sp.stat;
945 index = sp.index;
1095 return *this;
1096 }
1097
1098 public:
1099 // Common operators for stats
1100 /**
1101 * Increment the stat by 1. This calls the associated storage object inc
1102 * function.
1103 */
946 return *this;
947 }
948
949 public:
950 // Common operators for stats
951 /**
952 * Increment the stat by 1. This calls the associated storage object inc
953 * function.
954 */
1104 void operator++() { data()->inc(1, *params); }
955 void operator++() { stat->data(index)->inc(1, stat->params); }
1105 /**
1106 * Decrement the stat by 1. This calls the associated storage object dec
1107 * function.
1108 */
956 /**
957 * Decrement the stat by 1. This calls the associated storage object dec
958 * function.
959 */
1109 void operator--() { data()->dec(1, *params); }
960 void operator--() { stat->data(index)->dec(1, stat->params); }
1110
1111 /** Increment the stat by 1. */
1112 void operator++(int) { ++*this; }
1113 /** Decrement the stat by 1. */
1114 void operator--(int) { --*this; }
1115
1116 /**
1117 * Set the data value to the given value. This calls the associated storage
1118 * object set function.
1119 * @param v The new value.
1120 */
1121 template <typename U>
961
962 /** Increment the stat by 1. */
963 void operator++(int) { ++*this; }
964 /** Decrement the stat by 1. */
965 void operator--(int) { --*this; }
966
967 /**
968 * Set the data value to the given value. This calls the associated storage
969 * object set function.
970 * @param v The new value.
971 */
972 template <typename U>
1122 void operator=(const U &v) { data()->set(v, *params); }
973 void operator=(const U &v) { stat->data(index)->set(v, stat->params); }
1123
1124 /**
1125 * Increment the stat by the given value. This calls the associated
1126 * storage object inc function.
1127 * @param v The value to add.
1128 */
1129 template <typename U>
974
975 /**
976 * Increment the stat by the given value. This calls the associated
977 * storage object inc function.
978 * @param v The value to add.
979 */
980 template <typename U>
1130 void operator+=(const U &v) { data()->inc(v, *params); }
981 void operator+=(const U &v) { stat->data(index)->inc(v, stat->params); }
1131
1132 /**
1133 * Decrement the stat by the given value. This calls the associated
1134 * storage object dec function.
1135 * @param v The value to substract.
1136 */
1137 template <typename U>
982
983 /**
984 * Decrement the stat by the given value. This calls the associated
985 * storage object dec function.
986 * @param v The value to substract.
987 */
988 template <typename U>
1138 void operator-=(const U &v) { data()->dec(v, *params); }
989 void operator-=(const U &v) { stat->data(index)->dec(v, stat->params); }
1139
1140 /**
1141 * Return the number of elements, always 1 for a scalar.
1142 * @return 1.
1143 */
1144 size_t size() const { return 1; }
1145
1146 /**
990
991 /**
992 * Return the number of elements, always 1 for a scalar.
993 * @return 1.
994 */
995 size_t size() const { return 1; }
996
997 /**
1147 * Return true if stat is binned.
1148 *@return false since Proxies aren't printed/binned
1149 */
1150 bool binned() const { return false; }
1151
1152 /**
1153 * This stat has no state. Nothing to reset
1154 */
1155 void reset() { }
1156
1157 public:
998 * This stat has no state. Nothing to reset
999 */
1000 void reset() { }
1001
1002 public:
1158 const StatData *statData() const { return getStatData(stat); }
1159 std::string str() const
1003 std::string
1004 str() const
1160 {
1005 {
1161 return csprintf("%s[%d]", this->statData()->name, index);
1006 return csprintf("%s[%d]", stat->str(), index);
1162
1163 }
1164};
1165
1007
1008 }
1009};
1010
1166template <class Storage, class Bin>
1167inline ScalarProxy<Storage, Bin>
1168VectorBase<Storage, Bin>::operator[](int index)
1011/**
1012 * Implementation of a vector of stats. The type of stat is determined by the
1013 * Storage class. @sa ScalarBase
1014 */
1015template <class Stor>
1016class VectorBase : public DataAccess
1169{
1017{
1170 assert (index >= 0 && index < size());
1171 return ScalarProxy<Storage, Bin>(bin, params, index, this);
1172}
1018 public:
1019 typedef Stor Storage;
1173
1020
1174template <class Storage, class Bin>
1175class VectorProxy;
1021 /** Define the params of the storage class. */
1022 typedef typename Storage::Params Params;
1176
1023
1177template <class Storage, class Bin>
1178class Vector2dBase : public DataAccess
1179{
1180 public:
1181 typedef typename Storage::Params params_t;
1182 typedef typename Bin::template VectorBin<Storage> bin_t;
1024 /** Proxy type */
1025 typedef ScalarProxy<VectorBase<Storage> > Proxy;
1183
1026
1027 friend class ScalarProxy<VectorBase<Storage> >;
1028
1184 protected:
1029 protected:
1185 size_t x;
1186 size_t y;
1187 bin_t bin;
1188 params_t params;
1030 /** The storage of this stat. */
1031 Storage *storage;
1032 size_t _size;
1189
1033
1034 /** The parameters for this stat. */
1035 Params params;
1036
1190 protected:
1037 protected:
1191 Storage *data(int index) { return bin.data(index, params); }
1192 const Storage *data(int index) const
1038 /**
1039 * Retrieve the storage.
1040 * @param index The vector index to access.
1041 * @return The storage object at the given index.
1042 */
1043 Storage *data(int index) { return &storage[index]; }
1044
1045 /**
1046 * Retrieve a const pointer to the storage.
1047 * @param index The vector index to access.
1048 * @return A const pointer to the storage object at the given index.
1049 */
1050 const Storage *data(int index) const { return &storage[index]; }
1051
1052 void
1053 doInit(int s)
1193 {
1054 {
1194 bin_t *_bin = const_cast<bin_t *>(&bin);
1195 params_t *_params = const_cast<params_t *>(&params);
1196 return _bin->data(index, *_params);
1055 assert(s > 0 && "size must be positive!");
1056 assert(!storage && "already initialized");
1057 _size = s;
1058
1059 char *ptr = new char[_size * sizeof(Storage)];
1060 storage = reinterpret_cast<Storage *>(ptr);
1061
1062 for (int i = 0; i < _size; ++i)
1063 new (&storage[i]) Storage(params);
1064
1065 setInit();
1197 }
1198
1199 public:
1066 }
1067
1068 public:
1200 Vector2dBase() {}
1069 void value(VCounter &vec) const
1070 {
1071 vec.resize(size());
1072 for (int i = 0; i < size(); ++i)
1073 vec[i] = data(i)->value(params);
1074 }
1201
1075
1202 void update(Vector2dData *data)
1076 /**
1077 * Copy the values to a local vector and return a reference to it.
1078 * @return A reference to a vector of the stat values.
1079 */
1080 void result(VResult &vec) const
1203 {
1081 {
1204 int size = this->size();
1205 data->cvec.resize(size);
1206 for (int i = 0; i < size; ++i)
1207 data->cvec[i] = this->data(i)->value(params);
1082 vec.resize(size());
1083 for (int i = 0; i < size(); ++i)
1084 vec[i] = data(i)->result(params);
1208 }
1209
1085 }
1086
1210 std::string ysubname(int i) const { return (*this->y_subnames)[i]; }
1087 /**
1088 * Return a total of all entries in this vector.
1089 * @return The total of all vector entries.
1090 */
1091 Result total() const {
1092 Result total = 0.0;
1093 for (int i = 0; i < size(); ++i)
1094 total += data(i)->result(params);
1095 return total;
1096 }
1211
1097
1212 friend class VectorProxy<Storage, Bin>;
1213 VectorProxy<Storage, Bin> operator[](int index);
1098 /**
1099 * @return the number of elements in this vector.
1100 */
1101 size_t size() const { return _size; }
1214
1102
1215 size_t size() const { return bin.size(); }
1216 bool zero() const { return data(0)->value(params) == 0.0; }
1103 bool
1104 zero() const
1105 {
1106 for (int i = 0; i < size(); ++i)
1107 if (data(i)->zero())
1108 return false;
1109 return true;
1110 }
1217
1111
1112 bool
1113 check() const
1114 {
1115 return storage != NULL;
1116 }
1117
1118 void
1119 reset()
1120 {
1121 for (int i = 0; i < size(); ++i)
1122 data(i)->reset();
1123 }
1124
1125 public:
1126 VectorBase()
1127 : storage(NULL)
1128 {}
1129
1130 ~VectorBase()
1131 {
1132 if (!storage)
1133 return;
1134
1135 for (int i = 0; i < _size; ++i)
1136 data(i)->~Storage();
1137 delete [] reinterpret_cast<char *>(storage);
1138 }
1139
1218 /**
1140 /**
1219 * Reset stat value to default
1141 * Return a reference (ScalarProxy) to the stat at the given index.
1142 * @param index The vector index to access.
1143 * @return A reference of the stat.
1220 */
1144 */
1221 void reset() { bin.reset(); }
1145 Proxy
1146 operator[](int index)
1147 {
1148 assert (index >= 0 && index < size());
1149 return Proxy(this, index);
1150 }
1222
1151
1223 bool check() { return bin.initialized(); }
1152 void update(StatData *data) {}
1224};
1225
1153};
1154
1226template <class Storage, class Bin>
1155template <class Stat>
1227class VectorProxy
1228{
1156class VectorProxy
1157{
1229 public:
1230 typedef typename Storage::Params params_t;
1231 typedef typename Bin::template VectorBin<Storage> bin_t;
1232
1233 private:
1158 private:
1234 bin_t *bin;
1235 params_t *params;
1159 Stat *stat;
1236 int offset;
1237 int len;
1160 int offset;
1161 int len;
1238 void *stat;
1239
1240 private:
1162
1163 private:
1241 mutable VResult *vec;
1164 mutable VResult vec;
1242
1165
1243 Storage *data(int index) {
1166 typename Stat::Storage *
1167 data(int index)
1168 {
1244 assert(index < len);
1169 assert(index < len);
1245 return bin->data(offset + index, *params);
1170 return stat->data(offset + index);
1246 }
1247
1171 }
1172
1248 const Storage *data(int index) const {
1249 bin_t *_bin = const_cast<bin_t *>(bin);
1250 params_t *_params = const_cast<params_t *>(params);
1251 return _bin->data(offset + index, *_params);
1173 const typename Stat::Storage *
1174 data(int index) const
1175 {
1176 assert(index < len);
1177 return const_cast<Stat *>(stat)->data(offset + index);
1252 }
1253
1254 public:
1178 }
1179
1180 public:
1255 const VResult &result() const {
1256 if (vec)
1257 vec->resize(size());
1258 else
1259 vec = new VResult(size());
1181 const VResult &
1182 result() const
1183 {
1184 vec.resize(size());
1260
1261 for (int i = 0; i < size(); ++i)
1185
1186 for (int i = 0; i < size(); ++i)
1262 (*vec)[i] = data(i)->result(*params);
1187 vec[i] = data(i)->result(stat->params);
1263
1188
1264 return *vec;
1189 return vec;
1265 }
1266
1190 }
1191
1267 Result total() const {
1268 Result total = 0.0;
1192 Result
1193 total() const
1194 {
1195 Result total = 0;
1269 for (int i = 0; i < size(); ++i)
1196 for (int i = 0; i < size(); ++i)
1270 total += data(i)->result(*params);
1197 total += data(i)->result(stat->params);
1271 return total;
1272 }
1273
1274 public:
1198 return total;
1199 }
1200
1201 public:
1275 VectorProxy(bin_t &b, params_t &p, int o, int l, void *s)
1276 : bin(&b), params(&p), offset(o), len(l), stat(s), vec(NULL)
1202 VectorProxy(Stat *s, int o, int l)
1203 : stat(s), offset(o), len(l)
1277 {
1278 }
1279
1280 VectorProxy(const VectorProxy &sp)
1204 {
1205 }
1206
1207 VectorProxy(const VectorProxy &sp)
1281 : bin(sp.bin), params(sp.params), offset(sp.offset), len(sp.len),
1282 stat(sp.stat), vec(NULL)
1208 : stat(sp.stat), offset(sp.offset), len(sp.len)
1283 {
1284 }
1285
1209 {
1210 }
1211
1286 ~VectorProxy()
1212 const VectorProxy &
1213 operator=(const VectorProxy &sp)
1287 {
1214 {
1288 if (vec)
1289 delete vec;
1290 }
1291
1292 const VectorProxy &operator=(const VectorProxy &sp)
1293 {
1294 bin = sp.bin;
1295 params = sp.params;
1215 stat = sp.stat;
1296 offset = sp.offset;
1297 len = sp.len;
1216 offset = sp.offset;
1217 len = sp.len;
1298 stat = sp.stat;
1299 if (vec)
1300 delete vec;
1301 vec = NULL;
1302 return *this;
1303 }
1304
1218 return *this;
1219 }
1220
1305 ScalarProxy<Storage, Bin> operator[](int index)
1221 ScalarProxy<Stat> operator[](int index)
1306 {
1307 assert (index >= 0 && index < size());
1222 {
1223 assert (index >= 0 && index < size());
1308 return ScalarProxy<Storage, Bin>(*bin, *params, offset + index, stat);
1224 return ScalarProxy<Stat>(stat, offset + index);
1309 }
1310
1311 size_t size() const { return len; }
1312
1313 /**
1225 }
1226
1227 size_t size() const { return len; }
1228
1229 /**
1314 * Return true if stat is binned.
1315 *@return false since Proxies aren't printed/binned
1316 */
1317 bool binned() const { return false; }
1318
1319 /**
1320 * This stat has no state. Nothing to reset.
1321 */
1322 void reset() { }
1323};
1324
1230 * This stat has no state. Nothing to reset.
1231 */
1232 void reset() { }
1233};
1234
1325template <class Storage, class Bin>
1326inline VectorProxy<Storage, Bin>
1327Vector2dBase<Storage, Bin>::operator[](int index)
1235template
1236class Vector2dBase : public DataAccess
1328{
1237{
1329 int offset = index * y;
1330 assert (index >= 0 && offset < size());
1331 return VectorProxy<Storage, Bin>(bin, params, offset, y, this);
1332}
1238 public:
1239 typedef Stor Storage;
1240 typedef typename Storage::Params Params;
1241 typedef VectorProxy<Vector2dBase<Storage> > Proxy;
1242 friend class ScalarProxy<Vector2dBase<Storage> >;
1243 friend class VectorProxy<Vector2dBase<Storage> >;
1333
1244
1245 protected:
1246 size_t x;
1247 size_t y;
1248 size_t _size;
1249 Storage *storage;
1250 Params params;
1251
1252 protected:
1253 Storage *data(int index) { return &storage[index]; }
1254 const Storage *data(int index) const { return &storage[index]; }
1255
1256 void
1257 doInit(int _x, int _y)
1258 {
1259 assert(_x > 0 && _y > 0 && "sizes must be positive!");
1260 assert(!storage && "already initialized");
1261
1262 Vector2dData *statdata = dynamic_cast<Vector2dData *>(find());
1263
1264 x = _x;
1265 y = _y;
1266 statdata->x = _x;
1267 statdata->y = _y;
1268 _size = x * y;
1269
1270 char *ptr = new char[_size * sizeof(Storage)];
1271 storage = reinterpret_cast<Storage *>(ptr);
1272
1273 for (int i = 0; i < _size; ++i)
1274 new (&storage[i]) Storage(params);
1275
1276 setInit();
1277 }
1278
1279 public:
1280 Vector2dBase()
1281 : storage(NULL)
1282 {}
1283
1284 ~Vector2dBase()
1285 {
1286 if (!storage)
1287 return;
1288
1289 for (int i = 0; i < _size; ++i)
1290 data(i)->~Storage();
1291 delete [] reinterpret_cast<char *>(storage);
1292 }
1293
1294 void
1295 update(Vector2dData *newdata)
1296 {
1297 int size = this->size();
1298 newdata->cvec.resize(size);
1299 for (int i = 0; i < size; ++i)
1300 newdata->cvec[i] = data(i)->value(params);
1301 }
1302
1303 std::string ysubname(int i) const { return (*this->y_subnames)[i]; }
1304
1305 Proxy
1306 operator[](int index)
1307 {
1308 int offset = index * y;
1309 assert (index >= 0 && offset + index < size());
1310 return Proxy(this, offset, y);
1311 }
1312
1313
1314 size_t
1315 size() const
1316 {
1317 return _size;
1318 }
1319
1320 bool
1321 zero() const
1322 {
1323 return data(0)->zero();
1324#if 0
1325 for (int i = 0; i < size(); ++i)
1326 if (!data(i)->zero())
1327 return false;
1328 return true;
1329#endif
1330 }
1331
1332 /**
1333 * Reset stat value to default
1334 */
1335 void
1336 reset()
1337 {
1338 for (int i = 0; i < size(); ++i)
1339 data(i)->reset();
1340 }
1341
1342 bool
1343 check()
1344 {
1345 return storage != NULL;
1346 }
1347};
1348
1334//////////////////////////////////////////////////////////////////////
1335//
1336// Non formula statistics
1337//
1338//////////////////////////////////////////////////////////////////////
1339
1340/**
1341 * Templatized storage and interface for a distrbution stat.

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

1371 /** The sum of squares. */
1372 Counter squares;
1373 /** The number of samples. */
1374 Counter samples;
1375 /** Counter for each bucket. */
1376 VCounter cvec;
1377
1378 public:
1349//////////////////////////////////////////////////////////////////////
1350//
1351// Non formula statistics
1352//
1353//////////////////////////////////////////////////////////////////////
1354
1355/**
1356 * Templatized storage and interface for a distrbution stat.

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

1386 /** The sum of squares. */
1387 Counter squares;
1388 /** The number of samples. */
1389 Counter samples;
1390 /** Counter for each bucket. */
1391 VCounter cvec;
1392
1393 public:
1379 /**
1380 * Construct this storage with the supplied params.
1381 * @param params The parameters.
1382 */
1383 DistStor(const Params &params)
1394 DistStor(const Params &params)
1384 : min_val(INT_MAX), max_val(INT_MIN), underflow(Counter()),
1385 overflow(Counter()), sum(Counter()), squares(Counter()),
1386 samples(Counter()), cvec(params.size)
1395 : cvec(params.size)
1387 {
1388 reset();
1389 }
1390
1391 /**
1392 * Add a value to the distribution for the given number of times.
1393 * @param val The value to add.
1394 * @param number The number of times to add the value.

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

1613 squares = Counter();
1614 }
1615};
1616
1617/**
1618 * Implementation of a distribution stat. The type of distribution is
1619 * determined by the Storage template. @sa ScalarBase
1620 */
1396 {
1397 reset();
1398 }
1399
1400 /**
1401 * Add a value to the distribution for the given number of times.
1402 * @param val The value to add.
1403 * @param number The number of times to add the value.

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

1622 squares = Counter();
1623 }
1624};
1625
1626/**
1627 * Implementation of a distribution stat. The type of distribution is
1628 * determined by the Storage template. @sa ScalarBase
1629 */
1621template <class Storage, class Bin>
1630template
1622class DistBase : public DataAccess
1623{
1624 public:
1631class DistBase : public DataAccess
1632{
1633 public:
1634 typedef Stor Storage;
1625 /** Define the params of the storage class. */
1635 /** Define the params of the storage class. */
1626 typedef typename Storage::Params params_t;
1627 /** Define the bin type. */
1628 typedef typename Bin::template Bin<Storage> bin_t;
1636 typedef typename Storage::Params Params;
1629
1630 protected:
1637
1638 protected:
1631 /** The bin of this stat. */
1632 bin_t bin;
1639 /** The storage for this stat. */
1640 char storage[sizeof(Storage)];
1641
1633 /** The parameters for this stat. */
1642 /** The parameters for this stat. */
1634 params_t params;
1643 Params params;
1635
1636 protected:
1637 /**
1644
1645 protected:
1646 /**
1638 * Retrieve the storage from the bin.
1647 * Retrieve the storage.
1639 * @return The storage object for this stat.
1640 */
1648 * @return The storage object for this stat.
1649 */
1641 Storage *data() { return bin.data(params); }
1650 Storage *data()
1651 {
1652 return reinterpret_cast<Storage *>(storage);
1653 }
1654
1642 /**
1655 /**
1643 * Retrieve a const pointer to the storage from the bin.
1656 * Retrieve a const pointer to the storage.
1644 * @return A const pointer to the storage object for this stat.
1645 */
1657 * @return A const pointer to the storage object for this stat.
1658 */
1646 const Storage *data() const
1659 const Storage *
1660 data() const
1647 {
1661 {
1648 bin_t *_bin = const_cast<bin_t *>(&bin);
1649 params_t *_params = const_cast<params_t *>(&params);
1650 return _bin->data(*_params);
1662 return reinterpret_cast<const Storage *>(storage);
1651 }
1652
1663 }
1664
1665 void
1666 doInit()
1667 {
1668 new (storage) Storage(params);
1669 setInit();
1670 }
1671
1653 public:
1654 DistBase() { }
1655
1656 /**
1657 * Add a value to the distribtion n times. Calls sample on the storage
1658 * class.
1659 * @param v The value to add.
1660 * @param n The number of times to add it, defaults to 1.

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

1673 */
1674 bool zero() const { return data()->zero(params); }
1675
1676 void update(DistData *base)
1677 {
1678 base->data.fancy = Storage::fancy;
1679 data()->update(&(base->data), params);
1680 }
1672 public:
1673 DistBase() { }
1674
1675 /**
1676 * Add a value to the distribtion n times. Calls sample on the storage
1677 * class.
1678 * @param v The value to add.
1679 * @param n The number of times to add it, defaults to 1.

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

1692 */
1693 bool zero() const { return data()->zero(params); }
1694
1695 void update(DistData *base)
1696 {
1697 base->data.fancy = Storage::fancy;
1698 data()->update(&(base->data), params);
1699 }
1700
1681 /**
1701 /**
1682 * @return True is stat is binned.
1683 */
1684 bool binned() const { return bin_t::binned; }
1685 /**
1686 * Reset stat value to default
1687 */
1702 * Reset stat value to default
1703 */
1688 void reset()
1704 void
1705 reset()
1689 {
1706 {
1690 bin.reset();
1707 data()->reset();
1691 }
1692
1708 }
1709
1693 bool check() { return bin.initialized(); }
1710 bool
1711 check()
1712 {
1713 return true;
1714 }
1694};
1695
1715};
1716
1696template <class Storage, class Bin>
1717template <class Stat>
1697class DistProxy;
1698
1718class DistProxy;
1719
1699template <class Storage, class Bin>
1720template
1700class VectorDistBase : public DataAccess
1701{
1702 public:
1721class VectorDistBase : public DataAccess
1722{
1723 public:
1703 typedef typename Storage::Params params_t;
1704 typedef typename Bin::template VectorBin<Storage> bin_t;
1724 typedef Stor Storage;
1725 typedef typename Storage::Params Params;
1726 typedef DistProxy<VectorDistBase<Storage> > Proxy;
1727 friend class DistProxy<VectorDistBase<Storage> >;
1705
1706 protected:
1728
1729 protected:
1707 bin_t bin;
1708 params_t params;
1730 Storage *storage;
1731 size_t _size;
1732 Params params;
1709
1710 protected:
1733
1734 protected:
1711 Storage *data(int index) { return bin.data(index, params); }
1712 const Storage *data(int index) const
1735 Storage *
1736 data(int index)
1713 {
1737 {
1714 bin_t *_bin = const_cast<bin_t *>(&bin);
1715 params_t *_params = const_cast<params_t *>(&params);
1716 return _bin->data(index, *_params);
1738 return &storage[index];
1717 }
1718
1739 }
1740
1741 const Storage *
1742 data(int index) const
1743 {
1744 return &storage[index];
1745 }
1746
1747 void
1748 doInit(int s)
1749 {
1750 assert(s > 0 && "size must be positive!");
1751 assert(!storage && "already initialized");
1752 _size = s;
1753
1754 char *ptr = new char[_size * sizeof(Storage)];
1755 storage = reinterpret_cast<Storage *>(ptr);
1756
1757 for (int i = 0; i < _size; ++i)
1758 new (&storage[i]) Storage(params);
1759
1760 setInit();
1761 }
1762
1719 public:
1763 public:
1720 VectorDistBase() {}
1764 VectorDistBase()
1765 : storage(NULL)
1766 {}
1721
1767
1722 friend class DistProxy<Storage, Bin>;
1723 DistProxy<Storage, Bin> operator[](int index);
1724 const DistProxy<Storage, Bin> operator[](int index) const;
1768 ~VectorDistBase()
1769 {
1770 if (!storage)
1771 return ;
1725
1772
1726 size_t size() const { return bin.size(); }
1727 bool zero() const { return false; }
1773 for (int i = 0; i < _size; ++i)
1774 data(i)->~Storage();
1775 delete [] reinterpret_cast<char *>(storage);
1776 }
1777
1778 Proxy operator[](int index);
1779
1780 size_t
1781 size() const
1782 {
1783 return _size;
1784 }
1785
1786 bool
1787 zero() const
1788 {
1789 return false;
1790#if 0
1791 for (int i = 0; i < size(); ++i)
1792 if (!data(i)->zero(params))
1793 return false;
1794 return true;
1795#endif
1796 }
1797
1728 /**
1798 /**
1729 * Return true if stat is binned.
1730 *@return True is stat is binned.
1731 */
1732 bool binned() const { return bin_t::binned; }
1733 /**
1734 * Reset stat value to default
1735 */
1799 * Reset stat value to default
1800 */
1736 void reset() { bin.reset(); }
1801 void
1802 reset()
1803 {
1804 for (int i = 0; i < size(); ++i)
1805 data(i)->reset();
1806 }
1737
1807
1738 bool check() { return bin.initialized(); }
1739 void update(VectorDistData *base)
1808 bool
1809 check()
1740 {
1810 {
1811 return storage != NULL;
1812 }
1813
1814 void
1815 update(VectorDistData *base)
1816 {
1741 int size = this->size();
1742 base->data.resize(size);
1743 for (int i = 0; i < size; ++i) {
1744 base->data[i].fancy = Storage::fancy;
1745 data(i)->update(&(base->data[i]), params);
1746 }
1747 }
1748};
1749
1817 int size = this->size();
1818 base->data.resize(size);
1819 for (int i = 0; i < size; ++i) {
1820 base->data[i].fancy = Storage::fancy;
1821 data(i)->update(&(base->data[i]), params);
1822 }
1823 }
1824};
1825
1750template <class Storage, class Bin>
1826template <class Stat>
1751class DistProxy
1752{
1827class DistProxy
1828{
1753 public:
1754 typedef typename Storage::Params params_t;
1755 typedef typename Bin::template Bin<Storage> bin_t;
1756 typedef VectorDistBase<Storage, Bin> base_t;
1757
1758 private:
1829 private:
1759 union {
1760 base_t *stat;
1761 const base_t *cstat;
1762 };
1830 Stat *stat;
1763 int index;
1764
1765 protected:
1831 int index;
1832
1833 protected:
1766 Storage *data() { return stat->data(index); }
1767 const Storage *data() const { return cstat->data(index); }
1834 typename Stat::Storage *data() { return stat->data(index); }
1835 const typename Stat::Storage *data() const { return stat->data(index); }
1768
1769 public:
1836
1837 public:
1770 DistProxy(const VectorDistBase<Storage, Bin> &s, int i)
1771 : cstat(&s), index(i) {}
1838 DistProxy(Stat *s, int i)
1839 : stat(s), index(i)
1840 {}
1841
1772 DistProxy(const DistProxy &sp)
1842 DistProxy(const DistProxy &sp)
1773 : cstat(sp.cstat), index(sp.index) {}
1774 const DistProxy &operator=(const DistProxy &sp) {
1775 cstat = sp.cstat; index = sp.index; return *this;
1843 : stat(sp.stat), index(sp.index)
1844 {}
1845
1846 const DistProxy &operator=(const DistProxy &sp)
1847 {
1848 stat = sp.stat;
1849 index = sp.index;
1850 return *this;
1776 }
1777
1778 public:
1779 template <typename U>
1851 }
1852
1853 public:
1854 template <typename U>
1780 void sample(const U &v, int n = 1) { data()->sample(v, n, cstat->params); }
1855 void
1856 sample(const U &v, int n = 1)
1857 {
1858 data()->sample(v, n, stat->params);
1859 }
1781
1860
1782 size_t size() const { return 1; }
1783 bool zero() const { return data()->zero(cstat->params); }
1861 size_t
1862 size() const
1863 {
1864 return 1;
1865 }
1866
1867 bool
1868 zero() const
1869 {
1870 return data()->zero(stat->params);
1871 }
1872
1784 /**
1873 /**
1785 * Return true if stat is binned.
1786 *@return false since Proxies are not binned/printed.
1787 */
1788 bool binned() const { return false; }
1789 /**
1790 * Proxy has no state. Nothing to reset.
1791 */
1792 void reset() { }
1793};
1794
1874 * Proxy has no state. Nothing to reset.
1875 */
1876 void reset() { }
1877};
1878
1795template <class Storage, class Bin>
1796inline DistProxy<Storage, Bin>
1797VectorDistBase<Storage, Bin>::operator[](int index)
1879template
1880inline typename VectorDistBase<Storage>::Proxy
1881VectorDistBase::operator[](int index)
1798{
1799 assert (index >= 0 && index < size());
1882{
1883 assert (index >= 0 && index < size());
1800 return DistProxy<Storage, Bin>(*this, index);
1884 return typename VectorDistBase<Storage>::Proxy(this, index);
1801}
1802
1885}
1886
1803template <class Storage, class Bin>
1804inline const DistProxy<Storage, Bin>
1805VectorDistBase<Storage, Bin>::operator[](int index) const
1806{
1807 assert (index >= 0 && index < size());
1808 return DistProxy<Storage, Bin>(*this, index);
1809}
1810
1811#if 0
1887#if 0
1812template <class Storage, class Bin>
1888template
1813Result
1889Result
1814VectorDistBase<Storage, Bin>::total(int index) const
1890VectorDistBase::total(int index) const
1815{
1816 int total = 0;
1891{
1892 int total = 0;
1817 for (int i=0; i < x_size(); ++i) {
1818 total += data(i)->result(*params);
1893 for (int i = 0; i < x_size(); ++i) {
1894 total += data(i)->result(stat->params);
1819 }
1820}
1821#endif
1822
1823//////////////////////////////////////////////////////////////////////
1824//
1825// Formula Details
1826//

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

1843 * @return The result vector of this subtree.
1844 */
1845 virtual const VResult &result() const = 0;
1846 /**
1847 * Return the total of the result vector.
1848 * @return The total of the result vector.
1849 */
1850 virtual Result total() const = 0;
1895 }
1896}
1897#endif
1898
1899//////////////////////////////////////////////////////////////////////
1900//
1901// Formula Details
1902//

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

1919 * @return The result vector of this subtree.
1920 */
1921 virtual const VResult &result() const = 0;
1922 /**
1923 * Return the total of the result vector.
1924 * @return The total of the result vector.
1925 */
1926 virtual Result total() const = 0;
1851 /**
1852 * Return true if stat is binned.
1853 *@return True is stat is binned.
1854 */
1855 virtual bool binned() const = 0;
1856
1857 /**
1858 *
1859 */
1860 virtual std::string str() const = 0;
1861};
1862
1863/** Reference counting pointer to a function Node. */

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

1874 virtual const VResult &result() const
1875 {
1876 vresult[0] = data->result();
1877 return vresult;
1878 }
1879 virtual Result total() const { return data->result(); };
1880
1881 virtual size_t size() const { return 1; }
1927
1928 /**
1929 *
1930 */
1931 virtual std::string str() const = 0;
1932};
1933
1934/** Reference counting pointer to a function Node. */

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

1945 virtual const VResult &result() const
1946 {
1947 vresult[0] = data->result();
1948 return vresult;
1949 }
1950 virtual Result total() const { return data->result(); };
1951
1952 virtual size_t size() const { return 1; }
1882 /**
1883 * Return true if stat is binned.
1884 *@return True is stat is binned.
1885 */
1886 virtual bool binned() const { return data->binned(); }
1887
1888 /**
1889 *
1890 */
1891 virtual std::string str() const { return data->name; }
1892};
1893
1953
1954 /**
1955 *
1956 */
1957 virtual std::string str() const { return data->name; }
1958};
1959
1894template <class Storage, class Bin>
1960template <class Stat>
1895class ScalarProxyNode : public Node
1896{
1897 private:
1961class ScalarProxyNode : public Node
1962{
1963 private:
1898 const ScalarProxy<Storage, Bin> proxy;
1964 const ScalarProxy<Stat> proxy;
1899 mutable VResult vresult;
1900
1901 public:
1965 mutable VResult vresult;
1966
1967 public:
1902 ScalarProxyNode(const ScalarProxy<Storage, Bin> &p)
1903 : proxy(p), vresult(1) { }
1904 virtual const VResult &result() const
1968 ScalarProxyNode(const ScalarProxy<Stat> &p)
1969 : proxy(p), vresult(1)
1970 { }
1971
1972 virtual const VResult &
1973 result() const
1905 {
1906 vresult[0] = proxy.result();
1907 return vresult;
1908 }
1974 {
1975 vresult[0] = proxy.result();
1976 return vresult;
1977 }
1909 virtual Result total() const { return proxy.result(); };
1910
1978
1911 virtual size_t size() const { return 1; }
1912 /**
1913 * Return true if stat is binned.
1914 *@return True is stat is binned.
1915 */
1916 virtual bool binned() const { return proxy.binned(); }
1979 virtual Result
1980 total() const
1981 {
1982 return proxy.result();
1983 }
1917
1984
1985 virtual size_t
1986 size() const
1987 {
1988 return 1;
1989 }
1990
1918 /**
1919 *
1920 */
1991 /**
1992 *
1993 */
1921 virtual std::string str() const { return proxy.str(); }
1994 virtual std::string
1995 str() const
1996 {
1997 return proxy.str();
1998 }
1922};
1923
1924class VectorStatNode : public Node
1925{
1926 private:
1927 const VectorData *data;
1928
1929 public:
1930 VectorStatNode(const VectorData *d) : data(d) { }
1931 virtual const VResult &result() const { return data->result(); }
1932 virtual Result total() const { return data->total(); };
1933
1934 virtual size_t size() const { return data->size(); }
1999};
2000
2001class VectorStatNode : public Node
2002{
2003 private:
2004 const VectorData *data;
2005
2006 public:
2007 VectorStatNode(const VectorData *d) : data(d) { }
2008 virtual const VResult &result() const { return data->result(); }
2009 virtual Result total() const { return data->total(); };
2010
2011 virtual size_t size() const { return data->size(); }
1935 /**
1936 * Return true if stat is binned.
1937 *@return True is stat is binned.
1938 */
1939 virtual bool binned() const { return data->binned(); }
1940
1941 virtual std::string str() const { return data->name; }
1942};
1943
1944template <class T>
1945class ConstNode : public Node
1946{
1947 private:
1948 VResult vresult;
1949
1950 public:
1951 ConstNode(T s) : vresult(1, (Result)s) {}
1952 const VResult &result() const { return vresult; }
1953 virtual Result total() const { return vresult[0]; };
1954 virtual size_t size() const { return 1; }
2012
2013 virtual std::string str() const { return data->name; }
2014};
2015
2016template <class T>
2017class ConstNode : public Node
2018{
2019 private:
2020 VResult vresult;
2021
2022 public:
2023 ConstNode(T s) : vresult(1, (Result)s) {}
2024 const VResult &result() const { return vresult; }
2025 virtual Result total() const { return vresult[0]; };
2026 virtual size_t size() const { return 1; }
1955
1956 /**
1957 * Return true if stat is binned.
1958 *@return False since constants aren't binned.
1959 */
1960 virtual bool binned() const { return false; }
1961
1962 virtual std::string str() const { return to_string(vresult[0]); }
1963};
1964
1965template <class Op>
1966struct OpString;
1967
1968template<>
1969struct OpString<std::plus<Result> >

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

2027 }
2028
2029 Result total() const {
2030 Op op;
2031 return op(l->total());
2032 }
2033
2034 virtual size_t size() const { return l->size(); }
2027 virtual std::string str() const { return to_string(vresult[0]); }
2028};
2029
2030template <class Op>
2031struct OpString;
2032
2033template<>
2034struct OpString<std::plus<Result> >

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

2092 }
2093
2094 Result total() const {
2095 Op op;
2096 return op(l->total());
2097 }
2098
2099 virtual size_t size() const { return l->size(); }
2035 /**
2036 * Return true if child of node is binned.
2037 *@return True if child of node is binned.
2038 */
2039 virtual bool binned() const { return l->binned(); }
2040
2041 virtual std::string str() const
2042 {
2043 return OpString<Op>::str() + l->str();
2044 }
2045};
2046
2047template <class Op>

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

2098 return rs;
2099 else if (rs == 1)
2100 return ls;
2101 else {
2102 assert(ls == rs && "Node vector sizes are not equal");
2103 return ls;
2104 }
2105 }
2100
2101 virtual std::string str() const
2102 {
2103 return OpString<Op>::str() + l->str();
2104 }
2105};
2106
2107template <class Op>

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

2158 return rs;
2159 else if (rs == 1)
2160 return ls;
2161 else {
2162 assert(ls == rs && "Node vector sizes are not equal");
2163 return ls;
2164 }
2165 }
2106 /**
2107 * Return true if any children of node are binned
2108 *@return True if either child of node is binned.
2109 */
2110 virtual bool binned() const { return (l->binned() || r->binned()); }
2111
2112 virtual std::string str() const
2113 {
2114 return csprintf("(%s %s %s)", l->str(), OpString<Op>::str(), r->str());
2115 }
2116};
2117
2118template <class Op>

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

2151 Op op;
2152 for (int i = 0; i < size; ++i)
2153 vresult = op(vresult, lvec[i]);
2154
2155 return vresult;
2156 }
2157
2158 virtual size_t size() const { return 1; }
2166
2167 virtual std::string str() const
2168 {
2169 return csprintf("(%s %s %s)", l->str(), OpString<Op>::str(), r->str());
2170 }
2171};
2172
2173template <class Op>

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

2206 Op op;
2207 for (int i = 0; i < size; ++i)
2208 vresult = op(vresult, lvec[i]);
2209
2210 return vresult;
2211 }
2212
2213 virtual size_t size() const { return 1; }
2159 /**
2160 * Return true if child of node is binned.
2161 *@return True if child of node is binned.
2162 */
2163 virtual bool binned() const { return l->binned(); }
2164
2165 virtual std::string str() const
2166 {
2167 return csprintf("total(%s)", l->str());
2168 }
2169};
2170
2171
2172//////////////////////////////////////////////////////////////////////
2173//
2174// Visible Statistics Types
2175//
2176//////////////////////////////////////////////////////////////////////
2177/**
2178 * @defgroup VisibleStats "Statistic Types"
2214
2215 virtual std::string str() const
2216 {
2217 return csprintf("total(%s)", l->str());
2218 }
2219};
2220
2221
2222//////////////////////////////////////////////////////////////////////
2223//
2224// Visible Statistics Types
2225//
2226//////////////////////////////////////////////////////////////////////
2227/**
2228 * @defgroup VisibleStats "Statistic Types"
2179 * These are the statistics that are used in the simulator. By default these
2180 * store counters and don't use binning, but are templatized to accept any type
2181 * and any Bin class.
2229 * These are the statistics that are used in the simulator.
2182 * @{
2183 */
2184
2185/**
2230 * @{
2231 */
2232
2233/**
2186 * This is an easy way to assign all your stats to be binned or not
2187 * binned. If the typedef is NoBin, nothing is binned. If it is
2188 * MainBin, then all stats are binned under that Bin.
2189 */
2190#if STATS_BINNING
2191typedef MainBin DefaultBin;
2192#else
2193typedef NoBin DefaultBin;
2194#endif
2195
2196/**
2197 * This is a simple scalar statistic, like a counter.
2198 * @sa Stat, ScalarBase, StatStor
2199 */
2234 * This is a simple scalar statistic, like a counter.
2235 * @sa Stat, ScalarBase, StatStor
2236 */
2200template <class Bin = DefaultBin>
2201class Scalar
2202 : public Wrap<Scalar<Bin>,
2203 ScalarBase<StatStor, Bin>,
2204 ScalarStatData>
2237template<int N = 0>
2238class Scalar : public Wrap<Scalar<N>, ScalarBase<StatStor>, ScalarStatData>
2205{
2206 public:
2207 /** The base implementation. */
2239{
2240 public:
2241 /** The base implementation. */
2208 typedef ScalarBase<StatStor, Bin> Base;
2242 typedef ScalarBase Base;
2209
2210 Scalar()
2211 {
2243
2244 Scalar()
2245 {
2212 this->setInit();
2246 this->doInit();
2213 }
2214
2215 /**
2216 * Sets the stat equal to the given value. Calls the base implementation
2217 * of operator=
2218 * @param v The new value.
2219 */
2220 template <typename U>
2221 void operator=(const U &v) { Base::operator=(v); }
2222};
2223
2247 }
2248
2249 /**
2250 * Sets the stat equal to the given value. Calls the base implementation
2251 * of operator=
2252 * @param v The new value.
2253 */
2254 template <typename U>
2255 void operator=(const U &v) { Base::operator=(v); }
2256};
2257
2224class Value
2225 : public Wrap<Value,
2226 ValueBase,
2227 ScalarStatData>
2258class Value : public Wrap<Value, ValueBase, ScalarStatData>
2228{
2229 public:
2230 /** The base implementation. */
2231 typedef ValueBase Base;
2232
2233 template <class T>
2234 Value &scalar(T &value)
2235 {

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

2244 return *this;
2245 }
2246};
2247
2248/**
2249 * A stat that calculates the per cycle average of a value.
2250 * @sa Stat, ScalarBase, AvgStor
2251 */
2259{
2260 public:
2261 /** The base implementation. */
2262 typedef ValueBase Base;
2263
2264 template <class T>
2265 Value &scalar(T &value)
2266 {

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

2275 return *this;
2276 }
2277};
2278
2279/**
2280 * A stat that calculates the per cycle average of a value.
2281 * @sa Stat, ScalarBase, AvgStor
2282 */
2252template <class Bin = DefaultBin>
2253class Average
2254 : public Wrap<Average<Bin>,
2255 ScalarBase<AvgStor, Bin>,
2256 ScalarStatData>
2283template<int N = 0>
2284class Average : public Wrap<Average<N>, ScalarBase<AvgStor>, ScalarStatData>
2257{
2258 public:
2259 /** The base implementation. */
2285{
2286 public:
2287 /** The base implementation. */
2260 typedef ScalarBase<AvgStor, Bin> Base;
2288 typedef ScalarBase Base;
2261
2262 Average()
2263 {
2289
2290 Average()
2291 {
2264 this->setInit();
2292 this->doInit();
2265 }
2266
2267 /**
2268 * Sets the stat equal to the given value. Calls the base implementation
2269 * of operator=
2270 * @param v The new value.
2271 */
2272 template <typename U>
2273 void operator=(const U &v) { Base::operator=(v); }
2274};
2275
2276/**
2277 * A vector of scalar stats.
2278 * @sa Stat, VectorBase, StatStor
2279 */
2293 }
2294
2295 /**
2296 * Sets the stat equal to the given value. Calls the base implementation
2297 * of operator=
2298 * @param v The new value.
2299 */
2300 template <typename U>
2301 void operator=(const U &v) { Base::operator=(v); }
2302};
2303
2304/**
2305 * A vector of scalar stats.
2306 * @sa Stat, VectorBase, StatStor
2307 */
2280template <class Bin = DefaultBin>
2281class Vector
2282 : public WrapVec<Vector<Bin>,
2283 VectorBase<StatStor, Bin>,
2284 VectorStatData>
2308template<int N = 0>
2309class Vector : public WrapVec<Vector<N>, VectorBase<StatStor>, VectorStatData>
2285{
2286 public:
2287 /** The base implementation. */
2310{
2311 public:
2312 /** The base implementation. */
2288 typedef ScalarBase<StatStor, Bin> Base;
2313 typedef ScalarBase Base;
2289
2290 /**
2291 * Set this vector to have the given size.
2292 * @param size The new size.
2293 * @return A reference to this stat.
2294 */
2295 Vector &init(size_t size) {
2314
2315 /**
2316 * Set this vector to have the given size.
2317 * @param size The new size.
2318 * @return A reference to this stat.
2319 */
2320 Vector &init(size_t size) {
2296 this->bin.init(size, this->params);
2297 this->setInit();
2298
2321 this->doInit(size);
2299 return *this;
2300 }
2301};
2302
2303/**
2304 * A vector of Average stats.
2305 * @sa Stat, VectorBase, AvgStor
2306 */
2322 return *this;
2323 }
2324};
2325
2326/**
2327 * A vector of Average stats.
2328 * @sa Stat, VectorBase, AvgStor
2329 */
2307template <class Bin = DefaultBin>
2330template<int N = 0>
2308class AverageVector
2331class AverageVector
2309 : public WrapVec<AverageVector<Bin>,
2310 VectorBase<AvgStor, Bin>,
2311 VectorStatData>
2332 : public WrapVec<AverageVector<N>, VectorBase<AvgStor>, VectorStatData>
2312{
2313 public:
2314 /**
2315 * Set this vector to have the given size.
2316 * @param size The new size.
2317 * @return A reference to this stat.
2318 */
2319 AverageVector &init(size_t size) {
2333{
2334 public:
2335 /**
2336 * Set this vector to have the given size.
2337 * @param size The new size.
2338 * @return A reference to this stat.
2339 */
2340 AverageVector &init(size_t size) {
2320 this->bin.init(size, this->params);
2321 this->setInit();
2322
2341 this->doInit(size);
2323 return *this;
2324 }
2325};
2326
2327/**
2328 * A 2-Dimensional vecto of scalar stats.
2329 * @sa Stat, Vector2dBase, StatStor
2330 */
2342 return *this;
2343 }
2344};
2345
2346/**
2347 * A 2-Dimensional vecto of scalar stats.
2348 * @sa Stat, Vector2dBase, StatStor
2349 */
2331template <class Bin = DefaultBin>
2350template<int N = 0>
2332class Vector2d
2351class Vector2d
2333 : public WrapVec2d<Vector2d<Bin>,
2334 Vector2dBase<StatStor, Bin>,
2335 Vector2dStatData>
2352 : public WrapVec2d<Vector2d<N>, Vector2dBase<StatStor>, Vector2dStatData>
2336{
2337 public:
2353{
2354 public:
2338 Vector2d &init(size_t _x, size_t _y) {
2339 this->statData()->x = this->x = _x;
2340 this->statData()->y = this->y = _y;
2341 this->bin.init(this->x * this->y, this->params);
2342 this->setInit();
2343
2355 Vector2d &init(size_t x, size_t y) {
2356 this->doInit(x, y);
2344 return *this;
2345 }
2346};
2347
2348/**
2349 * A simple distribution stat.
2350 * @sa Stat, DistBase, DistStor
2351 */
2357 return *this;
2358 }
2359};
2360
2361/**
2362 * A simple distribution stat.
2363 * @sa Stat, DistBase, DistStor
2364 */
2352template <class Bin = DefaultBin>
2365template<int N = 0>
2353class Distribution
2366class Distribution
2354 : public Wrap<Distribution<Bin>,
2355 DistBase<DistStor, Bin>,
2356 DistStatData>
2367 : public Wrap<Distribution<N>, DistBase<DistStor>, DistStatData>
2357{
2358 public:
2359 /** Base implementation. */
2368{
2369 public:
2370 /** Base implementation. */
2360 typedef DistBase<DistStor, Bin> Base;
2371 typedef DistBase Base;
2361 /** The Parameter type. */
2372 /** The Parameter type. */
2362 typedef typename DistStor::Params Params;
2373 typedef DistStor::Params Params;
2363
2364 public:
2365 /**
2366 * Set the parameters of this distribution. @sa DistStor::Params
2367 * @param min The minimum value of the distribution.
2368 * @param max The maximum value of the distribution.
2369 * @param bkt The number of values in each bucket.
2370 * @return A reference to this distribution.
2371 */
2372 Distribution &init(Counter min, Counter max, Counter bkt) {
2373 this->params.min = min;
2374 this->params.max = max;
2375 this->params.bucket_size = bkt;
2376 this->params.size = (int)rint((max - min) / bkt + 1.0);
2374
2375 public:
2376 /**
2377 * Set the parameters of this distribution. @sa DistStor::Params
2378 * @param min The minimum value of the distribution.
2379 * @param max The maximum value of the distribution.
2380 * @param bkt The number of values in each bucket.
2381 * @return A reference to this distribution.
2382 */
2383 Distribution &init(Counter min, Counter max, Counter bkt) {
2384 this->params.min = min;
2385 this->params.max = max;
2386 this->params.bucket_size = bkt;
2387 this->params.size = (int)rint((max - min) / bkt + 1.0);
2377 this->bin.init(this->params);
2378 this->setInit();
2379
2388 this->doInit();
2380 return *this;
2381 }
2382};
2383
2384/**
2385 * Calculates the mean and variance of all the samples.
2386 * @sa Stat, DistBase, FancyStor
2387 */
2389 return *this;
2390 }
2391};
2392
2393/**
2394 * Calculates the mean and variance of all the samples.
2395 * @sa Stat, DistBase, FancyStor
2396 */
2388template <class Bin = DefaultBin>
2397template<int N = 0>
2389class StandardDeviation
2398class StandardDeviation
2390 : public Wrap<StandardDeviation<Bin>,
2391 DistBase<FancyStor, Bin>,
2392 DistStatData>
2399 : public Wrap<StandardDeviation<N>, DistBase<FancyStor>, DistStatData>
2393{
2394 public:
2395 /** The base implementation */
2400{
2401 public:
2402 /** The base implementation */
2396 typedef DistBase<DistStor, Bin> Base;
2403 typedef DistBase Base;
2397 /** The parameter type. */
2404 /** The parameter type. */
2398 typedef typename DistStor::Params Params;
2405 typedef DistStor::Params Params;
2399
2400 public:
2401 /**
2402 * Construct and initialize this distribution.
2403 */
2404 StandardDeviation() {
2406
2407 public:
2408 /**
2409 * Construct and initialize this distribution.
2410 */
2411 StandardDeviation() {
2405 this->bin.init(this->params);
2406 this->setInit();
2412 this->doInit();
2407 }
2408};
2409
2410/**
2411 * Calculates the per cycle mean and variance of the samples.
2412 * @sa Stat, DistBase, AvgFancy
2413 */
2413 }
2414};
2415
2416/**
2417 * Calculates the per cycle mean and variance of the samples.
2418 * @sa Stat, DistBase, AvgFancy
2419 */
2414template <class Bin = DefaultBin>
2420template<int N = 0>
2415class AverageDeviation
2421class AverageDeviation
2416 : public Wrap<AverageDeviation<Bin>,
2417 DistBase<AvgFancy, Bin>,
2418 DistStatData>
2422 : public Wrap<AverageDeviation<N>, DistBase<AvgFancy>, DistStatData>
2419{
2420 public:
2421 /** The base implementation */
2423{
2424 public:
2425 /** The base implementation */
2422 typedef DistBase<DistStor, Bin> Base;
2426 typedef DistBase Base;
2423 /** The parameter type. */
2427 /** The parameter type. */
2424 typedef typename DistStor::Params Params;
2428 typedef DistStor::Params Params;
2425
2426 public:
2427 /**
2428 * Construct and initialize this distribution.
2429 */
2430 AverageDeviation()
2431 {
2429
2430 public:
2431 /**
2432 * Construct and initialize this distribution.
2433 */
2434 AverageDeviation()
2435 {
2432 this->bin.init(this->params);
2433 this->setInit();
2436 this->doInit();
2434 }
2435};
2436
2437/**
2438 * A vector of distributions.
2439 * @sa Stat, VectorDistBase, DistStor
2440 */
2437 }
2438};
2439
2440/**
2441 * A vector of distributions.
2442 * @sa Stat, VectorDistBase, DistStor
2443 */
2441template <class Bin = DefaultBin>
2444template<int N = 0>
2442class VectorDistribution
2445class VectorDistribution
2443 : public WrapVec<VectorDistribution<Bin>,
2444 VectorDistBase<DistStor, Bin>,
2446 : public WrapVec<VectorDistribution<N>,
2447 VectorDistBase,
2445 VectorDistStatData>
2446{
2447 public:
2448 /** The base implementation */
2448 VectorDistStatData>
2449{
2450 public:
2451 /** The base implementation */
2449 typedef VectorDistBase<DistStor, Bin> Base;
2452 typedef VectorDistBase Base;
2450 /** The parameter type. */
2453 /** The parameter type. */
2451 typedef typename DistStor::Params Params;
2454 typedef DistStor::Params Params;
2452
2453 public:
2454 /**
2455 * Initialize storage and parameters for this distribution.
2456 * @param size The size of the vector (the number of distributions).
2457 * @param min The minimum value of the distribution.
2458 * @param max The maximum value of the distribution.
2459 * @param bkt The number of values in each bucket.
2460 * @return A reference to this distribution.
2461 */
2462 VectorDistribution &init(int size, Counter min, Counter max, Counter bkt) {
2463 this->params.min = min;
2464 this->params.max = max;
2465 this->params.bucket_size = bkt;
2466 this->params.size = (int)rint((max - min) / bkt + 1.0);
2455
2456 public:
2457 /**
2458 * Initialize storage and parameters for this distribution.
2459 * @param size The size of the vector (the number of distributions).
2460 * @param min The minimum value of the distribution.
2461 * @param max The maximum value of the distribution.
2462 * @param bkt The number of values in each bucket.
2463 * @return A reference to this distribution.
2464 */
2465 VectorDistribution &init(int size, Counter min, Counter max, Counter bkt) {
2466 this->params.min = min;
2467 this->params.max = max;
2468 this->params.bucket_size = bkt;
2469 this->params.size = (int)rint((max - min) / bkt + 1.0);
2467 this->bin.init(size, this->params);
2468 this->setInit();
2469
2470 this->doInit(size);
2470 return *this;
2471 }
2472};
2473
2474/**
2475 * This is a vector of StandardDeviation stats.
2476 * @sa Stat, VectorDistBase, FancyStor
2477 */
2471 return *this;
2472 }
2473};
2474
2475/**
2476 * This is a vector of StandardDeviation stats.
2477 * @sa Stat, VectorDistBase, FancyStor
2478 */
2478template <class Bin = DefaultBin>
2479template<int N = 0>
2479class VectorStandardDeviation
2480class VectorStandardDeviation
2480 : public WrapVec<VectorStandardDeviation<Bin>,
2481 VectorDistBase<FancyStor, Bin>,
2481 : public WrapVec<VectorStandardDeviation<N>,
2482 VectorDistBase,
2482 VectorDistStatData>
2483{
2484 public:
2485 /** The base implementation */
2483 VectorDistStatData>
2484{
2485 public:
2486 /** The base implementation */
2486 typedef VectorDistBase<FancyStor, Bin> Base;
2487 typedef VectorDistBase Base;
2487 /** The parameter type. */
2488 /** The parameter type. */
2488 typedef typename DistStor::Params Params;
2489 typedef DistStor::Params Params;
2489
2490 public:
2491 /**
2492 * Initialize storage for this distribution.
2493 * @param size The size of the vector.
2494 * @return A reference to this distribution.
2495 */
2496 VectorStandardDeviation &init(int size) {
2490
2491 public:
2492 /**
2493 * Initialize storage for this distribution.
2494 * @param size The size of the vector.
2495 * @return A reference to this distribution.
2496 */
2497 VectorStandardDeviation &init(int size) {
2497 this->bin.init(size, this->params);
2498 this->setInit();
2499
2498 this->doInit(size);
2500 return *this;
2501 }
2502};
2503
2504/**
2505 * This is a vector of AverageDeviation stats.
2506 * @sa Stat, VectorDistBase, AvgFancy
2507 */
2499 return *this;
2500 }
2501};
2502
2503/**
2504 * This is a vector of AverageDeviation stats.
2505 * @sa Stat, VectorDistBase, AvgFancy
2506 */
2508template <class Bin = DefaultBin>
2507template<int N = 0>
2509class VectorAverageDeviation
2508class VectorAverageDeviation
2510 : public WrapVec<VectorAverageDeviation<Bin>,
2511 VectorDistBase<AvgFancy, Bin>,
2509 : public WrapVec<VectorAverageDeviation<N>,
2510 VectorDistBase,
2512 VectorDistStatData>
2513{
2514 public:
2515 /** The base implementation */
2511 VectorDistStatData>
2512{
2513 public:
2514 /** The base implementation */
2516 typedef VectorDistBase<AvgFancy, Bin> Base;
2515 typedef VectorDistBase Base;
2517 /** The parameter type. */
2516 /** The parameter type. */
2518 typedef typename DistStor::Params Params;
2517 typedef DistStor::Params Params;
2519
2520 public:
2521 /**
2522 * Initialize storage for this distribution.
2523 * @param size The size of the vector.
2524 * @return A reference to this distribution.
2525 */
2526 VectorAverageDeviation &init(int size) {
2518
2519 public:
2520 /**
2521 * Initialize storage for this distribution.
2522 * @param size The size of the vector.
2523 * @return A reference to this distribution.
2524 */
2525 VectorAverageDeviation &init(int size) {
2527 this->bin.init(size, this->params);
2528 this->setInit();
2529
2526 this->doInit(size);
2530 return *this;
2531 }
2532};
2533
2534/**
2535 * A formula for statistics that is calculated when printed. A formula is
2536 * stored as a tree of Nodes that represent the equation to calculate.
2537 * @sa Stat, ScalarStat, VectorStat, Node, Temp

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

2565 */
2566 Result total() const;
2567
2568 /**
2569 * Return the number of elements in the tree.
2570 */
2571 size_t size() const;
2572
2527 return *this;
2528 }
2529};
2530
2531/**
2532 * A formula for statistics that is calculated when printed. A formula is
2533 * stored as a tree of Nodes that represent the equation to calculate.
2534 * @sa Stat, ScalarStat, VectorStat, Node, Temp

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

2562 */
2563 Result total() const;
2564
2565 /**
2566 * Return the number of elements in the tree.
2567 */
2568 size_t size() const;
2569
2573 /**
2574 * Return true if Formula is binned. i.e. any of its children
2575 * nodes are binned
2576 * @return True if Formula is binned.
2577 */
2578 bool binned() const;
2579
2580 bool check() const { return true; }
2581
2582 /**
2583 * Formulas don't need to be reset
2584 */
2585 void reset();
2586
2587 /**

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

2610 protected:
2611 Stat &s;
2612 mutable VResult vec;
2613 mutable VCounter cvec;
2614
2615 public:
2616 FormulaStatData(Stat &stat) : s(stat) {}
2617
2570 bool check() const { return true; }
2571
2572 /**
2573 * Formulas don't need to be reset
2574 */
2575 void reset();
2576
2577 /**

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

2600 protected:
2601 Stat &s;
2602 mutable VResult vec;
2603 mutable VCounter cvec;
2604
2605 public:
2606 FormulaStatData(Stat &stat) : s(stat) {}
2607
2618 virtual bool binned() const { return s.binned(); }
2619 virtual bool zero() const { return s.zero(); }
2620 virtual void reset() { s.reset(); }
2621
2622 virtual size_t size() const { return s.size(); }
2623 virtual const VResult &result() const
2624 {
2625 s.result(vec);
2626 return vec;

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

2677 mutable VResult vec;
2678
2679 public:
2680 FormulaNode(const Formula &f) : formula(f) {}
2681
2682 virtual size_t size() const { return formula.size(); }
2683 virtual const VResult &result() const { formula.result(vec); return vec; }
2684 virtual Result total() const { return formula.total(); }
2608 virtual bool zero() const { return s.zero(); }
2609 virtual void reset() { s.reset(); }
2610
2611 virtual size_t size() const { return s.size(); }
2612 virtual const VResult &result() const
2613 {
2614 s.result(vec);
2615 return vec;

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

2666 mutable VResult vec;
2667
2668 public:
2669 FormulaNode(const Formula &f) : formula(f) {}
2670
2671 virtual size_t size() const { return formula.size(); }
2672 virtual const VResult &result() const { formula.result(vec); return vec; }
2673 virtual Result total() const { return formula.total(); }
2685 virtual bool binned() const { return formula.binned(); }
2686
2687 virtual std::string str() const { return formula.str(); }
2688};
2689
2690/**
2691 * Helper class to construct formula node trees.
2692 */
2693class Temp

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

2711 */
2712 operator NodePtr&() { return node;}
2713
2714 public:
2715 /**
2716 * Create a new ScalarStatNode.
2717 * @param s The ScalarStat to place in a node.
2718 */
2674
2675 virtual std::string str() const { return formula.str(); }
2676};
2677
2678/**
2679 * Helper class to construct formula node trees.
2680 */
2681class Temp

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

2699 */
2700 operator NodePtr&() { return node;}
2701
2702 public:
2703 /**
2704 * Create a new ScalarStatNode.
2705 * @param s The ScalarStat to place in a node.
2706 */
2719 template <class Bin>
2720 Temp(const Scalar<Bin> &s)
2707 template <int N>
2708 Temp(const Scalar<N> &s)
2721 : node(new ScalarStatNode(s.statData())) { }
2722
2723 /**
2724 * Create a new ScalarStatNode.
2725 * @param s The ScalarStat to place in a node.
2726 */
2727 Temp(const Value &s)
2728 : node(new ScalarStatNode(s.statData())) { }
2729
2730 /**
2731 * Create a new ScalarStatNode.
2732 * @param s The ScalarStat to place in a node.
2733 */
2709 : node(new ScalarStatNode(s.statData())) { }
2710
2711 /**
2712 * Create a new ScalarStatNode.
2713 * @param s The ScalarStat to place in a node.
2714 */
2715 Temp(const Value &s)
2716 : node(new ScalarStatNode(s.statData())) { }
2717
2718 /**
2719 * Create a new ScalarStatNode.
2720 * @param s The ScalarStat to place in a node.
2721 */
2734 template <class Bin>
2735 Temp(const Average<Bin> &s)
2722 template <int N>
2723 Temp(const Average<N> &s)
2736 : node(new ScalarStatNode(s.statData())) { }
2737
2738 /**
2739 * Create a new VectorStatNode.
2740 * @param s The VectorStat to place in a node.
2741 */
2724 : node(new ScalarStatNode(s.statData())) { }
2725
2726 /**
2727 * Create a new VectorStatNode.
2728 * @param s The VectorStat to place in a node.
2729 */
2742 template <class Bin>
2743 Temp(const Vector<Bin> &s)
2730 template <int N>
2731 Temp(const Vector<N> &s)
2744 : node(new VectorStatNode(s.statData())) { }
2745
2746 /**
2747 *
2748 */
2749 Temp(const Formula &f)
2750 : node(new FormulaNode(f)) { }
2751
2752 /**
2753 * Create a new ScalarProxyNode.
2754 * @param p The ScalarProxy to place in a node.
2755 */
2732 : node(new VectorStatNode(s.statData())) { }
2733
2734 /**
2735 *
2736 */
2737 Temp(const Formula &f)
2738 : node(new FormulaNode(f)) { }
2739
2740 /**
2741 * Create a new ScalarProxyNode.
2742 * @param p The ScalarProxy to place in a node.
2743 */
2756 template <class Storage, class Bin>
2757 Temp(const ScalarProxy<Storage, Bin> &p)
2758 : node(new ScalarProxyNode<Storage, Bin>(p)) { }
2744 template <class Stat>
2745 Temp(const ScalarProxy<Stat> &p)
2746 : node(new ScalarProxyNode<Stat>(p)) { }
2759
2760 /**
2761 * Create a ConstNode
2762 * @param value The value of the const node.
2763 */
2764 Temp(signed char value)
2765 : node(new ConstNode<signed char>(value)) {}
2766

--- 133 unchanged lines hidden ---
2747
2748 /**
2749 * Create a ConstNode
2750 * @param value The value of the const node.
2751 */
2752 Temp(signed char value)
2753 : node(new ConstNode<signed char>(value)) {}
2754

--- 133 unchanged lines hidden ---