Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #657 +/- ##
==========================================
- Coverage 18.77% 18.36% -0.41%
==========================================
Files 66 68 +2
Lines 9752 10017 +265
Branches 516 544 +28
==========================================
+ Hits 1831 1840 +9
- Misses 7921 8177 +256
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| .ok() | ||
| } | ||
|
|
||
| fn parse_smaps_rollup(path: &Path) -> Option<(u64, u64, u64)> { |
There was a problem hiding this comment.
I think take a name for (u64,u64,u64) of Option<(u64,u64,u64)> would be better
There was a problem hiding this comment.
And if possible please add document (I mean kernel doc) reference to here would be better
There was a problem hiding this comment.
| map.into_values().collect() | ||
| } | ||
|
|
||
| fn read_hugepage_pools(root: &Path) -> UResult<Vec<HugePagePool>> { |
There was a problem hiding this comment.
For use case such as root: &Path, you can rewrite it into root: impl AsRef<Path>
| Ok(pools) | ||
| } | ||
|
|
||
| fn read_process_hugepage_usage(root: &Path) -> UResult<Vec<ProcessHugeUsage>> { |
There was a problem hiding this comment.
| number.parse::<u64>().ok() | ||
| } | ||
|
|
||
| fn read_u64(path: impl AsRef<Path>) -> u64 { |
There was a problem hiding this comment.
wow, you already knew about it :) https://github.com/uutils/procps/pull/657/changes#r2992646221
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use std::io::Write; | ||
|
|
||
| #[test] | ||
| fn parse_hugepage_name_works() { | ||
| assert_eq!(parse_hugepage_dir_name("hugepages-2048kB"), Some(2048)); | ||
| assert_eq!( | ||
| parse_hugepage_dir_name("hugepages-1048576kB"), | ||
| Some(1_048_576) | ||
| ); | ||
| assert_eq!(parse_hugepage_dir_name("hugepages-foo"), None); | ||
| } | ||
|
|
||
| #[test] | ||
| fn parse_smaps_rollup_works() { | ||
| let dir = tempfile::tempdir().unwrap(); | ||
| let file = dir.path().join("smaps_rollup"); | ||
| let mut f = fs::File::create(&file).unwrap(); | ||
| writeln!(f, "AnonHugePages: 512 kB").unwrap(); | ||
| writeln!(f, "Shared_Hugetlb: 64 kB").unwrap(); | ||
| writeln!(f, "Private_Hugetlb: 32 kB").unwrap(); | ||
|
|
||
| assert_eq!(parse_smaps_rollup(&file), Some((512, 64, 32))); | ||
| } | ||
|
|
||
| #[test] | ||
| fn reads_pools_from_tree() { | ||
| let dir = tempfile::tempdir().unwrap(); | ||
| let pool = dir.path().join("hugepages-2048kB"); | ||
| fs::create_dir(&pool).unwrap(); | ||
| fs::write(pool.join("nr_hugepages"), "10\n").unwrap(); | ||
| fs::write(pool.join("free_hugepages"), "3\n").unwrap(); | ||
| fs::write(pool.join("resv_hugepages"), "2\n").unwrap(); | ||
| fs::write(pool.join("surplus_hugepages"), "1\n").unwrap(); | ||
|
|
||
| let pools = read_hugepage_pools(dir.path()).unwrap(); | ||
| assert_eq!(pools.len(), 1); | ||
| assert_eq!(pools[0].size_kb, 2048); | ||
| assert_eq!(pools[0].total_pages, 10); | ||
| assert_eq!(pools[0].free_pages, 3); | ||
| } | ||
| } |
There was a problem hiding this comment.
Those tests only works on Linux I think, you can add #[cfg(target_os = "linux")]
| fn supports_lines_option() { | ||
| new_ucmd!().arg("-l").arg("1").succeeds(); | ||
| } | ||
|
|
||
| #[test] | ||
| fn supports_numa_option() { | ||
| new_ucmd!().arg("-n").succeeds(); | ||
| } |
There was a problem hiding this comment.
The hugetop command displays system-wide hugepage informantion as well as per-process hugepage information.
Add feature: #244