Skip to content

Commit d4c6551

Browse files
committed
Add badges to README
Signed-off-by: Nico Burns <[email protected]>
1 parent 4cf7d98 commit d4c6551

File tree

1 file changed

+6
-35
lines changed

1 file changed

+6
-35
lines changed

README.md

+6-35
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
# MallocSizeOf
22

3+
[![Build Status](https://github.com/servo/malloc_size_of/actions/workflows/ci.yml/badge.svg)](https://github.com/servo/malloc_size_of/actions)
4+
[![Crates.io](https://img.shields.io/crates/v/malloc_size_of.svg)](https://crates.io/crates/malloc_size_of)
5+
[![Docs](https://docs.rs/malloc_size_of/badge.svg)](https://docs.rs/malloc_size_of)
6+
![Crates.io License](https://img.shields.io/crates/l/malloc_size_of)
7+
[![dependency status](https://deps.rs/repo/github/servo/malloc_size_of/status.svg)](https://deps.rs/repo/github/servo/malloc_size_of)
8+
39
A an allocator-agnostic crate for measuring the runtime size of a value
410
including the size of any heap allocations that are owned by that value.
511

6-
- The core abstraction is provided by the [`MallocSizeOf`] trait which should be implemented for all
7-
types whose size you wish to measure.
8-
- A derive macro for implementing this trait on structs is provided by the [malloc_size_of_derive](https://docs.rs/malloc_size_of_derive) crate
9-
- Additionally there are [`MallocUnconditionalSizeOf`], [`MallocConditionalSizeOf`] traits for measuring
10-
types where ownership is shared (such as `Arc` and `Rc`).
11-
- Each of these traits also has a "shallow" variant ([`MallocShallowSizeOf`], [`MallocUnconditionalShallowSizeOf`], and [`MallocConditionalShallowSizeOf`]) which only measure the heap size of the value passed
12-
and not any nested allocations.
13-
14-
All of these traits rely on being provided with an instance of [`MallocSizeOfOps`] which allows size computations
15-
to call into the allocator to ask it for the underlyinhg size of the allocations backing data structures.
16-
1712
This crate is used by both Servo and Firefox for memory usage calculation.
1813

1914
## Features
@@ -26,27 +21,3 @@ This crate is used by both Servo and Firefox for memory usage calculation.
2621
on the heap allocator having suitable support, which `jemalloc` has.)
2722
- It allows handling of types like `Rc` and `Arc` by providing traits that
2823
are different to the ones for non-graph structures.
29-
30-
## Suggested usage
31-
32-
- When possible, use the `MallocSizeOf` trait. (Deriving support is
33-
provided by the `malloc_size_of_derive` crate.)
34-
- If you need an additional synchronization argument, provide a function
35-
that is like the standard trait method, but with the extra argument.
36-
- If you need multiple measurements for a type, provide a function named
37-
`add_size_of` that takes a mutable reference to a struct that contains
38-
the multiple measurement fields.
39-
- When deep measurement (via `MallocSizeOf`) cannot be implemented for a
40-
type, shallow measurement (via `MallocShallowSizeOf`) in combination with
41-
iteration can be a useful substitute.
42-
- `Rc` and `Arc` are always tricky, which is why `MallocSizeOf` is not (and
43-
should not be) implemented for them.
44-
- If an `Rc` or `Arc` is known to be a "primary" reference and can always
45-
be measured, it should be measured via the `MallocUnconditionalSizeOf`
46-
trait.
47-
- If an `Rc` or `Arc` should be measured only if it hasn't been seen
48-
before, it should be measured via the `MallocConditionalSizeOf` trait.
49-
- Using universal function call syntax is a good idea when measuring boxed
50-
fields in structs, because it makes it clear that the Box is being
51-
measured as well as the thing it points to. E.g.
52-
`<Box<_> as MallocSizeOf>::size_of(field, ops)`.

0 commit comments

Comments
 (0)