Changeset 1cb7fab2
- 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
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/Stats.h
r675716e r1cb7fab2 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Heap.h --7 // Stats.h -- 8 8 // 9 9 // Author : Thierry Delisle … … 18 18 #include "Common/Stats/Counter.h" 19 19 #include "Common/Stats/Heap.h" 20 #include "Common/Stats/Time.h" 21 22 namespace Stats { 23 void parse_params(const char * const params); 24 void print(); 25 } -
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++; -
src/Common/module.mk
r675716e r1cb7fab2 20 20 Common/PassVisitor.cc \ 21 21 Common/SemanticError.cc \ 22 Common/Stats/Counter.cc \ 22 23 Common/Stats/Heap.cc \ 23 Common/Stats/ Counter.cc \24 Common/Stats/Stats.cc \ 24 25 Common/UniqueName.cc 25 26 -
src/Makefile.in
r675716e r1cb7fab2 167 167 am__objects_2 = Common/Assert.$(OBJEXT) Common/Eval.$(OBJEXT) \ 168 168 Common/PassVisitor.$(OBJEXT) Common/SemanticError.$(OBJEXT) \ 169 Common/Stats/ Heap.$(OBJEXT) Common/Stats/Counter.$(OBJEXT) \170 Common/ UniqueName.$(OBJEXT)169 Common/Stats/Counter.$(OBJEXT) Common/Stats/Heap.$(OBJEXT) \ 170 Common/Stats/Stats.$(OBJEXT) Common/UniqueName.$(OBJEXT) 171 171 am__objects_3 = ControlStruct/ForExprMutator.$(OBJEXT) \ 172 172 ControlStruct/LabelFixer.$(OBJEXT) \ … … 564 564 Common/PassVisitor.cc \ 565 565 Common/SemanticError.cc \ 566 Common/Stats/Counter.cc \ 566 567 Common/Stats/Heap.cc \ 567 Common/Stats/ Counter.cc \568 Common/Stats/Stats.cc \ 568 569 Common/UniqueName.cc 569 570 … … 735 736 @$(MKDIR_P) Common/Stats/$(DEPDIR) 736 737 @: > Common/Stats/$(DEPDIR)/$(am__dirstamp) 738 Common/Stats/Counter.$(OBJEXT): Common/Stats/$(am__dirstamp) \ 739 Common/Stats/$(DEPDIR)/$(am__dirstamp) 737 740 Common/Stats/Heap.$(OBJEXT): Common/Stats/$(am__dirstamp) \ 738 741 Common/Stats/$(DEPDIR)/$(am__dirstamp) 739 Common/Stats/ Counter.$(OBJEXT): Common/Stats/$(am__dirstamp) \742 Common/Stats/Stats.$(OBJEXT): Common/Stats/$(am__dirstamp) \ 740 743 Common/Stats/$(DEPDIR)/$(am__dirstamp) 741 744 Common/UniqueName.$(OBJEXT): Common/$(am__dirstamp) \ … … 1124 1127 @AMDEP_TRUE@@am__include@ @am__quote@Common/Stats/$(DEPDIR)/Counter.Po@am__quote@ 1125 1128 @AMDEP_TRUE@@am__include@ @am__quote@Common/Stats/$(DEPDIR)/Heap.Po@am__quote@ 1129 @AMDEP_TRUE@@am__include@ @am__quote@Common/Stats/$(DEPDIR)/Stats.Po@am__quote@ 1126 1130 @AMDEP_TRUE@@am__include@ @am__quote@Concurrency/$(DEPDIR)/Keywords.Po@am__quote@ 1127 1131 @AMDEP_TRUE@@am__include@ @am__quote@Concurrency/$(DEPDIR)/Waitfor.Po@am__quote@ -
src/SymTab/Indexer.cc
r675716e r1cb7fab2 45 45 // Statistics block 46 46 namespace { 47 auto idtable_group = new Stats::Counters::CounterGroup("IdTable"); 48 auto idtable_find = new Stats::Counters::SimpleCounter("Find calls", idtable_group); 49 auto idtable_size = new Stats::Counters::AverageCounter<double>("Average Size", idtable_group); 50 auto idtable_key = new Stats::Counters::AverageCounter<double>("Average Key Size", idtable_group); 51 52 auto indexers_group = new Stats::Counters::CounterGroup("Indexers"); 53 auto indexers_count = new Stats::Counters::SimpleCounter("Count", indexers_group); 54 auto indexers_size = new Stats::Counters::AverageCounter<double>("Average Size", indexers_group); 55 auto indexers_depth_a = new Stats::Counters::AverageCounter<double>("Average Depth", indexers_group); 56 auto indexers_depth_m = new Stats::Counters::MaxCounter<size_t>("Max Depth", indexers_group); 47 48 static inline auto stats_idtable() { 49 using namespace Stats::Counters; 50 static auto group = build<CounterGroup>("IdTable"); 51 static struct { 52 SimpleCounter * find; 53 AverageCounter<double> * size; 54 AverageCounter<double> * key; 55 } ret = { 56 .find = build<SimpleCounter>("Find calls", group), 57 .size = build<AverageCounter<double>>("Average Size", group), 58 .key = build<AverageCounter<double>>("Average Key Size", group), 59 }; 60 return ret; 61 } 62 63 static inline auto stats_indexers() { 64 using namespace Stats::Counters; 65 static auto group = build<CounterGroup>("Indexers"); 66 static struct { 67 SimpleCounter * count; 68 AverageCounter<double> * size; 69 AverageCounter<double> * depth_a; 70 MaxCounter<size_t> * depth_m; 71 } ret = { 72 .count = build<SimpleCounter>("Count", group), 73 .size = build<AverageCounter<double>>("Average Size", group), 74 .depth_a = build<AverageCounter<double>>("Average Depth", group), 75 .depth_m = build<MaxCounter<size_t>>("Max Depth", group), 76 }; 77 return ret; 78 } 57 79 } 58 80 … … 214 236 215 237 Indexer::Indexer() : tables( 0 ), scope( 0 ) { 216 (* indexers_count)++;238 (*stats_indexers().count)++; 217 239 } 218 240 219 241 Indexer::Indexer( const Indexer &that ) : doDebug( that.doDebug ), tables( newRef( that.tables ) ), scope( that.scope ) { 220 (* indexers_count)++;242 (*stats_indexers().count)++; 221 243 } 222 244 … … 227 249 Indexer::~Indexer() { 228 250 if(tables) { 229 indexers_size->push( tables->idTable.size() );251 stats_indexers().size->push( tables->idTable.size() ); 230 252 size_t depth = 1; 231 253 for( auto crnt = tables->base.tables; crnt; crnt = crnt->base.tables ) { 232 254 ++depth; 233 255 } 234 indexers_depth_a->push( depth );235 indexers_depth_m->push( depth );256 stats_indexers().depth_a->push( depth ); 257 stats_indexers().depth_m->push( depth ); 236 258 } 237 259 deleteRef( tables ); … … 266 288 while ( searchTables ) { 267 289 268 (* idtable_find)++;269 idtable_key->push( id.size() );270 idtable_size->push( searchTables->idTable.size() );290 (*stats_idtable().find)++; 291 stats_idtable().key->push( id.size() ); 292 stats_idtable().size->push( searchTables->idTable.size() ); 271 293 IdTable::const_iterator decls = searchTables->idTable.find( id ); 272 294 if ( decls != searchTables->idTable.end() ) { … … 345 367 if ( tables->scope < scope ) return nullptr; 346 368 347 (* idtable_find)++;348 idtable_key->push( id.size() );349 idtable_size->push( tables->idTable.size() );369 (*stats_idtable().find)++; 370 stats_idtable().key->push( id.size() ); 371 stats_idtable().size->push( tables->idTable.size() ); 350 372 IdTable::const_iterator decls = tables->idTable.find( id ); 351 373 if ( decls != tables->idTable.end() ) { … … 366 388 if ( tables->scope < scope ) return false; 367 389 368 (* idtable_find)++;369 idtable_key->push( id.size() );370 idtable_size->push( tables->idTable.size() );390 (*stats_idtable().find)++; 391 stats_idtable().key->push( id.size() ); 392 stats_idtable().size->push( tables->idTable.size() ); 371 393 IdTable::const_iterator decls = tables->idTable.find( id ); 372 394 if ( decls != tables->idTable.end() ) { … … 385 407 if ( tables->scope < scope ) return false; 386 408 387 (* idtable_find)++;388 idtable_key->push( id.size() );389 idtable_size->push( tables->idTable.size() );409 (*stats_idtable().find)++; 410 stats_idtable().key->push( id.size() ); 411 stats_idtable().size->push( tables->idTable.size() ); 390 412 IdTable::const_iterator decls = tables->idTable.find( id ); 391 413 if ( decls != tables->idTable.end() ) { -
src/main.cc
r675716e r1cb7fab2 65 65 using namespace std; 66 66 67 auto pass_visitor_group = new Stats::Counters::CounterGroup("Pass Visitor");68 67 69 68 void NewPass(const char * const name) { 70 69 Stats::Heap::newPass(name); 71 auto pass = new Stats::Counters::CounterGroup(name, pass_visitor_group); 70 using namespace Stats::Counters; 71 static auto pass_visitor_group = build<CounterGroup>("Pass Visitor"); 72 auto pass = build<CounterGroup>(name, pass_visitor_group); 72 73 pass_visitor_stats.depth = 0; 73 pass_visitor_stats.avg = new Stats::Counters::AverageCounter<double>("Average Depth", pass);74 pass_visitor_stats.max = new Stats::Counters::MaxCounter<double>("Max Depth", pass);74 pass_visitor_stats.avg = build<AverageCounter<double>>("Average Depth", pass); 75 pass_visitor_stats.max = build<MaxCounter<double>>("Max Depth", pass); 75 76 } 76 77 … … 389 390 390 391 deleteAll( translationUnit ); 391 if(!libcfap && !treep) { 392 if(stats_counters) Stats::Counters::print(); 393 if(stats_heap) Stats::Heap::print(); 394 } 392 Stats::print(); 395 393 396 394 return 0; … … 508 506 break; 509 507 case Stats: 510 { 511 std::stringstream ss(optarg); 512 while(ss.good()) { 513 std::string substr; 514 getline( ss, substr, ',' ); 515 if(substr == "counters") { 516 stats_counters = true; 517 } else if(substr == "heap") { 518 stats_heap = true; 519 } else if(substr == "none") { 520 stats_counters = false; 521 stats_heap = false; 522 } else { 523 std::cerr << "Ignoring unknown statistic " << substr << std::endl; 524 } 525 } 526 527 } 508 Stats::parse_params(optarg); 528 509 break; 529 510 case Symbol:
Note: See TracChangeset
for help on using the changeset viewer.