report mem stats (#21258) (#22066)

(cherry picked from commit f8dcb2f38b)

# Conflicts:
#	Cargo.lock
#	core/Cargo.toml
#	core/src/system_monitor_service.rs
#	runtime/src/bucket_map_holder_stats.rs

Co-authored-by: Jeff Washington (jwash) <75863576+jeffwashington@users.noreply.github.com>
This commit is contained in:
mergify[bot]
2021-12-23 18:16:56 +00:00
committed by GitHub
parent cf34ae7d6f
commit 17d698d20a
4 changed files with 81 additions and 12 deletions

View File

@@ -32,6 +32,7 @@ pub fn duration_as_s(d: &Duration) -> f32 {
d.as_secs() as f32 + (d.subsec_nanos() as f32 / 1_000_000_000.0)
}
/// return timestamp as ms
pub fn timestamp() -> u64 {
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
@@ -70,14 +71,18 @@ pub struct AtomicInterval {
}
impl AtomicInterval {
pub fn should_update(&self, interval_time: u64) -> bool {
self.should_update_ext(interval_time, true)
/// true if 'interval_time_ms' has elapsed since last time we returned true as long as it has been 'interval_time_ms' since this struct was created
pub fn should_update(&self, interval_time_ms: u64) -> bool {
self.should_update_ext(interval_time_ms, true)
}
pub fn should_update_ext(&self, interval_time: u64, skip_first: bool) -> bool {
/// a primary use case is periodic metric reporting, potentially from different threads
/// true if 'interval_time_ms' has elapsed since last time we returned true
/// except, if skip_first=false, false until 'interval_time_ms' has elapsed since this struct was created
pub fn should_update_ext(&self, interval_time_ms: u64, skip_first: bool) -> bool {
let now = timestamp();
let last = self.last_update.load(Ordering::Relaxed);
now.saturating_sub(last) > interval_time
now.saturating_sub(last) > interval_time_ms
&& self
.last_update
.compare_exchange(last, now, Ordering::Relaxed, Ordering::Relaxed)