| 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> | 7 #include <iomanip> |
| 8 | 8 |
| 9 #include "src/base/platform/platform.h" | 9 #include "src/base/platform/platform.h" |
| 10 #include "src/isolate.h" | 10 #include "src/isolate.h" |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 << std::string(86, '=') << std::endl; | 205 << std::string(86, '=') << std::endl; |
| 206 for (Entry& entry : entries) { | 206 for (Entry& entry : entries) { |
| 207 entry.SetTotal(total_time, total_call_count); | 207 entry.SetTotal(total_time, total_call_count); |
| 208 entry.Print(os); | 208 entry.Print(os); |
| 209 } | 209 } |
| 210 os << std::string(86, '-') << std::endl; | 210 os << std::string(86, '-') << std::endl; |
| 211 Entry("Total", total_time, total_call_count).Print(os); | 211 Entry("Total", total_time, total_call_count).Print(os); |
| 212 } | 212 } |
| 213 } | 213 } |
| 214 | 214 |
| 215 void Add(const char* name, base::TimeDelta time, uint32_t count) { | 215 void Add(const char* name, RuntimeCallCounter counter) { |
| 216 entries.push_back(Entry(name, time, count)); | 216 entries.push_back(Entry(name, counter.time, counter.count)); |
| 217 total_time += time; | 217 total_time += counter.time; |
| 218 total_call_count += count; | 218 total_call_count += counter.count; |
| 219 } | 219 } |
| 220 | 220 |
| 221 private: | 221 private: |
| 222 class Entry { | 222 class Entry { |
| 223 public: | 223 public: |
| 224 Entry(const char* name, base::TimeDelta time, uint64_t count) | 224 Entry(const char* name, base::TimeDelta time, uint64_t count) |
| 225 : name_(name), | 225 : name_(name), |
| 226 time_(time.InMilliseconds()), | 226 time_(time.InMilliseconds()), |
| 227 count_(count), | 227 count_(count), |
| 228 time_percent_(100), | 228 time_percent_(100), |
| (...skipping 27 matching lines...) Expand all Loading... |
| 256 uint64_t count_; | 256 uint64_t count_; |
| 257 double time_percent_; | 257 double time_percent_; |
| 258 double count_percent_; | 258 double count_percent_; |
| 259 }; | 259 }; |
| 260 | 260 |
| 261 uint64_t total_call_count = 0; | 261 uint64_t total_call_count = 0; |
| 262 base::TimeDelta total_time; | 262 base::TimeDelta total_time; |
| 263 std::vector<Entry> entries; | 263 std::vector<Entry> entries; |
| 264 }; | 264 }; |
| 265 | 265 |
| 266 void RuntimeCallCounter::Reset() { |
| 267 count = 0; |
| 268 time = base::TimeDelta(); |
| 269 } |
| 270 |
| 271 void RuntimeCallStats::Enter(RuntimeCallCounter* counter) { |
| 272 counter->count++; |
| 273 counter->parent_counter = current_counter; |
| 274 current_counter = counter; |
| 275 } |
| 276 void RuntimeCallStats::Leave(base::TimeDelta time) { |
| 277 RuntimeCallCounter* counter = current_counter; |
| 278 counter->time += time; |
| 279 current_counter = counter->parent_counter; |
| 280 counter->parent_counter = NULL; |
| 281 if (current_counter != NULL) { |
| 282 current_counter->time -= time; |
| 283 } |
| 284 } |
| 285 |
| 266 void RuntimeCallStats::Print(std::ostream& os) { | 286 void RuntimeCallStats::Print(std::ostream& os) { |
| 267 RuntimeCallStatEntries entries; | 287 RuntimeCallStatEntries entries; |
| 268 | 288 |
| 269 #define PRINT_COUNTER(name, nargs, ressize) \ | 289 #define PRINT_COUNTER(name, nargs, ressize) \ |
| 270 if (this->Count_Runtime_##name > 0) { \ | 290 if (this->Runtime_##name.count > 0) { \ |
| 271 entries.Add(#name, this->Time_Runtime_##name, this->Count_Runtime_##name); \ | 291 entries.Add(#name, this->Runtime_##name); \ |
| 272 } | 292 } |
| 273 FOR_EACH_INTRINSIC(PRINT_COUNTER) | 293 FOR_EACH_INTRINSIC(PRINT_COUNTER) |
| 274 #undef PRINT_COUNTER | 294 #undef PRINT_COUNTER |
| 275 #define PRINT_COUNTER(name, type) \ | 295 #define PRINT_COUNTER(name, type) \ |
| 276 if (this->Count_Builtin_##name > 0) { \ | 296 if (this->Builtin_##name.count > 0) { \ |
| 277 entries.Add(#name, this->Time_Builtin_##name, this->Count_Builtin_##name); \ | 297 entries.Add(#name, this->Builtin_##name); \ |
| 278 } | 298 } |
| 279 BUILTIN_LIST_C(PRINT_COUNTER) | 299 BUILTIN_LIST_C(PRINT_COUNTER) |
| 280 #undef PRINT_COUNTER | 300 #undef PRINT_COUNTER |
| 281 entries.Print(os); | 301 entries.Print(os); |
| 282 } | 302 } |
| 283 | 303 |
| 284 void RuntimeCallStats::Reset() { | 304 void RuntimeCallStats::Reset() { |
| 285 #define RESET_COUNTER(name, nargs, ressize) \ | 305 #define RESET_COUNTER(name, nargs, ressize) this->Runtime_##name.Reset(); |
| 286 Count_Runtime_##name = 0; \ | |
| 287 Time_Runtime_##name = base::TimeDelta(); | |
| 288 FOR_EACH_INTRINSIC(RESET_COUNTER) | 306 FOR_EACH_INTRINSIC(RESET_COUNTER) |
| 289 #undef RESET_COUNTER | 307 #undef RESET_COUNTER |
| 290 #define RESET_COUNTER(name, type) \ | 308 #define RESET_COUNTER(name, type) this->Builtin_##name.Reset(); |
| 291 Count_Builtin_##name = 0; \ | |
| 292 Time_Builtin_##name = base::TimeDelta(); | |
| 293 BUILTIN_LIST_C(RESET_COUNTER) | 309 BUILTIN_LIST_C(RESET_COUNTER) |
| 294 #undef RESET_COUNTER | 310 #undef RESET_COUNTER |
| 295 } | 311 } |
| 296 | 312 |
| 297 } // namespace internal | 313 } // namespace internal |
| 298 } // namespace v8 | 314 } // namespace v8 |
| OLD | NEW |