Add missing docs for diagnostics.rs (#19264)
# Objective Fill in some more missing doc comments. --------- Co-authored-by: Jan Hohenheim <jan@hohenheim.ch>
This commit is contained in:
parent
16a286dac3
commit
523600133d
@ -113,7 +113,9 @@ impl core::fmt::Display for DiagnosticPath {
|
|||||||
/// A single measurement of a [`Diagnostic`].
|
/// A single measurement of a [`Diagnostic`].
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct DiagnosticMeasurement {
|
pub struct DiagnosticMeasurement {
|
||||||
|
/// When this measurement was taken.
|
||||||
pub time: Instant,
|
pub time: Instant,
|
||||||
|
/// Value of the measurement.
|
||||||
pub value: f64,
|
pub value: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,12 +124,14 @@ pub struct DiagnosticMeasurement {
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Diagnostic {
|
pub struct Diagnostic {
|
||||||
path: DiagnosticPath,
|
path: DiagnosticPath,
|
||||||
|
/// Suffix to use when logging measurements for this [`Diagnostic`], for example to show units.
|
||||||
pub suffix: Cow<'static, str>,
|
pub suffix: Cow<'static, str>,
|
||||||
history: VecDeque<DiagnosticMeasurement>,
|
history: VecDeque<DiagnosticMeasurement>,
|
||||||
sum: f64,
|
sum: f64,
|
||||||
ema: f64,
|
ema: f64,
|
||||||
ema_smoothing_factor: f64,
|
ema_smoothing_factor: f64,
|
||||||
max_history_length: usize,
|
max_history_length: usize,
|
||||||
|
/// Disabled [`Diagnostic`]s are not measured or logged.
|
||||||
pub is_enabled: bool,
|
pub is_enabled: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,6 +223,7 @@ impl Diagnostic {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the [`DiagnosticPath`] that identifies this [`Diagnostic`].
|
||||||
pub fn path(&self) -> &DiagnosticPath {
|
pub fn path(&self) -> &DiagnosticPath {
|
||||||
&self.path
|
&self.path
|
||||||
}
|
}
|
||||||
@ -282,10 +287,12 @@ impl Diagnostic {
|
|||||||
self.max_history_length
|
self.max_history_length
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// All measured values from this [`Diagnostic`], up to the configured maximum history length.
|
||||||
pub fn values(&self) -> impl Iterator<Item = &f64> {
|
pub fn values(&self) -> impl Iterator<Item = &f64> {
|
||||||
self.history.iter().map(|x| &x.value)
|
self.history.iter().map(|x| &x.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// All measurements from this [`Diagnostic`], up to the configured maximum history length.
|
||||||
pub fn measurements(&self) -> impl Iterator<Item = &DiagnosticMeasurement> {
|
pub fn measurements(&self) -> impl Iterator<Item = &DiagnosticMeasurement> {
|
||||||
self.history.iter()
|
self.history.iter()
|
||||||
}
|
}
|
||||||
@ -312,10 +319,12 @@ impl DiagnosticsStore {
|
|||||||
self.diagnostics.insert(diagnostic.path.clone(), diagnostic);
|
self.diagnostics.insert(diagnostic.path.clone(), diagnostic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the [`DiagnosticMeasurement`] with the given [`DiagnosticPath`], if it exists.
|
||||||
pub fn get(&self, path: &DiagnosticPath) -> Option<&Diagnostic> {
|
pub fn get(&self, path: &DiagnosticPath) -> Option<&Diagnostic> {
|
||||||
self.diagnostics.get(path)
|
self.diagnostics.get(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Mutably get the [`DiagnosticMeasurement`] with the given [`DiagnosticPath`], if it exists.
|
||||||
pub fn get_mut(&mut self, path: &DiagnosticPath) -> Option<&mut Diagnostic> {
|
pub fn get_mut(&mut self, path: &DiagnosticPath) -> Option<&mut Diagnostic> {
|
||||||
self.diagnostics.get_mut(path)
|
self.diagnostics.get_mut(path)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user