wasmtime_jit/
profiling.rs1use crate::{demangling::demangle_function_name_or_index, CompiledModule};
2use wasmtime_environ::{DefinedFuncIndex, EntityRef};
3
4cfg_if::cfg_if! {
5 if #[cfg(all(feature = "jitdump", target_os = "linux"))] {
6 #[path = "profiling/jitdump_linux.rs"]
7 mod jitdump;
8 } else {
9 #[path = "profiling/jitdump_disabled.rs"]
10 mod jitdump;
11 }
12}
13
14cfg_if::cfg_if! {
15 if #[cfg(target_os = "linux")] {
16 #[path = "profiling/perfmap_linux.rs"]
17 mod perfmap;
18 } else {
19 #[path = "profiling/perfmap_disabled.rs"]
20 mod perfmap;
21 }
22}
23
24cfg_if::cfg_if! {
25 if #[cfg(all(feature = "vtune", target_arch = "x86_64", not(all(target_os = "windows", target_env = "gnu"))))] {
28 #[path = "profiling/vtune.rs"]
29 mod vtune;
30 } else {
31 #[path = "profiling/vtune_disabled.rs"]
32 mod vtune;
33 }
34}
35
36pub use jitdump::JitDumpAgent;
37pub use perfmap::PerfMapAgent;
38pub use vtune::VTuneAgent;
39
40pub trait ProfilingAgent: Send + Sync + 'static {
42 fn module_load(&self, module: &CompiledModule, dbg_image: Option<&[u8]>);
44
45 fn load_single_trampoline(&self, name: &str, addr: *const u8, size: usize, pid: u32, tid: u32);
48}
49
50#[derive(Debug, Default, Clone, Copy)]
52pub struct NullProfilerAgent;
53
54impl ProfilingAgent for NullProfilerAgent {
55 fn module_load(&self, _module: &CompiledModule, _dbg_image: Option<&[u8]>) {}
56 fn load_single_trampoline(
57 &self,
58 _name: &str,
59 _addr: *const u8,
60 _size: usize,
61 _pid: u32,
62 _tid: u32,
63 ) {
64 }
65}
66
67#[allow(dead_code)]
68fn debug_name(module: &CompiledModule, index: DefinedFuncIndex) -> String {
69 let index = module.module().func_index(index);
70 let mut debug_name = String::new();
71 demangle_function_name_or_index(&mut debug_name, module.func_name(index), index.index())
72 .unwrap();
73 debug_name
74}