Skip to content

Commit fbbe063

Browse files
authored
Merge pull request #475 from Bluemangoo/feature/vmstat-forks
vmstat: implement `--forks`
2 parents 1c8283b + 6a64f1b commit fbbe063

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/uu/vmstat/src/vmstat.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
2626
let matches = uu_app().try_get_matches_from(args)?;
2727
#[cfg(target_os = "linux")]
2828
{
29+
if matches.get_flag("forks") {
30+
return print_forks();
31+
}
2932
if matches.get_flag("stats") {
3033
return print_stats();
3134
}
@@ -83,6 +86,16 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
8386
Ok(())
8487
}
8588

89+
#[cfg(target_os = "linux")]
90+
fn print_forks() -> UResult<()> {
91+
let data = get_stats();
92+
93+
let fork_data = data.last().unwrap();
94+
println!("{:>13} {}", fork_data.1, fork_data.0);
95+
96+
Ok(())
97+
}
98+
8699
#[cfg(target_os = "linux")]
87100
fn print_stats() -> UResult<()> {
88101
let data = get_stats();
@@ -177,10 +190,13 @@ pub fn uu_app() -> Command {
177190
.required(false)
178191
.value_parser(value_parser!(u64)),
179192
arg!(-a --active "Display active and inactive memory"),
180-
// arg!(-f --forks "switch displays the number of forks since boot"),
181-
arg!(-m --slabs "Display slabinfo"),
193+
arg!(-f --forks "switch displays the number of forks since boot")
194+
.conflicts_with_all(["slabs", "stats", /*"disk", "disk-sum", "partition"*/]),
195+
arg!(-m --slabs "Display slabinfo")
196+
.conflicts_with_all(["forks", "stats", /*"disk", "disk-sum", "partition"*/]),
182197
arg!(-n --"one-header" "Display the header only once rather than periodically"),
183-
arg!(-s --stats "Displays a table of various event counters and memory statistics"),
198+
arg!(-s --stats "Displays a table of various event counters and memory statistics")
199+
.conflicts_with_all(["forks", "slabs", /*"disk", "disk-sum", "partition"*/]),
184200
// arg!(-d --disk "Report disk statistics"),
185201
// arg!(-D --"disk-sum" "Report some summary statistics about disk activity"),
186202
// arg!(-p --partition <device> "Detailed statistics about partition"),

tests/by-util/test_vmstat.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ fn test_invalid_arg() {
1919
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
2020
}
2121

22+
#[test]
23+
fn test_conflict_arg() {
24+
new_ucmd!().args(&["-s", "-m"]).fails().code_is(1);
25+
}
26+
2227
#[test]
2328
fn test_invalid_number() {
2429
new_ucmd!().arg("-1").fails().code_is(1);

0 commit comments

Comments
 (0)