Commit d1054287 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Add counters for asynchronous compile time

We currently only sample synchronous compilation via
"V8.WasmCompileModuleMicroSeconds.wasm". This adds a similar counter
for asynchronous and streaming compilation. Both use the
{AsyncCompileJob}, which now records the start time of compilation and
records a sample when baseline compilation finished.
The sample will only be taken if a high-resolution clock is available.

R=ahaas@chromium.org
CC=jwd@chromium.org

Bug: chromium:978425
Change-Id: I4b083a8ebba685a1cc8fa87bfe30e9a0943e3394
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1675963Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62367}
parent 89661dbe
...@@ -181,6 +181,10 @@ namespace internal { ...@@ -181,6 +181,10 @@ namespace internal {
10000000, MICROSECOND) \ 10000000, MICROSECOND) \
HT(wasm_compile_wasm_module_time, V8.WasmCompileModuleMicroSeconds.wasm, \ HT(wasm_compile_wasm_module_time, V8.WasmCompileModuleMicroSeconds.wasm, \
10000000, MICROSECOND) \ 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, \ HT(wasm_compile_asm_function_time, V8.WasmCompileFunctionMicroSeconds.asm, \
1000000, MICROSECOND) \ 1000000, MICROSECOND) \
HT(wasm_compile_wasm_function_time, V8.WasmCompileFunctionMicroSeconds.wasm, \ HT(wasm_compile_wasm_function_time, V8.WasmCompileFunctionMicroSeconds.wasm, \
......
...@@ -1429,6 +1429,7 @@ void AsyncCompileJob::FinishCompile() { ...@@ -1429,6 +1429,7 @@ void AsyncCompileJob::FinishCompile() {
// TODO(wasm): compiling wrappers should be made async. // TODO(wasm): compiling wrappers should be made async.
CompileWrappers(); CompileWrappers();
} }
FinishModule(); FinishModule();
} }
...@@ -1468,6 +1469,21 @@ class AsyncCompileJob::CompilationStateCallback { ...@@ -1468,6 +1469,21 @@ class AsyncCompileJob::CompilationStateCallback {
switch (event) { switch (event) {
case CompilationEvent::kFinishedBaselineCompilation: case CompilationEvent::kFinishedBaselineCompilation:
DCHECK(!last_event_.has_value()); 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<int>(duration.InMilliseconds()));
}
if (job_->DecrementAndCheckFinisherCount()) { if (job_->DecrementAndCheckFinisherCount()) {
job_->DoSync<CompileFinished>(); job_->DoSync<CompileFinished>();
} }
...@@ -1732,6 +1748,13 @@ class AsyncCompileJob::PrepareAndStartCompile : public CompileStep { ...@@ -1732,6 +1748,13 @@ class AsyncCompileJob::PrepareAndStartCompile : public CompileStep {
CompilationStateImpl* compilation_state = CompilationStateImpl* compilation_state =
Impl(job->native_module_->compilation_state()); Impl(job->native_module_->compilation_state());
compilation_state->AddCallback(CompilationStateCallback{job}); 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_) { if (start_compilation_) {
// TODO(ahaas): Try to remove the {start_compilation_} check when // TODO(ahaas): Try to remove the {start_compilation_} check when
// streaming decoding is done in the background. If // streaming decoding is done in the background. If
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <memory> #include <memory>
#include "src/base/optional.h" #include "src/base/optional.h"
#include "src/base/platform/time.h"
#include "src/common/globals.h" #include "src/common/globals.h"
#include "src/tasks/cancelable-task.h" #include "src/tasks/cancelable-task.h"
#include "src/wasm/compilation-environment.h" #include "src/wasm/compilation-environment.h"
...@@ -221,6 +222,10 @@ class AsyncCompileJob { ...@@ -221,6 +222,10 @@ class AsyncCompileJob {
// compilation. The AsyncCompileJob does not actively use the // compilation. The AsyncCompileJob does not actively use the
// StreamingDecoder. // StreamingDecoder.
std::shared_ptr<StreamingDecoder> stream_; std::shared_ptr<StreamingDecoder> stream_;
// The start time of asychronous compilation. Only set if a high-resolution
// clock is available.
base::TimeTicks compile_start_time_;
}; };
} // namespace wasm } // namespace wasm
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment