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

Function wasm_bench_create

crates/bench-api/src/lib.rs:273–371  ·  view source on GitHub ↗
(
    config: WasmBenchConfig,
    out_bench_ptr: *mut *mut c_void,
)

Source from the content-addressed store, hash-verified

271/// untouched.
272#[unsafe(no_mangle)]
273pub extern "C" fn wasm_bench_create(
274 config: WasmBenchConfig,
275 out_bench_ptr: *mut *mut c_void,
276) -> ExitCode {
277 let result = (|| -> Result<_> {
278 // Clone paths for the core Wasm WASI closure.
279 let working_dir = config.working_dir()?;
280 let stdout_path = config.stdout_path()?;
281 let stderr_path = config.stderr_path()?;
282 let stdin_path = config.stdin_path()?;
283 let options = config.execution_flags()?;
284
285 // Clone paths for the component WASI closure.
286 let working_dir2 = working_dir.clone();
287 let stdout_path2 = stdout_path.clone();
288 let stderr_path2 = stderr_path.clone();
289 let stdin_path2 = stdin_path.clone();
290
291 let state = Box::new(BenchState::new(
292 options,
293 config.compilation_timer,
294 config.compilation_start,
295 config.compilation_end,
296 config.instantiation_timer,
297 config.instantiation_start,
298 config.instantiation_end,
299 config.execution_timer,
300 config.execution_start,
301 config.execution_end,
302 move || {
303 let mut cx = WasiCtx::builder();
304
305 let stdout = std::fs::File::create(&stdout_path)
306 .with_context(|| format!("failed to create {}", stdout_path.display()))?;
307 cx.stdout(OutputFile::new(stdout));
308
309 let stderr = std::fs::File::create(&stderr_path)
310 .with_context(|| format!("failed to create {}", stderr_path.display()))?;
311 cx.stderr(OutputFile::new(stderr));
312
313 if let Some(stdin_path) = &stdin_path {
314 let stdin = std::fs::File::open(stdin_path)
315 .with_context(|| format!("failed to open {}", stdin_path.display()))?;
316 cx.stdin(InputFile::new(stdin));
317 }
318
319 // Allow access to the working directory so that the benchmark can read
320 // its input workload(s).
321 cx.preopened_dir(working_dir.clone(), ".", DirPerms::READ, FilePerms::READ)?;
322
323 // Pass this env var along so that the benchmark program can use smaller
324 // input workload(s) if it has them and that has been requested.
325 if let Ok(val) = env::var("WASM_BENCH_USE_SMALL_WORKLOAD") {
326 cx.env("WASM_BENCH_USE_SMALL_WORKLOAD", &val);
327 }
328
329 Ok(cx.build_p1())
330 },

Callers

nothing calls this directly

Calls 15

OkFunction · 0.85
to_exit_codeFunction · 0.85
working_dirMethod · 0.80
stdout_pathMethod · 0.80
stderr_pathMethod · 0.80
stdin_pathMethod · 0.80
execution_flagsMethod · 0.80
with_contextMethod · 0.80
build_p1Method · 0.80
newFunction · 0.50
builderFunction · 0.50
createFunction · 0.50

Tested by

no test coverage detected