add memory creation logging

This commit is contained in:
Valery Antopol 2023-04-28 23:13:26 +03:00
parent 61b826c82b
commit 514d9fe699
2 changed files with 29 additions and 3 deletions

View File

@ -68,7 +68,29 @@ impl WasmBackend for WasmtimeWasmBackend {
}
}
#[derive(Default)]
struct MyStoreLimiter {
memories: i32
}
impl wasmtime::ResourceLimiter for MyStoreLimiter {
fn memory_growing(&mut self, current: usize, desired: usize, maximum: Option<usize>) -> bool {
if current == 0 {
self.memories += 1;
log::debug!("Wasmtime created a memory. Total memories in this Store: {}", self.memories)
}
true
}
fn table_growing(&mut self, current: u32, desired: u32, maximum: Option<u32>) -> bool {
true
}
}
#[derive(Default)]
pub struct StoreState {
wasi: Vec<WasiCtx>, // wasmtime store does not release memory until drop, so do we
limiter: MyStoreLimiter,
}

View File

@ -19,7 +19,7 @@ use crate::WasmtimeWasmBackend;
use marine_wasm_backend_traits::prelude::*;
use wasmtime::StoreContext;
use wasmtime::{ResourceLimiter, StoreContext};
use wasmtime::StoreContextMut;
use wasmtime::AsContext as WasmtimeAsContext;
use wasmtime::AsContextMut as WasmtimeAsContextMut;
@ -45,9 +45,13 @@ pub struct WasmtimeContextMut<'s> {
impl Store<WasmtimeWasmBackend> for WasmtimeStore {
fn new(backend: &WasmtimeWasmBackend) -> Self {
Self {
let mut res = Self {
inner: wasmtime::Store::new(&backend.engine, <_>::default()),
}
};
res.inner.limiter(|ctx| &mut ctx.limiter);
res
}
}