Profile side module loading phases
This commit is contained in:
@@ -119,6 +119,12 @@ struct WasmRequestProfile
|
||||
u64 component_artifact_total_us = 0;
|
||||
u64 component_load_total_us = 0;
|
||||
u64 component_link_total_us = 0;
|
||||
u64 unit_load_count = 0;
|
||||
u64 unit_module_total_us = 0;
|
||||
u64 unit_allocate_total_us = 0;
|
||||
u64 unit_import_total_us = 0;
|
||||
u64 unit_instantiate_total_us = 0;
|
||||
u64 unit_initialize_total_us = 0;
|
||||
u64 hostcall_count = 0;
|
||||
u64 hostcall_total_us = 0;
|
||||
u64 mysql_hostcall_count = 0;
|
||||
@@ -1274,13 +1280,18 @@ private:
|
||||
return("");
|
||||
}
|
||||
|
||||
unit_load_count++;
|
||||
String error;
|
||||
auto module_start = std::chrono::steady_clock::now();
|
||||
auto mod = worker.unit_module(source_path, error);
|
||||
unit_module_total_us += (u64)std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::steady_clock::now() - module_start).count();
|
||||
if(!mod)
|
||||
return(error);
|
||||
// Compiling/deserializing a cold module is host work. Refresh the guest
|
||||
// watchdog before the first core call so that wall time cannot make the
|
||||
// otherwise harmless malloc/reloc sequence trap immediately.
|
||||
auto allocate_start = std::chrono::steady_clock::now();
|
||||
ctx().set_epoch_deadline(worker.cfg.epoch_deadline_ticks);
|
||||
if(mod->abi.version != abi_version)
|
||||
return(mod->wasm_path + ": uce.abi version " + std::to_string(mod->abi.version)
|
||||
@@ -1302,8 +1313,11 @@ private:
|
||||
if(mod->dylink.table_size > table->size(cx) - table_next_free)
|
||||
return("funcref table headroom exhausted by " + source_path);
|
||||
table_next_free += mod->dylink.table_size;
|
||||
unit_allocate_total_us += (u64)std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::steady_clock::now() - allocate_start).count();
|
||||
|
||||
// import resolution
|
||||
auto import_start = std::chrono::steady_clock::now();
|
||||
std::vector<wasmtime::Extern> imports;
|
||||
std::vector<std::pair<String, wasmtime::Global>> deferred_got;
|
||||
for(auto import_type : module.imports())
|
||||
@@ -1390,8 +1404,13 @@ private:
|
||||
}
|
||||
return(source_path + ": import policy violation: " + mod_name + "." + name);
|
||||
}
|
||||
unit_import_total_us += (u64)std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::steady_clock::now() - import_start).count();
|
||||
|
||||
auto instantiate_start = std::chrono::steady_clock::now();
|
||||
auto created = wasmtime::Instance::create(cx, module, imports);
|
||||
unit_instantiate_total_us += (u64)std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::steady_clock::now() - instantiate_start).count();
|
||||
if(!created)
|
||||
return(source_path + ": instantiation failed: " + trap_text(created.err()));
|
||||
|
||||
@@ -1405,6 +1424,7 @@ private:
|
||||
unit_index_out = unit_index;
|
||||
|
||||
// deferred GOT: the unit's own data exports are module-relative —
|
||||
auto initialize_start = std::chrono::steady_clock::now();
|
||||
// add this unit's memory base (Phase 0 FINDINGS erratum)
|
||||
for(auto& [name, got] : deferred_got)
|
||||
{
|
||||
@@ -1439,6 +1459,8 @@ private:
|
||||
if(worker.cfg.verbose)
|
||||
fprintf(stderr, "[wasm] loaded %s (mem_base=%u table_base=%u)\n",
|
||||
source_path.c_str(), memory_base, table_base);
|
||||
unit_initialize_total_us += (u64)std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::steady_clock::now() - initialize_start).count();
|
||||
// Exclude the rest of host-side loading as well. A genuine runaway loop
|
||||
// makes no loads, so it still trips the deadline.
|
||||
ctx().set_epoch_deadline(worker.cfg.epoch_deadline_ticks);
|
||||
@@ -1889,6 +1911,12 @@ private:
|
||||
response["component_artifact_us"] = (f64)self->component_artifact_total_us;
|
||||
response["component_load_us"] = (f64)self->component_load_total_us;
|
||||
response["component_link_us"] = (f64)self->component_link_total_us;
|
||||
response["unit_load_count"] = (f64)self->unit_load_count;
|
||||
response["unit_module_us"] = (f64)self->unit_module_total_us;
|
||||
response["unit_allocate_us"] = (f64)self->unit_allocate_total_us;
|
||||
response["unit_import_us"] = (f64)self->unit_import_total_us;
|
||||
response["unit_instantiate_us"] = (f64)self->unit_instantiate_total_us;
|
||||
response["unit_initialize_us"] = (f64)self->unit_initialize_total_us;
|
||||
f64 running_us = response["running_us"].to_f64();
|
||||
f64 accounted_us = (f64)(self->dispatch_us + self->workspace_setup_us + self->workspace_birth_us + self->context_apply_us + self->hostcall_total_us);
|
||||
response["guest_us"] = running_us > accounted_us ? running_us - accounted_us : 0.0;
|
||||
|
||||
Reference in New Issue
Block a user