mirror of
https://github.com/fluencelabs/marine.git
synced 2025-03-14 13:30:50 +00:00
add memory creation logging
This commit is contained in:
parent
61b826c82b
commit
514d9fe699
@ -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,
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user