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 #ifndef V8_COUNTERS_H_ | 5 #ifndef V8_COUNTERS_H_ |
6 #define V8_COUNTERS_H_ | 6 #define V8_COUNTERS_H_ |
7 | 7 |
8 #include "include/v8.h" | 8 #include "include/v8.h" |
9 #include "src/allocation.h" | 9 #include "src/allocation.h" |
10 #include "src/base/atomic-utils.h" | 10 #include "src/base/atomic-utils.h" |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 void* CreateHistogram() const; | 240 void* CreateHistogram() const; |
241 | 241 |
242 const char* name_; | 242 const char* name_; |
243 int min_; | 243 int min_; |
244 int max_; | 244 int max_; |
245 int num_buckets_; | 245 int num_buckets_; |
246 void* histogram_; | 246 void* histogram_; |
247 Counters* counters_; | 247 Counters* counters_; |
248 }; | 248 }; |
249 | 249 |
250 // A HistogramTimer allows distributions of results to be created. | 250 enum class HistogramTimerResolution { MILLISECOND, MICROSECOND }; |
251 class HistogramTimer : public Histogram { | 251 |
| 252 // A thread safe histogram timer. It also allows distributions of |
| 253 // nested timed results. |
| 254 class TimedHistogram : public Histogram { |
252 public: | 255 public: |
253 enum Resolution { | 256 // Start the timer. Log if isolate non-null. |
254 MILLISECOND, | 257 void Start(base::ElapsedTimer* timer, Isolate* isolate); |
255 MICROSECOND | |
256 }; | |
257 | 258 |
258 // Note: public for testing purposes only. | 259 // Stop the timer and record the results. Log if isolate non-null. |
259 HistogramTimer(const char* name, int min, int max, Resolution resolution, | 260 void Stop(base::ElapsedTimer* timer, Isolate* isolate); |
260 int num_buckets, Counters* counters) | 261 |
| 262 protected: |
| 263 friend class Counters; |
| 264 HistogramTimerResolution resolution_; |
| 265 |
| 266 TimedHistogram() {} |
| 267 TimedHistogram(const char* name, int min, int max, |
| 268 HistogramTimerResolution resolution, int num_buckets, |
| 269 Counters* counters) |
261 : Histogram(name, min, max, num_buckets, counters), | 270 : Histogram(name, min, max, num_buckets, counters), |
262 resolution_(resolution) {} | 271 resolution_(resolution) {} |
| 272 void AddTimeSample(); |
| 273 }; |
263 | 274 |
264 // Start the timer. | 275 // Helper class for scoping a TimedHistogram. |
265 void Start(); | 276 class TimedHistogramScope { |
| 277 public: |
| 278 explicit TimedHistogramScope(TimedHistogram* histogram, |
| 279 Isolate* isolate = nullptr) |
| 280 : histogram_(histogram), isolate_(isolate) { |
| 281 histogram_->Start(&timer_, isolate); |
| 282 } |
| 283 ~TimedHistogramScope() { histogram_->Stop(&timer_, isolate_); } |
266 | 284 |
267 // Stop the timer and record the results. | 285 private: |
268 void Stop(); | 286 base::ElapsedTimer timer_; |
| 287 TimedHistogram* histogram_; |
| 288 Isolate* isolate_; |
| 289 |
| 290 DISALLOW_IMPLICIT_CONSTRUCTORS(TimedHistogramScope); |
| 291 }; |
| 292 |
| 293 // A HistogramTimer allows distributions of non-nested timed results |
| 294 // to be created. WARNING: This class is not thread safe and can only |
| 295 // be run on the foreground thread. |
| 296 class HistogramTimer : public TimedHistogram { |
| 297 public: |
| 298 // Note: public for testing purposes only. |
| 299 HistogramTimer(const char* name, int min, int max, |
| 300 HistogramTimerResolution resolution, int num_buckets, |
| 301 Counters* counters) |
| 302 : TimedHistogram(name, min, max, resolution, num_buckets, counters) {} |
| 303 |
| 304 inline void Start(); |
| 305 inline void Stop(); |
269 | 306 |
270 // Returns true if the timer is running. | 307 // Returns true if the timer is running. |
271 bool Running() { | 308 bool Running() { |
272 return Enabled() && timer_.IsStarted(); | 309 return Enabled() && timer_.IsStarted(); |
273 } | 310 } |
274 | 311 |
275 // TODO(bmeurer): Remove this when HistogramTimerScope is fixed. | 312 // TODO(bmeurer): Remove this when HistogramTimerScope is fixed. |
276 #ifdef DEBUG | 313 #ifdef DEBUG |
277 base::ElapsedTimer* timer() { return &timer_; } | 314 base::ElapsedTimer* timer() { return &timer_; } |
278 #endif | 315 #endif |
279 | 316 |
280 private: | 317 private: |
281 friend class Counters; | 318 friend class Counters; |
282 | 319 |
283 base::ElapsedTimer timer_; | 320 base::ElapsedTimer timer_; |
284 Resolution resolution_; | |
285 | 321 |
286 HistogramTimer() {} | 322 HistogramTimer() {} |
287 }; | 323 }; |
288 | 324 |
289 // Helper class for scoping a HistogramTimer. | 325 // Helper class for scoping a HistogramTimer. |
290 // TODO(bmeurer): The ifdeffery is an ugly hack around the fact that the | 326 // TODO(bmeurer): The ifdeffery is an ugly hack around the fact that the |
291 // Parser is currently reentrant (when it throws an error, we call back | 327 // Parser is currently reentrant (when it throws an error, we call back |
292 // into JavaScript and all bets are off), but ElapsedTimer is not | 328 // into JavaScript and all bets are off), but ElapsedTimer is not |
293 // reentry-safe. Fix this properly and remove |allow_nesting|. | 329 // reentry-safe. Fix this properly and remove |allow_nesting|. |
294 class HistogramTimerScope BASE_EMBEDDED { | 330 class HistogramTimerScope BASE_EMBEDDED { |
(...skipping 24 matching lines...) Expand all Loading... |
319 #endif | 355 #endif |
320 } | 356 } |
321 | 357 |
322 private: | 358 private: |
323 HistogramTimer* timer_; | 359 HistogramTimer* timer_; |
324 #ifdef DEBUG | 360 #ifdef DEBUG |
325 bool skipped_timer_start_; | 361 bool skipped_timer_start_; |
326 #endif | 362 #endif |
327 }; | 363 }; |
328 | 364 |
329 | |
330 // A histogram timer that can aggregate events within a larger scope. | 365 // A histogram timer that can aggregate events within a larger scope. |
331 // | 366 // |
332 // Intended use of this timer is to have an outer (aggregating) and an inner | 367 // Intended use of this timer is to have an outer (aggregating) and an inner |
333 // (to be aggregated) scope, where the inner scope measure the time of events, | 368 // (to be aggregated) scope, where the inner scope measure the time of events, |
334 // and all those inner scope measurements will be summed up by the outer scope. | 369 // and all those inner scope measurements will be summed up by the outer scope. |
335 // An example use might be to aggregate the time spent in lazy compilation | 370 // An example use might be to aggregate the time spent in lazy compilation |
336 // while running a script. | 371 // while running a script. |
337 // | 372 // |
338 // Helpers: | 373 // Helpers: |
339 // - AggregatingHistogramTimerScope, the "outer" scope within which | 374 // - AggregatingHistogramTimerScope, the "outer" scope within which |
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1001 MICROSECOND) \ | 1036 MICROSECOND) \ |
1002 /* Total compilation time incl. caching/parsing */ \ | 1037 /* Total compilation time incl. caching/parsing */ \ |
1003 HT(compile_script, V8.CompileScriptMicroSeconds, 1000000, MICROSECOND) \ | 1038 HT(compile_script, V8.CompileScriptMicroSeconds, 1000000, MICROSECOND) \ |
1004 /* Total JavaScript execution time (including callbacks and runtime calls */ \ | 1039 /* Total JavaScript execution time (including callbacks and runtime calls */ \ |
1005 HT(execute, V8.Execute, 1000000, MICROSECOND) \ | 1040 HT(execute, V8.Execute, 1000000, MICROSECOND) \ |
1006 /* Asm/Wasm */ \ | 1041 /* Asm/Wasm */ \ |
1007 HT(wasm_instantiate_asm_module_time, \ | 1042 HT(wasm_instantiate_asm_module_time, \ |
1008 V8.WasmInstantiateModuleMicroSeconds.asm, 10000000, MICROSECOND) \ | 1043 V8.WasmInstantiateModuleMicroSeconds.asm, 10000000, MICROSECOND) \ |
1009 HT(wasm_instantiate_wasm_module_time, \ | 1044 HT(wasm_instantiate_wasm_module_time, \ |
1010 V8.WasmInstantiateModuleMicroSeconds.wasm, 10000000, MICROSECOND) \ | 1045 V8.WasmInstantiateModuleMicroSeconds.wasm, 10000000, MICROSECOND) \ |
1011 HT(wasm_decode_asm_module_time, V8.WasmDecodeModuleMicroSeconds.asm, \ | |
1012 1000000, MICROSECOND) \ | |
1013 HT(wasm_decode_wasm_module_time, V8.WasmDecodeModuleMicroSeconds.wasm, \ | |
1014 1000000, MICROSECOND) \ | |
1015 HT(wasm_decode_asm_function_time, V8.WasmDecodeFunctionMicroSeconds.asm, \ | |
1016 1000000, MICROSECOND) \ | |
1017 HT(wasm_decode_wasm_function_time, V8.WasmDecodeFunctionMicroSeconds.wasm, \ | |
1018 1000000, MICROSECOND) \ | |
1019 HT(wasm_compile_asm_module_time, V8.WasmCompileModuleMicroSeconds.asm, \ | |
1020 10000000, MICROSECOND) \ | |
1021 HT(wasm_compile_wasm_module_time, V8.WasmCompileModuleMicroSeconds.wasm, \ | |
1022 10000000, MICROSECOND) \ | |
1023 HT(wasm_compile_function_time, V8.WasmCompileFunctionMicroSeconds, 1000000, \ | 1046 HT(wasm_compile_function_time, V8.WasmCompileFunctionMicroSeconds, 1000000, \ |
1024 MICROSECOND) \ | 1047 MICROSECOND) \ |
1025 HT(asm_wasm_translation_time, V8.AsmWasmTranslationMicroSeconds, 1000000, \ | 1048 HT(asm_wasm_translation_time, V8.AsmWasmTranslationMicroSeconds, 1000000, \ |
1026 MICROSECOND) \ | 1049 MICROSECOND) \ |
1027 HT(wasm_lazy_compilation_time, V8.WasmLazyCompilationMicroSeconds, 1000000, \ | 1050 HT(wasm_lazy_compilation_time, V8.WasmLazyCompilationMicroSeconds, 1000000, \ |
1028 MICROSECOND) | 1051 MICROSECOND) |
1029 | 1052 |
| 1053 #define TIMED_HISTOGRAM_LIST(HT) \ |
| 1054 HT(wasm_decode_asm_module_time, V8.WasmDecodeModuleMicroSeconds.asm, \ |
| 1055 1000000, MICROSECOND) \ |
| 1056 HT(wasm_decode_wasm_module_time, V8.WasmDecodeModuleMicroSeconds.wasm, \ |
| 1057 1000000, MICROSECOND) \ |
| 1058 HT(wasm_decode_asm_function_time, V8.WasmDecodeFunctionMicroSeconds.asm, \ |
| 1059 1000000, MICROSECOND) \ |
| 1060 HT(wasm_decode_wasm_function_time, V8.WasmDecodeFunctionMicroSeconds.wasm, \ |
| 1061 1000000, MICROSECOND) \ |
| 1062 HT(wasm_compile_asm_module_time, V8.WasmCompileModuleMicroSeconds.asm, \ |
| 1063 10000000, MICROSECOND) \ |
| 1064 HT(wasm_compile_wasm_module_time, V8.WasmCompileModuleMicroSeconds.wasm, \ |
| 1065 10000000, MICROSECOND) |
| 1066 |
1030 #define AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) \ | 1067 #define AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) \ |
1031 AHT(compile_lazy, V8.CompileLazyMicroSeconds) | 1068 AHT(compile_lazy, V8.CompileLazyMicroSeconds) |
1032 | 1069 |
1033 #define HISTOGRAM_PERCENTAGE_LIST(HP) \ | 1070 #define HISTOGRAM_PERCENTAGE_LIST(HP) \ |
1034 /* Heap fragmentation. */ \ | 1071 /* Heap fragmentation. */ \ |
1035 HP(external_fragmentation_total, V8.MemoryExternalFragmentationTotal) \ | 1072 HP(external_fragmentation_total, V8.MemoryExternalFragmentationTotal) \ |
1036 HP(external_fragmentation_old_space, V8.MemoryExternalFragmentationOldSpace) \ | 1073 HP(external_fragmentation_old_space, V8.MemoryExternalFragmentationOldSpace) \ |
1037 HP(external_fragmentation_code_space, \ | 1074 HP(external_fragmentation_code_space, \ |
1038 V8.MemoryExternalFragmentationCodeSpace) \ | 1075 V8.MemoryExternalFragmentationCodeSpace) \ |
1039 HP(external_fragmentation_map_space, V8.MemoryExternalFragmentationMapSpace) \ | 1076 HP(external_fragmentation_map_space, V8.MemoryExternalFragmentationMapSpace) \ |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1230 #define HR(name, caption, min, max, num_buckets) \ | 1267 #define HR(name, caption, min, max, num_buckets) \ |
1231 Histogram* name() { return &name##_; } | 1268 Histogram* name() { return &name##_; } |
1232 HISTOGRAM_RANGE_LIST(HR) | 1269 HISTOGRAM_RANGE_LIST(HR) |
1233 #undef HR | 1270 #undef HR |
1234 | 1271 |
1235 #define HT(name, caption, max, res) \ | 1272 #define HT(name, caption, max, res) \ |
1236 HistogramTimer* name() { return &name##_; } | 1273 HistogramTimer* name() { return &name##_; } |
1237 HISTOGRAM_TIMER_LIST(HT) | 1274 HISTOGRAM_TIMER_LIST(HT) |
1238 #undef HT | 1275 #undef HT |
1239 | 1276 |
| 1277 #define HT(name, caption, max, res) \ |
| 1278 TimedHistogram* name() { return &name##_; } |
| 1279 TIMED_HISTOGRAM_LIST(HT) |
| 1280 #undef HT |
| 1281 |
1240 #define AHT(name, caption) \ | 1282 #define AHT(name, caption) \ |
1241 AggregatableHistogramTimer* name() { return &name##_; } | 1283 AggregatableHistogramTimer* name() { return &name##_; } |
1242 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) | 1284 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) |
1243 #undef AHT | 1285 #undef AHT |
1244 | 1286 |
1245 #define HP(name, caption) \ | 1287 #define HP(name, caption) \ |
1246 Histogram* name() { return &name##_; } | 1288 Histogram* name() { return &name##_; } |
1247 HISTOGRAM_PERCENTAGE_LIST(HP) | 1289 HISTOGRAM_PERCENTAGE_LIST(HP) |
1248 #undef HP | 1290 #undef HP |
1249 | 1291 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1298 { return &count_of_CODE_AGE_##name##_; } \ | 1340 { return &count_of_CODE_AGE_##name##_; } \ |
1299 StatsCounter* size_of_CODE_AGE_##name() \ | 1341 StatsCounter* size_of_CODE_AGE_##name() \ |
1300 { return &size_of_CODE_AGE_##name##_; } | 1342 { return &size_of_CODE_AGE_##name##_; } |
1301 CODE_AGE_LIST_COMPLETE(SC) | 1343 CODE_AGE_LIST_COMPLETE(SC) |
1302 #undef SC | 1344 #undef SC |
1303 | 1345 |
1304 // clang-format off | 1346 // clang-format off |
1305 enum Id { | 1347 enum Id { |
1306 #define RATE_ID(name, caption, max, res) k_##name, | 1348 #define RATE_ID(name, caption, max, res) k_##name, |
1307 HISTOGRAM_TIMER_LIST(RATE_ID) | 1349 HISTOGRAM_TIMER_LIST(RATE_ID) |
| 1350 TIMED_HISTOGRAM_LIST(RATE_ID) |
1308 #undef RATE_ID | 1351 #undef RATE_ID |
1309 #define AGGREGATABLE_ID(name, caption) k_##name, | 1352 #define AGGREGATABLE_ID(name, caption) k_##name, |
1310 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AGGREGATABLE_ID) | 1353 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AGGREGATABLE_ID) |
1311 #undef AGGREGATABLE_ID | 1354 #undef AGGREGATABLE_ID |
1312 #define PERCENTAGE_ID(name, caption) k_##name, | 1355 #define PERCENTAGE_ID(name, caption) k_##name, |
1313 HISTOGRAM_PERCENTAGE_LIST(PERCENTAGE_ID) | 1356 HISTOGRAM_PERCENTAGE_LIST(PERCENTAGE_ID) |
1314 #undef PERCENTAGE_ID | 1357 #undef PERCENTAGE_ID |
1315 #define MEMORY_ID(name, caption) k_##name, | 1358 #define MEMORY_ID(name, caption) k_##name, |
1316 HISTOGRAM_LEGACY_MEMORY_LIST(MEMORY_ID) | 1359 HISTOGRAM_LEGACY_MEMORY_LIST(MEMORY_ID) |
1317 HISTOGRAM_MEMORY_LIST(MEMORY_ID) | 1360 HISTOGRAM_MEMORY_LIST(MEMORY_ID) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1366 Isolate* isolate() { return isolate_; } | 1409 Isolate* isolate() { return isolate_; } |
1367 | 1410 |
1368 #define HR(name, caption, min, max, num_buckets) Histogram name##_; | 1411 #define HR(name, caption, min, max, num_buckets) Histogram name##_; |
1369 HISTOGRAM_RANGE_LIST(HR) | 1412 HISTOGRAM_RANGE_LIST(HR) |
1370 #undef HR | 1413 #undef HR |
1371 | 1414 |
1372 #define HT(name, caption, max, res) HistogramTimer name##_; | 1415 #define HT(name, caption, max, res) HistogramTimer name##_; |
1373 HISTOGRAM_TIMER_LIST(HT) | 1416 HISTOGRAM_TIMER_LIST(HT) |
1374 #undef HT | 1417 #undef HT |
1375 | 1418 |
| 1419 #define HT(name, caption, max, res) TimedHistogram name##_; |
| 1420 TIMED_HISTOGRAM_LIST(HT) |
| 1421 #undef HT |
| 1422 |
1376 #define AHT(name, caption) \ | 1423 #define AHT(name, caption) \ |
1377 AggregatableHistogramTimer name##_; | 1424 AggregatableHistogramTimer name##_; |
1378 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) | 1425 AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) |
1379 #undef AHT | 1426 #undef AHT |
1380 | 1427 |
1381 #define HP(name, caption) \ | 1428 #define HP(name, caption) \ |
1382 Histogram name##_; | 1429 Histogram name##_; |
1383 HISTOGRAM_PERCENTAGE_LIST(HP) | 1430 HISTOGRAM_PERCENTAGE_LIST(HP) |
1384 #undef HP | 1431 #undef HP |
1385 | 1432 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1426 StatsCounter size_of_CODE_AGE_##name##_; \ | 1473 StatsCounter size_of_CODE_AGE_##name##_; \ |
1427 StatsCounter count_of_CODE_AGE_##name##_; | 1474 StatsCounter count_of_CODE_AGE_##name##_; |
1428 CODE_AGE_LIST_COMPLETE(SC) | 1475 CODE_AGE_LIST_COMPLETE(SC) |
1429 #undef SC | 1476 #undef SC |
1430 | 1477 |
1431 RuntimeCallStats runtime_call_stats_; | 1478 RuntimeCallStats runtime_call_stats_; |
1432 | 1479 |
1433 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters); | 1480 DISALLOW_IMPLICIT_CONSTRUCTORS(Counters); |
1434 }; | 1481 }; |
1435 | 1482 |
| 1483 void HistogramTimer::Start() { |
| 1484 TimedHistogram::Start(&timer_, counters()->isolate()); |
| 1485 } |
| 1486 |
| 1487 void HistogramTimer::Stop() { |
| 1488 TimedHistogram::Stop(&timer_, counters()->isolate()); |
| 1489 } |
| 1490 |
1436 } // namespace internal | 1491 } // namespace internal |
1437 } // namespace v8 | 1492 } // namespace v8 |
1438 | 1493 |
1439 #endif // V8_COUNTERS_H_ | 1494 #endif // V8_COUNTERS_H_ |
OLD | NEW |