Skip to main content

GuestProfilerModules

Struct GuestProfilerModules 

Source
pub struct GuestProfilerModules { /* private fields */ }
Available on crate features 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

Source

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.

Source

pub fn new_component( engine: &Engine, component: &Component, extra_modules: impl IntoIterator<Item = (String, Module)>, ) -> Result<Self>

Available on crate feature 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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GuestProfilerModules

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.