Skip to content

Add missing docs for diagnostics.rs #19264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions crates/bevy_diagnostic/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ impl core::fmt::Display for DiagnosticPath {
/// A single measurement of a [`Diagnostic`].
#[derive(Debug)]
pub struct DiagnosticMeasurement {
/// When this measurement was taken.
pub time: Instant,
/// Value of the measurement.
pub value: f64,
}

Expand All @@ -122,12 +124,14 @@ pub struct DiagnosticMeasurement {
#[derive(Debug)]
pub struct Diagnostic {
path: DiagnosticPath,
/// Suffix to use when logging measurements for this [`Diagnostic`], for example to show units.
pub suffix: Cow<'static, str>,
history: VecDeque<DiagnosticMeasurement>,
sum: f64,
ema: f64,
ema_smoothing_factor: f64,
max_history_length: usize,
/// Disabled [`Diagnostic`]s are not measured or logged.
pub is_enabled: bool,
}

Expand Down Expand Up @@ -219,6 +223,7 @@ impl Diagnostic {
self
}

/// Get the [`DiagnosticPath`] that identifies this [`Diagnostic`].
pub fn path(&self) -> &DiagnosticPath {
&self.path
}
Expand Down Expand Up @@ -282,10 +287,12 @@ impl Diagnostic {
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> {
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> {
self.history.iter()
}
Expand All @@ -310,10 +317,12 @@ impl DiagnosticsStore {
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> {
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> {
self.diagnostics.get_mut(path)
}
Expand Down