interoptopus 0.16.0

The polyglot bindings generator for your library (C#, C, Python, ...). 🐙
Documentation
//! Per-call telemetry for plugins.
//!
//! Every plugin generated by `plugin!` embeds a metric recorder that can record
//! wall-clock durations for sync and async call. Recording is disabled by default,
//! but can be enabled at runtime through the [`Metrics`] trait.
//!
//! Internally each function slot maps to a fixed-size ring buffer that
//! stores the last durations without heap allocation on the hot path.
//!
//! # Usage
//!
//! ```
//! # use interoptopus::plugin;
//! # use crate::interoptopus::telemetry::Metrics;
//! // Define a plugin
//! plugin!(MyService {
//!     fn foo();
//! });
//!
//! # fn f(plugin: &MyService) {
//! // Enable recording
//! plugin.metrics_enable(true);
//!
//! // Call plugin
//! plugin.foo();
//!
//! // Retrieve report
//! let report = plugin.metrics_report();
//! # }
//! ```
mod metrics;
mod report;
mod ringbuffer;

const MAX_RECORDED_DURATIONS: usize = 16 * 1024;

pub use metrics::MetricsRecorder;
pub use report::{FunctionReport, Report};

/// A trait for things that can record performance metrics.
pub trait Metrics {
    fn metrics_report(&self) -> Report;
    fn metrics_enable(&self, enabled: bool);
}