Commit a626bc03 authored by Emanuel Ziegler's avatar Emanuel Ziegler Committed by Commit Bot

[ukm][wasm] Add event WasmModuleInstantiated

Add an event for recording metrics related to instantiating Wasm modules.

R=clemensb@chromium.org

Bug: chromium:1092417
Change-Id: I5c87aba7d2cdb012951249b336684580595844cd
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2351675
Commit-Queue: Emanuel Ziegler <ecmziegler@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69472}
parent f16d3abf
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "src/asmjs/asm-js.h" #include "src/asmjs/asm-js.h"
#include "src/logging/counters.h" #include "src/logging/counters.h"
#include "src/logging/metrics.h"
#include "src/numbers/conversions-inl.h" #include "src/numbers/conversions-inl.h"
#include "src/objects/property-descriptor.h" #include "src/objects/property-descriptor.h"
#include "src/tracing/trace-event.h" #include "src/tracing/trace-event.h"
...@@ -203,8 +204,8 @@ Handle<Map> AllocateSubRtt(Isolate* isolate, ...@@ -203,8 +204,8 @@ Handle<Map> AllocateSubRtt(Isolate* isolate,
// It closes over the {Isolate}, the {ErrorThrower}, etc. // It closes over the {Isolate}, the {ErrorThrower}, etc.
class InstanceBuilder { class InstanceBuilder {
public: public:
InstanceBuilder(Isolate* isolate, ErrorThrower* thrower, InstanceBuilder(Isolate* isolate, v8::metrics::Recorder::ContextId context_id,
Handle<WasmModuleObject> module_object, ErrorThrower* thrower, Handle<WasmModuleObject> module_object,
MaybeHandle<JSReceiver> ffi, MaybeHandle<JSReceiver> ffi,
MaybeHandle<JSArrayBuffer> memory_buffer); MaybeHandle<JSArrayBuffer> memory_buffer);
...@@ -222,6 +223,7 @@ class InstanceBuilder { ...@@ -222,6 +223,7 @@ class InstanceBuilder {
}; };
Isolate* isolate_; Isolate* isolate_;
v8::metrics::Recorder::ContextId context_id_;
const WasmFeatures enabled_; const WasmFeatures enabled_;
const WasmModule* const module_; const WasmModule* const module_;
ErrorThrower* thrower_; ErrorThrower* thrower_;
...@@ -357,7 +359,9 @@ MaybeHandle<WasmInstanceObject> InstantiateToInstanceObject( ...@@ -357,7 +359,9 @@ MaybeHandle<WasmInstanceObject> InstantiateToInstanceObject(
Isolate* isolate, ErrorThrower* thrower, Isolate* isolate, ErrorThrower* thrower,
Handle<WasmModuleObject> module_object, MaybeHandle<JSReceiver> imports, Handle<WasmModuleObject> module_object, MaybeHandle<JSReceiver> imports,
MaybeHandle<JSArrayBuffer> memory_buffer) { MaybeHandle<JSArrayBuffer> memory_buffer) {
InstanceBuilder builder(isolate, thrower, module_object, imports, v8::metrics::Recorder::ContextId context_id =
isolate->GetOrRegisterRecorderContextId(isolate->native_context());
InstanceBuilder builder(isolate, context_id, thrower, module_object, imports,
memory_buffer); memory_buffer);
auto instance = builder.Build(); auto instance = builder.Build();
if (!instance.is_null() && builder.ExecuteStartFunction()) { if (!instance.is_null() && builder.ExecuteStartFunction()) {
...@@ -367,11 +371,14 @@ MaybeHandle<WasmInstanceObject> InstantiateToInstanceObject( ...@@ -367,11 +371,14 @@ MaybeHandle<WasmInstanceObject> InstantiateToInstanceObject(
return {}; return {};
} }
InstanceBuilder::InstanceBuilder(Isolate* isolate, ErrorThrower* thrower, InstanceBuilder::InstanceBuilder(Isolate* isolate,
v8::metrics::Recorder::ContextId context_id,
ErrorThrower* thrower,
Handle<WasmModuleObject> module_object, Handle<WasmModuleObject> module_object,
MaybeHandle<JSReceiver> ffi, MaybeHandle<JSReceiver> ffi,
MaybeHandle<JSArrayBuffer> memory_buffer) MaybeHandle<JSArrayBuffer> memory_buffer)
: isolate_(isolate), : isolate_(isolate),
context_id_(context_id),
enabled_(module_object->native_module()->enabled_features()), enabled_(module_object->native_module()->enabled_features()),
module_(module_object->module()), module_(module_object->module()),
thrower_(thrower), thrower_(thrower),
...@@ -401,6 +408,11 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() { ...@@ -401,6 +408,11 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
// Record build time into correct bucket, then build instance. // Record build time into correct bucket, then build instance.
TimedHistogramScope wasm_instantiate_module_time_scope(SELECT_WASM_COUNTER( TimedHistogramScope wasm_instantiate_module_time_scope(SELECT_WASM_COUNTER(
isolate_->counters(), module_->origin, wasm_instantiate, module_time)); isolate_->counters(), module_->origin, wasm_instantiate, module_time));
v8::metrics::WasmModuleInstantiated wasm_module_instantiated;
metrics::TimedScope<v8::metrics::WasmModuleInstantiated>
wasm_module_instantiated_timed_scope(
&wasm_module_instantiated,
&v8::metrics::WasmModuleInstantiated::wall_clock_time_in_us);
NativeModule* native_module = module_object_->native_module(); NativeModule* native_module = module_object_->native_module();
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
...@@ -579,6 +591,7 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() { ...@@ -579,6 +591,7 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
int num_imported_functions = ProcessImports(instance); int num_imported_functions = ProcessImports(instance);
if (num_imported_functions < 0) return {}; if (num_imported_functions < 0) return {};
wasm_module_instantiated.imported_function_count = num_imported_functions;
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
// Create maps for managed objects (GC proposal). // Create maps for managed objects (GC proposal).
...@@ -714,6 +727,10 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() { ...@@ -714,6 +727,10 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
DCHECK(!isolate_->has_pending_exception()); DCHECK(!isolate_->has_pending_exception());
TRACE("Successfully built instance for module %p\n", TRACE("Successfully built instance for module %p\n",
module_object_->native_module()); module_object_->native_module());
wasm_module_instantiated.success = true;
wasm_module_instantiated_timed_scope.Stop();
isolate_->metrics_recorder()->DelayMainThreadEvent(wasm_module_instantiated,
context_id_);
return instance; return instance;
} }
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#define V8_WASM_MODULE_INSTANTIATE_H_ #define V8_WASM_MODULE_INSTANTIATE_H_
#include <stdint.h> #include <stdint.h>
#include "include/v8-metrics.h"
#include "include/v8config.h" #include "include/v8config.h"
namespace v8 { namespace v8 {
......
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