Profile workspace thread CPU time
This commit is contained in:
+23
-2
@@ -228,6 +228,14 @@ static u64 wasm_monotonic_ms()
|
||||
return((u64)ts.tv_sec * 1000ull + (u64)ts.tv_nsec / 1000000ull);
|
||||
}
|
||||
|
||||
static f64 wasm_thread_cpu_time()
|
||||
{
|
||||
struct timespec ts;
|
||||
if(clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts) != 0)
|
||||
return(0);
|
||||
return((f64)ts.tv_sec + (f64)ts.tv_nsec / 1000000000.0);
|
||||
}
|
||||
|
||||
static int wasm_open_locked_file(const String& file_name, int flags, int lock_type, bool truncate_after_lock)
|
||||
{
|
||||
int fd = open(file_name.c_str(), flags, 0644);
|
||||
@@ -1202,6 +1210,8 @@ public:
|
||||
f64 time_params = 0;
|
||||
f64 time_input = 0;
|
||||
f64 time_start = 0;
|
||||
f64 workspace_wall_start = 0;
|
||||
f64 workspace_cpu_start = 0;
|
||||
bool active = false;
|
||||
} request_perf;
|
||||
|
||||
@@ -1210,7 +1220,8 @@ public:
|
||||
}
|
||||
|
||||
void set_perf_snapshot(u64 worker_pid, u64 parent_pid, u64 request_count,
|
||||
f64 time_init, f64 time_params, f64 time_input, f64 time_start)
|
||||
f64 time_init, f64 time_params, f64 time_input, f64 time_start,
|
||||
f64 workspace_wall_start, f64 workspace_cpu_start)
|
||||
{
|
||||
request_perf.worker_pid = worker_pid;
|
||||
request_perf.parent_pid = parent_pid;
|
||||
@@ -1219,6 +1230,8 @@ public:
|
||||
request_perf.time_params = time_params;
|
||||
request_perf.time_input = time_input;
|
||||
request_perf.time_start = time_start;
|
||||
request_perf.workspace_wall_start = workspace_wall_start;
|
||||
request_perf.workspace_cpu_start = workspace_cpu_start;
|
||||
request_perf.active = true;
|
||||
}
|
||||
|
||||
@@ -2263,6 +2276,7 @@ private:
|
||||
if(self->request_perf.active)
|
||||
{
|
||||
f64 now = time_precise();
|
||||
f64 cpu_now = wasm_thread_cpu_time();
|
||||
response["worker_pid"] = (f64)self->request_perf.worker_pid;
|
||||
response["parent_pid"] = (f64)self->request_perf.parent_pid;
|
||||
response["request_count"] = (f64)self->request_perf.request_count;
|
||||
@@ -2278,6 +2292,11 @@ private:
|
||||
response["running_us"] = (f64)((now - self->request_perf.time_start) * 1000000.0);
|
||||
if(self->request_perf.time_init > 0)
|
||||
response["total_us"] = (f64)((now - self->request_perf.time_init) * 1000000.0);
|
||||
u64 workspace_wall_us = self->request_perf.workspace_wall_start > 0 ? (u64)((now - self->request_perf.workspace_wall_start) * 1000000.0) : 0;
|
||||
u64 workspace_cpu_us = self->request_perf.workspace_cpu_start > 0 && cpu_now > 0 ? (u64)((cpu_now - self->request_perf.workspace_cpu_start) * 1000000.0) : 0;
|
||||
response["workspace_wall_us"] = (f64)workspace_wall_us;
|
||||
response["workspace_cpu_us"] = (f64)workspace_cpu_us;
|
||||
response["workspace_wait_us"] = (f64)(workspace_wall_us > workspace_cpu_us ? workspace_wall_us - workspace_cpu_us : 0);
|
||||
response["dispatch_us"] = (f64)self->dispatch_us;
|
||||
response["workspace_setup_us"] = (f64)self->workspace_setup_us;
|
||||
response["workspace_birth_us"] = (f64)self->workspace_birth_us;
|
||||
@@ -3428,6 +3447,7 @@ inline WasmResponse wasm_worker_serve(WasmWorker& worker, const DValue& context_
|
||||
{
|
||||
WasmResponse response;
|
||||
f64 serve_started = time_precise();
|
||||
f64 cpu_started = wasm_thread_cpu_time();
|
||||
auto workspace_start = std::chrono::steady_clock::now();
|
||||
WasmWorkspace workspace(worker);
|
||||
workspace.workspace_setup_us = (u64)std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
@@ -3435,7 +3455,8 @@ inline WasmResponse wasm_worker_serve(WasmWorker& worker, const DValue& context_
|
||||
if(request)
|
||||
{
|
||||
workspace.set_perf_snapshot(my_pid, (u64)parent_pid, request->server ? request->server->request_count : 0,
|
||||
request->stats.time_init, request->stats.time_params, request->stats.time_input, request->stats.time_start);
|
||||
request->stats.time_init, request->stats.time_params, request->stats.time_input, request->stats.time_start,
|
||||
serve_started, cpu_started);
|
||||
if(request->stats.time_start > 0 && serve_started > request->stats.time_start)
|
||||
workspace.dispatch_us = (u64)((serve_started - request->stats.time_start) * 1000000.0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user