Skip to content

Commit a73c418

Browse files
committed
Enable jemalloc profiling support by default
Include `tikv-jemalloc-sys` in the `jemalloc` feature to allow runtime heap profiling without requiring a rebuild. Profiling remains inactive by default (`prof_active:false`) and must be explicitly enabled via the HTTP API.
1 parent 93222a7 commit a73c418

File tree

4 files changed

+7
-21
lines changed

4 files changed

+7
-21
lines changed

common/malloc_utils/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ edition = { workspace = true }
77
[features]
88
mallinfo2 = []
99
jemalloc = ["tikv-jemallocator", "tikv-jemalloc-ctl", "tikv-jemalloc-sys"]
10-
jemalloc-profiling = ["jemalloc", "tikv-jemallocator/profiling"]
1110

1211
[dependencies]
1312
libc = "0.2.79"
@@ -17,7 +16,7 @@ tikv-jemalloc-ctl = { version = "0.6.0", optional = true, features = ["stats"] }
1716
tikv-jemalloc-sys = { version = "0.6.0", optional = true }
1817

1918
[target.'cfg(not(target_os = "linux"))'.dependencies]
20-
tikv-jemallocator = { version = "0.6.0", optional = true, features = ["stats"] }
19+
tikv-jemallocator = { version = "0.6.0", optional = true, features = ["stats", "profiling"] }
2120

2221
# Jemalloc's background_threads feature requires Linux (pthreads).
2322
[target.'cfg(target_os = "linux")'.dependencies]

common/malloc_utils/src/jemalloc.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
use metrics::{
1212
set_gauge, set_gauge_vec, try_create_int_gauge, try_create_int_gauge_vec, IntGauge, IntGaugeVec,
1313
};
14-
#[cfg(feature = "jemalloc-profiling")]
1514
use std::ffi::{c_char, c_int};
1615
use std::sync::LazyLock;
17-
#[cfg(feature = "jemalloc-profiling")]
1816
use std::{mem, ptr};
1917
use tikv_jemalloc_ctl::{arenas, epoch, raw, stats, Access, AsName, Error};
2018

@@ -130,7 +128,6 @@ pub fn page_size() -> Result<usize, Error> {
130128
}
131129

132130
/// A convenience wrapper around `mallctl` for writing `value` to `name`.
133-
#[cfg(feature = "jemalloc-profiling")]
134131
pub unsafe fn mallctl_write<T>(name: &[u8], mut value: T) -> Result<(), c_int> {
135132
// Use `tikv_jemalloc_sys::mallctl` directly since the `jemalloc_ctl::raw`
136133
// functions artifically limit the `name` values.
@@ -162,7 +159,6 @@ fn terminate_string_for_c(s: &str) -> Vec<u8> {
162159
///
163160
/// This generates a heap profile at `filename`.
164161
#[allow(dead_code)]
165-
#[cfg(feature = "jemalloc-profiling")]
166162
pub fn prof_dump(filename: &str) -> Result<(), String> {
167163
let terminated_filename = terminate_string_for_c(filename);
168164

@@ -179,7 +175,6 @@ pub fn prof_dump(filename: &str) -> Result<(), String> {
179175
///
180176
/// Controls wether profile sampling is active.
181177
#[allow(dead_code)]
182-
#[cfg(feature = "jemalloc-profiling")]
183178
pub fn prof_active(enable: bool) -> Result<(), String> {
184179
unsafe { mallctl_write("prof.active\0".as_ref(), enable) }
185180
.map_err(|e| format!("Failed to call prof.active on mallctl with code {e:?}"))

common/malloc_utils/src/lib.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ mod interface {
4545
pub use crate::glibc::configure_glibc_malloc as configure_memory_allocator;
4646
pub use crate::glibc::scrape_mallinfo_metrics as scrape_allocator_metrics;
4747

48+
#[allow(dead_code)]
49+
pub use super::prof_active_unsupported as prof_active;
4850
#[allow(dead_code)]
4951
pub use super::prof_dump_unsupported as prof_dump;
5052
}
@@ -56,17 +58,9 @@ mod interface {
5658
Ok(())
5759
}
5860

59-
pub use crate::jemalloc::scrape_jemalloc_metrics as scrape_allocator_metrics;
60-
61-
#[cfg(not(feature = "jemalloc-profiling"))]
62-
pub use super::prof_dump_unsupported as prof_dump;
63-
#[cfg(feature = "jemalloc-profiling")]
64-
pub use crate::jemalloc::prof_dump;
65-
66-
#[cfg(not(feature = "jemalloc-profiling"))]
67-
pub use super::prof_active_unsupported as prof_active;
68-
#[cfg(feature = "jemalloc-profiling")]
6961
pub use crate::jemalloc::prof_active;
62+
pub use crate::jemalloc::prof_dump;
63+
pub use crate::jemalloc::scrape_jemalloc_metrics as scrape_allocator_metrics;
7064
}
7165

7266
#[cfg(all(
@@ -93,7 +87,7 @@ mod interface {
9387
pub fn prof_dump_unsupported(_: &str) -> Result<(), String> {
9488
Err(
9589
"Profile dumps are only supported when Lighthouse is built for Linux \
96-
using the `jemalloc` and `jemalloc-profiling` features."
90+
using the `jemalloc` feature."
9791
.to_string(),
9892
)
9993
}
@@ -102,7 +96,7 @@ pub fn prof_dump_unsupported(_: &str) -> Result<(), String> {
10296
pub fn prof_active_unsupported(_: bool) -> Result<(), String> {
10397
Err(
10498
"Enabling profiling is only supported when Lighthouse is built for Linux \
105-
using the `jemalloc` and `jemalloc-profiling` features."
99+
using the `jemalloc` feature."
106100
.to_string(),
107101
)
108102
}

lighthouse/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ console-subscriber = ["console-subscriber/default"]
3838

3939
# Deprecated. This is now enabled by default on non windows targets.
4040
jemalloc = []
41-
# Enable profiling in jemalloc.
42-
jemalloc-profiling = ["malloc_utils/jemalloc-profiling"]
4341

4442
[dependencies]
4543
account_manager = { "path" = "../account_manager" }

0 commit comments

Comments
 (0)