#[non_exhaustive]pub struct Sample { /* private fields */ }Expand description
A single sample within a SampledStat.
Mirrors SampledStat.Sample. Java exposes the fields publicly to
SampledStat subclasses; here a SampledStatKind implementation reads
them through getters and writes the ones Java’s stats write through setters.
Implementations§
Source§impl Sample
impl Sample
Sourcepub fn new(initial_value: f64, now: i64) -> Self
pub fn new(initial_value: f64, now: i64) -> Self
Create a sample with no explicit time window.
§Arguments
initial_value- the value the sample starts fromnow- the start time of the sample, in milliseconds
Sourcepub fn with_time_window_ms(
initial_value: f64,
now: i64,
time_window_ms: i64,
) -> Self
pub fn with_time_window_ms( initial_value: f64, now: i64, time_window_ms: i64, ) -> Self
Create a sample with an explicit time window.
§Arguments
initial_value- the value the sample starts fromnow- the start time of the sample, in millisecondstime_window_ms- the sample’s time window, or-1for the config’s
Sourcepub fn reset(&mut self, now: i64)
pub fn reset(&mut self, now: i64)
Reset the sample for reuse at now, keeping its configured initial value.
§Arguments
now- the new start time of the sample, in milliseconds
Sourcepub fn is_complete(&self, time_ms: i64, config: &MetricConfig) -> bool
pub fn is_complete(&self, time_ms: i64, config: &MetricConfig) -> bool
Returns whether this sample’s window is complete at time_ms.
§Arguments
time_ms- the current POSIX time in millisecondsconfig- the metric’s configuration, giving the event and time windows
Sourcepub fn initial_value(&self) -> f64
pub fn initial_value(&self) -> f64
Returns the initial (reset) value of this sample.
Java’s public Sample.initialValue.
Sourcepub fn event_count(&self) -> i64
pub fn event_count(&self) -> i64
Returns the number of events recorded into this sample.
Java’s public Sample.eventCount.
Sourcepub fn start_time_ms(&self) -> i64
pub fn start_time_ms(&self) -> i64
Returns the time the sample started.
Java’s public Sample.startTimeMs.
Sourcepub fn last_event_ms(&self) -> i64
pub fn last_event_ms(&self) -> i64
Returns the time of the last event recorded into the sample.
Java’s public Sample.lastEventMs.
Sourcepub fn value(&self) -> f64
pub fn value(&self) -> f64
Returns the accumulated value of the sample.
Java’s public Sample.value.
Sourcepub fn time_window_ms(&self) -> i64
pub fn time_window_ms(&self) -> i64
Returns the per-sample time window (or -1 to use the config’s window).
Java’s public Sample.timeWindowMs.
Sourcepub fn set_event_count(&mut self, event_count: i64)
pub fn set_event_count(&mut self, event_count: i64)
Sets the number of events recorded into this sample, as Java’s
SampledStat.record does through the public Sample.eventCount.
§Arguments
event_count- the number of events
Sourcepub fn set_last_event_ms(&mut self, last_event_ms: i64)
pub fn set_last_event_ms(&mut self, last_event_ms: i64)
Sets the time of the last event recorded into the sample, as Java’s
SampledStat.record does through the public Sample.lastEventMs.
§Arguments
last_event_ms- the time of the last event, in milliseconds