Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ inherits = "release"
opt-level = 1
lto = "off"

[profile.profiling]
inherits = "dev"
opt-level = 0
debug = true
split-debuginfo = "unpacked"
panic = "abort"

[profile.release]
# https://doc.rust-lang.org/cargo/reference/profiles.html#strip
strip = true
Expand All @@ -295,9 +302,10 @@ doctest-private = [] # see
benchmark-private = [] # see lib.rs::benchmark_private
interop-tests-private = [] # see lib.rs::interop_tests_private

# Allocator
# Allocator. Use at most one of these.
rustalloc = []
jemalloc = ["dep:tikv-jemallocator"]
system-alloc = [] # Use the platform allocator (for memory profiling).

Comment thread
LesnyRumcajs marked this conversation as resolved.
tokio-console = ["dep:console-subscriber"]
tracing-loki = ["dep:tracing-loki"]
Expand Down
34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,38 @@ license:
docs:
cargo doc --no-deps

##
## Memory Profiling
##

# Read up on memory profiling in Forest: https://rumcajs.dev/posts/memory-analysis-in-rust/

# Memory profiling is done with the `profiling` profile. There's no silver bullet for memory profiling, so we provide a few options here.

### Gperftools
# https://github.com/gperftools/gperftools

# Profile with gperftools (Memory/Heap profiler)
# There is a workaround there, as outlined in https://github.com/gperftools/gperftools/issues/1603
gperfheapprofile = FOREST_PROFILING_GPERFTOOLS_BUILD=1 cargo build --no-default-features --features system-alloc --profile=profiling --bin $(1); \
ulimit -n 8192; \
HEAPPROFILE_USE_PID=t HEAPPROFILE=/tmp/gperfheap.$(1).prof target/profiling/$(1) $(2)

gperfheapprofile.forest:
$(call gperfheapprofile,forest, --chain calibnet --encrypt-keystore=false)

# To visualize the heap profile, run:
# pprof -http=localhost:8080 <path/to/profiled/binary> <path/to/gperfheap.forest.prof
# Don't use the default `pprof` package; use the one from google instead: https://github.com/google/pprof

#### Heaptrack
# https://github.com/KDE/heaptrack

memprofile-heaptrack = cargo build --no-default-features --features system-alloc --profile=profiling --bin $(1); \
ulimit -n 8192; \
heaptrack -o /tmp/heaptrack.$(1).%p.zst target/profiling/$(1) $(2)

memprofile-heaptrack.forest:
$(call memprofile-heaptrack,forest, --chain calibnet --encrypt-keystore=false)

.PHONY: $(MAKECMDGOALS)
18 changes: 11 additions & 7 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
use std::io::Write;

fn main() {
// Only needed when profiling Forest with `gperftools`. This might not work on all platforms.
if is_env_truthy("FOREST_PROFILING_GPERFTOOLS_BUILD") {
println!("cargo:rustc-link-lib=tcmalloc");
}

// whitelist the cfg for cargo clippy
println!("cargo::rustc-check-cfg=cfg(f3sidecar)");

// Do not build f3-sidecar on docs.rs publishing
// No proper version of Go compiler is available.
if !is_docs_rs() && is_sidecar_ffi_enabled() {
if !is_docs_rs() && !is_env_truthy("FOREST_F3_SIDECAR_FFI_BUILD_OPT_OUT") {
println!("cargo:rustc-cfg=f3sidecar");
println!("cargo::rerun-if-changed=f3-sidecar");
unsafe {
Expand Down Expand Up @@ -41,12 +46,11 @@ fn is_docs_rs() -> bool {
std::env::var("DOCS_RS").is_ok()
}

fn is_sidecar_ffi_enabled() -> bool {
// Opt-out building the F3 sidecar staticlib
match std::env::var("FOREST_F3_SIDECAR_FFI_BUILD_OPT_OUT") {
Ok(value) => !matches!(value.to_lowercase().as_str(), "1" | "true"),
_ => true,
}
fn is_env_truthy(env: &str) -> bool {
std::env::var(env)
.ok()
.map(|var| matches!(var.to_lowercase().as_str(), "1" | "true" | "yes" | "_yes_"))
.unwrap_or_default()
}

fn rpc_regression_tests_gen() {
Expand Down
1 change: 0 additions & 1 deletion documentation/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
- [Developer documentation](./developer_documentation/introduction.md)
- [Database migrations](./developer_documentation/database_migrations.md)
- [Local GH Actions](./developer_documentation/local_actions.md)
- [Memory analysis](./developer_documentation/memory-analysis.md)
- [Release checklist](./developer_documentation/release_checklist.md)
- [State migration guide](./developer_documentation/state_migration_guide.md)
- [Devnet Notes](./developer_documentation/devnet_notes.md)
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
135 changes: 0 additions & 135 deletions documentation/src/developer_documentation/memory-analysis.md

This file was deleted.

4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ cfg_if::cfg_if! {
use crate::cli_shared::tikv_jemallocator::Jemalloc;
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;
} else if #[cfg(feature = "system-alloc")] {
use std::alloc::System;
#[global_allocator]
static GLOBAL: System = System;
}
}

Expand Down
Loading