Enable jitdump profiling support by default (#1310)
* Enable jitdump profiling support by default This the result of some of the investigation I was doing for #1017. I've done a number of refactorings here which culminated in a number of changes that all amount to what I think should result in jitdump support being enabled by default: * Pass in a list of finished functions instead of just a range to ensure that we're emitting jit dump data for a specific module rather than a whole `CodeMemory` which may have other modules. * Define `ProfilingStrategy` in the `wasmtime` crate to have everything locally-defined * Add support to the C API to enable profiling * Documentation added for profiling with jitdump to the book * Split out supported/unsupported files in `jitdump.rs` to avoid having lots of `#[cfg]`. * Make dependencies optional that are only used for `jitdump`. * Move initialization up-front to `JitDumpAgent::new()` instead of deferring it to the first module. * Pass around `Arc<dyn ProfilingAgent>` instead of `Option<Arc<Mutex<Box<dyn ProfilingAgent>>>>` The `jitdump` Cargo feature is now enabled by default which means that our published binaries, C API artifacts, and crates will support profiling at runtime by default. The support I don't think is fully fleshed out and working but I think it's probably in a good enough spot we can get users playing around with it!
This commit is contained in:
@@ -1,40 +1,36 @@
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
use wasmtime_environ::entity::{EntityRef, PrimaryMap};
|
||||
use wasmtime_environ::wasm::DefinedFuncIndex;
|
||||
use wasmtime_environ::Module;
|
||||
use wasmtime_runtime::VMFunctionBody;
|
||||
|
||||
#[cfg(feature = "jitdump")]
|
||||
mod jitdump;
|
||||
|
||||
#[cfg(feature = "jitdump")]
|
||||
pub use crate::jitdump::JitDumpAgent;
|
||||
|
||||
#[cfg(not(feature = "jitdump"))]
|
||||
pub type JitDumpAgent = NullProfilerAgent;
|
||||
|
||||
/// Select which profiling technique to use
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum ProfilingStrategy {
|
||||
/// No profiler support
|
||||
NullProfiler,
|
||||
|
||||
/// Collect profile for jitdump file format
|
||||
JitDumpProfiler,
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(all(feature = "jitdump", target_os = "linux"))] {
|
||||
#[path = "jitdump_linux.rs"]
|
||||
mod jitdump;
|
||||
} else {
|
||||
#[path = "jitdump_disabled.rs"]
|
||||
mod jitdump;
|
||||
}
|
||||
}
|
||||
|
||||
pub use crate::jitdump::JitDumpAgent;
|
||||
|
||||
/// Common interface for profiling tools.
|
||||
pub trait ProfilingAgent {
|
||||
pub trait ProfilingAgent: Send + Sync + 'static {
|
||||
/// Notify the profiler of a new module loaded into memory
|
||||
fn module_load(
|
||||
&mut self,
|
||||
module_name: &str,
|
||||
addr: *const u8,
|
||||
len: usize,
|
||||
&self,
|
||||
module: &Module,
|
||||
functions: &PrimaryMap<DefinedFuncIndex, *mut [VMFunctionBody]>,
|
||||
dbg_image: Option<&[u8]>,
|
||||
) -> ();
|
||||
}
|
||||
|
||||
/// Default agent for unsupported profiling build.
|
||||
#[derive(Debug, Default, Clone, Copy)]
|
||||
pub struct NullProfilerAgent {}
|
||||
pub struct NullProfilerAgent;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct NullProfilerAgentError;
|
||||
@@ -55,11 +51,19 @@ impl Error for NullProfilerAgentError {
|
||||
|
||||
impl ProfilingAgent for NullProfilerAgent {
|
||||
fn module_load(
|
||||
&mut self,
|
||||
_module_name: &str,
|
||||
_addr: *const u8,
|
||||
_len: usize,
|
||||
&self,
|
||||
_module: &Module,
|
||||
_functions: &PrimaryMap<DefinedFuncIndex, *mut [VMFunctionBody]>,
|
||||
_dbg_image: Option<&[u8]>,
|
||||
) -> () {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn debug_name(module: &Module, index: DefinedFuncIndex) -> String {
|
||||
let index = module.local.func_index(index);
|
||||
match module.func_names.get(&index) {
|
||||
Some(s) => s.clone(),
|
||||
None => format!("wasm::wasm-function[{}]", index.index()),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user