diff --git a/src/logging/counters-definitions.h b/src/logging/counters-definitions.h index 45d80cef37..9fc8e44bde 100644 --- a/src/logging/counters-definitions.h +++ b/src/logging/counters-definitions.h @@ -181,6 +181,10 @@ namespace internal { 10000000, MICROSECOND) \ HT(wasm_compile_wasm_module_time, V8.WasmCompileModuleMicroSeconds.wasm, \ 10000000, MICROSECOND) \ + HT(wasm_async_compile_wasm_module_time, \ + V8.WasmCompileModuleAsyncMicroSeconds, 100000000, MICROSECOND) \ + HT(wasm_streaming_compile_wasm_module_time, \ + V8.WasmCompileModuleStreamingMicroSeconds, 100000000, MICROSECOND) \ HT(wasm_compile_asm_function_time, V8.WasmCompileFunctionMicroSeconds.asm, \ 1000000, MICROSECOND) \ HT(wasm_compile_wasm_function_time, V8.WasmCompileFunctionMicroSeconds.wasm, \ diff --git a/src/wasm/module-compiler.cc b/src/wasm/module-compiler.cc index 1fe835bd8a..af032b57cb 100644 --- a/src/wasm/module-compiler.cc +++ b/src/wasm/module-compiler.cc @@ -1429,6 +1429,7 @@ void AsyncCompileJob::FinishCompile() { // TODO(wasm): compiling wrappers should be made async. CompileWrappers(); } + FinishModule(); } @@ -1468,6 +1469,21 @@ class AsyncCompileJob::CompilationStateCallback { switch (event) { case CompilationEvent::kFinishedBaselineCompilation: DCHECK(!last_event_.has_value()); + // Sample compilation time (if a high-resolution clock is available; + // otherwise {job_->compile_start_time_} will be Null). + DCHECK_EQ(base::TimeTicks::IsHighResolution(), + !job_->compile_start_time_.IsNull()); + if (!job_->compile_start_time_.IsNull()) { + auto duration = base::TimeTicks::Now() - job_->compile_start_time_; + auto* comp_state = Impl(job_->native_module_->compilation_state()); + auto* counters = comp_state->counters(); + TimedHistogram* histogram = + job_->stream_ + ? counters->wasm_async_compile_wasm_module_time() + : counters->wasm_streaming_compile_wasm_module_time(); + histogram->AddSample(static_cast(duration.InMilliseconds())); + } + if (job_->DecrementAndCheckFinisherCount()) { job_->DoSync(); } @@ -1732,6 +1748,13 @@ class AsyncCompileJob::PrepareAndStartCompile : public CompileStep { CompilationStateImpl* compilation_state = Impl(job->native_module_->compilation_state()); compilation_state->AddCallback(CompilationStateCallback{job}); + + // Record current time as start time of asynchronous compilation. + DCHECK(job->compile_start_time_.IsNull()); + if (base::TimeTicks::IsHighResolution()) { + job->compile_start_time_ = base::TimeTicks::Now(); + } + if (start_compilation_) { // TODO(ahaas): Try to remove the {start_compilation_} check when // streaming decoding is done in the background. If diff --git a/src/wasm/module-compiler.h b/src/wasm/module-compiler.h index dd4829d92d..ba0a4361f6 100644 --- a/src/wasm/module-compiler.h +++ b/src/wasm/module-compiler.h @@ -10,6 +10,7 @@ #include #include "src/base/optional.h" +#include "src/base/platform/time.h" #include "src/common/globals.h" #include "src/tasks/cancelable-task.h" #include "src/wasm/compilation-environment.h" @@ -221,6 +222,10 @@ class AsyncCompileJob { // compilation. The AsyncCompileJob does not actively use the // StreamingDecoder. std::shared_ptr stream_; + + // The start time of asychronous compilation. Only set if a high-resolution + // clock is available. + base::TimeTicks compile_start_time_; }; } // namespace wasm