Should succeed to set prof: `name` or `mib` specifies an unknown/invalid value

89 views Asked by At

I want to use jemalloc https://github.com/jemalloc/jemalloc to detect the memory leak in rust. I need to generate a dump file from rust and can control the dump from external application dynamic. First I add the dependencies in rust project Cargo.toml like this:

[package]
name = "rust-learn"
version = "0.1.0"
edition = "2018"

[dependencies]
tokio = { version = "1.17.0", features = ["full"] }
actix-web = "4"
serde = { version = "1.0.64", features = ["derive"] }
serde_json = "1.0.64"
log4rs = "1.2.0"
jemallocator = "0.5.4"
jemalloc-ctl = "0.5.4"

[dependencies.jemalloc-sys]
version = "0.5.4"
features = ["stats", "profiling", "unprefixed_malloc_on_supported_platforms"]

[profile.release]
debug = true

[build-dependencies]

then add a rest http api to set the profile switch like this(main.rs, the minimal reproduce file):

use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder};
use jemalloc_ctl::{AsName, Access};

#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
const PROF_ACTIVE: &'static [u8] = b"prof.active\0";

#[get("/active")]
async fn hello() -> impl Responder {
    let name = PROF_ACTIVE.name();
    name.write(true).expect("Should succeed to set prof");
    HttpResponse::Ok().body("Hello, world!")
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| {
        App::new()
            .service(hello)
    })
    .bind("127.0.0.1:8080")?
    .run()
    .await
}

when I using this command to invoke the http rest api in macOS terminal like this:

> curl http://127.0.0.1:8080/active
curl: (52) Empty reply from server

and the server side show error:

thread 'actix-rt|system:0|arbiter:1' panicked at src/main.rs:17:22:
Should succeed to set prof: `name` or `mib` specifies an unknown/invalid value.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Am I missing something? what should I do to fixed this issue? The OS is macOS 13.3.1. the rust version is 1.73. I have tried to add env in .cargo/config.toml:

[env]
MALLOC_CONF="prof:true"

did not fix it.

0

There are 0 answers