Skip to content
Open
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
2 changes: 2 additions & 0 deletions jemalloc-ctl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ tikv-jemallocator = { path = "../jemallocator", version = "0.7.0" }
default = []
stats = ["tikv-jemalloc-sys/stats"]
profiling = ["tikv-jemalloc-sys/profiling"]
# `profiling_libunwind` and `profiling_frameptr` are mutually exclusive
profiling_libunwind = ["tikv-jemalloc-sys/profiling_libunwind", "profiling"]
profiling_frameptr = ["tikv-jemalloc-sys/profiling_frameptr", "profiling"]
use_std = [ "libc/use_std" ]
disable_initial_exec_tls = ["tikv-jemalloc-sys/disable_initial_exec_tls"]

Expand Down
2 changes: 2 additions & 0 deletions jemalloc-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ cc = "^1.0.13"
[features]
default = ["background_threads_runtime_support"]
profiling = []
# `profiling_libunwind` and `profiling_frameptr` are mutually exclusive
profiling_libunwind = ["profiling"]
profiling_frameptr = ["profiling"]
debug = []
background_threads_runtime_support = []
background_threads = [ "background_threads_runtime_support" ]
Expand Down
11 changes: 10 additions & 1 deletion jemalloc-sys/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ This crate provides following cargo feature flags:
list that appears to function correctly:

* `libunwind` (requires --enable-prof-libunwind)
* frame-pointer walk (requires --enable-prof-frameptr; Linux only)
* `libgcc` (unless --disable-prof-libgcc)
* `gcc intrinsics` (unless --disable-prof-gcc)

Expand All @@ -52,7 +53,15 @@ This crate provides following cargo feature flags:
multi-threaded programs using `_Unwind_Backtrace`. Enables `profiling`
automatically. On Linux, this requires `libunwind-dev` (or `libunwind-devel`)
to be installed. On macOS/iOS, unwind symbols are provided by the system and
no extra library is needed.
no extra library is needed. Mutually exclusive with `profiling_frameptr`.

* `profiling_frameptr` (configure `jemalloc` with `--enable-prof-frameptr`):
Force jemalloc to use its Linux frame-pointer unwinder for backtracing during
heap profiling instead of libgcc/gcc-intrinsics DWARF unwind. Enables
`profiling` automatically. Only supported on Linux targets. Profiled code
should be built with frame pointers (for example Rust
`-C force-frame-pointers=yes`, C/C++ `-fno-omit-frame-pointer`) for useful
stacks. Mutually exclusive with `profiling_libunwind`.

* `stats` (configure `jemalloc` with `--enable-stats`): Enable statistics
gathering functionality. See the `jemalloc`'s "`opt.stats_print`" option
Expand Down
22 changes: 21 additions & 1 deletion jemalloc-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,19 @@ fn main() {
cmd.arg("--enable-prof");
}

if env::var("CARGO_FEATURE_PROFILING_LIBUNWIND").is_ok() {
let profiling_libunwind = env::var("CARGO_FEATURE_PROFILING_LIBUNWIND").is_ok();
let profiling_frameptr = env::var("CARGO_FEATURE_PROFILING_FRAMEPTR").is_ok();
// jemalloc picks a single backtrace method at configure time, and libunwind
// wins over frameptr if both are enabled. We make them mutually exclusive to
// avoid confusion resulting from configuration priority.
if profiling_libunwind && profiling_frameptr {
panic!(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about a warning instead?

"features `profiling_libunwind` and `profiling_frameptr` are mutually \
exclusive; enable only one heap-profiling backtrace method"
);
}

if profiling_libunwind {
info!("CARGO_FEATURE_PROFILING_LIBUNWIND set");
cmd.arg("--enable-prof-libunwind");
// On Apple platforms unwind symbols live in libSystem, and on
Expand All @@ -306,6 +318,14 @@ fn main() {
}
}

if profiling_frameptr {
if !target.contains("linux") {
panic!("feature `profiling_frameptr` is only supported on Linux targets");
}
info!("CARGO_FEATURE_PROFILING_FRAMEPTR set");
cmd.arg("--enable-prof-frameptr");
}

Comment thread
coderabbitai[bot] marked this conversation as resolved.
if env::var("CARGO_FEATURE_STATS").is_ok() {
info!("CARGO_FEATURE_STATS set");
cmd.arg("--enable-stats");
Expand Down
2 changes: 2 additions & 0 deletions jemallocator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ tikv-jemalloc-ctl = { path = "../jemalloc-ctl", version = "0.7.0" }
default = ["background_threads_runtime_support"]
alloc_trait = []
profiling = ["tikv-jemalloc-sys/profiling"]
# `profiling_libunwind` and `profiling_frameptr` are mutually exclusive
profiling_libunwind = ["tikv-jemalloc-sys/profiling_libunwind", "profiling"]
profiling_frameptr = ["tikv-jemalloc-sys/profiling_frameptr", "profiling"]
debug = ["tikv-jemalloc-sys/debug"]
stats = ["tikv-jemalloc-sys/stats"]
background_threads_runtime_support = ["tikv-jemalloc-sys/background_threads_runtime_support"]
Expand Down