Skip to content

Commit 5380b4a

Browse files
authored
Merge pull request #120 from lars-t-hansen/w-100-early-timestamp
Fix #100 - obtain timestamp early
2 parents 79a3889 + 74e78dd commit 5380b4a

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/main.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ enum Commands {
6767
}
6868

6969
fn main() {
70+
// Obtain the time stamp early so that it more properly reflects the time the sample was
71+
// obtained, not the time when reporting was allowed to run. The latter is subject to greater
72+
// system effects, and using that timestamp increases the risk that the samples' timestamp order
73+
// improperly reflects the true order in which they were obtained. See #100.
74+
let timestamp = util::time_iso8601();
75+
7076
env_logger::init();
7177

7278
let cli = Cli::parse();
@@ -102,10 +108,10 @@ fn main() {
102108
};
103109
if *batchless {
104110
let mut jm = batchless::BatchlessJobManager::new();
105-
ps::create_snapshot(&mut jm, &opts);
111+
ps::create_snapshot(&mut jm, &opts, &timestamp);
106112
} else {
107113
let mut jm = slurm::SlurmJobManager {};
108-
ps::create_snapshot(&mut jm, &opts);
114+
ps::create_snapshot(&mut jm, &opts, &timestamp);
109115
}
110116
}
111117
Commands::Analyze {} => {

src/ps.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use crate::jobs;
99
use crate::nvidia;
1010
use crate::process;
1111
use crate::procfs;
12+
use crate::util::three_places;
1213
use crate::procfsapi;
13-
use crate::util::{three_places, time_iso8601};
1414

1515
use csv::{Writer, WriterBuilder};
1616
use std::collections::{HashMap, HashSet};
@@ -163,7 +163,7 @@ pub struct PsOptions<'a> {
163163
pub exclude_commands: Vec<&'a str>,
164164
}
165165

166-
pub fn create_snapshot(jobs: &mut dyn jobs::JobManager, opts: &PsOptions) {
166+
pub fn create_snapshot(jobs: &mut dyn jobs::JobManager, opts: &PsOptions, timestamp: &str) {
167167
let no_gpus = empty_gpuset();
168168
let mut proc_by_pid = ProcTable::new();
169169

@@ -313,13 +313,12 @@ pub fn create_snapshot(jobs: &mut dyn jobs::JobManager, opts: &PsOptions) {
313313
.flexible(true)
314314
.from_writer(io::stdout());
315315

316-
let timestamp = time_iso8601();
317316
let hostname = hostname::get().unwrap().into_string().unwrap();
318317
let num_cores = num_cpus::get();
319318
const VERSION: &str = env!("CARGO_PKG_VERSION");
320319
let print_params = PrintParameters {
321320
hostname: &hostname,
322-
timestamp: &timestamp,
321+
timestamp: timestamp,
323322
num_cores,
324323
version: VERSION,
325324
opts,

0 commit comments

Comments
 (0)