Support fuel and epoch interruption in the benchmarking API (#5449)
When these engine flags are passed be sure to configure the store appropriately to ensure that the wasm can actually run instead of crashing immediately, enabling benchmarking comparisons between these modes.
This commit is contained in:
@@ -406,6 +406,8 @@ struct BenchState {
|
|||||||
make_wasi_cx: Box<dyn FnMut() -> Result<WasiCtx>>,
|
make_wasi_cx: Box<dyn FnMut() -> Result<WasiCtx>>,
|
||||||
module: Option<Module>,
|
module: Option<Module>,
|
||||||
store_and_instance: Option<(Store<HostState>, Instance)>,
|
store_and_instance: Option<(Store<HostState>, Instance)>,
|
||||||
|
epoch_interruption: bool,
|
||||||
|
fuel: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct HostState {
|
struct HostState {
|
||||||
@@ -454,6 +456,13 @@ impl BenchState {
|
|||||||
Ok(())
|
Ok(())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
let mut epoch_interruption = false;
|
||||||
|
let mut fuel = None;
|
||||||
|
if let Some(opts) = &options {
|
||||||
|
epoch_interruption = opts.epoch_interruption;
|
||||||
|
fuel = opts.fuel;
|
||||||
|
}
|
||||||
|
|
||||||
let wasi_modules = options
|
let wasi_modules = options
|
||||||
.map(|o| o.wasi_modules)
|
.map(|o| o.wasi_modules)
|
||||||
.flatten()
|
.flatten()
|
||||||
@@ -484,6 +493,8 @@ impl BenchState {
|
|||||||
make_wasi_cx: Box::new(make_wasi_cx) as _,
|
make_wasi_cx: Box::new(make_wasi_cx) as _,
|
||||||
module: None,
|
module: None,
|
||||||
store_and_instance: None,
|
store_and_instance: None,
|
||||||
|
epoch_interruption,
|
||||||
|
fuel,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -520,6 +531,13 @@ impl BenchState {
|
|||||||
// stdin/stdout/stderr.
|
// stdin/stdout/stderr.
|
||||||
(self.instantiation_start)(self.instantiation_timer);
|
(self.instantiation_start)(self.instantiation_timer);
|
||||||
let mut store = Store::new(self.linker.engine(), host);
|
let mut store = Store::new(self.linker.engine(), host);
|
||||||
|
if self.epoch_interruption {
|
||||||
|
store.set_epoch_deadline(1);
|
||||||
|
}
|
||||||
|
if let Some(fuel) = self.fuel {
|
||||||
|
store.add_fuel(fuel).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
let instance = self.linker.instantiate(&mut store, &module)?;
|
let instance = self.linker.instantiate(&mut store, &module)?;
|
||||||
(self.instantiation_end)(self.instantiation_timer);
|
(self.instantiation_end)(self.instantiation_timer);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user