1 | // |
---|
2 | // Cforall Version 1.0.0 Copyright (C) 2019 University of Waterloo |
---|
3 | // |
---|
4 | // The contents of this file are covered under the licence agreement in the |
---|
5 | // file "LICENCE" distributed with Cforall. |
---|
6 | // |
---|
7 | // Heap.h -- |
---|
8 | // |
---|
9 | // Author : Thierry Delisle |
---|
10 | // Created On : Thu Feb 28 12::05:10 2019 |
---|
11 | // Last Modified By : |
---|
12 | // Last Modified On : |
---|
13 | // Update Count : |
---|
14 | // |
---|
15 | |
---|
16 | #pragma once |
---|
17 | |
---|
18 | #include <cstdint> |
---|
19 | #include <iostream> |
---|
20 | #include <string> |
---|
21 | |
---|
22 | #include "Common/Stats/Base.h" |
---|
23 | |
---|
24 | namespace Stats { |
---|
25 | namespace Counters { |
---|
26 | void print(); |
---|
27 | |
---|
28 | extern Base::TreeImpl::Top top; |
---|
29 | |
---|
30 | class CounterGroup : public Base::Tree<top> { |
---|
31 | public: |
---|
32 | CounterGroup(const std::string & name ) : Base::Tree<top>(name) {} |
---|
33 | CounterGroup(const std::string & name, Base::Tree<top> * parent) : Base::Tree<top>(name, parent) {} |
---|
34 | |
---|
35 | virtual void print(std::ostream & os) override { os << ""; } |
---|
36 | protected: |
---|
37 | virtual ~CounterGroup() = default; |
---|
38 | }; |
---|
39 | |
---|
40 | class SimpleCounter : public Base::Tree<top> { |
---|
41 | public: |
---|
42 | SimpleCounter(const std::string & name ) : Base::Tree<top>(name) {} |
---|
43 | SimpleCounter(const std::string & name, Base::Tree<top> * parent) : Base::Tree<top>(name, parent) {} |
---|
44 | |
---|
45 | virtual void print(std::ostream & os) override { os << count; } |
---|
46 | |
---|
47 | inline void operator++(int) { count++; } |
---|
48 | inline void operator+=(size_t value) { count += value; } |
---|
49 | protected: |
---|
50 | virtual ~SimpleCounter() = default; |
---|
51 | |
---|
52 | private: |
---|
53 | size_t count = 0; |
---|
54 | }; |
---|
55 | |
---|
56 | template<typename T> |
---|
57 | class AverageCounter : public Base::Tree<top> { |
---|
58 | public: |
---|
59 | AverageCounter(const std::string & name ) : Base::Tree<top>(name), sum{} {} |
---|
60 | AverageCounter(const std::string & name, Base::Tree<top> * parent) : Base::Tree<top>(name, parent), sum{} {} |
---|
61 | |
---|
62 | virtual void print(std::ostream & os) { os << sum / count; } |
---|
63 | |
---|
64 | inline void push(T value) { |
---|
65 | sum += value; |
---|
66 | count++; |
---|
67 | } |
---|
68 | |
---|
69 | protected: |
---|
70 | virtual ~AverageCounter() = default; |
---|
71 | |
---|
72 | private: |
---|
73 | T sum; |
---|
74 | size_t count = 1; |
---|
75 | }; |
---|
76 | |
---|
77 | template<typename T> |
---|
78 | class MaxCounter : public Base::Tree<top> { |
---|
79 | public: |
---|
80 | MaxCounter(const std::string & name ) : Base::Tree<top>(name), max{} {} |
---|
81 | MaxCounter(const std::string & name, Base::Tree<top> * parent) : Base::Tree<top>(name, parent), max{} {} |
---|
82 | |
---|
83 | virtual void print(std::ostream & os) { os << max; } |
---|
84 | |
---|
85 | inline void push(T value) { max = std::max(max, value); } |
---|
86 | protected: |
---|
87 | virtual ~MaxCounter() = default; |
---|
88 | |
---|
89 | private: |
---|
90 | T max; |
---|
91 | }; |
---|
92 | } |
---|
93 | } |
---|