mirror of
https://github.com/uutils/procps.git
synced 2026-06-10 16:14:00 -07:00
vmstat: implement --forks
This commit is contained in:
@@ -26,6 +26,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let matches = uu_app().try_get_matches_from(args)?;
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
if matches.get_flag("forks") {
|
||||
return print_forks();
|
||||
}
|
||||
if matches.get_flag("stats") {
|
||||
return print_stats();
|
||||
}
|
||||
@@ -83,6 +86,16 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn print_forks() -> UResult<()> {
|
||||
let data = get_stats();
|
||||
|
||||
let fork_data = data.last().unwrap();
|
||||
println!("{:>13} {}", fork_data.1, fork_data.0);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn print_stats() -> UResult<()> {
|
||||
let data = get_stats();
|
||||
@@ -177,10 +190,13 @@ pub fn uu_app() -> Command {
|
||||
.required(false)
|
||||
.value_parser(value_parser!(u64)),
|
||||
arg!(-a --active "Display active and inactive memory"),
|
||||
// arg!(-f --forks "switch displays the number of forks since boot"),
|
||||
arg!(-m --slabs "Display slabinfo"),
|
||||
arg!(-f --forks "switch displays the number of forks since boot")
|
||||
.conflicts_with_all(["slabs", "stats", /*"disk", "disk-sum", "partition"*/]),
|
||||
arg!(-m --slabs "Display slabinfo")
|
||||
.conflicts_with_all(["forks", "stats", /*"disk", "disk-sum", "partition"*/]),
|
||||
arg!(-n --"one-header" "Display the header only once rather than periodically"),
|
||||
arg!(-s --stats "Displays a table of various event counters and memory statistics"),
|
||||
arg!(-s --stats "Displays a table of various event counters and memory statistics")
|
||||
.conflicts_with_all(["forks", "slabs", /*"disk", "disk-sum", "partition"*/]),
|
||||
// arg!(-d --disk "Report disk statistics"),
|
||||
// arg!(-D --"disk-sum" "Report some summary statistics about disk activity"),
|
||||
// arg!(-p --partition <device> "Detailed statistics about partition"),
|
||||
|
||||
@@ -19,6 +19,11 @@ fn test_invalid_arg() {
|
||||
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conflict_arg() {
|
||||
new_ucmd!().args(&["-s", "-m"]).fails().code_is(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid_number() {
|
||||
new_ucmd!().arg("-1").fails().code_is(1);
|
||||
|
||||
Reference in New Issue
Block a user