Gauge

Struct Gauge 

Source
#[repr(align(64))]
pub struct Gauge { /* private fields */ }
Expand description

Ultra-fast atomic gauge for f64 values

Uses IEEE 754 bit manipulation for atomic operations on floating-point values. Cache-line aligned to prevent false sharing.

Implementations§

Source§

impl Gauge

Source

pub fn new() -> Self

Create new gauge starting at zero

Source

pub fn with_value(initial: f64) -> Self

Create gauge with initial value

Source

pub fn set(&self, value: f64)

Set gauge value - THE FASTEST PATH

This is optimized for maximum speed:

  • Convert f64 to IEEE 754 bits
  • Single atomic store instruction
  • Relaxed memory ordering for speed
  • Inlined for zero function call overhead
Source

pub fn get(&self) -> f64

Get current value - single atomic load

Source

pub fn add(&self, delta: f64)

Add to current value - atomic read-modify-write loop

Uses compare-and-swap loop for lock-free addition

Source

pub fn sub(&self, delta: f64)

Subtract from current value

Source

pub fn set_max(&self, value: f64)

Set to maximum of current value and new value

Source

pub fn set_min(&self, value: f64)

Set to minimum of current value and new value

Source

pub fn compare_and_swap(&self, expected: f64, new: f64) -> Result<f64, f64>

Atomic compare-and-swap

Returns Ok(previous_value) if successful, Err(current_value) if failed

Source

pub fn reset(&self)

Reset to zero

Source

pub fn multiply(&self, factor: f64)

Multiply current value by factor

Source

pub fn divide(&self, divisor: f64)

Divide current value by divisor

Source

pub fn abs(&self)

Set to absolute value of current value

Source

pub fn clamp(&self, min: f64, max: f64)

Clamp value to range [min, max]

Source

pub fn update_ema(&self, sample: f64, alpha: f64)

Exponential moving average update

new_value = alpha * sample + (1 - alpha) * old_value

Source

pub fn stats(&self) -> GaugeStats

Get comprehensive statistics

Source

pub fn age(&self) -> Duration

Get age since creation

Source

pub fn is_zero(&self) -> bool

Check if gauge is zero

Source

pub fn is_positive(&self) -> bool

Check if value is positive

Source

pub fn is_negative(&self) -> bool

Check if value is negative

Source

pub fn is_finite(&self) -> bool

Check if value is finite (not NaN or infinity)

Trait Implementations§

Source§

impl Debug for Gauge

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Gauge

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Gauge

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Send for Gauge

Source§

impl Sync for Gauge

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.