pub struct GuestProfilerModules { /* private fields */ }profiling and runtime only.Expand description
The set of modules a GuestProfiler attributes samples to, prepared
once and shared by any number of profilers.
Preparing a module builds its symbol table, which demangles the name of
every function it defines; for modules with many functions this is the
bulk of the cost of starting a profile. GuestProfiler::new does this
work every time it is called. Embedders that profile the same modules
repeatedly, for example once per request or once per instance, can instead
build a GuestProfilerModules once and pass it to
GuestProfiler::new_with_modules for each profile, which then does no
per-module work beyond registering the prepared symbol tables.
Cloning is cheap, since the prepared modules are reference-counted, and a
GuestProfilerModules can be shared between threads. Profiles started
from the same set are independent of one another.
§Example
let engine = Engine::default();
let module = Module::new(&engine, r#"(module (func (export "run")))"#)?;
// Prepare the modules once...
let modules = GuestProfilerModules::new(&engine, [("main.wasm".to_string(), module.clone())])?;
// ...then start a profile for each guest that runs them.
for _ in 0..3 {
let profiler = GuestProfiler::new_with_modules("main", Duration::from_millis(10), &modules);
let mut store = Store::new(&engine, profiler);
// Arrange to call `GuestProfiler::sample` while the guest runs, for
// example from `Store::epoch_deadline_callback`.
let instance = Instance::new(&mut store, &module, &[])?;
instance
.get_typed_func::<(), ()>(&mut store, "run")?
.call(&mut store, ())?;
let mut profile = Vec::new();
store.into_data().finish(&mut profile)?;
}Implementations§
Source§impl GuestProfilerModules
impl GuestProfilerModules
Sourcepub fn new(
engine: &Engine,
modules: impl IntoIterator<Item = (String, Module)>,
) -> Result<Self>
pub fn new( engine: &Engine, modules: impl IntoIterator<Item = (String, Module)>, ) -> Result<Self>
Prepares modules for profiling.
Each entry pairs a module with the name it is given in profiles. Only
modules in modules appear in stack traces of profiles that use this
set; stack frames executing host code or functions from other modules
are omitted. See the “Security” section of the GuestProfiler
documentation for guidance on which modules to include. Modules that
define no functions are skipped, since no sample can land in them.
§Errors
Returns an error if engine has guest debugging enabled, which
profiling does not support.
§Panics
Panics if any module in modules was not created with engine.
Sourcepub fn new_component(
engine: &Engine,
component: &Component,
extra_modules: impl IntoIterator<Item = (String, Module)>,
) -> Result<Self>
Available on crate feature component-model only.
pub fn new_component( engine: &Engine, component: &Component, extra_modules: impl IntoIterator<Item = (String, Module)>, ) -> Result<Self>
component-model only.Prepares the static modules of component, plus extra_modules, for
profiling.
See GuestProfilerModules::new for additional information.
Trait Implementations§
Source§impl Clone for GuestProfilerModules
impl Clone for GuestProfilerModules
Auto Trait Implementations§
impl !RefUnwindSafe for GuestProfilerModules
impl !UnwindSafe for GuestProfilerModules
impl Freeze for GuestProfilerModules
impl Send for GuestProfilerModules
impl Sync for GuestProfilerModules
impl Unpin for GuestProfilerModules
impl UnsafeUnpin for GuestProfilerModules
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more