当我尝试在带有 M1 芯片的 macOS 13.4 中转储 Rust 时,如下所示:
use jemalloc_ctl::{AsName, Access};
use std::collections::HashMap;
#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
const PROF_ACTIVE: &'static [u8] = b"prof.active\0";
const PROF_DUMP: &'static [u8] = b"prof.dump\0";
const PROFILE_OUTPUT: &'static [u8] = b"profile.out\0";
fn set_prof_active(active: bool) {
let name = PROF_ACTIVE.name();
name.write(active).expect("Should succeed to set prof");
}
fn dump_profile() {
let name = PROF_DUMP.name();
name.write(PROFILE_OUTPUT).expect("Should succeed to dump profile")
}
fn main() {
set_prof_active(true);
let mut buffers: Vec<HashMap<i32, i32>> = Vec::new();
for _ in 0..100 {
buffers.push(HashMap::with_capacity(1024));
}
set_prof_active(false);
dump_profile();
}
输出显示以下错误:
thread 'main' panicked at src/main.rs:18:32:
Should succeed to dump profile: An interface with side effects failed in some way not directly related to `mallctl*()` read/write processing.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
jemolloc 不支持 macOS 吗?我是不是漏掉了什么?这是Cargo.toml
:
[package]
name = "rust-learn"
version = "0.1.0"
edition = "2018"
[dependencies]
jemallocator = "0.3.2"
jemalloc-ctl = "0.3.2"
[dependencies.jemalloc-sys]
version = "0.3.2"
features = ["stats", "profiling", "unprefixed_malloc_on_supported_platforms"]
[profile.release]
debug = true
这是 Rust 版本:
➜ rust-learn git:(rustflags) ✗ rustup -V
rustup 1.27.1 (54dd3d00f 2024-04-24)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.79.0 (129f3b996 2024-06-10)
MALLOC_CONF=prof:true
在构建jemalloc时需要设置。在构建项目之前,请进行如下设置:
这将指示
jemalloc-sys
将其传递给 jemalloc。如果这仍然不起作用,请运行
cargo clean
并重建项目。