Changeset 79eaeb7
- Timestamp:
- Mar 5, 2019, 1:14:52 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:
- 3c0d4cd
- Parents:
- 4f97937
- Location:
- src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/Stats/Time.cc
r4f97937 r79eaeb7 31 31 Base::TreeTop top; 32 32 33 typedef std::chrono::time_point<std::chrono::high_resolution_clock> point_t; 34 std::chrono::duration<double> total; 35 std::chrono::duration<double> parent; 36 37 point_t global_begin; 38 39 template<typename T> 40 static inline std::ostream & operator<<(std::ostream & os, const std::chrono::duration<T> & dd) { 41 auto d = std::chrono::duration_cast<std::chrono::milliseconds>(dd); 42 auto minutes = std::chrono::duration_cast<std::chrono::minutes>(d); 43 auto seconds = std::chrono::duration_cast<std::chrono::seconds>(d % std::chrono::minutes(1)); 44 auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(d % std::chrono::seconds(1)); 45 46 bool zmin = minutes == minutes.zero(); 47 bool zsec = seconds == seconds.zero(); 48 bool zmil = millis == millis .zero(); 49 50 if(!zmin) { 51 os << std::setw(4) << minutes.count() << "m"; 52 } else { 53 os << std::string(5, ' '); 54 } 55 56 if(!zmin || !zsec) { 57 if(!zmin) os << std::setfill('0'); 58 os << std::setw(2) << seconds.count() << "s"; 59 } else { 60 os << std::string(3, ' '); 61 } 62 os << std::setfill(' '); 63 64 if(!zmin || !zsec || !zmil) { 65 if(!zmin || !zsec) os << std::setfill('0'); 66 os << std::setw(3) << millis .count(); 67 } else { 68 os << std::string(4, ' '); 69 } 70 os << std::setfill(' '); 71 72 return os; 73 } 74 33 75 class TimerNode : public Base::Tree<top> { 34 76 public: … … 45 87 assert(finished); 46 88 std::chrono::duration<double> diff = end - begin; 47 os << diff.count(); 89 os << diff << " | "; 90 os << std::setw(7) << std::setprecision(0); 91 os << size_t(100.0 * diff.count() / total.count()) << "% | "; 92 os << std::setw(5) << std::setprecision(0); 93 os << size_t(100.0 * diff.count() / total.count()) << "% "; 48 94 } 49 95 … … 63 109 bool finished = false; 64 110 65 typedef std::chrono::time_point<std::chrono::high_resolution_clock> point_t;66 111 point_t begin; 67 112 point_t end; … … 69 114 70 115 std::stack<TimerNode *> nodes; 116 117 void StartGlobal() { 118 global_begin = std::chrono::high_resolution_clock::now(); 119 } 71 120 72 121 void StartBlock(const char * const name) { … … 88 137 void print() { 89 138 if(!top.head) return; 139 auto global_end = std::chrono::high_resolution_clock::now(); 140 total = global_end - global_begin; 141 parent = total; 142 90 143 size_t nc = 0; 91 144 Base::ForAll(top, 0, [&](Base::TreeImpl * node, size_t level) { … … 93 146 }); 94 147 148 size_t nct = nc + 37; 149 std::cerr << std::string(nct, '=') << std::endl; 95 150 const char * const title = "Timing Results"; 96 size_t nct = nc + 14;97 std::cerr << std::string(nct, '=') << std::endl;98 151 std::cerr << std::string((nct - std::strlen(title)) / 2, ' '); 99 152 std::cerr << title << std::endl; 100 153 std::cerr << std::string(nct, '-') << std::endl; 101 154 std::cerr << "Location"; 155 std::cerr << std::string(nc - (std::strlen("Location")), ' '); 156 std::cerr << " | "; 157 std::cerr << " Time | "; 158 std::cerr << "% parent | "; 159 std::cerr << "% total |" << std::endl; 160 std::cerr << std::string(nct, '-') << std::endl; 102 161 103 162 Base::ForAll(top, 0, [&](Base::TreeImpl * node, size_t level) { … … 106 165 std::cerr << std::string(nc - ((level * 4) + std::strlen(node->name)), ' '); 107 166 std::cerr << " | "; 108 std::cerr << std::setw(9);109 167 node->print(std::cerr); 110 168 std::cerr << " |"; … … 113 171 114 172 std::cerr << std::string(nct, '-') << std::endl; 173 std::cerr << "Total " << total << std::endl; 174 std::cerr << std::string(nct, '-') << std::endl; 115 175 } 116 176 # endif -
src/Common/Stats/Time.h
r4f97937 r79eaeb7 25 25 namespace Time { 26 26 # if defined(NO_TIME_STATISTICS) 27 inline void StartGlobal() {} 28 27 29 inline void StartBlock(const char * const) {} 28 30 inline void StopBlock() {} … … 38 40 inline void TimeBLock(const char *, func_t) {} 39 41 # else 42 void StartGlobal(); 43 40 44 void StartBlock(const char * const name); 41 45 void StopBlock(); -
src/main.cc
r4f97937 r79eaeb7 195 195 196 196 NewPass("Parse"); 197 Stats::Time::StartGlobal(); 197 198 198 199 // read in the builtins, extras, and the prelude
Note: See TracChangeset
for help on using the changeset viewer.