solana/metrics/src/lib.rs

85 lines
2.4 KiB
Rust
Raw Normal View History

#![allow(clippy::arithmetic_side_effects)]
pub mod counter;
pub mod datapoint;
pub mod metrics;
Poh timing service (#23736) * initial work for poh timing report service * add poh_timing_report_service to validator * fix comments * clippy * imrove test coverage * delete record when complete * rename shred full to slot full. * debug logging * fix slot full * remove debug comments * adding fmt trait * derive default * default for poh timing reporter * better comments * remove commented code * fix test * more test fixes * delete timestamps for slot that are older than root_slot * debug log * record poh start end in bank reset * report full to start time instead * fix poh slot offset * report poh start for normal ticks * fix typo * refactor out poh point report fn * rename * optimize delete - delete only when last_root changed * change log level to trace * convert if to match * remove redudant check * fix SlotPohTiming comments * review feedback on poh timing reporter * review feedback on poh_recorder * add test case for out-of-order arrival of timing points and incomplete timing points * refactor poh_timing_points into its own mod * remove option for poh_timing_report service * move poh_timing_point_sender to constructor * clippy * better comments * more clippy * more clippy * add slot poh timing point macro * clippy * assert in test * comments and display fmt * fix check * assert format * revise comments * refactor * extrac send fn * revert reporting_poh_timing_point * align loggin * small refactor * move type declaration to the top of the module * replace macro with constructor * clippy: remove redundant closure * review comments * simplify poh timing point creation Co-authored-by: Haoran Yi <hyi@Haorans-MacBook-Air.local>
2022-03-30 07:04:49 -07:00
pub mod poh_timing_point;
pub use crate::metrics::{flush, query, set_host_id, set_panic_hook, submit};
use std::sync::{
atomic::{AtomicU64, Ordering},
Arc,
};
// To track an external counter which cannot be reset and is always increasing
#[derive(Default)]
pub struct MovingStat {
value: AtomicU64,
}
impl MovingStat {
pub fn update_stat(&self, old_value: &MovingStat, new_value: u64) {
let old = old_value.value.swap(new_value, Ordering::Acquire);
self.value
.fetch_add(new_value.saturating_sub(old), Ordering::Release);
}
pub fn load_and_reset(&self) -> u64 {
self.value.swap(0, Ordering::Acquire)
}
}
/// A helper that sends the count of created tokens as a datapoint.
#[allow(clippy::redundant_allocation)]
pub struct TokenCounter(Arc<&'static str>);
impl TokenCounter {
/// Creates a new counter with the specified metrics `name`.
pub fn new(name: &'static str) -> Self {
Self(Arc::new(name))
}
/// Creates a new token for this counter. The metric's value will be equal
/// to the number of `CounterToken`s.
pub fn create_token(&self) -> CounterToken {
// new_count = strong_count
// - 1 (in TokenCounter)
// + 1 (token that's being created)
datapoint_info!(*self.0, ("count", Arc::strong_count(&self.0), i64));
CounterToken(self.0.clone())
}
}
/// A token for `TokenCounter`.
#[allow(clippy::redundant_allocation)]
pub struct CounterToken(Arc<&'static str>);
impl Clone for CounterToken {
fn clone(&self) -> Self {
// new_count = strong_count
// - 1 (in TokenCounter)
// + 1 (token that's being created)
datapoint_info!(*self.0, ("count", Arc::strong_count(&self.0), i64));
CounterToken(self.0.clone())
}
}
impl Drop for CounterToken {
fn drop(&mut self) {
// new_count = strong_count
// - 1 (in TokenCounter, if it still exists)
// - 1 (token that's being dropped)
datapoint_info!(
*self.0,
("count", Arc::strong_count(&self.0).saturating_sub(2), i64)
);
}
}
impl Drop for TokenCounter {
fn drop(&mut self) {
datapoint_info!(
*self.0,
("count", Arc::strong_count(&self.0).saturating_sub(2), i64)
);
}
}