-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add --track-peak-rss to daemon (#2696)
- Loading branch information
1 parent
0f0a9c3
commit e499495
Showing
10 changed files
with
96 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ pub mod encoding; | |
pub mod io; | ||
pub mod json; | ||
pub mod macros; | ||
pub mod monitoring; | ||
pub mod net; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2019-2023 ChainSafe Systems | ||
// SPDX-License-Identifier: Apache-2.0, MIT | ||
|
||
use std::{ | ||
sync::atomic::{self, AtomicBool, AtomicUsize}, | ||
time::Duration, | ||
}; | ||
|
||
use human_repr::HumanCount; | ||
use log::info; | ||
use memory_stats::memory_stats; | ||
|
||
pub struct MemStatsTracker { | ||
check_interval: Duration, | ||
peak_physical_mem: AtomicUsize, | ||
cancelled: AtomicBool, | ||
} | ||
|
||
impl MemStatsTracker { | ||
pub fn new(check_interval: Duration) -> Self { | ||
assert!(check_interval > Duration::default()); | ||
|
||
Self { | ||
check_interval, | ||
peak_physical_mem: Default::default(), | ||
cancelled: Default::default(), | ||
} | ||
} | ||
|
||
/// A blocking loop that records peak RRS periodically | ||
pub async fn run_loop(&self) { | ||
while !self.cancelled.load(atomic::Ordering::Relaxed) { | ||
if let Some(usage) = memory_stats() { | ||
self.peak_physical_mem | ||
.fetch_max(usage.physical_mem, atomic::Ordering::Relaxed); | ||
} | ||
tokio::time::sleep(self.check_interval).await; | ||
} | ||
} | ||
} | ||
|
||
impl Default for MemStatsTracker { | ||
fn default() -> Self { | ||
Self::new(Duration::from_millis(1000)) | ||
} | ||
} | ||
|
||
impl Drop for MemStatsTracker { | ||
fn drop(&mut self) { | ||
self.cancelled.store(true, atomic::Ordering::Relaxed); | ||
info!( | ||
"Peak physical memory usage: {}", | ||
self.peak_physical_mem | ||
.load(atomic::Ordering::Relaxed) | ||
.human_count_bytes() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Copyright 2019-2023 ChainSafe Systems | ||
// SPDX-License-Identifier: Apache-2.0, MIT | ||
|
||
mod mem_tracker; | ||
pub use mem_tracker::*; |