Support vtune profiling of trampolines too (#3687)
* Provide helpers for demangling function names * Profile trampolines in vtune too * get rid of mapping * avoid code duplication with jitdump_linux * maintain previous default display name for wasm functions * no dash, grrr * Remove unused profiling error type
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
use crate::CompiledModule;
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
use crate::{demangling::demangle_function_name_or_index, CompiledModule};
|
||||
use wasmtime_environ::{DefinedFuncIndex, EntityRef, Module};
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
@@ -30,45 +28,38 @@ pub use vtune::VTuneAgent;
|
||||
pub trait ProfilingAgent: Send + Sync + 'static {
|
||||
/// Notify the profiler of a new module loaded into memory
|
||||
fn module_load(&self, module: &CompiledModule, dbg_image: Option<&[u8]>);
|
||||
/// Notify the profiler that the object file provided contains
|
||||
/// dynamically-generated trampolines which are now being loaded.
|
||||
fn trampoline_load(&self, file: &object::File<'_>);
|
||||
|
||||
/// Notify the profiler about a single dynamically-generated trampoline (for host function)
|
||||
/// that is being loaded now.`
|
||||
fn load_single_trampoline(&self, name: &str, addr: *const u8, size: usize, pid: u32, tid: u32);
|
||||
}
|
||||
|
||||
/// Default agent for unsupported profiling build.
|
||||
#[derive(Debug, Default, Clone, Copy)]
|
||||
pub struct NullProfilerAgent;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct NullProfilerAgentError;
|
||||
|
||||
impl fmt::Display for NullProfilerAgentError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "A profiler agent is not supported by this build")
|
||||
}
|
||||
}
|
||||
|
||||
// This is important for other errors to wrap this one.
|
||||
impl Error for NullProfilerAgentError {
|
||||
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
||||
// Generic error, underlying cause isn't tracked.
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl ProfilingAgent for NullProfilerAgent {
|
||||
fn module_load(&self, _module: &CompiledModule, _dbg_image: Option<&[u8]>) {}
|
||||
fn trampoline_load(&self, _file: &object::File<'_>) {}
|
||||
fn load_single_trampoline(
|
||||
&self,
|
||||
_name: &str,
|
||||
_addr: *const u8,
|
||||
_size: usize,
|
||||
_pid: u32,
|
||||
_tid: u32,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn debug_name(module: &Module, index: DefinedFuncIndex) -> String {
|
||||
let index = module.func_index(index);
|
||||
match module.func_names.get(&index) {
|
||||
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()),
|
||||
}
|
||||
let mut debug_name = String::new();
|
||||
demangle_function_name_or_index(
|
||||
&mut debug_name,
|
||||
module.func_names.get(&index).map(|s| s.as_str()),
|
||||
index.index(),
|
||||
)
|
||||
.unwrap();
|
||||
debug_name
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user