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 Instance #2201

Merged
merged 8 commits into from
Mar 23, 2021

Conversation

Hywan
Copy link
Contributor

@Hywan Hywan commented Mar 19, 2021

Description

This patch implements loupe::MemoryUsage for wasmer::Instance.

This PR includes #2200. To review unique patches: https://github.com/Hywan/wasmer/compare/feat-memory-usage-module...feat-memory-usage-instance?expand=1

Review

  • Add a short description of the the change to the CHANGELOG.md file

Cargo.toml Outdated Show resolved Hide resolved
lib/api/src/exports.rs Outdated Show resolved Hide resolved
pub struct WasmFunctionDefinition {
// Address of the trampoline to do the call.
#[memoryusage(ignore)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider #[loupe(ignore)] or #[loupe(skip)]. I think it's more common to use the crate name as a the unique first element in the attribute than the name of the trait. For example serde, structopt, WasmerEnv.

Serde even does #[serde(skip_serializing)] and #[serde(skip_deserializing)] to disambiguate the two

Copy link
Contributor Author

@Hywan Hywan Mar 22, 2021

Choose a reason for hiding this comment

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

I agree. Let's move to #[loupe(skip)].

lib/compiler/src/function.rs Outdated Show resolved Hide resolved
lib/vm/src/instance/ref.rs Show resolved Hide resolved
lib/vm/src/vmcontext.rs Outdated Show resolved Hide resolved
Comment on lines 284 to 298
impl<K, V> MemoryUsage for SecondaryMap<K, V>
where
K: EntityRef,
V: Clone + MemoryUsage,
{
fn size_of_val(&self, tracker: &mut dyn MemoryUsageTracker) -> usize {
mem::size_of_val(self)
+ self
.elems
.iter()
.map(|value| value.size_of_val(tracker) - mem::size_of_val(value))
.sum::<usize>()
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you probably also need to do self.default.size_of_val(tracker), but that's a small nit pick

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@Hywan Hywan force-pushed the feat-memory-usage-instance branch from 6a8fa5d to 64c1f08 Compare March 22, 2021 15:07
@Hywan Hywan changed the title WIP feat: Implement MemoryUsage for Instance feat: Implement MemoryUsage for Instance Mar 22, 2021
@Hywan Hywan force-pushed the feat-memory-usage-instance branch from 64c1f08 to d801eb4 Compare March 23, 2021 13:58
`MemoryUsage` is implemented for `[T; N]` only on rustc
nightly. Wasmer uses the stable channel of rustc. Thus, we
re-implement `MemoryUsage` for `V128` by using `V128.as_slice()`.
@Hywan
Copy link
Contributor Author

Hywan commented Mar 23, 2021

bors r+

bors bot added a commit that referenced this pull request Mar 23, 2021
2201: feat: Implement `MemoryUsage` for `Instance` r=Hywan a=Hywan

# Description

This patch implements `loupe::MemoryUsage` for `wasmer::Instance`.

~~This PR includes #2200. To review unique patches: https://github.com/Hywan/wasmer/compare/feat-memory-usage-module...feat-memory-usage-instance?expand=1~~

# Review

- [x] Add a short description of the the change to the CHANGELOG.md file


Co-authored-by: Ivan Enderlin <ivan@mnt.io>
@bors
Copy link
Contributor

bors bot commented Mar 23, 2021

Build failed:

@Hywan
Copy link
Contributor Author

Hywan commented Mar 23, 2021

bors r+

@bors bors bot merged commit a683145 into wasmerio:master Mar 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants