{"record":{"id":"e109de1369801591","repo":"rust-lang/rust","slug":"please-set-rust-analyzer-profiling-memoryprofile","errorCode":null,"errorMessage":"Please set `rust-analyzer.profiling.memoryProfile` to the path where you want to save the profile.","messagePattern":"Please set `rust-analyzer\\.profiling\\.memoryProfile` to the path where you want to save the profile\\.","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"warning","filePath":"src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/request.rs","lineNumber":153,"sourceCode":"            \"Memory profiling is not enabled for this build of rust-analyzer.\\n\\n\\\n            To build rust-analyzer with profiling support, pass `--features dhat --profile dev-rel` to `cargo build`\n            when building from source, or pass `--enable-profiling` to `cargo xtask`.\"\n        ))\n    }\n    #[cfg(feature = \"dhat\")]\n    {\n        if let Some(dhat_output_file) = _state.config.dhat_output_file() {\n            let mut profiler = crate::DHAT_PROFILER.lock().unwrap();\n            let old_profiler = profiler.take();\n            // Need to drop the old profiler before creating a new one.\n            drop(old_profiler);\n            *profiler = Some(dhat::Profiler::builder().file_name(&dhat_output_file).build());\n            Ok(format!(\n                \"Memory profile was saved successfully to {dhat_output_file}.\\n\\n\\\n                See https://docs.rs/dhat/latest/dhat/#viewing for how to inspect the profile.\"\n            ))\n        } else {\n            Err(anyhow::anyhow!(\n                \"Please set `rust-analyzer.profiling.memoryProfile` to the path where you want to save the profile.\"\n            ))\n        }\n    }\n}\n\npub(crate) fn handle_view_syntax_tree(\n    snap: GlobalStateSnapshot,\n    params: lsp_ext::ViewSyntaxTreeParams,\n) -> anyhow::Result<String> {\n    let _p = tracing::info_span!(\"handle_view_syntax_tree\").entered();\n    let id = try_default!(from_proto::file_id(&snap, &params.text_document.uri)?);\n    let res = snap.analysis.view_syntax_tree(id)?;\n    Ok(res)\n}\n\npub(crate) fn handle_view_hir(\n    snap: GlobalStateSnapshot,","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/request.rs#L135-L171","documentation":"Returned by handle_memory_usage in the dhat-enabled arm when the server has no output path configured (config.dhat_output_file() returns None). Even on a profiling build the user must tell rust-analyzer where to write the profile, via the rust-analyzer.profiling.memoryProfile setting.","triggerScenarios":"Invoking the memory profiling request on a correctly-built (dhat) rust-analyzer while the client has not set rust-analyzer.profiling.memoryProfile to a writable path.","commonSituations":"Enabling the profiling command for the first time without configuring the output path; the setting being cleared/renamed after an extension update; pointing at an unwritable directory (handled separately at write time).","solutions":["Set rust-analyzer.profiling.memoryProfile to an absolute writable file path in the client/extension settings.","Ensure the directory portion of that path exists and is writable by the server process.","Re-trigger the profiling request after saving the setting."],"exampleFix":"// settings.json (VS Code) — before: no setting\n{}\n\n// after\n{\n  \"rust-analyzer.profiling.memoryProfile\": \"/home/me/ra-dhat.json\"\n}","handlingStrategy":"validation","validationCode":"// Validate the memoryProfile setting is a writable path before sending the request:\nfn profile_path_ok(p: &str) -> bool {\n    let path = std::path::Path::new(p);\n    path.is_absolute() && path.parent().map(|d| d.exists() && std::fs::metadata(d).map(|m| !m.permissions().readonly()).unwrap_or(false)).unwrap_or(false)\n}","typeGuard":"null","tryCatchPattern":"match ra.handle_memory_usage() {\n    Ok(msg) => Ok(msg),\n    Err(e) if e.to_string().contains(\"memoryProfile\") => {\n        eprintln!(\"set rust-analyzer.profiling.memoryProfile to a writable file path, then retry\");\n        Err(e)\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Always configure rust-analyzer.profiling.memoryProfile before triggering profiling.","Use an absolute path in a directory the server can write.","Re-verify the setting after extension updates in case it was renamed."],"tags":["rust-analyzer","profiling","configuration","dhat"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}