OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/counters.h" | 5 #include "src/counters.h" |
6 | 6 |
| 7 #include <iomanip> |
| 8 |
7 #include "src/base/platform/platform.h" | 9 #include "src/base/platform/platform.h" |
8 #include "src/isolate.h" | 10 #include "src/isolate.h" |
9 #include "src/log-inl.h" | 11 #include "src/log-inl.h" |
10 | 12 |
11 namespace v8 { | 13 namespace v8 { |
12 namespace internal { | 14 namespace internal { |
13 | 15 |
14 StatsTable::StatsTable() | 16 StatsTable::StatsTable() |
15 : lookup_function_(NULL), | 17 : lookup_function_(NULL), |
16 create_histogram_function_(NULL), | 18 create_histogram_function_(NULL), |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 | 188 |
187 #define HP(name, caption) name##_.Reset(); | 189 #define HP(name, caption) name##_.Reset(); |
188 HISTOGRAM_PERCENTAGE_LIST(HP) | 190 HISTOGRAM_PERCENTAGE_LIST(HP) |
189 #undef HP | 191 #undef HP |
190 | 192 |
191 #define HM(name, caption) name##_.Reset(); | 193 #define HM(name, caption) name##_.Reset(); |
192 HISTOGRAM_LEGACY_MEMORY_LIST(HM) | 194 HISTOGRAM_LEGACY_MEMORY_LIST(HM) |
193 #undef HM | 195 #undef HM |
194 } | 196 } |
195 | 197 |
| 198 class RuntimeCallStatEntries { |
| 199 public: |
| 200 void Print(std::ostream& os) { |
| 201 if (total_call_count > 0) { |
| 202 std::sort(entries.rbegin(), entries.rend()); |
| 203 os << std::setw(50) << "Runtime Function/C++ Builtin" << std::setw(10) |
| 204 << "Time" << std::setw(18) << "Count" << std::endl |
| 205 << std::string(86, '=') << std::endl; |
| 206 for (Entry& entry : entries) { |
| 207 entry.SetTotal(total_time, total_call_count); |
| 208 entry.Print(os); |
| 209 } |
| 210 os << std::string(86, '-') << std::endl; |
| 211 Entry("Total", total_time, total_call_count).Print(os); |
| 212 } |
| 213 } |
| 214 |
| 215 void Add(const char* name, base::TimeDelta time, uint32_t count) { |
| 216 entries.push_back(Entry(name, time, count)); |
| 217 total_time += time; |
| 218 total_call_count += count; |
| 219 } |
| 220 |
| 221 private: |
| 222 class Entry { |
| 223 public: |
| 224 Entry(const char* name, base::TimeDelta time, uint64_t count) |
| 225 : name_(name), |
| 226 time_(time.InMilliseconds()), |
| 227 count_(count), |
| 228 time_percent_(100), |
| 229 count_percent_(100) {} |
| 230 |
| 231 bool operator<(const Entry& other) const { |
| 232 if (time_ < other.time_) return true; |
| 233 if (time_ > other.time_) return false; |
| 234 return count_ < other.count_; |
| 235 } |
| 236 |
| 237 void Print(std::ostream& os) { |
| 238 os.precision(2); |
| 239 os << std::fixed; |
| 240 os << std::setw(50) << name_; |
| 241 os << std::setw(8) << time_ << "ms "; |
| 242 os << std::setw(6) << time_percent_ << "%"; |
| 243 os << std::setw(10) << count_ << " "; |
| 244 os << std::setw(6) << count_percent_ << "%"; |
| 245 os << std::endl; |
| 246 } |
| 247 |
| 248 void SetTotal(base::TimeDelta total_time, uint64_t total_count) { |
| 249 time_percent_ = 100.0 * time_ / total_time.InMilliseconds(); |
| 250 count_percent_ = 100.0 * count_ / total_count; |
| 251 } |
| 252 |
| 253 private: |
| 254 const char* name_; |
| 255 int64_t time_; |
| 256 uint64_t count_; |
| 257 double time_percent_; |
| 258 double count_percent_; |
| 259 }; |
| 260 |
| 261 uint64_t total_call_count = 0; |
| 262 base::TimeDelta total_time; |
| 263 std::vector<Entry> entries; |
| 264 }; |
| 265 |
| 266 void RuntimeCallStats::Print(std::ostream& os) { |
| 267 RuntimeCallStatEntries entries; |
| 268 |
| 269 #define PRINT_COUNTER(name, nargs, ressize) \ |
| 270 if (this->Count_Runtime_##name > 0) { \ |
| 271 entries.Add(#name, this->Time_Runtime_##name, this->Count_Runtime_##name); \ |
| 272 } |
| 273 FOR_EACH_INTRINSIC(PRINT_COUNTER) |
| 274 #undef PRINT_COUNTER |
| 275 #define PRINT_COUNTER(name, type) \ |
| 276 if (this->Count_Builtin_##name > 0) { \ |
| 277 entries.Add(#name, this->Time_Builtin_##name, this->Count_Builtin_##name); \ |
| 278 } |
| 279 BUILTIN_LIST_C(PRINT_COUNTER) |
| 280 #undef PRINT_COUNTER |
| 281 entries.Print(os); |
| 282 } |
| 283 |
| 284 void RuntimeCallStats::Reset() { |
| 285 #define RESET_COUNTER(name, nargs, ressize) \ |
| 286 Count_Runtime_##name = 0; \ |
| 287 Time_Runtime_##name = base::TimeDelta(); |
| 288 FOR_EACH_INTRINSIC(RESET_COUNTER) |
| 289 #undef RESET_COUNTER |
| 290 #define RESET_COUNTER(name, type) \ |
| 291 Count_Builtin_##name = 0; \ |
| 292 Time_Builtin_##name = base::TimeDelta(); |
| 293 BUILTIN_LIST_C(RESET_COUNTER) |
| 294 #undef RESET_COUNTER |
| 295 } |
| 296 |
196 } // namespace internal | 297 } // namespace internal |
197 } // namespace v8 | 298 } // namespace v8 |
OLD | NEW |