Profile component resolution subphases

This commit is contained in:
udo
2026-07-16 17:34:46 +00:00
parent 6a02c07bcb
commit fd276f8343
4 changed files with 36 additions and 2 deletions
+27
View File
@@ -115,6 +115,10 @@ struct WasmRequestProfile
u64 context_apply_us = 0;
u64 component_resolve_count = 0;
u64 component_resolve_total_us = 0;
u64 component_path_total_us = 0;
u64 component_artifact_total_us = 0;
u64 component_load_total_us = 0;
u64 component_link_total_us = 0;
u64 hostcall_count = 0;
u64 hostcall_total_us = 0;
u64 mysql_hostcall_count = 0;
@@ -1678,11 +1682,15 @@ private:
file_name = current_unit;
if(file_name == "")
{
component_path_total_us += (u64)std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::steady_clock::now() - probe_start).count();
record_probe();
return(0);
}
String resolved = resolve_source_path(file_name, current_unit);
component_path_total_us += (u64)std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::steady_clock::now() - probe_start).count();
if(resolved == "")
{
record_probe();
@@ -1695,6 +1703,7 @@ private:
return(1);
}
auto artifact_start = std::chrono::steady_clock::now();
bool artifact_exists = file_exists_host(worker.unit_wasm_path(resolved));
bool can_serve_stale = compiler_request_can_serve_stale_artifact(context);
// The proactive compiler owns freshness while stale HTTP artifacts may be
@@ -1703,20 +1712,31 @@ private:
bool stale = !can_serve_stale && artifact_exists && compiler_unit_needs_recompile(context, resolved, 0);
if(!artifact_exists || stale)
get_shared_unit(context, resolved);
component_artifact_total_us += (u64)std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::steady_clock::now() - artifact_start).count();
auto load_start = std::chrono::steady_clock::now();
size_t unit_index = 0;
String error = load_unit(resolved, unit_index);
component_load_total_us += (u64)std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::steady_clock::now() - load_start).count();
if(error != "")
{
fprintf(stderr, "[wasm] component load failed: %s\n", error.c_str());
record_probe();
return(0);
}
auto link_start = std::chrono::steady_clock::now();
auto record_link = [&]() {
component_link_total_us += (u64)std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::steady_clock::now() - link_start).count();
};
String symbol = handler_export_symbol(handler);
String slot_key = resolved + ":" + symbol;
auto cached = handler_slots.find(slot_key);
if(cached != handler_slots.end())
{
record_link();
record_probe();
return((int32_t)cached->second);
}
@@ -1726,6 +1746,7 @@ private:
// ONCE is optional per unit; a missing __uce_once is not an error
if(handler != "once")
fprintf(stderr, "[wasm] %s does not export %s\n", resolved.c_str(), symbol.c_str());
record_link();
record_probe();
return(0);
}
@@ -1734,10 +1755,12 @@ private:
if(error != "")
{
fprintf(stderr, "[wasm] %s\n", error.c_str());
record_link();
record_probe();
return(0);
}
handler_slots[slot_key] = slot;
record_link();
record_probe();
return((int32_t)slot);
}
@@ -1862,6 +1885,10 @@ private:
response["memcache_hostcall_us"] = (f64)self->memcache_hostcall_total_us;
response["component_resolve_count"] = (f64)self->component_resolve_count;
response["component_resolve_us"] = (f64)self->component_resolve_total_us;
response["component_path_us"] = (f64)self->component_path_total_us;
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;
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;