From e53f213ac426f32f27d9f89087753ac8ea81d849 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Wed, 12 Jan 2022 19:17:42 +0100 Subject: [PATCH] Try demangling names before forwarding them to the profiler Before this PR, each profiler (perf/vtune, at the moment) had to have a demangler for each of the programming languages that could have been compiled to wasm and fed into wasmtime. With this, wasmtime now demangles names before even forwarding them to the underlying profiler, which makes for a unified representation in profilers, and avoids incorrect demangling in profilers. --- Cargo.lock | 2 ++ crates/jit/Cargo.toml | 2 ++ crates/jit/src/profiling.rs | 5 ++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 0f897137f1..499faa59d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3560,10 +3560,12 @@ dependencies = [ "anyhow", "bincode", "cfg-if 1.0.0", + "cpp_demangle", "gimli", "ittapi-rs", "object", "region", + "rustc-demangle", "rustix", "serde", "target-lexicon", diff --git a/crates/jit/Cargo.toml b/crates/jit/Cargo.toml index 9768b8b7ad..733fc1ff96 100644 --- a/crates/jit/Cargo.toml +++ b/crates/jit/Cargo.toml @@ -24,6 +24,8 @@ serde = { version = "1.0.94", features = ["derive"] } addr2line = { version = "0.17.0", default-features = false } ittapi-rs = { version = "0.1.6", optional = true } bincode = "1.2.1" +rustc-demangle = "0.1.16" +cpp_demangle = "0.3.2" [target.'cfg(target_os = "windows")'.dependencies] winapi = { version = "0.3.8", features = ["winnt", "impl-default"] } diff --git a/crates/jit/src/profiling.rs b/crates/jit/src/profiling.rs index 7fddcb296f..08f9a957c6 100644 --- a/crates/jit/src/profiling.rs +++ b/crates/jit/src/profiling.rs @@ -65,7 +65,10 @@ impl ProfilingAgent for NullProfilerAgent { fn debug_name(module: &Module, index: DefinedFuncIndex) -> String { let index = module.func_index(index); match module.func_names.get(&index) { - Some(s) => s.clone(), + Some(s) => rustc_demangle::try_demangle(s) + .map(|demangle| demangle.to_string()) + .or_else(|_| cpp_demangle::Symbol::new(s).map(|sym| sym.to_string())) + .unwrap_or_else(|_| s.clone()), None => format!("wasm::wasm-function[{}]", index.index()), } }