| 160 | } |
| 161 | |
| 162 | string InstructionCounter::PrintCounters() const { |
| 163 | // Find the longest length of all the InstructionCount count_ strings. |
| 164 | int max_count_len = 0; |
| 165 | stringstream count_stream; |
| 166 | for (const CounterMap::value_type& counter: counters_) { |
| 167 | count_stream << counter.second; |
| 168 | max_count_len = |
| 169 | max(max_count_len, static_cast<int>(strlen(count_stream.str().c_str()))); |
| 170 | count_stream.str(""); |
| 171 | } |
| 172 | stringstream stream; |
| 173 | // Print header |
| 174 | stream << "\n===" << string(73, '-') << "===\n\n" |
| 175 | << " ... Instruction Counts ...\n\n" |
| 176 | << "===" << string(73, '-') << "===\n\n"; |
| 177 | |
| 178 | for (const CounterMap::value_type& counter: counters_) { |
| 179 | // Conditional is only used in order to print the top level counters |
| 180 | // separate from the other counters. |
| 181 | if (strcmp(counter.first.c_str(), TOTAL_BLOCKS) == 0) { |
| 182 | stream << "\n===" << string(73, '-') << "===\n" |
| 183 | << " ... Totals ...\n" |
| 184 | << "===" << string(73, '-') << "===\n\n"; |
| 185 | } |
| 186 | PrintCounter(counter.first.c_str(), counter.second, max_count_len, &stream); |
| 187 | } |
| 188 | stream << '\n'; |
| 189 | return stream.str(); |
| 190 | } |
| 191 | |
| 192 | void InstructionCounter::IncrementCount(const char* name) { |
| 193 | CounterMap::iterator iter = counters_.find(name); |