Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/uu/vmstat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ version.workspace = true

[dependencies]
bytesize = { workspace = true }
chrono = { workspace = true, default-features = false, features = ["clock"] }
clap = { workspace = true }
terminal_size = { workspace = true }
uucore = { workspace = true }
uucore = { workspace = true, features = ["custom-tz-fmt"] }

[lib]
path = "src/vmstat.rs"
Expand Down
27 changes: 25 additions & 2 deletions src/uu/vmstat/src/picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub type Picker = (
#[cfg(target_os = "linux")]
pub fn get_pickers(matches: &ArgMatches) -> Vec<Picker> {
let wide = matches.get_flag("wide");
vec![
let mut pickers = vec![
concat_helper(
if wide {
("--procs--".into(), " r b".into())
Expand Down Expand Up @@ -62,7 +62,18 @@ pub fn get_pickers(matches: &ArgMatches) -> Vec<Picker> {
},
get_cpu_info,
),
]
];
if matches.get_flag("timestamp") {
pickers.push(concat_helper(
(
"-----timestamp-----".into(),
format!("{:>19}", uucore::custom_tz_fmt::custom_time_format("%Z")),
),
get_timestamp,
));
}

pickers
}

#[cfg(target_os = "linux")]
Expand Down Expand Up @@ -267,3 +278,15 @@ fn get_cpu_info(
(len, format!("{:.0}", cpu_load.guest)),
]
}

#[cfg(target_os = "linux")]
fn get_timestamp(
_proc_data: &ProcData,
_proc_data_before: Option<&ProcData>,
_matches: &ArgMatches,
) -> Vec<(usize, String)> {
vec![(
10,
chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string(),
)]
}
2 changes: 1 addition & 1 deletion src/uu/vmstat/src/vmstat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub fn uu_app() -> Command {
// arg!(-D --"disk-sum" "Report some summary statistics about disk activity"),
// arg!(-p --partition <device> "Detailed statistics about partition"),
arg!(-S --unit <character> "Switches outputs between 1000 (k), 1024 (K), 1000000 (m), or 1048576 (M) bytes"),
// arg!(-t --timestamp "Append timestamp to each line"),
arg!(-t --timestamp "Append timestamp to each line"),
arg!(-w --wide "Wide output mode"),
arg!(-y --"no-first" "Omits first report with statistics since system boot"),
])
Expand Down
12 changes: 12 additions & 0 deletions tests/by-util/test_vmstat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,15 @@ fn test_active() {
.unwrap()
.contains("active"));
}

#[test]
#[cfg(target_os = "linux")]
fn test_timestamp() {
let result = new_ucmd!().arg("-t").succeeds();
assert!(result
.stdout_str()
.lines()
.next()
.unwrap()
.contains("timestamp"));
}
Loading