-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
64 additions
and
7 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
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use std::sync::atomic::{AtomicU64, Ordering}; | ||
|
||
pub(crate) static COUNT_ACTIVE_SEGMENT: AtomicU64 = AtomicU64::new(0); | ||
pub(crate) static COUNT_MMAP_FAILED: AtomicU64 = AtomicU64::new(0); | ||
pub(crate) static COUNT_MUNMAP_FAILED: AtomicU64 = AtomicU64::new(0); | ||
|
||
/// Provides few statistics about low level segment allocation. | ||
/// | ||
/// This stats can be useful to debug or to export in various monitoring | ||
/// systems. | ||
#[derive(Debug, Default)] | ||
pub struct MmapStats; | ||
|
||
impl MmapStats { | ||
/// Get number of current segment mounted by this library. | ||
/// | ||
/// On linux there is a `systctl` limit you can access with: | ||
/// ```shell | ||
/// sysctl vm.max_map_count | ||
/// ``` | ||
pub fn active_segment(&self) -> u64 { | ||
COUNT_ACTIVE_SEGMENT.load(Ordering::Relaxed) | ||
} | ||
|
||
/// Get number of segment creation failed. | ||
pub fn map_failed(&self) -> u64 { | ||
COUNT_MMAP_FAILED.load(Ordering::Relaxed) | ||
} | ||
|
||
/// Get number of segment deletion failed. | ||
pub fn unmap_failed(&self) -> u64 { | ||
COUNT_MUNMAP_FAILED.load(Ordering::Relaxed) | ||
} | ||
} |
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,18 @@ | ||
use mmap_vec::{MmapStats, MmapVec}; | ||
|
||
#[test] | ||
fn test_stats() { | ||
assert_eq!(MmapStats.active_segment(), 0); | ||
assert_eq!(MmapStats.map_failed(), 0); | ||
assert_eq!(MmapStats.unmap_failed(), 0); | ||
|
||
let v = MmapVec::<u8>::with_capacity(500).unwrap(); | ||
assert_eq!(MmapStats.active_segment(), 1); | ||
assert_eq!(MmapStats.map_failed(), 0); | ||
assert_eq!(MmapStats.unmap_failed(), 0); | ||
|
||
drop(v); | ||
assert_eq!(MmapStats.active_segment(), 0); | ||
assert_eq!(MmapStats.map_failed(), 0); | ||
assert_eq!(MmapStats.unmap_failed(), 0); | ||
} |