Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement MemoryUsage for Store #2199

Merged
merged 9 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- [#2135](https://github.com/wasmerio/wasmer/pull/2135) [Documentation](./PACKAGING.md) for linux distribution maintainers

### Changed
- [#2199](https://github.com/wasmerio/wasmer/pull/2199) Implement `loupe::MemoryUsage` for `wasmer::Store`.
- [#2140](https://github.com/wasmerio/wasmer/pull/2140) Reduce the number of dependencies in the `wasmer.dll` shared library by statically compiling CRT.
- [#2113](https://github.com/wasmerio/wasmer/pull/2113) Bump minimum supported Rust version to 1.49
- [#2144](https://github.com/wasmerio/wasmer/pull/2144) Bump cranelift version to 0.70
Expand Down
92 changes: 58 additions & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ criterion = "0.3"
lazy_static = "1.4"
wasmer-engine-dummy = { path = "tests/lib/engine-dummy" }
tempfile = "3.1"
loupe = "0.1"

[features]
# Don't add the compiler features in default, please add them on the Makefile
Expand Down
8 changes: 8 additions & 0 deletions examples/tunables_limit_memory.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::mem;
use std::ptr::NonNull;
use std::sync::Arc;

use loupe::{MemoryUsage, MemoryUsageTracker};
use wasmer::{
imports,
vm::{self, MemoryError, MemoryStyle, TableStyle, VMMemoryDefinition, VMTableDefinition},
Expand Down Expand Up @@ -131,6 +133,12 @@ impl<T: Tunables> Tunables for LimitingTunables<T> {
}
}

impl<T: Tunables> MemoryUsage for LimitingTunables<T> {
fn size_of_val(&self, _tracker: &mut dyn MemoryUsageTracker) -> usize {
mem::size_of_val(self)
}
}

Comment on lines +136 to +141
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit surprising to me that this isn't something the macro can generate. I'm not sure how common of a base case it is, maybe it isn't worth it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because of the generic here. I need to dig into loupe-derive to see what's going on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by wasmerio/loupe#14. I'll update this file in #2200 probably.

fn main() -> Result<(), Box<dyn std::error::Error>> {
// A Wasm module with one exported memory (min: 7 pages, max: unset)
let wat = br#"(module (memory 7) (export "memory" (memory 0)))"#;
Expand Down
Loading