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:
@@ -10,7 +10,7 @@ use crate::resolver::Resolver;
|
||||
use std::collections::HashMap;
|
||||
use std::io::Write;
|
||||
use std::rc::Rc;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::sync::Arc;
|
||||
use thiserror::Error;
|
||||
use wasmtime_debug::read_debuginfo;
|
||||
use wasmtime_environ::entity::{BoxedSlice, PrimaryMap};
|
||||
@@ -64,7 +64,7 @@ impl<'data> RawCompiledModule<'data> {
|
||||
compiler: &mut Compiler,
|
||||
data: &'data [u8],
|
||||
debug_info: bool,
|
||||
profiler: Option<&Arc<Mutex<Box<dyn ProfilingAgent + Send>>>>,
|
||||
profiler: &dyn ProfilingAgent,
|
||||
) -> Result<Self, SetupError> {
|
||||
let environ = ModuleEnvironment::new(compiler.frontend_config(), compiler.tunables());
|
||||
|
||||
@@ -105,19 +105,11 @@ impl<'data> RawCompiledModule<'data> {
|
||||
compiler.publish_compiled_code();
|
||||
|
||||
// Initialize profiler and load the wasm module
|
||||
match profiler {
|
||||
Some(_) => {
|
||||
let region_name = String::from("wasm_module");
|
||||
let mut profiler = profiler.unwrap().lock().unwrap();
|
||||
match &compilation.dbg_image {
|
||||
Some(dbg) => {
|
||||
compiler.profiler_module_load(&mut profiler, ®ion_name, Some(&dbg))
|
||||
}
|
||||
_ => compiler.profiler_module_load(&mut profiler, ®ion_name, None),
|
||||
};
|
||||
}
|
||||
_ => (),
|
||||
};
|
||||
profiler.module_load(
|
||||
&translation.module,
|
||||
&compilation.finished_functions,
|
||||
compilation.dbg_image.as_deref(),
|
||||
);
|
||||
|
||||
let dbg_jit_registration = if let Some(img) = compilation.dbg_image {
|
||||
let mut bytes = Vec::new();
|
||||
@@ -157,7 +149,7 @@ impl CompiledModule {
|
||||
compiler: &mut Compiler,
|
||||
data: &'data [u8],
|
||||
debug_info: bool,
|
||||
profiler: Option<&Arc<Mutex<Box<dyn ProfilingAgent + Send>>>>,
|
||||
profiler: &dyn ProfilingAgent,
|
||||
) -> Result<Self, SetupError> {
|
||||
let raw = RawCompiledModule::<'data>::new(compiler, data, debug_info, profiler)?;
|
||||
|
||||
@@ -290,7 +282,7 @@ pub unsafe fn instantiate(
|
||||
resolver: &mut dyn Resolver,
|
||||
debug_info: bool,
|
||||
is_bulk_memory: bool,
|
||||
profiler: Option<&Arc<Mutex<Box<dyn ProfilingAgent + Send>>>>,
|
||||
profiler: &dyn ProfilingAgent,
|
||||
) -> Result<InstanceHandle, SetupError> {
|
||||
let instance = CompiledModule::new(compiler, data, debug_info, profiler)?.instantiate(
|
||||
is_bulk_memory,
|
||||
|
||||
Reference in New Issue
Block a user