use crate::tx::TxStats;
use std::ops::{AddAssign, Sub};
#[derive(Clone, Debug)]
pub struct Stats {
pub free_page_n: usize,
pub pending_page_n: usize,
pub free_alloc: usize,
pub freelist_in_use: usize,
pub tx_n: usize,
pub open_tx_n: usize,
pub tx_stats: TxStats,
}
impl Default for Stats {
fn default() -> Self {
Self {
free_page_n: 0,
pending_page_n: 0,
free_alloc: 0,
freelist_in_use: 0,
tx_n: 0,
open_tx_n: 0,
tx_stats: Default::default(),
}
}
}
impl Sub for Stats {
type Output = Stats;
fn sub(self, other: Stats) -> Stats {
Stats {
free_page_n: self.free_page_n,
pending_page_n: self.pending_page_n,
free_alloc: self.free_alloc,
freelist_in_use: self.freelist_in_use,
tx_n: self.tx_n - other.tx_n,
open_tx_n: self.open_tx_n - other.open_tx_n,
tx_stats: self.tx_stats.sub(&other.tx_stats),
}
}
}
impl AddAssign for Stats {
fn add_assign(&mut self, other: Stats) {
self.tx_stats += other.tx_stats;
}
}