rust-lang/rust-analyzer · error
profiler failed to start
Error message
profiler failed to start
What it means
After atomically transitioning OFF -> PENDING, `start` invokes the gperftools `ProfilerStart` C function. If it returns 0 the native profiler failed to begin recording, and the wrapper panics with 'profiler failed to start'.
Source
Thrown at crates/profile/src/google_cpu_profiler.rs:33
}
const OFF: usize = 0;
const ON: usize = 1;
const PENDING: usize = 2;
fn transition(current: usize, new: usize) -> bool {
static STATE: AtomicUsize = AtomicUsize::new(OFF);
STATE.compare_exchange(current, new, Ordering::SeqCst, Ordering::SeqCst).is_ok()
}
pub(crate) fn start(path: &Path) {
if !transition(OFF, PENDING) {
panic!("profiler already started");
}
let path = CString::new(path.display().to_string()).unwrap();
if unsafe { ProfilerStart(path.as_ptr()) } == 0 {
panic!("profiler failed to start")
}
assert!(transition(PENDING, ON));
}
pub(crate) fn stop() {
if !transition(ON, PENDING) {
panic!("profiler is not started")
}
unsafe { ProfilerStop() };
assert!(transition(PENDING, OFF));
}
View on GitHub (pinned to e8f7e90aa3)
Solutions
- Verify the output directory exists and is writable before calling start
- Check the path for invalid characters and that the filesystem has space
- Wrap profiler startup in a check and fall back to running unprofiled if the environment disallows it
Example fix
// before
profiler::start(&Path::new("/proc/1/cpu.prof"));
// after
let path = Path::new("/tmp/cpu.prof");
if path.parent().map_or(false, |d| d.is_dir()) {
profiler::start(path);
} Defensive patterns
Strategy: validation
Validate before calling
fn profiler_output_ok(path: &Path) -> bool {
path.parent().map_or(false, |d| d.is_dir())
&& path.extension().is_some()
} Try / catch
std::panic::catch_unwind(|| profiler::start(path))
.err()
.map(|_| eprintln!("profiling unavailable; continuing unprofiled")); Prevention
- Ensure the profile output directory exists and is writable before starting
- Test profiler startup in your deployment sandbox/container
- Validate the path (no interior NULs, valid filesystem) before calling start
- Treat profiling as optional: fail soft when the native profiler refuses to start
When it happens
Trigger: `ProfilerStart(path)` returning 0, typically because the output file at `path` cannot be created/written (bad directory, permissions, invalid path bytes).
Common situations: Passing a profile output path in a non-existent or read-only directory; running in a sandboxed/containerized environment without write access; path containing interior NUL would instead hit the CString unwrap earlier.
Related errors
- profiler already started
- profiler is not started
- We explicitly do not provide canonicalization API, as that i
- bad kind {other}
- bad spacing {other}
AI-assisted analysis of rust-lang/rust-analyzer@e8f7e90aa3 (2026-09-03).
Data as JSON: /api/errors/31be6ad582dc565b.
Report an issue: GitHub.