Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: src/counters.h

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

Powered by Google App Engine
This is Rietveld 408576698