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

Commit 0c6ed8c

Browse files
committed
Remove jemalloc dependency.
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.
1 parent ebf51e6 commit 0c6ed8c

File tree

7 files changed

+135
-122
lines changed

7 files changed

+135
-122
lines changed

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ notifications:
1313
webhooks: http://build.servo.org:54856/travis
1414

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

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "heapsize"
3-
version = "0.4.0"
3+
version = "0.5.0"
44
authors = [ "The Servo Project Developers" ]
55
description = "Infrastructure for measuring the total runtime size of an object on the heap"
66
license = "MIT/Apache-2.0"
@@ -12,6 +12,7 @@ kernel32-sys = "0.2.1"
1212

1313
[features]
1414
unstable = []
15+
jemalloc = []
1516

1617
# https://github.com/servo/heapsize/issues/74
1718
flexible-tests = []

derive/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "heapsize_derive"
3-
version = "0.1.4"
3+
version = "0.2.0"
44
authors = ["The Servo Project Developers"]
55
description = "Automatically generating infrastructure for measuring the total runtime size of an object on the heap"
66
license = "MIT/Apache-2.0"

derive/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ fn expand_string(input: &str) -> String {
3030
} else if let syn::Ty::Array(..) = binding.field.ty {
3131
Some(quote! {
3232
for item in #binding.iter() {
33-
sum += ::heapsize::HeapSizeOf::heap_size_of_children(item);
33+
sum += ::heapsize::HeapSizeOf::heap_size_of_children(item, heap_size);
3434
}
3535
})
3636
} else {
3737
Some(quote! {
38-
sum += ::heapsize::HeapSizeOf::heap_size_of_children(#binding);
38+
sum += ::heapsize::HeapSizeOf::heap_size_of_children(#binding, heap_size);
3939
})
4040
}
4141
});
@@ -61,7 +61,7 @@ fn expand_string(input: &str) -> String {
6161
impl #impl_generics ::heapsize::HeapSizeOf for #name #ty_generics #where_clause {
6262
#[inline]
6363
#[allow(unused_variables, unused_mut, unreachable_code)]
64-
fn heap_size_of_children(&self) -> usize {
64+
fn heap_size_of_children(&self, heap_size: ::heapsize::HeapSizeOfFn) -> usize {
6565
let mut sum = 0;
6666
match *self {
6767
#match_body

derive/test.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#[macro_use] extern crate heapsize_derive;
22

33
mod heapsize {
4+
pub type HeapSizeOfFn = unsafe fn(ptr: *const ()) -> usize;
5+
46
pub trait HeapSizeOf {
5-
fn heap_size_of_children(&self) -> usize;
7+
fn heap_size_of_children(&self, heap_size: HeapSizeOfFn) -> usize;
68
}
79

810
impl<T> HeapSizeOf for Box<T> {
9-
fn heap_size_of_children(&self) -> usize {
11+
fn heap_size_of_children(&self, _heap_size: HeapSizeOfFn) -> usize {
1012
::std::mem::size_of::<T>()
1113
}
1214
}
@@ -19,5 +21,8 @@ struct Foo([Box<u32>; 2], Box<u8>);
1921
#[test]
2022
fn test() {
2123
use heapsize::HeapSizeOf;
22-
assert_eq!(Foo([Box::new(1), Box::new(2)], Box::new(3)).heap_size_of_children(), 9);
24+
unsafe fn test_heap_size(_ptr: *const ()) -> usize {
25+
unreachable!()
26+
}
27+
assert_eq!(Foo([Box::new(1), Box::new(2)], Box::new(3)).heap_size_of_children(test_heap_size), 9);
2328
}

0 commit comments

Comments
 (0)