feat: Start implementing loupe::MemoryUsage on wasmer::Module.

This commit is contained in:
Ivan Enderlin
2021-03-23 11:23:32 +01:00
parent af59fcbf22
commit 44dc884260
39 changed files with 197 additions and 64 deletions

View File

@@ -7,6 +7,8 @@
use crate::mmap::Mmap;
use crate::vmcontext::VMMemoryDefinition;
use loupe::MemoryUsage;
use loupe_derive::MemoryUsage;
use more_asserts::assert_ge;
use serde::{Deserialize, Serialize};
use std::borrow::BorrowMut;
@@ -61,7 +63,7 @@ pub enum MemoryError {
}
/// Implementation styles for WebAssembly linear memory.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, MemoryUsage)]
pub enum MemoryStyle {
/// The actual memory can be resized and moved.
Dynamic {
@@ -96,7 +98,7 @@ impl MemoryStyle {
}
/// Trait for implementing Wasm Memory used by Wasmer.
pub trait Memory: fmt::Debug + Send + Sync {
pub trait Memory: fmt::Debug + Send + Sync + MemoryUsage {
/// Returns the memory type for this memory.
fn ty(&self) -> &MemoryType;
@@ -116,7 +118,7 @@ pub trait Memory: fmt::Debug + Send + Sync {
}
/// A linear memory instance.
#[derive(Debug)]
#[derive(Debug, MemoryUsage)]
pub struct LinearMemory {
// The underlying allocation.
mmap: Mutex<WasmMmap>,
@@ -144,7 +146,7 @@ pub struct LinearMemory {
/// A type to help manage who is responsible for the backing memory of them
/// `VMMemoryDefinition`.
#[derive(Debug)]
#[derive(Debug, MemoryUsage)]
enum VMMemoryDefinitionOwnership {
/// The `VMMemoryDefinition` is owned by the `Instance` and we should use
/// its memory. This is how a local memory that's exported should be stored.
@@ -167,7 +169,7 @@ unsafe impl Send for LinearMemory {}
/// This is correct because all internal mutability is protected by a mutex.
unsafe impl Sync for LinearMemory {}
#[derive(Debug)]
#[derive(Debug, MemoryUsage)]
struct WasmMmap {
// Our OS allocation of mmap'd memory.
alloc: Mmap,