Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
Remove jemalloc dependency.
Browse files Browse the repository at this point in the history
Add optional jemalloc feature to expose jemalloc-based heap measurement
API that can be passed as the argument to heap_size_of and
heap_size_of_children.
  • Loading branch information
jdm committed Jul 4, 2017
1 parent ebf51e6 commit 0c6ed8c
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 122 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ notifications:
webhooks: http://build.servo.org:54856/travis

script:
- cargo test
- "[ $TRAVIS_RUST_VERSION != nightly ] || cargo test --features unstable"
- cargo test --features jemalloc
- "[ $TRAVIS_RUST_VERSION != nightly ] || cargo test --features unstable,jemalloc"
- "[[ $TRAVIS_RUST_VERSION != nightly && $TRAVIS_RUST_VERSION != beta ]] || cargo test --manifest-path derive/Cargo.toml"

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "heapsize"
version = "0.4.0"
version = "0.5.0"
authors = [ "The Servo Project Developers" ]
description = "Infrastructure for measuring the total runtime size of an object on the heap"
license = "MIT/Apache-2.0"
Expand All @@ -12,6 +12,7 @@ kernel32-sys = "0.2.1"

[features]
unstable = []
jemalloc = []

# https://github.com/servo/heapsize/issues/74
flexible-tests = []
2 changes: 1 addition & 1 deletion derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "heapsize_derive"
version = "0.1.4"
version = "0.2.0"
authors = ["The Servo Project Developers"]
description = "Automatically generating infrastructure for measuring the total runtime size of an object on the heap"
license = "MIT/Apache-2.0"
Expand Down
6 changes: 3 additions & 3 deletions derive/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ fn expand_string(input: &str) -> String {
} else if let syn::Ty::Array(..) = binding.field.ty {
Some(quote! {
for item in #binding.iter() {
sum += ::heapsize::HeapSizeOf::heap_size_of_children(item);
sum += ::heapsize::HeapSizeOf::heap_size_of_children(item, heap_size);
}
})
} else {
Some(quote! {
sum += ::heapsize::HeapSizeOf::heap_size_of_children(#binding);
sum += ::heapsize::HeapSizeOf::heap_size_of_children(#binding, heap_size);
})
}
});
Expand All @@ -61,7 +61,7 @@ fn expand_string(input: &str) -> String {
impl #impl_generics ::heapsize::HeapSizeOf for #name #ty_generics #where_clause {
#[inline]
#[allow(unused_variables, unused_mut, unreachable_code)]
fn heap_size_of_children(&self) -> usize {
fn heap_size_of_children(&self, heap_size: ::heapsize::HeapSizeOfFn) -> usize {
let mut sum = 0;
match *self {
#match_body
Expand Down
11 changes: 8 additions & 3 deletions derive/test.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#[macro_use] extern crate heapsize_derive;

mod heapsize {
pub type HeapSizeOfFn = unsafe fn(ptr: *const ()) -> usize;

pub trait HeapSizeOf {
fn heap_size_of_children(&self) -> usize;
fn heap_size_of_children(&self, heap_size: HeapSizeOfFn) -> usize;
}

impl<T> HeapSizeOf for Box<T> {
fn heap_size_of_children(&self) -> usize {
fn heap_size_of_children(&self, _heap_size: HeapSizeOfFn) -> usize {
::std::mem::size_of::<T>()
}
}
Expand All @@ -19,5 +21,8 @@ struct Foo([Box<u32>; 2], Box<u8>);
#[test]
fn test() {
use heapsize::HeapSizeOf;
assert_eq!(Foo([Box::new(1), Box::new(2)], Box::new(3)).heap_size_of_children(), 9);
unsafe fn test_heap_size(_ptr: *const ()) -> usize {
unreachable!()
}
assert_eq!(Foo([Box::new(1), Box::new(2)], Box::new(3)).heap_size_of_children(test_heap_size), 9);
}
Loading

0 comments on commit 0c6ed8c

Please sign in to comment.