Changeset 1cb7fab2 for src/Common/Stats
- Timestamp:
- Mar 4, 2019, 2:53:55 PM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, persistent-indexer, pthread-emulation, qualifiedEnum
- Children:
- 874ffa4
- Parents:
- 675716e
- Location:
- src/Common/Stats
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/Stats/Base.h
r675716e r1cb7fab2 16 16 #pragma once 17 17 18 #include <string>19 20 18 namespace Stats { 21 19 namespace Base { 20 class TreeImpl; 21 22 struct TreeTop { 23 TreeImpl * head = nullptr; 24 TreeImpl * tail = nullptr; 25 26 inline void append(TreeImpl * node); 27 }; 28 29 template<typename func_t> 30 void ForAll(TreeTop & range, size_t level, func_t func, bool destroy = false); 31 22 32 class TreeImpl { 23 33 public: 24 struct Top {25 TreeImpl * head = nullptr;26 TreeImpl * tail = nullptr;27 28 void append(TreeImpl * node) {29 if(!head) { head = node; }30 else { tail->next = node;}31 tail = node;32 }33 };34 35 34 virtual void print(std::ostream &) = 0; 36 35 37 const std::stringname;38 TreeImpl(const std::string &name) : name(name) {}36 const char * const name; 37 TreeImpl(const char * const name) : name(name) {} 39 38 40 39 protected: … … 42 41 43 42 TreeImpl * next = nullptr; 44 Top children; 43 TreeTop children; 44 45 friend struct TreeTop; 45 46 46 47 template<typename func_t> 47 friend void ForAll(Tree Impl::Top & range, size_t level, func_t func, bool destroy = false);48 friend void ForAll(TreeTop & range, size_t level, func_t func, bool destroy); 48 49 }; 49 50 51 void TreeTop::append(TreeImpl * node) { 52 if(!head) { head = node; } 53 else { tail->next = node;} 54 tail = node; 55 } 56 50 57 template<typename func_t> 51 inline void ForAll(Tree Impl::Top & range, size_t level, func_t func, bool destroy) {58 inline void ForAll(TreeTop & range, size_t level, func_t func, bool destroy) { 52 59 auto it = range.head; 53 60 while(it) { … … 60 67 } 61 68 62 template<Tree Impl::Top & top>69 template<TreeTop & top> 63 70 class Tree : public TreeImpl { 64 71 public: 65 Tree(const std::string &name) : TreeImpl{name} {72 Tree(const char * const name) : TreeImpl{name} { 66 73 top.append(this); 67 74 } 68 75 69 Tree(const std::string &name, Tree * parent) : TreeImpl{name} {76 Tree(const char * const name, Tree * parent) : TreeImpl{name} { 70 77 parent->children.append(this); 71 78 } -
src/Common/Stats/Counter.cc
r675716e r1cb7fab2 27 27 size_t nc = 0; 28 28 Base::ForAll(top, 0, [&](Base::TreeImpl * node, size_t level) { 29 nc = std::max(nc, (4 * level) + node->name.size());29 nc = std::max(nc, (4 * level) + std::strlen(node->name)); 30 30 }); 31 31 32 const std::string &title = "Counter Statistic";32 const char * const title = "Counter Statistic"; 33 33 size_t nct = nc + 14; 34 34 std::cerr << std::string(nct, '=') << std::endl; 35 std::cerr << std::string((nct - title.size()) / 2, ' ');35 std::cerr << std::string((nct - std::strlen(title)) / 2, ' '); 36 36 std::cerr << title << std::endl; 37 37 std::cerr << std::string(nct, '-') << std::endl; … … 41 41 std::cerr << std::string(level * 4, ' '); 42 42 std::cerr << node->name; 43 std::cerr << std::string(nc - ((level * 4) + node->name.size()), ' ');43 std::cerr << std::string(nc - ((level * 4) + std::strlen(node->name)), ' '); 44 44 std::cerr << " | "; 45 45 std::cerr << std::setw(9); … … 52 52 } 53 53 54 Base::TreeImpl::Top top; 54 Base::TreeTop top; 55 56 extern bool enabled; 55 57 } 56 58 } -
src/Common/Stats/Counter.h
r675716e r1cb7fab2 18 18 #include <cstdint> 19 19 #include <iostream> 20 #include <string>21 20 22 21 #include "Common/Stats/Base.h" 23 22 23 #if defined( NO_STATISTICS ) 24 #define NO_COUNTER_STATISTICS 25 #endif 26 24 27 namespace Stats { 25 28 namespace Counters { 26 void print(); 29 # if defined(NO_COUNTERS_STATISTICS) 27 30 28 extern Base::TreeImpl::Top top;31 static inline void print() {} 29 32 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) {} 33 class CounterGroup { 34 public: 35 }; 34 36 35 virtual void print(std::ostream & os) override { os << ""; } 36 protected: 37 virtual ~CounterGroup() = default; 38 }; 37 class SimpleCounter { 38 public: 39 inline void operator++(int) {} 40 inline void operator+=(size_t) {} 41 }; 39 42 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) {} 43 template<typename T> 44 class AverageCounter { 45 public: 46 inline void push(T value) {} 47 }; 44 48 45 virtual void print(std::ostream & os) override { os << count; } 49 template<typename T> 50 class MaxCounter { 51 public: 52 inline void push(T value) {} 53 }; 46 54 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++; 55 template<typename counter_t> 56 counter_t * build(const char * const name) { 57 return nullptr; 67 58 } 68 59 69 protected: 70 virtual ~AverageCounter() = default; 60 template<typename counter_t> 61 counter_t * build(const char * const name, Base::Tree<top> * parent) { 62 return nullptr; 63 } 64 # else 65 extern bool enabled; 71 66 72 private: 73 T sum; 74 size_t count = 1; 75 }; 67 extern Base::TreeTop top; 76 68 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{} {} 69 class CounterGroup : public Base::Tree<top> { 70 public: 71 CounterGroup(const char * const name ) : Base::Tree<top>(name) {} 72 CounterGroup(const char * const name, Base::Tree<top> * parent) : Base::Tree<top>(name, parent) {} 82 73 83 virtual void print(std::ostream & os) { os << max; } 74 virtual void print(std::ostream & os) override { os << ""; } 75 protected: 76 virtual ~CounterGroup() = default; 77 }; 84 78 85 inline void push(T value) { max = std::max(max, value); } 86 protected: 87 virtual ~MaxCounter() = default; 79 class SimpleCounter : public Base::Tree<top> { 80 public: 81 SimpleCounter(const char * const name ) : Base::Tree<top>(name) {} 82 SimpleCounter(const char * const name, Base::Tree<top> * parent) : Base::Tree<top>(name, parent) {} 88 83 89 private: 90 T max; 91 }; 84 virtual void print(std::ostream & os) override { os << count; } 85 86 inline void operator++(int) { if(!enabled) return; count++; } 87 inline void operator+=(size_t value) { if(!enabled) return; count += value; } 88 89 protected: 90 virtual ~SimpleCounter() = default; 91 92 private: 93 size_t count = 0; 94 }; 95 96 template<typename T> 97 class AverageCounter : public Base::Tree<top> { 98 public: 99 AverageCounter(const char * const name ) : Base::Tree<top>(name), sum{} {} 100 AverageCounter(const char * const name, Base::Tree<top> * parent) : Base::Tree<top>(name, parent), sum{} {} 101 102 virtual void print(std::ostream & os) { os << sum / count; } 103 104 inline void push(T value) { if(!enabled) return; sum += value; count++; } 105 106 protected: 107 virtual ~AverageCounter() = default; 108 109 private: 110 T sum; 111 size_t count = 1; 112 }; 113 114 template<typename T> 115 class MaxCounter : public Base::Tree<top> { 116 public: 117 MaxCounter(const char * const name ) : Base::Tree<top>(name), max{} {} 118 MaxCounter(const char * const name, Base::Tree<top> * parent) : Base::Tree<top>(name, parent), max{} {} 119 120 virtual void print(std::ostream & os) { os << max; } 121 122 inline void push(T value) { if(!enabled) return; max = std::max(max, value); } 123 124 protected: 125 virtual ~MaxCounter() = default; 126 127 private: 128 T max; 129 }; 130 131 template<typename counter_t> 132 counter_t * build(const char * const name) { 133 if(!enabled) return nullptr; 134 return new counter_t(name); 135 } 136 137 template<typename counter_t> 138 counter_t * build(const char * const name, Base::Tree<top> * parent) { 139 if(!enabled) return nullptr; 140 return new counter_t(name, parent); 141 } 142 # endif 92 143 } 93 144 } -
src/Common/Stats/Heap.cc
r675716e r1cb7fab2 21 21 #include <iostream> 22 22 23 #if defined( NO_STATISTICS ) 24 #define NO_HEAP_STATISTICS 25 #endif 26 23 27 namespace Stats { 24 28 namespace Heap { … … 28 32 void print() {} 29 33 #else 34 extern bool enabled; 35 30 36 struct StatBlock { 31 37 const char * name = nullptr; ///< Name of this pass … … 77 83 78 84 void print() { 85 if(!enabled) return; 86 79 87 size_t nc = 0; 80 88 size_t total_mallocs = 0; … … 166 174 void * malloc( size_t size ) { 167 175 static auto __malloc = reinterpret_cast<void * (*)(size_t)>(interpose_symbol( "malloc", nullptr )); 168 if( passes_cnt > 0 ) {176 if( enabled && passes_cnt > 0 ) { 169 177 passes[passes_cnt - 1].mallocs++; 170 178 passes[passes_cnt - 1].n_allocs++; … … 177 185 void free( void * ptr ) { 178 186 static auto __free = reinterpret_cast<void (*)(void *)>(interpose_symbol( "free", nullptr )); 179 if( passes_cnt > 0 ) {187 if( enabled && passes_cnt > 0 ) { 180 188 passes[passes_cnt - 1].frees++; 181 189 passes[passes_cnt - 1].n_allocs--; … … 186 194 void * calloc( size_t nelem, size_t size ) { 187 195 static auto __calloc = reinterpret_cast<void * (*)(size_t, size_t)>(interpose_symbol( "calloc", nullptr )); 188 if( passes_cnt > 0 ) {196 if( enabled && passes_cnt > 0 ) { 189 197 passes[passes_cnt - 1].mallocs++; 190 198 passes[passes_cnt - 1].n_allocs++; … … 198 206 static auto __realloc = reinterpret_cast<void * (*)(void *, size_t)>(interpose_symbol( "realloc", nullptr )); 199 207 void * s = __realloc( ptr, size ); 200 if ( s != ptr && passes_cnt > 0 ) { // did realloc get new storage ?208 if ( enabled && s != ptr && passes_cnt > 0 ) { // did realloc get new storage ? 201 209 passes[passes_cnt - 1].mallocs++; 202 210 passes[passes_cnt - 1].frees++;
Note: See TracChangeset
for help on using the changeset viewer.