Skip to content

Commit

Permalink
Update crates/core/src/host/wasm_common/instrumentation.rs
Browse files Browse the repository at this point in the history
Co-authored-by: Phoebe Goldman <phoebe@clockworklabs.io>
Signed-off-by: George Kulakowski <george.kulakowski@gmail.com>
  • Loading branch information
kulakowski and gefjon committed Oct 17, 2023
1 parent 068c223 commit afff6e8
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions crates/core/src/host/wasm_common/instrumentation.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
//! This file defines `CallSpan` and `CallSpanStart`,
//! which describe the time that a module spends executing "host calls,"
//! the WASM analog to syscalls.
//!
//! We can collect `CallSpan` timing data for various parts of host-call execution:
//! - `WasmInstanceEnv`, responsible for direct communication between WASM and the host.
//! - `InstanceEnv`, responsible for calls into the relational DB.
//! - Others?
//!
//! The instrumentation has non-negligible overhead,
//! so we enable it on a per-component basis with `cfg` attributes.
//! This is accomplished by defining two interchangeable modules,
//! `noop` and `op`, both of which implement the call-span interface.
//! `noop` does nothing.
//! `op` uses `std::time::Instant` and `std::time::Duration` to capture timings.
//! Components which use the time-span interface will conditionally import one of the two modules, like:
//! ```no-run
//! #[cfg(feature = "spacetimedb-wasm-instance-times)]
//! use instrumentation::op as span;
//! #[cfg(not(feature = "spacetimedb-wasm-instance-times)]
//! use instrumentation::noop as span;
//! ```
use std::time::{Duration, Instant};

use enum_map::{enum_map, Enum, EnumMap};
Expand Down

0 comments on commit afff6e8

Please sign in to comment.