Index: src/counters.h |
diff --git a/src/counters.h b/src/counters.h |
index 5071609334d1267b23d0dedd76ee98dc66de3097..96d71753e3aa4aa7eef216e9383b77218894596b 100644 |
--- a/src/counters.h |
+++ b/src/counters.h |
@@ -248,24 +248,60 @@ class Histogram { |
Counters* counters_; |
}; |
-// A HistogramTimer allows distributions of results to be created. |
-class HistogramTimer : public Histogram { |
+enum class HistogramTimerResolution { MILLISECOND, MICROSECOND }; |
+ |
+// A thread safe histogram timer, allowing distributions of |
+// (non-nested) timed results. |
+class TimedHistogram : public Histogram { |
public: |
- enum Resolution { |
- MILLISECOND, |
- MICROSECOND |
- }; |
+ // Start the timer. Log if isolate non-null. |
+ void Start(base::ElapsedTimer* timer, Isolate* isolate); |
- // Note: public for testing purposes only. |
- HistogramTimer(const char* name, int min, int max, Resolution resolution, |
- int num_buckets, Counters* counters) |
+ // Stop the timer and record the results. Log if isolate non-null. |
+ void Stop(base::ElapsedTimer* timer, Isolate* isolate); |
+ |
+ protected: |
+ friend class Counters; |
+ HistogramTimerResolution resolution_; |
+ |
+ TimedHistogram() {} |
+ TimedHistogram(const char* name, int min, int max, |
+ HistogramTimerResolution resolution, int num_buckets, |
+ Counters* counters) |
: Histogram(name, min, max, num_buckets, counters), |
resolution_(resolution) {} |
+}; |
- // Start the timer. |
- void Start(); |
+// Helper class for scoping a TimedHistogram. |
+class TimedHistogramScope { |
+ public: |
+ explicit TimedHistogramScope(TimedHistogram* histogram, |
+ Isolate* isolate = nullptr) |
+ : histogram_(histogram), isolate_(isolate) { |
+ histogram_->Start(&timer_, isolate); |
+ } |
+ ~TimedHistogramScope() { histogram_->Stop(&timer_, isolate_); } |
+ |
+ private: |
+ base::ElapsedTimer timer_; |
+ TimedHistogram* histogram_; |
+ Isolate* isolate_; |
+ |
+ DISALLOW_IMPLICIT_CONSTRUCTORS(TimedHistogramScope); |
+}; |
- // Stop the timer and record the results. |
+// A HistogramTimer allows distributions of (non-nested) timed results |
+// to be created. WARNING: This class is not thread safe and can only |
+// be run on the foreground thread. |
+class HistogramTimer : public TimedHistogram { |
+ public: |
+ // Note: public for testing purposes only. |
+ HistogramTimer(const char* name, int min, int max, |
+ HistogramTimerResolution resolution, int num_buckets, |
+ Counters* counters) |
+ : TimedHistogram(name, min, max, resolution, num_buckets, counters) {} |
+ |
+ void Start(); |
void Stop(); |
// Returns true if the timer is running. |
@@ -282,7 +318,6 @@ class HistogramTimer : public Histogram { |
friend class Counters; |
base::ElapsedTimer timer_; |
- Resolution resolution_; |
HistogramTimer() {} |
}; |
@@ -327,7 +362,6 @@ class HistogramTimerScope BASE_EMBEDDED { |
#endif |
}; |
- |
// A histogram timer that can aggregate events within a larger scope. |
// |
// Intended use of this timer is to have an outer (aggregating) and an inner |
@@ -1007,18 +1041,6 @@ class RuntimeCallTimerScope { |
V8.WasmInstantiateModuleMicroSeconds.asm, 10000000, MICROSECOND) \ |
HT(wasm_instantiate_wasm_module_time, \ |
V8.WasmInstantiateModuleMicroSeconds.wasm, 10000000, MICROSECOND) \ |
- HT(wasm_decode_asm_module_time, V8.WasmDecodeModuleMicroSeconds.asm, \ |
- 1000000, MICROSECOND) \ |
- HT(wasm_decode_wasm_module_time, V8.WasmDecodeModuleMicroSeconds.wasm, \ |
- 1000000, MICROSECOND) \ |
- HT(wasm_decode_asm_function_time, V8.WasmDecodeFunctionMicroSeconds.asm, \ |
- 1000000, MICROSECOND) \ |
- HT(wasm_decode_wasm_function_time, V8.WasmDecodeFunctionMicroSeconds.wasm, \ |
- 1000000, MICROSECOND) \ |
- HT(wasm_compile_asm_module_time, V8.WasmCompileModuleMicroSeconds.asm, \ |
- 10000000, MICROSECOND) \ |
- HT(wasm_compile_wasm_module_time, V8.WasmCompileModuleMicroSeconds.wasm, \ |
- 10000000, MICROSECOND) \ |
HT(wasm_compile_function_time, V8.WasmCompileFunctionMicroSeconds, 1000000, \ |
MICROSECOND) \ |
HT(asm_wasm_translation_time, V8.AsmWasmTranslationMicroSeconds, 1000000, \ |
@@ -1026,6 +1048,20 @@ class RuntimeCallTimerScope { |
HT(wasm_lazy_compilation_time, V8.WasmLazyCompilationMicroSeconds, 1000000, \ |
MICROSECOND) |
+#define TIMED_HISTOGRAM_LIST(HT) \ |
+ HT(wasm_decode_asm_module_time, V8.WasmDecodeModuleMicroSeconds.asm, \ |
+ 1000000, MICROSECOND) \ |
+ HT(wasm_decode_wasm_module_time, V8.WasmDecodeModuleMicroSeconds.wasm, \ |
+ 1000000, MICROSECOND) \ |
+ HT(wasm_decode_asm_function_time, V8.WasmDecodeFunctionMicroSeconds.asm, \ |
+ 1000000, MICROSECOND) \ |
+ HT(wasm_decode_wasm_function_time, V8.WasmDecodeFunctionMicroSeconds.wasm, \ |
+ 1000000, MICROSECOND) \ |
+ HT(wasm_compile_asm_module_time, V8.WasmCompileModuleMicroSeconds.asm, \ |
+ 10000000, MICROSECOND) \ |
+ HT(wasm_compile_wasm_module_time, V8.WasmCompileModuleMicroSeconds.wasm, \ |
+ 10000000, MICROSECOND) |
+ |
#define AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) \ |
AHT(compile_lazy, V8.CompileLazyMicroSeconds) |
@@ -1237,6 +1273,11 @@ class Counters : public std::enable_shared_from_this<Counters> { |
HISTOGRAM_TIMER_LIST(HT) |
#undef HT |
+#define HT(name, caption, max, res) \ |
+ TimedHistogram* name() { return &name##_; } |
+ TIMED_HISTOGRAM_LIST(HT) |
+#undef HT |
+ |
#define AHT(name, caption) \ |
AggregatableHistogramTimer* name() { return &name##_; } |
AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) |
@@ -1305,6 +1346,7 @@ class Counters : public std::enable_shared_from_this<Counters> { |
enum Id { |
#define RATE_ID(name, caption, max, res) k_##name, |
HISTOGRAM_TIMER_LIST(RATE_ID) |
+ TIMED_HISTOGRAM_LIST(RATE_ID) |
#undef RATE_ID |
#define AGGREGATABLE_ID(name, caption) k_##name, |
AGGREGATABLE_HISTOGRAM_TIMER_LIST(AGGREGATABLE_ID) |
@@ -1373,6 +1415,10 @@ class Counters : public std::enable_shared_from_this<Counters> { |
HISTOGRAM_TIMER_LIST(HT) |
#undef HT |
+#define HT(name, caption, max, res) TimedHistogram name##_; |
+ TIMED_HISTOGRAM_LIST(HT) |
+#undef HT |
+ |
#define AHT(name, caption) \ |
AggregatableHistogramTimer name##_; |
AGGREGATABLE_HISTOGRAM_TIMER_LIST(AHT) |