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.
This commit is contained in:
Benjamin Bouvier
2022-01-12 19:17:42 +01:00
parent 7454f1f3af
commit e53f213ac4
3 changed files with 8 additions and 1 deletions

2
Cargo.lock generated
View File

@@ -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",

View File

@@ -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"] }

View File

@@ -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()),
}
}