pub struct OperationStats {
pub count: u64,
pub total_duration_ms: f64,
pub min_duration_ms: f64,
pub max_duration_ms: f64,
pub avg_duration_ms: f64,
}Expand description
Performance statistics for a profiled operation.
§Examples
use chie_shared::OperationStats;
// Track 100 database queries
let stats = OperationStats::new(100, 5000.0, 10.0, 200.0);
// Analyze performance
assert_eq!(stats.avg_duration_ms, 50.0);
assert_eq!(stats.ops_per_second(), 20.0);
// Check if operations are slow (> 100ms threshold)
assert!(!stats.is_slow(100.0));
// Get percentile estimates
assert_eq!(stats.p50_estimate_ms(), 50.0);
assert_eq!(stats.p99_estimate_ms(), 200.0);
// Convert to seconds
assert_eq!(stats.total_duration_secs(), 5.0);Fields§
§count: u64Number of times the operation was executed.
total_duration_ms: f64Total time spent in milliseconds.
min_duration_ms: f64Minimum execution time in milliseconds.
max_duration_ms: f64Maximum execution time in milliseconds.
avg_duration_ms: f64Average execution time in milliseconds.
Implementations§
Source§impl OperationStats
impl OperationStats
Sourcepub fn new(
count: u64,
total_duration_ms: f64,
min_duration_ms: f64,
max_duration_ms: f64,
) -> Self
pub fn new( count: u64, total_duration_ms: f64, min_duration_ms: f64, max_duration_ms: f64, ) -> Self
Create new operation statistics.
Sourcepub fn ops_per_second(&self) -> f64
pub fn ops_per_second(&self) -> f64
Get operations per second based on total time.
Sourcepub fn p99_estimate_ms(&self) -> f64
pub fn p99_estimate_ms(&self) -> f64
Get p99 estimate (uses max as approximation).
Sourcepub fn p50_estimate_ms(&self) -> f64
pub fn p50_estimate_ms(&self) -> f64
Get p50 estimate (uses avg as approximation).
Sourcepub fn total_duration_secs(&self) -> f64
pub fn total_duration_secs(&self) -> f64
Get total time in seconds.
Trait Implementations§
Source§impl Clone for OperationStats
impl Clone for OperationStats
Source§fn clone(&self) -> OperationStats
fn clone(&self) -> OperationStats
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for OperationStats
impl Debug for OperationStats
Source§impl Default for OperationStats
impl Default for OperationStats
Source§impl<'de> Deserialize<'de> for OperationStats
impl<'de> Deserialize<'de> for OperationStats
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for OperationStats
impl PartialEq for OperationStats
Source§impl Serialize for OperationStats
impl Serialize for OperationStats
impl StructuralPartialEq for OperationStats
Auto Trait Implementations§
impl Freeze for OperationStats
impl RefUnwindSafe for OperationStats
impl Send for OperationStats
impl Sync for OperationStats
impl Unpin for OperationStats
impl UnwindSafe for OperationStats
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
Mutably borrows from an owned value. Read more