From 357972f0f24aac67252f52a40d06260fd6799213 Mon Sep 17 00:00:00 2001 From: Lars T Hansen Date: Fri, 27 Oct 2023 10:25:41 +0200 Subject: [PATCH] Fix #100 - obtain timestamp early --- src/main.rs | 10 ++++++++-- src/ps.rs | 7 +++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 98e129b..f5c6f1f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -66,6 +66,12 @@ enum Commands { } fn main() { + // Obtain the time stamp early so that it more properly reflects the time the sample was + // obtained, not the time when reporting was allowed to run. The latter is subject to greater + // system effects, and using that timestamp increases the risk that the samples' timestamp order + // improperly reflects the true order in which they were obtained. See #100. + let timestamp = util::time_iso8601(); + env_logger::init(); let cli = Cli::parse(); @@ -101,10 +107,10 @@ fn main() { }; if *batchless { let mut jm = batchless::BatchlessJobManager::new(); - ps::create_snapshot(&mut jm, &opts); + ps::create_snapshot(&mut jm, &opts, ×tamp); } else { let mut jm = slurm::SlurmJobManager {}; - ps::create_snapshot(&mut jm, &opts); + ps::create_snapshot(&mut jm, &opts, ×tamp); } } Commands::Analyze {} => { diff --git a/src/ps.rs b/src/ps.rs index a02deae..45a19ca 100644 --- a/src/ps.rs +++ b/src/ps.rs @@ -9,7 +9,7 @@ use crate::jobs; use crate::nvidia; use crate::process; use crate::procfs; -use crate::util::{three_places, time_iso8601}; +use crate::util::three_places; use csv::{Writer, WriterBuilder}; use std::collections::{HashMap, HashSet}; @@ -162,7 +162,7 @@ pub struct PsOptions<'a> { pub exclude_commands: Vec<&'a str>, } -pub fn create_snapshot(jobs: &mut dyn jobs::JobManager, opts: &PsOptions) { +pub fn create_snapshot(jobs: &mut dyn jobs::JobManager, opts: &PsOptions, timestamp: &str) { let no_gpus = empty_gpuset(); let mut proc_by_pid = ProcTable::new(); @@ -309,13 +309,12 @@ pub fn create_snapshot(jobs: &mut dyn jobs::JobManager, opts: &PsOptions) { .flexible(true) .from_writer(io::stdout()); - let timestamp = time_iso8601(); let hostname = hostname::get().unwrap().into_string().unwrap(); let num_cores = num_cpus::get(); const VERSION: &str = env!("CARGO_PKG_VERSION"); let print_params = PrintParameters { hostname: &hostname, - timestamp: ×tamp, + timestamp: timestamp, num_cores, version: VERSION, opts,