Skip to content

Commit bb01155

Browse files
authored
Add macOS support for memory profiling (#4606)
## Motivation We're using the `unprefixed_malloc_on_supported_platforms` feature to be able to use `malloc_conf` instead of the prefixed `_rjem_malloc_conf`, as it's recommended, but MacOS is not one of the supported platforms. ## Proposal Use the prefixed version for MacOS ## Test Plan Ran `linera net up` with memory profiling enabled from my MacOS, it works now ## Release Plan - Nothing to do / These changes follow the usual release cycle.
1 parent 881ce71 commit bb01155

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

linera-service/src/cli/main.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,19 @@ static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
1111
// jemalloc configuration for memory profiling with jemalloc_pprof
1212
// prof:true,prof_active:true - Enable profiling from start
1313
// lg_prof_sample:19 - Sample every 512KB for good detail/overhead balance
14-
#[cfg(feature = "memory-profiling")]
14+
15+
// Linux/other platforms: use unprefixed malloc (with unprefixed_malloc_on_supported_platforms)
16+
#[cfg(all(feature = "memory-profiling", not(target_os = "macos")))]
1517
#[allow(non_upper_case_globals)]
1618
#[export_name = "malloc_conf"]
1719
pub static malloc_conf: &[u8] = b"prof:true,prof_active:true,lg_prof_sample:19\0";
1820

21+
// macOS: use prefixed malloc (without unprefixed_malloc_on_supported_platforms)
22+
#[cfg(all(feature = "memory-profiling", target_os = "macos"))]
23+
#[allow(non_upper_case_globals)]
24+
#[export_name = "_rjem_malloc_conf"]
25+
pub static malloc_conf: &[u8] = b"prof:true,prof_active:true,lg_prof_sample:19\0";
26+
1927
use std::{
2028
collections::{BTreeMap, BTreeSet},
2129
env,

linera-service/src/proxy/main.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,19 @@ static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
88
// jemalloc configuration for memory profiling with jemalloc_pprof
99
// prof:true,prof_active:true - Enable profiling from start
1010
// lg_prof_sample:19 - Sample every 512KB for good detail/overhead balance
11-
#[cfg(feature = "memory-profiling")]
11+
12+
// Linux/other platforms: use unprefixed malloc (with unprefixed_malloc_on_supported_platforms)
13+
#[cfg(all(feature = "memory-profiling", not(target_os = "macos")))]
1214
#[allow(non_upper_case_globals)]
1315
#[export_name = "malloc_conf"]
1416
pub static malloc_conf: &[u8] = b"prof:true,prof_active:true,lg_prof_sample:19\0";
1517

18+
// macOS: use prefixed malloc (without unprefixed_malloc_on_supported_platforms)
19+
#[cfg(all(feature = "memory-profiling", target_os = "macos"))]
20+
#[allow(non_upper_case_globals)]
21+
#[export_name = "_rjem_malloc_conf"]
22+
pub static malloc_conf: &[u8] = b"prof:true,prof_active:true,lg_prof_sample:19\0";
23+
1624
use std::{net::SocketAddr, path::PathBuf, time::Duration};
1725

1826
use anyhow::{anyhow, bail, ensure, Result};

linera-service/src/server.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,19 @@ static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
99
// jemalloc configuration for memory profiling with jemalloc_pprof
1010
// prof:true,prof_active:true - Enable profiling from start
1111
// lg_prof_sample:19 - Sample every 512KB for good detail/overhead balance
12-
#[cfg(feature = "memory-profiling")]
12+
13+
// Linux/other platforms: use unprefixed malloc (with unprefixed_malloc_on_supported_platforms)
14+
#[cfg(all(feature = "memory-profiling", not(target_os = "macos")))]
1315
#[allow(non_upper_case_globals)]
1416
#[export_name = "malloc_conf"]
1517
pub static malloc_conf: &[u8] = b"prof:true,prof_active:true,lg_prof_sample:19\0";
1618

19+
// macOS: use prefixed malloc (without unprefixed_malloc_on_supported_platforms)
20+
#[cfg(all(feature = "memory-profiling", target_os = "macos"))]
21+
#[allow(non_upper_case_globals)]
22+
#[export_name = "_rjem_malloc_conf"]
23+
pub static malloc_conf: &[u8] = b"prof:true,prof_active:true,lg_prof_sample:19\0";
24+
1725
use std::{
1826
borrow::Cow,
1927
num::NonZeroU16,

0 commit comments

Comments
 (0)