diff --git a/Cargo.lock b/Cargo.lock index 04786340550..3ebaca6ac15 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -545,9 +545,9 @@ dependencies = [ [[package]] name = "csv" -version = "1.1.5" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9d58633299b24b515ac72a3f869f8b91306a3cec616a602843a383acd6f9e97" +checksum = "22813a6dc45b335f9bade10bf7271dc477e81113e89eb251a0bc2a8a81c536e1" dependencies = [ "bstr", "csv-core", @@ -941,9 +941,9 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "indexmap" -version = "1.6.1" +version = "1.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb1fa934250de4de8aef298d81c729a7d33d8c239daa3a7575e6b92bfc7313b" +checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" dependencies = [ "autocfg", "hashbrown", @@ -1088,9 +1088,9 @@ checksum = "3576a87f2ba00f6f106fdfcd16db1d698d648a26ad8e0573cad8537c3c362d2a" [[package]] name = "libc" -version = "0.2.87" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "265d751d31d6780a3f956bb5b8022feba2d94eeee5a84ba64f4212eedca42213" +checksum = "03b07a082330a35e43f63177cc01689da34fbffa0105e1246cf0311472cac73a" [[package]] name = "libffi" @@ -1154,6 +1154,24 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "loupe" +version = "0.1.0" +source = "git+https://github.com/wasmerio/loupe?branch=master#63c2f4a5acf1f3a8ed3568119cad96a731c71d21" +dependencies = [ + "loupe-derive", + "rustversion", +] + +[[package]] +name = "loupe-derive" +version = "0.1.0" +source = "git+https://github.com/wasmerio/loupe?branch=master#63c2f4a5acf1f3a8ed3568119cad96a731c71d21" +dependencies = [ + "quote", + "syn", +] + [[package]] name = "mach" version = "0.3.2" @@ -1372,9 +1390,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5d65c4d95931acda4498f675e332fcbdc9a06705cd07086c510e9b6009cd1c1" +checksum = "acbf547ad0c65e31259204bd90935776d1c693cec2f4ff7abb7a1bbbd40dfe58" [[package]] name = "peeking_take_while" @@ -1393,9 +1411,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cf491442e4b033ed1c722cb9f0df5fcfcf4de682466c46469c36bc47dc5548a" +checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" [[package]] name = "pkg-config" @@ -1627,14 +1645,13 @@ dependencies = [ [[package]] name = "regex" -version = "1.4.3" +version = "1.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a" +checksum = "957056ecddbeba1b26965114e191d2e8589ce74db242b6ea25fc4062427a5c19" dependencies = [ "aho-corasick", "memchr", "regex-syntax", - "thread_local", ] [[package]] @@ -1648,9 +1665,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.22" +version = "0.6.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581" +checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548" [[package]] name = "region" @@ -1825,9 +1842,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.123" +version = "1.0.124" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d5161132722baa40d802cc70b15262b98258453e85e5d1d365c757c73869ae" +checksum = "bd761ff957cb2a45fbb9ab3da6512de9de55872866160b23c25f1a841e99d29f" dependencies = [ "serde_derive", ] @@ -1853,9 +1870,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.123" +version = "1.0.124" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9391c295d64fc0abb2c556bad848f33cb8296276b1ad2677d1ae1ace4f258f31" +checksum = "1800f7693e94e186f5e25a28291ae1570da908aff7d97a095dec1e56ff99069b" dependencies = [ "proc-macro2", "quote", @@ -1922,9 +1939,9 @@ checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" [[package]] name = "syn" -version = "1.0.60" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081" +checksum = "3fd9d1e9976102a03c542daa2eff1b43f9d72306342f3f8b3ed5fb8908195d6f" dependencies = [ "proc-macro2", "quote", @@ -2041,15 +2058,6 @@ dependencies = [ "syn", ] -[[package]] -name = "thread_local" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd" -dependencies = [ - "once_cell", -] - [[package]] name = "time" version = "0.1.43" @@ -2094,9 +2102,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.13" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8a9bd1db7706f2373a190b0d067146caa39350c486f3d455b0e33b431f94c07" +checksum = "c42e6fa53307c8a17e4ccd4dc81cf5ec38db9209f59b222210375b54ee40d1e2" dependencies = [ "proc-macro2", "quote", @@ -2120,9 +2128,9 @@ checksum = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41" [[package]] name = "typenum" -version = "1.12.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" +checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06" [[package]] name = "typetag" @@ -2295,6 +2303,7 @@ dependencies = [ "cfg-if 0.1.10", "indexmap", "libc", + "loupe", "more-asserts", "target-lexicon", "tempfile", @@ -2390,6 +2399,7 @@ version = "1.0.2" dependencies = [ "enumset", "hashbrown", + "loupe", "serde", "serde_bytes", "smallvec", @@ -2410,6 +2420,7 @@ dependencies = [ "gimli", "hashbrown", "lazy_static", + "loupe", "more-asserts", "rayon", "serde", @@ -2432,6 +2443,7 @@ dependencies = [ "itertools 0.10.0", "lazy_static", "libc", + "loupe", "rayon", "regex", "rustc_version 0.2.3", @@ -2452,6 +2464,7 @@ dependencies = [ "dynasmrt", "hashbrown", "lazy_static", + "loupe", "more-asserts", "rayon", "serde", @@ -2494,6 +2507,7 @@ dependencies = [ "backtrace", "bincode", "lazy_static", + "loupe", "memmap2", "more-asserts", "rustc-demangle", @@ -2511,6 +2525,7 @@ name = "wasmer-engine-dummy" version = "1.0.2" dependencies = [ "bincode", + "loupe", "serde", "serde_bytes", "wasmer-compiler", @@ -2525,6 +2540,7 @@ version = "1.0.2" dependencies = [ "bincode", "cfg-if 0.1.10", + "loupe", "region", "serde", "serde_bytes", @@ -2543,6 +2559,7 @@ dependencies = [ "cfg-if 0.1.10", "leb128", "libloading", + "loupe", "serde", "tempfile", "tracing", @@ -2562,6 +2579,7 @@ dependencies = [ "cfg-if 0.1.10", "leb128", "libloading", + "loupe", "serde", "tempfile", "tracing", @@ -2584,6 +2602,7 @@ dependencies = [ name = "wasmer-middlewares" version = "1.0.2" dependencies = [ + "loupe", "wasmer", "wasmer-types", "wasmer-vm", @@ -2603,6 +2622,7 @@ dependencies = [ name = "wasmer-types" version = "1.0.2" dependencies = [ + "loupe", "serde", "thiserror", ] @@ -2616,6 +2636,7 @@ dependencies = [ "cfg-if 0.1.10", "indexmap", "libc", + "loupe", "memoffset", "more-asserts", "region", diff --git a/lib/api/Cargo.toml b/lib/api/Cargo.toml index f9286c04c17..f69280e6d55 100644 --- a/lib/api/Cargo.toml +++ b/lib/api/Cargo.toml @@ -27,6 +27,7 @@ wat = { version = "1.0", optional = true } thiserror = "1.0" more-asserts = "0.2" target-lexicon = { version = "0.11", default-features = false } +loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } [target.'cfg(target_os = "windows")'.dependencies] winapi = "0.3" diff --git a/lib/api/src/store.rs b/lib/api/src/store.rs index 66137508240..2371fd18b2c 100644 --- a/lib/api/src/store.rs +++ b/lib/api/src/store.rs @@ -1,4 +1,5 @@ use crate::tunables::BaseTunables; +use loupe::MemoryUsage; use std::fmt; use std::sync::Arc; #[cfg(all(feature = "compiler", feature = "engine"))] @@ -15,7 +16,7 @@ use wasmer_engine::{Engine, Tunables}; /// [`Tunables`] (that are used to create the memories, tables and globals). /// /// Spec: -#[derive(Clone)] +#[derive(Clone, MemoryUsage)] pub struct Store { engine: Arc, tunables: Arc, diff --git a/lib/api/src/tunables.rs b/lib/api/src/tunables.rs index 2425400010e..d714ffd602b 100644 --- a/lib/api/src/tunables.rs +++ b/lib/api/src/tunables.rs @@ -1,4 +1,5 @@ use crate::{MemoryType, Pages, TableType}; +use loupe::MemoryUsage; use std::cmp::min; use std::ptr::NonNull; use std::sync::Arc; @@ -19,7 +20,7 @@ use wasmer_vm::{ /// implementation or use composition to wrap your Tunables around /// this one. The later approach is demonstrated in the /// tunables-limit-memory example. -#[derive(Clone)] +#[derive(Clone, MemoryUsage)] pub struct BaseTunables { /// For static heaps, the size in wasm pages of the heap protected by bounds checking. pub static_memory_bound: Pages, diff --git a/lib/compiler-cranelift/Cargo.toml b/lib/compiler-cranelift/Cargo.toml index 017daca3731..cb0d3630d72 100644 --- a/lib/compiler-cranelift/Cargo.toml +++ b/lib/compiler-cranelift/Cargo.toml @@ -25,6 +25,7 @@ serde = { version = "1.0", features = ["derive"] } more-asserts = "0.2" gimli = { version = "0.23", optional = true } smallvec = "1.6" +loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } [dev-dependencies] target-lexicon = { version = "0.11", default-features = false } diff --git a/lib/compiler-cranelift/src/compiler.rs b/lib/compiler-cranelift/src/compiler.rs index 9b28a0a3a70..dd297033098 100644 --- a/lib/compiler-cranelift/src/compiler.rs +++ b/lib/compiler-cranelift/src/compiler.rs @@ -18,6 +18,7 @@ use cranelift_codegen::print_errors::pretty_error; use cranelift_codegen::{binemit, Context}; #[cfg(feature = "unwind")] use gimli::write::{Address, EhFrame, FrameTable}; +use loupe::MemoryUsage; use rayon::prelude::{IntoParallelRefIterator, ParallelIterator}; use std::sync::Arc; use wasmer_compiler::CompileError; @@ -32,6 +33,7 @@ use wasmer_types::{FunctionIndex, LocalFunctionIndex, SignatureIndex}; /// A compiler that compiles a WebAssembly module with Cranelift, translating the Wasm to Cranelift IR, /// optimizing it and then translating to assembly. +#[derive(MemoryUsage)] pub struct CraneliftCompiler { config: Cranelift, } diff --git a/lib/compiler-cranelift/src/config.rs b/lib/compiler-cranelift/src/config.rs index 5a7b671b329..ed8419c2fce 100644 --- a/lib/compiler-cranelift/src/config.rs +++ b/lib/compiler-cranelift/src/config.rs @@ -1,6 +1,7 @@ use crate::compiler::CraneliftCompiler; use cranelift_codegen::isa::{lookup, TargetIsa}; use cranelift_codegen::settings::{self, Configurable}; +use loupe::MemoryUsage; use std::sync::Arc; use wasmer_compiler::{ Architecture, Compiler, CompilerConfig, CpuFeature, ModuleMiddleware, Target, @@ -10,7 +11,7 @@ use wasmer_compiler::{ /// Possible optimization levels for the Cranelift codegen backend. #[non_exhaustive] -#[derive(Clone, Debug)] +#[derive(Clone, Debug, MemoryUsage)] pub enum CraneliftOptLevel { /// No optimizations performed, minimizes compilation time by disabling most /// optimizations. @@ -27,7 +28,7 @@ pub enum CraneliftOptLevel { /// /// This structure exposes a builder-like interface and is primarily /// consumed by `wasmer_engine::Engine::new`. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, MemoryUsage)] pub struct Cranelift { enable_nan_canonicalization: bool, enable_verifier: bool, diff --git a/lib/compiler-llvm/Cargo.toml b/lib/compiler-llvm/Cargo.toml index ce5159448c0..d6aac52fa35 100644 --- a/lib/compiler-llvm/Cargo.toml +++ b/lib/compiler-llvm/Cargo.toml @@ -22,6 +22,7 @@ libc = { version = "^0.2", default-features = false } byteorder = "1" itertools = "0.10" rayon = "1.5" +loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } [dependencies.inkwell] version = "=0.1.0-beta.2" diff --git a/lib/compiler-llvm/src/compiler.rs b/lib/compiler-llvm/src/compiler.rs index d08f34bad2f..d3d1b842856 100644 --- a/lib/compiler-llvm/src/compiler.rs +++ b/lib/compiler-llvm/src/compiler.rs @@ -7,6 +7,7 @@ use inkwell::memory_buffer::MemoryBuffer; use inkwell::module::{Linkage, Module}; use inkwell::targets::FileType; use inkwell::DLLStorageClass; +use loupe::MemoryUsage; use rayon::iter::ParallelBridge; use rayon::prelude::{IntoParallelIterator, IntoParallelRefIterator, ParallelIterator}; use std::sync::Arc; @@ -22,6 +23,7 @@ use wasmer_types::{FunctionIndex, LocalFunctionIndex, SignatureIndex}; /// A compiler that compiles a WebAssembly module with LLVM, translating the Wasm to LLVM IR, /// optimizing it and then translating to assembly. +#[derive(MemoryUsage)] pub struct LLVMCompiler { config: LLVM, } diff --git a/lib/compiler-llvm/src/config.rs b/lib/compiler-llvm/src/config.rs index 6ae8085aaf1..245a27e92f6 100644 --- a/lib/compiler-llvm/src/config.rs +++ b/lib/compiler-llvm/src/config.rs @@ -5,6 +5,7 @@ use inkwell::targets::{ }; pub use inkwell::OptimizationLevel as LLVMOptLevel; use itertools::Itertools; +use loupe::MemoryUsage; use std::fmt::Debug; use std::sync::Arc; use target_lexicon::Architecture; @@ -37,12 +38,14 @@ pub trait LLVMCallbacks: Debug + Send + Sync { fn obj_memory_buffer(&self, function: &CompiledKind, memory_buffer: &InkwellMemoryBuffer); } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, MemoryUsage)] pub struct LLVM { pub(crate) enable_nan_canonicalization: bool, pub(crate) enable_verifier: bool, + #[loupe(skip)] pub(crate) opt_level: LLVMOptLevel, is_pic: bool, + #[loupe(skip)] pub(crate) callbacks: Option>, /// The middleware chain. pub(crate) middlewares: Vec>, diff --git a/lib/compiler-singlepass/Cargo.toml b/lib/compiler-singlepass/Cargo.toml index 2c771c8c552..ede05f8bb56 100644 --- a/lib/compiler-singlepass/Cargo.toml +++ b/lib/compiler-singlepass/Cargo.toml @@ -24,6 +24,7 @@ dynasmrt = "1.0" lazy_static = "1.4" byteorder = "1.3" smallvec = "1.6" +loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } [dev-dependencies] target-lexicon = { version = "0.11", default-features = false } diff --git a/lib/compiler-singlepass/src/compiler.rs b/lib/compiler-singlepass/src/compiler.rs index 0f2f6520b62..edc1d93a4a4 100644 --- a/lib/compiler-singlepass/src/compiler.rs +++ b/lib/compiler-singlepass/src/compiler.rs @@ -7,6 +7,7 @@ use crate::codegen_x64::{ CodegenError, FuncGen, }; use crate::config::Singlepass; +use loupe::MemoryUsage; use rayon::prelude::{IntoParallelIterator, IntoParallelRefIterator, ParallelIterator}; use std::sync::Arc; use wasmer_compiler::TrapInformation; @@ -22,6 +23,7 @@ use wasmer_vm::{ModuleInfo, TrapCode, VMOffsets}; /// A compiler that compiles a WebAssembly module with Singlepass. /// It does the compilation in one pass +#[derive(MemoryUsage)] pub struct SinglepassCompiler { config: Singlepass, } diff --git a/lib/compiler-singlepass/src/config.rs b/lib/compiler-singlepass/src/config.rs index 669b8be0770..d788478a9b9 100644 --- a/lib/compiler-singlepass/src/config.rs +++ b/lib/compiler-singlepass/src/config.rs @@ -2,11 +2,12 @@ #![allow(unused_imports, dead_code)] use crate::compiler::SinglepassCompiler; +use loupe::MemoryUsage; use std::sync::Arc; use wasmer_compiler::{Compiler, CompilerConfig, CpuFeature, ModuleMiddleware, Target}; use wasmer_types::Features; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, MemoryUsage)] pub struct Singlepass { pub(crate) enable_nan_canonicalization: bool, pub(crate) enable_stack_check: bool, diff --git a/lib/compiler/Cargo.toml b/lib/compiler/Cargo.toml index 92625b684b6..579f7814ed0 100644 --- a/lib/compiler/Cargo.toml +++ b/lib/compiler/Cargo.toml @@ -21,6 +21,7 @@ serde = { version = "1.0", features = ["derive"], optional = true } thiserror = "1.0" serde_bytes = { version = "0.11", optional = true } smallvec = "1.6" +loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } [features] default = ["std", "enable-serde"] diff --git a/lib/compiler/src/compiler.rs b/lib/compiler/src/compiler.rs index db2313b4ac5..eff21365c8a 100644 --- a/lib/compiler/src/compiler.rs +++ b/lib/compiler/src/compiler.rs @@ -11,6 +11,7 @@ use crate::translator::ModuleMiddleware; use crate::FunctionBodyData; use crate::ModuleTranslationState; use crate::SectionIndex; +use loupe::MemoryUsage; use wasmer_types::entity::PrimaryMap; use wasmer_types::{Features, FunctionIndex, LocalFunctionIndex, SignatureIndex}; use wasmparser::{Validator, WasmFeatures}; @@ -58,7 +59,7 @@ where } /// An implementation of a Compiler from parsed WebAssembly module to Compiled native code. -pub trait Compiler: Send { +pub trait Compiler: Send + MemoryUsage { /// Validates a module. /// /// It returns the a succesful Result in case is valid, `CompileError` in case is not. diff --git a/lib/compiler/src/target.rs b/lib/compiler/src/target.rs index 9d18d79e87d..12b2b06f1c6 100644 --- a/lib/compiler/src/target.rs +++ b/lib/compiler/src/target.rs @@ -3,6 +3,7 @@ use crate::error::ParseCpuFeatureError; use crate::lib::std::str::FromStr; use crate::lib::std::string::{String, ToString}; use enumset::{EnumSet, EnumSetType}; +use loupe::MemoryUsage; pub use target_lexicon::{ Architecture, BinaryFormat, CallingConvention, Endianness, OperatingSystem, PointerWidth, Triple, @@ -160,9 +161,11 @@ impl ToString for CpuFeature { /// This is the target that we will use for compiling /// the WebAssembly ModuleInfo, and then run it. -#[derive(Clone, Debug, PartialEq, Eq, Hash)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, MemoryUsage)] pub struct Target { + #[loupe(skip)] triple: Triple, + #[loupe(skip)] cpu_features: EnumSet, } diff --git a/lib/compiler/src/translator/middleware.rs b/lib/compiler/src/translator/middleware.rs index 5efcc562f9b..3dd8c6aeda1 100644 --- a/lib/compiler/src/translator/middleware.rs +++ b/lib/compiler/src/translator/middleware.rs @@ -1,6 +1,7 @@ //! The middleware parses the function binary bytecodes and transform them //! with the chosen functions. +use loupe::MemoryUsage; use smallvec::SmallVec; use std::collections::VecDeque; use std::fmt::Debug; @@ -12,7 +13,7 @@ use wasmparser::{BinaryReader, Operator, Type}; use crate::error::{MiddlewareError, WasmResult}; /// A shared builder for function middlewares. -pub trait ModuleMiddleware: Debug + Send + Sync { +pub trait ModuleMiddleware: Debug + Send + Sync + MemoryUsage { /// Generates a `FunctionMiddleware` for a given function. /// /// Here we generate a separate object for each function instead of executing directly on per-function operators, diff --git a/lib/engine-jit/Cargo.toml b/lib/engine-jit/Cargo.toml index a4d1c6f90d0..38b70474e25 100644 --- a/lib/engine-jit/Cargo.toml +++ b/lib/engine-jit/Cargo.toml @@ -21,6 +21,7 @@ serde = { version = "1.0", features = ["derive", "rc"] } serde_bytes = { version = "0.11" } bincode = "1.3" cfg-if = "0.1" +loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } [target.'cfg(target_os = "windows")'.dependencies] winapi = { version = "0.3", features = ["winnt", "impl-default"] } diff --git a/lib/engine-jit/src/code_memory.rs b/lib/engine-jit/src/code_memory.rs index 3d23e1eda5c..1498a23ea13 100644 --- a/lib/engine-jit/src/code_memory.rs +++ b/lib/engine-jit/src/code_memory.rs @@ -3,6 +3,7 @@ //! Memory management for executable code. use crate::unwind::UnwindRegistry; +use loupe::MemoryUsage; use wasmer_compiler::{CompiledFunctionUnwindInfo, CustomSection, FunctionBody}; use wasmer_vm::{Mmap, VMFunctionBody}; @@ -18,6 +19,7 @@ const ARCH_FUNCTION_ALIGNMENT: usize = 16; const DATA_SECTION_ALIGNMENT: usize = 64; /// Memory manager for executable code. +#[derive(MemoryUsage)] pub struct CodeMemory { unwind_registry: UnwindRegistry, mmap: Mmap, diff --git a/lib/engine-jit/src/engine.rs b/lib/engine-jit/src/engine.rs index c3ff020ff49..9009d937b62 100644 --- a/lib/engine-jit/src/engine.rs +++ b/lib/engine-jit/src/engine.rs @@ -1,6 +1,7 @@ //! JIT compilation. use crate::{CodeMemory, JITArtifact}; +use loupe::MemoryUsage; use std::sync::{Arc, Mutex}; #[cfg(feature = "compiler")] use wasmer_compiler::Compiler; @@ -17,7 +18,7 @@ use wasmer_vm::{ }; /// A WebAssembly `JIT` Engine. -#[derive(Clone)] +#[derive(Clone, MemoryUsage)] pub struct JITEngine { inner: Arc>, /// The target for the compiler @@ -138,6 +139,7 @@ impl Engine for JITEngine { } /// The inner contents of `JITEngine` +#[derive(MemoryUsage)] pub struct JITEngineInner { /// The compiler #[cfg(feature = "compiler")] diff --git a/lib/engine-jit/src/unwind/dummy.rs b/lib/engine-jit/src/unwind/dummy.rs index 3d029ecd981..cfb636bd2c8 100644 --- a/lib/engine-jit/src/unwind/dummy.rs +++ b/lib/engine-jit/src/unwind/dummy.rs @@ -1,9 +1,11 @@ //! Module for Dummy unwind registry. +use loupe::MemoryUsage; use wasmer_compiler::CompiledFunctionUnwindInfo; /// Represents a registry of function unwind information when the host system /// support any one in specific. +#[derive(MemoryUsage)] pub struct DummyUnwindRegistry {} impl DummyUnwindRegistry { diff --git a/lib/engine-jit/src/unwind/systemv.rs b/lib/engine-jit/src/unwind/systemv.rs index d08ea778077..8362fec499c 100644 --- a/lib/engine-jit/src/unwind/systemv.rs +++ b/lib/engine-jit/src/unwind/systemv.rs @@ -2,9 +2,12 @@ // Attributions: https://github.com/wasmerio/wasmer/blob/master/ATTRIBUTIONS.md //! Module for System V ABI unwind registry. + +use loupe::MemoryUsage; use wasmer_compiler::CompiledFunctionUnwindInfo; /// Represents a registry of function unwind information for System V ABI. +#[derive(MemoryUsage)] pub struct UnwindRegistry { registrations: Vec, published: bool, @@ -65,7 +68,11 @@ impl UnwindRegistry { // deregistering it. We must avoid this // scenario. Usually, this is handled upstream by the // compilers. - debug_assert_ne!(eh_frame, &[0, 0, 0, 0], "`eh_frame` seems to contain empty FDEs"); + debug_assert_ne!( + eh_frame, + &[0, 0, 0, 0], + "`eh_frame` seems to contain empty FDEs" + ); // On gnu (libgcc), `__register_frame` will walk the FDEs until an entry of length 0 let ptr = eh_frame.as_ptr(); diff --git a/lib/engine-jit/src/unwind/windows_x64.rs b/lib/engine-jit/src/unwind/windows_x64.rs index 96cac39239c..1db1658acc7 100644 --- a/lib/engine-jit/src/unwind/windows_x64.rs +++ b/lib/engine-jit/src/unwind/windows_x64.rs @@ -2,6 +2,7 @@ // Attributions: https://github.com/wasmerio/wasmer/blob/master/ATTRIBUTIONS.md //! Module for Windows x64 ABI unwind registry. +use loupe::{MemoryUsage, MemoryUsageTracker}; use std::collections::HashMap; use wasmer_compiler::CompiledFunctionUnwindInfo; use winapi::um::winnt; @@ -103,3 +104,22 @@ impl Drop for UnwindRegistry { } } } + +impl MemoryUsage for UnwindRegistry { + fn size_of_val(&self, tracker: &mut dyn MemoryUsageTracker) -> usize { + // To count `RUNTIME_FUNCTION`, we first check the + // [documentation][doc1]. We see that it's a type alias to + // `_IMAGE_RUNTIME_FUNCTION_ENTRY`, let's check the + // [documentation][doc2]. It's composed of two `DWORD`, so two + // `u64`, and one `IMAGE_RUNTIME_FUNCTION_ENTRY_u`, which we + // approximate to size of `u64`. + // + // [doc1]: https://docs.rs/winapi/0.3.9/winapi/um/winnt/type.RUNTIME_FUNCTION.html + // [doc2]: https://docs.rs/winapi/0.3.9/winapi/um/winnt/struct._IMAGE_RUNTIME_FUNCTION_ENTRY.html + self.functions + .iter() + .map(|(key, _)| (key, std::mem::size_of::() * 3)) + .sum::() + + self.published.size_of_val(tracker) + } +} diff --git a/lib/engine-native/Cargo.toml b/lib/engine-native/Cargo.toml index c8f5c125dda..be045b7a4df 100644 --- a/lib/engine-native/Cargo.toml +++ b/lib/engine-native/Cargo.toml @@ -24,6 +24,7 @@ leb128 = "0.2" libloading = "0.7" tempfile = "3.1" which = "4.0" +loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } [features] # Enable the `compiler` feature if you want the engine to compile diff --git a/lib/engine-native/src/engine.rs b/lib/engine-native/src/engine.rs index 03d49d6424a..84f857fd6d6 100644 --- a/lib/engine-native/src/engine.rs +++ b/lib/engine-native/src/engine.rs @@ -2,6 +2,7 @@ use crate::NativeArtifact; use libloading::Library; +use loupe::MemoryUsage; use std::path::Path; use std::sync::Arc; use std::sync::Mutex; @@ -15,7 +16,7 @@ use wasmer_types::FunctionType; use wasmer_vm::{SignatureRegistry, VMSharedSignatureIndex}; /// A WebAssembly `Native` Engine. -#[derive(Clone)] +#[derive(Clone, MemoryUsage)] pub struct NativeEngine { inner: Arc>, /// The target for the compiler @@ -174,7 +175,7 @@ impl Engine for NativeEngine { } } -#[derive(Clone, Copy)] +#[derive(Clone, Copy, MemoryUsage)] pub(crate) enum Linker { None, Clang11, @@ -219,25 +220,34 @@ impl Linker { } /// The inner contents of `NativeEngine` +#[derive(MemoryUsage)] pub struct NativeEngineInner { /// The compiler #[cfg(feature = "compiler")] compiler: Option>, + /// The WebAssembly features to use #[cfg(feature = "compiler")] features: Features, + /// The signature registry is used mainly to operate with trampolines /// performantly. signatures: SignatureRegistry, + /// The prefixer returns the a String to prefix each of /// the functions in the shared object generated by the `NativeEngine`, /// so we can assure no collisions. + #[loupe(skip)] prefixer: Option String + Send>>, + /// Whether the native engine will cross-compile. is_cross_compiling: bool, + /// The linker to use. linker: Linker, + /// List of libraries loaded by this engine. + #[loupe(skip)] libraries: Vec, } diff --git a/lib/engine-object-file/Cargo.toml b/lib/engine-object-file/Cargo.toml index 36a0ee634fb..17ee1e01661 100644 --- a/lib/engine-object-file/Cargo.toml +++ b/lib/engine-object-file/Cargo.toml @@ -23,6 +23,7 @@ bincode = "1.3" leb128 = "0.2" libloading = "0.7" tempfile = "3.1" +loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } [features] # Enable the `compiler` feature if you want the engine to compile diff --git a/lib/engine-object-file/src/engine.rs b/lib/engine-object-file/src/engine.rs index 3f00db11977..8bd589361d2 100644 --- a/lib/engine-object-file/src/engine.rs +++ b/lib/engine-object-file/src/engine.rs @@ -1,4 +1,5 @@ use crate::ObjectFileArtifact; +use loupe::MemoryUsage; use std::io::Read; use std::path::Path; use std::sync::{Arc, Mutex}; @@ -12,7 +13,7 @@ use wasmer_types::FunctionType; use wasmer_vm::{SignatureRegistry, VMSharedSignatureIndex}; /// A WebAssembly `ObjectFile` Engine. -#[derive(Clone)] +#[derive(Clone, MemoryUsage)] pub struct ObjectFileEngine { inner: Arc>, /// The target for the compiler @@ -165,19 +166,24 @@ impl Engine for ObjectFileEngine { } /// The inner contents of `ObjectFileEngine` +#[derive(MemoryUsage)] pub struct ObjectFileEngineInner { /// The compiler #[cfg(feature = "compiler")] compiler: Option>, + /// The WebAssembly features to use #[cfg(feature = "compiler")] features: Features, + /// The signature registry is used mainly to operate with trampolines /// performantly. signatures: SignatureRegistry, + /// The prefixer returns the a String to prefix each of /// the functions in the shared object generated by the `ObjectFileEngine`, /// so we can assure no collisions. + #[loupe(skip)] prefixer: Option String + Send>>, } diff --git a/lib/engine/Cargo.toml b/lib/engine/Cargo.toml index eab531b0f6b..a8ae21becf7 100644 --- a/lib/engine/Cargo.toml +++ b/lib/engine/Cargo.toml @@ -25,6 +25,7 @@ serde = { version = "1.0", features = ["derive", "rc"] } serde_bytes = { version = "0.11" } bincode = "1.3" lazy_static = "1.4" +loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } [badges] maintenance = { status = "actively-developed" } diff --git a/lib/engine/src/engine.rs b/lib/engine/src/engine.rs index 8cfceb3a83f..8d5f6c360bc 100644 --- a/lib/engine/src/engine.rs +++ b/lib/engine/src/engine.rs @@ -2,6 +2,7 @@ use crate::tunables::Tunables; use crate::{Artifact, DeserializeError}; +use loupe::MemoryUsage; use memmap2::Mmap; use std::path::Path; use std::sync::atomic::{AtomicUsize, Ordering::SeqCst}; @@ -16,7 +17,7 @@ use wasmer_vm::VMSharedSignatureIndex; /// such as: JIT or Native. /// /// The product that an `Engine` produces and consumes is the [`Artifact`]. -pub trait Engine { +pub trait Engine: MemoryUsage { /// Gets the target fn target(&self) -> &Target; @@ -68,7 +69,7 @@ pub trait Engine { fn cloned(&self) -> Arc; } -#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, MemoryUsage)] #[repr(transparent)] /// A unique identifier for an Engine. pub struct EngineId { diff --git a/lib/engine/src/tunables.rs b/lib/engine/src/tunables.rs index 7d3de72918a..adad964c697 100644 --- a/lib/engine/src/tunables.rs +++ b/lib/engine/src/tunables.rs @@ -1,4 +1,5 @@ use crate::error::LinkError; +use loupe::MemoryUsage; use std::ptr::NonNull; use std::sync::Arc; use wasmer_types::entity::{EntityRef, PrimaryMap}; @@ -13,7 +14,7 @@ use wasmer_vm::{VMMemoryDefinition, VMTableDefinition}; /// An engine delegates the creation of memories, tables, and globals /// to a foreign implementor of this trait. -pub trait Tunables { +pub trait Tunables: MemoryUsage { /// Construct a `MemoryStyle` for the provided `MemoryType` fn memory_style(&self, memory: &MemoryType) -> MemoryStyle; diff --git a/lib/middlewares/Cargo.toml b/lib/middlewares/Cargo.toml index 6ffde00e35c..5fd6837df79 100644 --- a/lib/middlewares/Cargo.toml +++ b/lib/middlewares/Cargo.toml @@ -14,6 +14,7 @@ edition = "2018" wasmer = { path = "../api", version = "1.0.2" } wasmer-types = { path = "../wasmer-types", version = "1.0.2" } wasmer-vm = { path = "../vm", version = "1.0.2" } +loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } [badges] maintenance = { status = "actively-developed" } diff --git a/lib/middlewares/src/metering.rs b/lib/middlewares/src/metering.rs index 94a07df2880..faea363e073 100644 --- a/lib/middlewares/src/metering.rs +++ b/lib/middlewares/src/metering.rs @@ -1,8 +1,10 @@ //! `metering` is a middleware for tracking how many operators are executed in total //! and putting a limit on the total number of operators executed. +use loupe::{MemoryUsage, MemoryUsageTracker}; use std::convert::TryInto; use std::fmt; +use std::mem; use std::sync::{Arc, Mutex}; use wasmer::wasmparser::{Operator, Type as WpType, TypeOrFuncType as WpTypeOrFuncType}; use wasmer::{ @@ -12,7 +14,7 @@ use wasmer::{ use wasmer_types::GlobalIndex; use wasmer_vm::ModuleInfo; -#[derive(Clone)] +#[derive(Clone, MemoryUsage)] struct MeteringGlobalIndexes(GlobalIndex, GlobalIndex); impl MeteringGlobalIndexes { @@ -154,6 +156,13 @@ impl u64 + Send + Sync + 'static> ModuleMiddleware for Meter } } +impl u64 + Send + Sync + 'static> MemoryUsage for Metering { + fn size_of_val(&self, tracker: &mut dyn MemoryUsageTracker) -> usize { + mem::size_of_val(self) + self.global_indexes.size_of_val(tracker) + - mem::size_of_val(&self.global_indexes) + } +} + impl u64 + Send + Sync> fmt::Debug for FunctionMetering { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("FunctionMetering") diff --git a/lib/vm/Cargo.toml b/lib/vm/Cargo.toml index 5f1c88d104c..cc12923e68b 100644 --- a/lib/vm/Cargo.toml +++ b/lib/vm/Cargo.toml @@ -21,6 +21,7 @@ more-asserts = "0.2" cfg-if = "0.1" backtrace = "0.3" serde = { version = "1.0", features = ["derive", "rc"] } +loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } [target.'cfg(target_os = "windows")'.dependencies] winapi = { version = "0.3", features = ["winbase", "memoryapi", "errhandlingapi"] } diff --git a/lib/vm/src/mmap.rs b/lib/vm/src/mmap.rs index 6b3dcdd19cd..7f33e88628e 100644 --- a/lib/vm/src/mmap.rs +++ b/lib/vm/src/mmap.rs @@ -4,6 +4,7 @@ //! Low-level abstraction for allocating and managing zero-filled pages //! of memory. +use loupe::{MemoryUsage, MemoryUsageTracker}; use more_asserts::assert_le; use more_asserts::assert_lt; use std::io; @@ -279,6 +280,14 @@ impl Drop for Mmap { } } +impl MemoryUsage for Mmap { + fn size_of_val(&self, tracker: &mut dyn MemoryUsageTracker) -> usize { + tracker.track(self.as_ptr() as *const ()); + + self.len() + } +} + fn _assert() { fn _assert_send_sync() {} _assert_send_sync::(); diff --git a/lib/vm/src/sig_registry.rs b/lib/vm/src/sig_registry.rs index 58b690fc6b7..051006bc960 100644 --- a/lib/vm/src/sig_registry.rs +++ b/lib/vm/src/sig_registry.rs @@ -5,6 +5,7 @@ //! signature checking. use crate::vmcontext::VMSharedSignatureIndex; +use loupe::MemoryUsage; use more_asserts::{assert_lt, debug_assert_lt}; use std::collections::{hash_map, HashMap}; use std::convert::TryFrom; @@ -15,7 +16,7 @@ use wasmer_types::FunctionType; /// call must match. To implement this efficiently, keep a registry of all /// signatures, shared by all instances, so that call sites can just do an /// index comparison. -#[derive(Debug)] +#[derive(Debug, MemoryUsage)] pub struct SignatureRegistry { // This structure is stored in an `Engine` and is intended to be shared // across many instances. Ideally instances can themselves be sent across @@ -25,7 +26,7 @@ pub struct SignatureRegistry { inner: RwLock, } -#[derive(Debug, Default)] +#[derive(Debug, Default, MemoryUsage)] struct Inner { signature2index: HashMap, index2signature: HashMap, diff --git a/lib/vm/src/vmcontext.rs b/lib/vm/src/vmcontext.rs index 4e50eb459cb..929c1126f2d 100644 --- a/lib/vm/src/vmcontext.rs +++ b/lib/vm/src/vmcontext.rs @@ -9,6 +9,7 @@ use crate::instance::Instance; use crate::memory::Memory; use crate::table::Table; use crate::trap::{Trap, TrapCode}; +use loupe::MemoryUsage; use std::any::Any; use std::convert::TryFrom; use std::fmt; @@ -705,7 +706,7 @@ impl VMGlobalDefinition { /// An index into the shared signature registry, usable for checking signatures /// at indirect calls. #[repr(C)] -#[derive(Debug, Eq, PartialEq, Clone, Copy, Hash)] +#[derive(Debug, Eq, PartialEq, Clone, Copy, Hash, MemoryUsage)] pub struct VMSharedSignatureIndex(u32); #[cfg(test)] diff --git a/lib/wasmer-types/Cargo.toml b/lib/wasmer-types/Cargo.toml index 892c13ad943..8bff64a3dd7 100644 --- a/lib/wasmer-types/Cargo.toml +++ b/lib/wasmer-types/Cargo.toml @@ -13,6 +13,7 @@ edition = "2018" [dependencies] serde = { version = "1.0", features = ["derive"], optional = true, default-features = false } thiserror = "1.0" +loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } [features] default = ["std", "enable-serde"] diff --git a/lib/wasmer-types/src/features.rs b/lib/wasmer-types/src/features.rs index 557c4e6323d..4fc19564dcf 100644 --- a/lib/wasmer-types/src/features.rs +++ b/lib/wasmer-types/src/features.rs @@ -1,3 +1,4 @@ +use loupe::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; @@ -5,7 +6,7 @@ use serde::{Deserialize, Serialize}; /// Features usually have a corresponding [WebAssembly proposal]. /// /// [WebAssembly proposal]: https://github.com/WebAssembly/proposals -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Debug, Eq, PartialEq, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct Features { /// Threads proposal should be enabled diff --git a/lib/wasmer-types/src/indexes.rs b/lib/wasmer-types/src/indexes.rs index 7c2247f8eb6..ed5f320150d 100644 --- a/lib/wasmer-types/src/indexes.rs +++ b/lib/wasmer-types/src/indexes.rs @@ -1,83 +1,84 @@ //! Helper functions and structures for the translation. use crate::entity::entity_impl; use core::u32; +use loupe::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; /// Index type of a function defined locally inside the WebAssembly module. -#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct LocalFunctionIndex(u32); entity_impl!(LocalFunctionIndex); /// Index type of a table defined locally inside the WebAssembly module. -#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct LocalTableIndex(u32); entity_impl!(LocalTableIndex); /// Index type of a memory defined locally inside the WebAssembly module. -#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct LocalMemoryIndex(u32); entity_impl!(LocalMemoryIndex); /// Index type of a global defined locally inside the WebAssembly module. -#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct LocalGlobalIndex(u32); entity_impl!(LocalGlobalIndex); /// Index type of a function (imported or local) inside the WebAssembly module. -#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct FunctionIndex(u32); entity_impl!(FunctionIndex); /// Index type of a table (imported or local) inside the WebAssembly module. -#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct TableIndex(u32); entity_impl!(TableIndex); /// Index type of a global variable (imported or local) inside the WebAssembly module. -#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct GlobalIndex(u32); entity_impl!(GlobalIndex); /// Index type of a linear memory (imported or local) inside the WebAssembly module. -#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct MemoryIndex(u32); entity_impl!(MemoryIndex); /// Index type of a signature (imported or local) inside the WebAssembly module. -#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct SignatureIndex(u32); entity_impl!(SignatureIndex); /// Index type of a passive data segment inside the WebAssembly module. -#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct DataIndex(u32); entity_impl!(DataIndex); /// Index type of a passive element segment inside the WebAssembly module. -#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct ElemIndex(u32); entity_impl!(ElemIndex); /// Index type of a custom section inside a WebAssembly module. -#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct CustomSectionIndex(u32); entity_impl!(CustomSectionIndex); /// An entity to export. -#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub enum ExportIndex { /// Function export. @@ -91,7 +92,7 @@ pub enum ExportIndex { } /// An entity to import. -#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub enum ImportIndex { /// Function import. diff --git a/lib/wasmer-types/src/types.rs b/lib/wasmer-types/src/types.rs index 6a9b9b9ab4d..168f947616f 100644 --- a/lib/wasmer-types/src/types.rs +++ b/lib/wasmer-types/src/types.rs @@ -6,6 +6,7 @@ use crate::lib::std::string::{String, ToString}; use crate::lib::std::vec::Vec; use crate::units::Pages; use crate::values::Value; +use loupe::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; @@ -15,7 +16,7 @@ use serde::{Deserialize, Serialize}; // Value Types /// A list of all possible value types in WebAssembly. -#[derive(Copy, Debug, Clone, Eq, PartialEq, Hash)] +#[derive(Copy, Debug, Clone, Eq, PartialEq, Hash, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub enum Type { /// Signed 32 bit integer. @@ -225,7 +226,7 @@ impl ExternType { /// in a Wasm module or exposed to Wasm by the host. /// /// WebAssembly functions can have 0 or more parameters and results. -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct FunctionType { /// The parameters of the function diff --git a/lib/wasmer-types/src/units.rs b/lib/wasmer-types/src/units.rs index 93e9f04d473..1d1360b60c9 100644 --- a/lib/wasmer-types/src/units.rs +++ b/lib/wasmer-types/src/units.rs @@ -1,6 +1,7 @@ use crate::lib::std::convert::TryFrom; use crate::lib::std::fmt; use crate::lib::std::ops::{Add, Sub}; +use loupe::MemoryUsage; #[cfg(feature = "enable-serde")] use serde::{Deserialize, Serialize}; use std::convert::TryInto; @@ -19,7 +20,7 @@ pub const WASM_MAX_PAGES: u32 = 0x10000; pub const WASM_MIN_PAGES: u32 = 0x100; /// Units of WebAssembly pages (as specified to be 65,536 bytes). -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, MemoryUsage)] #[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))] pub struct Pages(pub u32); diff --git a/tests/lib/engine-dummy/Cargo.toml b/tests/lib/engine-dummy/Cargo.toml index 22c659d64af..2a12de6d88e 100644 --- a/tests/lib/engine-dummy/Cargo.toml +++ b/tests/lib/engine-dummy/Cargo.toml @@ -15,6 +15,7 @@ wasmer-engine = { path = "../../../lib/engine", version = "1.0.2" } serde = { version = "1.0", features = ["derive", "rc"], optional = true } serde_bytes = { version = "0.11", optional = true } bincode = { version = "1.2", optional = true } +loupe = { git = "https://github.com/wasmerio/loupe", branch = "master" } [features] # Enable the `compiler` feature if you want the engine to compile diff --git a/tests/lib/engine-dummy/src/engine.rs b/tests/lib/engine-dummy/src/engine.rs index bdfab988571..ca9b0c4a9c0 100644 --- a/tests/lib/engine-dummy/src/engine.rs +++ b/tests/lib/engine-dummy/src/engine.rs @@ -1,6 +1,7 @@ //! Dummy Engine. use crate::DummyArtifact; +use loupe::MemoryUsage; use std::sync::Arc; use wasmer_compiler::{CompileError, Features, Target}; use wasmer_engine::{Artifact, DeserializeError, Engine, EngineId, Tunables}; @@ -17,7 +18,7 @@ extern "C" fn dummy_trampoline( } /// A WebAssembly `Dummy` Engine. -#[derive(Clone)] +#[derive(Clone, MemoryUsage)] pub struct DummyEngine { signatures: Arc, features: Arc,