Skip to content

Commit e388dcf

Browse files
authored
Initialize a crate for memory related tools (#89)
Initialize a crate for memory related tools. Mainly heapsize measurement through malloc_size_of traits.
1 parent 5b56003 commit e388dcf

File tree

11 files changed

+1838
-0
lines changed

11 files changed

+1838
-0
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ script:
2424
- cd uint/ && cargo test --features=std,quickcheck --release && cd ..
2525
- cd hashdb/ && cargo test --no-default-features && cd ..
2626
- cd plain_hasher/ && cargo test --no-default-features && cd ..
27+
- cd parity-util-mem/ && cargo test --features=estimate-heapsize && cd ..

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ members = [
1818
"trie-standardmap",
1919
"triehash",
2020
"uint",
21+
"parity-util-mem",
2122
"primitive-types",
2223
]

parity-util-mem/Cargo.toml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[package]
2+
name = "parity-util-mem"
3+
version = "0.1.0"
4+
authors = ["Parity Technologies <[email protected]>"]
5+
repository = "https://github.com/paritytech/parity-common"
6+
description = "Collection of memory related utilities"
7+
license = "GPL-3.0"
8+
9+
[dependencies]
10+
clear_on_drop = "0.2"
11+
cfg-if = "0.1.6"
12+
malloc_size_of_derive = "0.1.0"
13+
dlmalloc = { version = "0.1", features = ["global"], optional = true }
14+
wee_alloc = { version = "0.4", optional = true }
15+
jemallocator = { version = "0.1", optional = true }
16+
17+
elastic-array = { version = "*", optional = true }
18+
ethereum-types = { version = "*", optional = true }
19+
parking_lot = { version = "*", optional = true }
20+
21+
[target."cfg(windows)".dependencies.winapi]
22+
version = "0.3.4"
23+
24+
[features]
25+
default = ["std", "ethereum-impls"]
26+
std = []
27+
# when activated mem is removed through volatile primitive instead of clear_on_drop crate
28+
volatile-erase = []
29+
# use dlmalloc as global allocator
30+
dlmalloc-global = ["dlmalloc", "estimate-heapsize"]
31+
# use wee_alloc as global allocator
32+
weealloc-global = ["wee_alloc", "estimate-heapsize"]
33+
# use jemalloc as global allocator
34+
jemalloc-global = ["jemallocator"]
35+
# implement additional types
36+
ethereum-impls = ["ethereum-types", "elastic-array", "parking_lot"]
37+
# Full estimate: no call to allocator
38+
estimate-heapsize = []

parity-util-mem/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# parity-util-mem
2+
3+
Collection of memory related utilities.
4+
5+
## Features
6+
7+
- volatile-erase : Not set by default, `Memzero` struct will be erasing memory through a simple [`write_volatile`](https://doc.rust-lang.org/std/ptr/fn.write_volatile.html) call.
8+
- estimate-heapsize : Do not use allocator, but `size_of` or `size_of_val`.
9+
10+
Others features define global allocator, see `src/alloc.rs`.
11+
12+
## Dependency
13+
14+
This crate groups common dependency, [`clear_on_drop`](https://crates.io/crates/clear_on_drop) is reexported, and a patched copy of unpublished [`malloc_size_of`](https://github.com/servo/servo/tree/master/components/malloc_size_of) from servo project is copied and partially reexported.
15+
16+
`Malloc_size_of` code is used internally as a module with a few modification to be able to implement type locally.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
# script/process to update code from servo project (malloc_size_of)
4+
# untested, note that we do not use submodule due to size of git repo
5+
git clone https://github.com/servo/servo.git
6+
cd servo
7+
git checkout 5bdea7dc1c80790a852a3fb03edfb2b8fbd403dc
8+
git apply ../slim_malloc_size_of.patch
9+
#git merge master
10+
#cp components/malloc_size_of/lib.rs ../src/malloc_size.rs
11+
#cd ..
12+
#rm -rf ./servo

0 commit comments

Comments
 (0)