diff --git a/Cargo.lock b/Cargo.lock index 3a4572ebab8..9749c2d891a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -703,6 +703,7 @@ dependencies = [ "log", "mach2", "nix", + "rustc-demangle", "serde_json", ] diff --git a/components/background_hang_monitor/Cargo.toml b/components/background_hang_monitor/Cargo.toml index 5046bd6dff8..cb3632b9e1a 100644 --- a/components/background_hang_monitor/Cargo.toml +++ b/components/background_hang_monitor/Cargo.toml @@ -21,6 +21,7 @@ crossbeam-channel = { workspace = true } ipc-channel = { workspace = true } libc = { workspace = true } log = { workspace = true } +rustc-demangle = { version = "0.1", optional = true } serde_json = { workspace = true } [target.'cfg(target_os = "macos")'.dependencies] @@ -33,4 +34,4 @@ nix = { workspace = true, features = ["signal"], optional = true } nix = { workspace = true, features = ["signal"], optional = true } [features] -sampler = ["mach2", "nix"] +sampler = ["mach2", "nix", "rustc-demangle"] diff --git a/components/background_hang_monitor/sampler.rs b/components/background_hang_monitor/sampler.rs index e99572b2d2b..b57a3641b80 100644 --- a/components/background_hang_monitor/sampler.rs +++ b/components/background_hang_monitor/sampler.rs @@ -86,10 +86,15 @@ impl NativeStack { continue; } backtrace::resolve(*ip, |symbol| { - // TODO: use the demangled or C++ demangled symbols if available. let name = symbol .name() .map(|n| String::from_utf8_lossy(n.as_bytes()).to_string()); + // demangle if possible - + // the `rustc_demangle` crate transparently supports both + // "legacy" (C++ style) and "v0" mangling formats. + #[cfg(feature = "sampler")] + let name = name.map(|n| rustc_demangle::demangle(&n).to_string()); + let filename = symbol.filename().map(|n| n.to_string_lossy().to_string()); let lineno = symbol.lineno(); profile.backtrace.push(HangProfileSymbol {