Skip to content

Commit dbc44ad

Browse files
committed
V8: measure call-reducer timings & memory usage
1 parent ef56c90 commit dbc44ad

1 file changed

Lines changed: 23 additions & 12 deletions

File tree

crates/core/src/host/v8/mod.rs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::host::wasm_common::module_host_actor::{
1010
use crate::host::ArgsTuple;
1111
use crate::{host::Scheduler, module_host_context::ModuleCreationContext, replica_context::ReplicaContext};
1212
use anyhow::anyhow;
13-
use core::time::Duration;
13+
use std::time::Instant;
1414
use de::deserialize_js;
1515
use error::{catch_exception, exception_already_thrown, log_traceback, ExcResult, Throwable};
1616
use from_value::cast;
@@ -147,35 +147,46 @@ impl ModuleInstance for JsInstance {
147147
}
148148

149149
fn call_reducer(&mut self, tx: Option<MutTxId>, params: CallReducerParams) -> super::ReducerCallResult {
150-
// TODO(centril): snapshots, module->host calls
151-
let mut isolate = Isolate::new(<_>::default());
152-
let scope = &mut HandleScope::new(&mut isolate);
153-
let context = Context::new(scope, ContextOptions::default());
154-
let scope = &mut ContextScope::new(scope, context);
155-
156150
self.common.call_reducer_with_tx(
157151
&self.replica_ctx.clone(),
158152
tx,
159153
params,
160154
log_traceback,
161155
|tx, op, _budget| {
162-
let call_result = call_call_reducer_from_op(scope, op);
156+
// TODO(centril): snapshots, module->host calls
157+
// Setup V8 scope.
158+
let mut isolate: v8::OwnedIsolate = Isolate::new(<_>::default());
159+
let mut scope_1 = HandleScope::new(&mut isolate);
160+
let context = Context::new(&mut scope_1, ContextOptions::default());
161+
let mut scope_2 = ContextScope::new(&mut scope_1, context);
162+
163+
// Call the reducer.
164+
let start = Instant::now();
165+
let call_result = call_call_reducer_from_op(&mut scope_2, op);
166+
let total_duration = start.elapsed();
167+
163168
// TODO(centril): energy metrering.
164169
let energy = EnergyStats {
165170
used: EnergyQuanta::ZERO,
166171
wasmtime_fuel_used: 0,
167172
remaining: ReducerBudget::ZERO,
168173
};
169-
// TODO(centril): timings.
170174
let timings = ExecutionTimings {
171-
total_duration: Duration::ZERO,
175+
total_duration,
176+
// TODO(centril): call times.
172177
wasm_instance_env_call_times: CallTimes::new(),
173178
};
179+
180+
// Fetch the currently used heap size in V8.
181+
// The used size is ostensibly fairer than the total size.
182+
drop(scope_2);
183+
drop(scope_1);
184+
let memory_allocation = isolate.get_heap_statistics().used_heap_size();
185+
174186
let exec_result = ExecuteResult {
175187
energy,
176188
timings,
177-
// TODO(centril): memory allocation.
178-
memory_allocation: 0,
189+
memory_allocation,
179190
call_result,
180191
};
181192
(tx, exec_result)

0 commit comments

Comments
 (0)