MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / new

Method new

crates/bench-api/src/lib.rs:467–551  ·  view source on GitHub ↗
(
        mut options: CommonOptions,
        compilation_timer: *mut u8,
        compilation_start: extern "C" fn(*mut u8),
        compilation_end: extern "C" fn(*mut u8),
        instantiation_time

Source from the content-addressed store, hash-verified

465
466impl BenchState {
467 fn new(
468 mut options: CommonOptions,
469 compilation_timer: *mut u8,
470 compilation_start: extern "C" fn(*mut u8),
471 compilation_end: extern "C" fn(*mut u8),
472 instantiation_timer: *mut u8,
473 instantiation_start: extern "C" fn(*mut u8),
474 instantiation_end: extern "C" fn(*mut u8),
475 execution_timer: *mut u8,
476 execution_start: extern "C" fn(*mut u8),
477 execution_end: extern "C" fn(*mut u8),
478 make_wasi_cx: impl FnMut() -> Result<WasiP1Ctx> + 'static,
479 make_component_wasi_cx: impl FnMut() -> Result<ComponentHostState> + 'static,
480 ) -> Result<Self> {
481 let mut config = options.config(None)?;
482 // NB: always disable the compilation cache.
483 config.cache(None);
484 let engine = Engine::new(&config)?;
485 let mut linker = Linker::<HostState>::new(&engine);
486 let mut component_linker = wasmtime::component::Linker::<ComponentHostState>::new(&engine);
487
488 // Define the benchmarking start/end functions.
489 let execution_timer = unsafe {
490 // Safe because this bench API's contract requires that its methods
491 // are only ever called from a single thread.
492 UnsafeSendSync::new(execution_timer)
493 };
494 linker.func_wrap("bench", "start", move || {
495 execution_start(*execution_timer.get());
496 Ok(())
497 })?;
498 linker.func_wrap("bench", "end", move || {
499 execution_end(*execution_timer.get());
500 Ok(())
501 })?;
502
503 // Define the same benchmarking functions on the component linker.
504 let mut bench_instance = component_linker.instance("bench")?;
505 bench_instance.func_wrap(
506 "start",
507 move |_: wasmtime::StoreContextMut<'_, ComponentHostState>, (): ()| {
508 execution_start(*execution_timer.get());
509 Ok(())
510 },
511 )?;
512 bench_instance.func_wrap(
513 "end",
514 move |_: wasmtime::StoreContextMut<'_, ComponentHostState>, (): ()| {
515 execution_end(*execution_timer.get());
516 Ok(())
517 },
518 )?;
519
520 let epoch_interruption = options.wasm.epoch_interruption.unwrap_or(false);
521 let fuel = options.wasm.fuel;
522
523 if options.wasi.common != Some(false) {
524 wasmtime_wasi::p1::add_to_linker_sync(&mut linker, |cx| &mut cx.wasi)?;

Callers

nothing calls this directly

Calls 9

OkFunction · 0.85
newFunction · 0.50
add_to_linker_syncFunction · 0.50
add_to_linkerFunction · 0.50
configMethod · 0.45
cacheMethod · 0.45
func_wrapMethod · 0.45
getMethod · 0.45
instanceMethod · 0.45

Tested by

no test coverage detected