Skip to content

Commit

Permalink
Allocation tracker (rerun-io#325)
Browse files Browse the repository at this point in the history
* Add per-callstack allocation statistics

* Count how many bytes we aren't tracking

* Keep track how much memory is used by the allocation tracker

* Simpler code

* Activate allocation tracker with RERUN_TRACK_ALLOCATIONS

* Show allocation purges in the memory panel graph

* Purge image cache on global memory purge

* Improve memory stats UI

* Try to fix --run-forever

* build fix

* Implement all members of std::alloc::GlobalAlloc

* Make format_usize reusable

* Fix doctests and doclinks

* Only enforce net limit

* Refactor App::update

* fix for the limit change

* Revert change to objectron

* remove a log line

* objectron: sleep when running forever

* Improve purge strategy

* python format

* Move the "improving compile times" section to CONTRIBUTING.md

* Don't recommend RUST_LOG=debug – it fills terminal with wgpu spam

* Document RERUN_MEMORY_LIMIT

* Refactor: add CountAndSize

* Simplify callstack tracking

* Even simpler

* Call it "purge" instead of "prune"

* Use TrackingAllocator and MiMalloc in the Python SDK

* Use gross for limiting if net is not available

* don't glob-import

* Add TODO + a fix

* Turn on memory tracking in SDK if RERUN_TRACK_ALLOCATIONS is set

* Put all environment variables in one file

* Document the environment variables when running `rerun --help`

* build fix

* create helper add/sub functions

* TLS-friendly mimalloc, confirmed working on linux

* Rename "gross" to "resident"

* Rename TrackingAllocator to AccountingAllocator

* net -> counted

* tracker_bookkeeping -> overhead

* Small ui improvement

* Add TODO about stochastic hashing

* Add PtrHash helper

* Fix wrong callstack

* Do stochastic sampling of small allocations

* Disable RSS on Linux

* Fix doclinks

* Work around annoying limitation on Windows

Co-authored-by: Clement Rey <[email protected]>
  • Loading branch information
emilk and teh-cmc authored Nov 24, 2022
1 parent ab38473 commit cd58833
Show file tree
Hide file tree
Showing 39 changed files with 1,270 additions and 430 deletions.
76 changes: 76 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,79 @@ For consistency, we use the same naming convention for other non-matrix transfor

#### Vectors vs points
Vectors are directions with magnitudes. Points are positions.


## Improving compile times

As of today, we link everything statically in both debug and release builds, which makes custom linkers and split debuginfo the two most impactful tools we have at our disposal in order to improve compile times.

These tools can configured through your `Cargo` configuration, available at `$HOME/.cargo/config.toml`.

### macOS

On macOS, use the [zld](https://github.com/michaeleisel/zld) linker and keep debuginfo in a single separate file.

Pre-requisites:
- Install [zld](https://github.com/michaeleisel/zld): `brew install michaeleisel/zld/zld`.

`config.toml` (x64):
```toml
[target.x86_64-apple-darwin]
rustflags = [
"-C",
"link-arg=-fuse-ld=/usr/local/bin/zld",
"-C",
"split-debuginfo=packed",
]
```

`config.toml` (M1):
```toml
[target.aarch64-apple-darwin]
rustflags = [
"-C",
"link-arg=-fuse-ld=/opt/homebrew/bin/zld",
"-C",
"split-debuginfo=packed",
]
```

### Linux

On Linux, use the [mold](https://github.com/rui314/mold) linker and keep DWARF debuginfo in separate files.

Pre-requisites:
- Install [mold](https://github.com/rui314/mold) through your package manager.

`config.toml`:
```toml
[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = [
"-C",
"link-arg=-fuse-ld=/usr/bin/mold",
"-C",
"split-debuginfo=unpacked",
]
```

### Windows

On Windows, use LLVM's `lld` linker and keep debuginfo in a single separate file.

Pre-requisites:
- Install `lld`:
```
cargo install -f cargo-binutils
rustup component add llvm-tools-preview
```

`config.toml`:
```toml
[target.x86_64-pc-windows-msvc]
linker = "rust-lld.exe"
rustflags = [
"-C",
"split-debuginfo=packed",
]
```
63 changes: 55 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 12 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ opt-level = 2
debug = true

[patch.crates-io]
# 2022-11-21 - move `egui::util::History` to `emath::History`.
eframe = { git = "https://github.com/emilk/egui", rev = "1c8cf9e3d59d8aee4c073b9e17695ee85c40bdbf" }
egui = { git = "https://github.com/emilk/egui", rev = "1c8cf9e3d59d8aee4c073b9e17695ee85c40bdbf" }
egui_extras = { git = "https://github.com/emilk/egui", rev = "1c8cf9e3d59d8aee4c073b9e17695ee85c40bdbf" }
egui-wgpu = { git = "https://github.com/emilk/egui", rev = "1c8cf9e3d59d8aee4c073b9e17695ee85c40bdbf" }
emath = { git = "https://github.com/emilk/egui", rev = "1c8cf9e3d59d8aee4c073b9e17695ee85c40bdbf" }

# eframe = { path = "../egui/crates/eframe" }
# egui = { path = "../egui/crates/egui" }
# egui_extras = { path = "../egui/crates/egui_extras" }
# egui-wgpu = { path = "../egui/crates/egui-wgpu" }
# 2022-11-21 - add support for thin space
eframe = { git = "https://github.com/emilk/egui", rev = "8671aa26e1f65340c41f6b2c6f3ef2d6d80a6567" }
egui = { git = "https://github.com/emilk/egui", rev = "8671aa26e1f65340c41f6b2c6f3ef2d6d80a6567" }
egui_extras = { git = "https://github.com/emilk/egui", rev = "8671aa26e1f65340c41f6b2c6f3ef2d6d80a6567" }
egui-wgpu = { git = "https://github.com/emilk/egui", rev = "8671aa26e1f65340c41f6b2c6f3ef2d6d80a6567" }
emath = { git = "https://github.com/emilk/egui", rev = "8671aa26e1f65340c41f6b2c6f3ef2d6d80a6567" }

# eframe = { path = "../../egui/crates/eframe" }
# egui = { path = "../../egui/crates/egui" }
# egui_extras = { path = "../../egui/crates/egui_extras" }
# egui-wgpu = { path = "../../egui/crates/egui-wgpu" }
# emath = { path = "../../egui/crates/emath" }

# Because gltf hasn't published a new version: https://github.com/gltf-rs/gltf/issues/357
gltf = { git = "https://github.com/rerun-io/gltf", rev = "3c14ded73755d1ce9e47010edb06db63cb7e2cca" }
Expand Down
80 changes: 5 additions & 75 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,80 +82,10 @@ cargo install --path ./crates/rerun/
```
You should now be able to run `rerun --help` in any terminal.

# Development
Take a look at [`CONTRIBUTING.md`](CONTRIBUTING.md).

## Improving compile times

As of today, we link everything statically in both debug and release builds, which makes custom linkers and split debuginfo the two most impactful tools we have at our disposal in order to improve compile times.

These tools can configured through your `Cargo` configuration, available at `$HOME/.cargo/config.toml`.

### macOS

On macOS, use the [zld](https://github.com/michaeleisel/zld) linker and keep debuginfo in a single separate file.

Pre-requisites:
- Install [zld](https://github.com/michaeleisel/zld): `brew install michaeleisel/zld/zld`.

`config.toml` (x64):
```toml
[target.x86_64-apple-darwin]
rustflags = [
"-C",
"link-arg=-fuse-ld=/usr/local/bin/zld",
"-C",
"split-debuginfo=packed",
]
```

`config.toml` (M1):
```toml
[target.aarch64-apple-darwin]
rustflags = [
"-C",
"link-arg=-fuse-ld=/opt/homebrew/bin/zld",
"-C",
"split-debuginfo=packed",
]
```
## Bounded memory use
You can set `RERUN_MEMORY_LIMIT=16GB` to tell the Rerun Viewer to purge older log data when memory use goes above that limit. This is useful for using Rerun in _continuous_ mode, i.e. where you keep logging new data to Rerun forever.

### Linux
It is still possible to log data faster than the Rerun Viewer can process it, and in those cases you may still run out of memory (since the Rerun communication does not yet implement back-pressure).

On Linux, use the [mold](https://github.com/rui314/mold) linker and keep DWARF debuginfo in separate files.

Pre-requisites:
- Install [mold](https://github.com/rui314/mold) through your package manager.

`config.toml`:
```toml
[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = [
"-C",
"link-arg=-fuse-ld=/usr/bin/mold",
"-C",
"split-debuginfo=unpacked",
]
```

### Windows

On Windows, use LLVM's `lld` linker and keep debuginfo in a single separate file.

Pre-requisites:
- Install `lld`:
```
cargo install -f cargo-binutils
rustup component add llvm-tools-preview
```

`config.toml`:
```toml
[target.x86_64-pc-windows-msvc]
linker = "rust-lld.exe"
rustflags = [
"-C",
"split-debuginfo=packed",
]
```
# Development
Take a look at [`CONTRIBUTING.md`](CONTRIBUTING.md).
Loading

0 comments on commit cd58833

Please sign in to comment.