Profile hostcall thread CPU
This commit is contained in:
@@ -196,9 +196,11 @@ struct WasmRequestProfile
|
||||
u64 unit_initialize_total_us = 0;
|
||||
u64 hostcall_count = 0;
|
||||
u64 hostcall_total_us = 0;
|
||||
u64 hostcall_cpu_total_us = 0;
|
||||
u64 hostcall_operation_slots = 0;
|
||||
u64 hostcall_operation_counts[HOSTCALL_OPERATION_MAX] = {};
|
||||
u64 hostcall_operation_us[HOSTCALL_OPERATION_MAX] = {};
|
||||
u64 hostcall_operation_cpu_us[HOSTCALL_OPERATION_MAX] = {};
|
||||
u64 mysql_hostcall_count = 0;
|
||||
u64 mysql_hostcall_total_us = 0;
|
||||
u64 mysql_operation_count = 0;
|
||||
@@ -2236,21 +2238,27 @@ private:
|
||||
bool profile_memcache = name == "uce_host_memcache_command";
|
||||
auto profiled = [self, callback, profile_index, profile_enabled, profile_mysql, profile_memcache](Caller caller, Span<const Val> args, Span<Val> results) mutable -> Result<std::monostate, Trap> {
|
||||
auto started = std::chrono::steady_clock::now();
|
||||
f64 cpu_started = profile_enabled ? wasm_thread_cpu_time() : 0;
|
||||
auto result = callback(caller, args, results);
|
||||
// Epoch interruption limits guest CPU, not time spent in native I/O,
|
||||
// process management, hashing, or other host work. Re-arm at the one
|
||||
// membrane every hostcall crosses so newly added blocking imports
|
||||
// cannot silently consume the next guest segment's budget.
|
||||
caller.context().set_epoch_deadline(self->worker.cfg.epoch_deadline_ticks);
|
||||
f64 cpu_finished = profile_enabled ? wasm_thread_cpu_time() : 0;
|
||||
if(profile_enabled)
|
||||
{
|
||||
u64 elapsed = (u64)std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - started).count();
|
||||
u64 cpu_elapsed = cpu_started > 0 && cpu_finished > cpu_started ?
|
||||
(u64)((cpu_finished - cpu_started) * 1000000.0) : 0;
|
||||
self->hostcall_count++;
|
||||
self->hostcall_total_us += elapsed;
|
||||
self->hostcall_cpu_total_us += cpu_elapsed;
|
||||
if(profile_index < WasmRequestProfile::HOSTCALL_OPERATION_MAX)
|
||||
{
|
||||
self->hostcall_operation_counts[profile_index]++;
|
||||
self->hostcall_operation_us[profile_index] += elapsed;
|
||||
self->hostcall_operation_cpu_us[profile_index] += cpu_elapsed;
|
||||
}
|
||||
if(profile_mysql)
|
||||
{
|
||||
@@ -2340,6 +2348,7 @@ private:
|
||||
response["execution_cpu_us"] = (f64)(workspace_cpu_us > phase_cpu_us ? workspace_cpu_us - phase_cpu_us : 0);
|
||||
response["hostcall_count"] = (f64)self->hostcall_count;
|
||||
response["hostcall_us"] = (f64)self->hostcall_total_us;
|
||||
response["hostcall_cpu_us"] = (f64)self->hostcall_cpu_total_us;
|
||||
std::vector<u64> invoked_hostcalls;
|
||||
for(u64 i = 0; i < self->hostcall_operation_slots; i++)
|
||||
if(self->hostcall_operation_counts[i] > 0)
|
||||
@@ -2359,6 +2368,7 @@ private:
|
||||
item["name"] = operation_name.rfind("uce_host_", 0) == 0 ? operation_name.substr(9) : operation_name;
|
||||
item["count"] = (f64)self->hostcall_operation_counts[operation_index];
|
||||
item["us"] = (f64)self->hostcall_operation_us[operation_index];
|
||||
item["cpu_us"] = (f64)self->hostcall_operation_cpu_us[operation_index];
|
||||
response["hostcall_operations"].push(item);
|
||||
}
|
||||
response["mysql_hostcall_count"] = (f64)self->mysql_hostcall_count;
|
||||
|
||||
Reference in New Issue
Block a user