pub(crate) static METRIC_ACTIVE_PROTO_WASM_SANDBOXES: &str = "active_proto_wasm_sandboxes";
pub(crate) static METRIC_ACTIVE_WASM_SANDBOXES: &str = "active_wasm_sandboxes";
pub(crate) static METRIC_ACTIVE_LOADED_WASM_SANDBOXES: &str = "active_loaded_wasm_sandboxes";
pub(crate) static METRIC_TOTAL_PROTO_WASM_SANDBOXES: &str = "proto_wasm_sandboxes_total";
pub(crate) static METRIC_TOTAL_WASM_SANDBOXES: &str = "wasm_sandboxes_total";
pub(crate) static METRIC_TOTAL_LOADED_WASM_SANDBOXES: &str = "loaded_wasm_sandboxes_total";
pub(crate) static METRIC_SANDBOX_LOADS: &str = "sandbox_loads_total";
pub(crate) static METRIC_SANDBOX_UNLOADS: &str = "sandbox_unloads_total";
#[cfg(test)]
mod tests {
use examples_common::get_wasm_module_path;
use hyperlight_host::HyperlightError;
use crate::{LoadedWasmSandbox, ProtoWasmSandbox, Result};
fn get_time_since_boot_microsecond() -> Result<i64> {
let res = std::time::SystemTime::now()
.duration_since(std::time::SystemTime::UNIX_EPOCH)?
.as_micros();
i64::try_from(res).map_err(HyperlightError::IntConversionFailure)
}
#[test]
#[ignore = "Needs to run separately to not get influenced by other tests"]
fn test_metrics() {
let recorder = metrics_util::debugging::DebuggingRecorder::new();
let snapshotter = recorder.snapshotter();
recorder.install().unwrap();
let snapshot = {
let mut sandbox = ProtoWasmSandbox::default();
sandbox
.register(
"GetTimeSinceBootMicrosecond",
get_time_since_boot_microsecond,
)
.unwrap();
let wasm_sandbox = sandbox.load_runtime().unwrap();
let loaded_wasm_sandbox: LoadedWasmSandbox = {
let mod_path = get_wasm_module_path("RunWasm.aot").unwrap();
wasm_sandbox.load_module(mod_path).unwrap()
};
loaded_wasm_sandbox.unload_module().unwrap();
snapshotter.snapshot()
};
let snapshot = snapshot.into_vec();
if cfg!(feature = "function_call_metrics") {
assert_eq!(snapshot.len(), 10);
} else {
assert_eq!(snapshot.len(), 8);
}
}
}