Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #100 - obtain timestamp early #120

Merged
merged 2 commits into from
Nov 1, 2023
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
10 changes: 8 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,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();
Expand Down Expand Up @@ -102,10 +108,10 @@ fn main() {
};
if *batchless {
let mut jm = batchless::BatchlessJobManager::new();
ps::create_snapshot(&mut jm, &opts);
ps::create_snapshot(&mut jm, &opts, &timestamp);
} else {
let mut jm = slurm::SlurmJobManager {};
ps::create_snapshot(&mut jm, &opts);
ps::create_snapshot(&mut jm, &opts, &timestamp);
}
}
Commands::Analyze {} => {
Expand Down
7 changes: 3 additions & 4 deletions src/ps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::jobs;
use crate::nvidia;
use crate::process;
use crate::procfs;
use crate::util::three_places;
use crate::procfsapi;
use crate::util::{three_places, time_iso8601};

use csv::{Writer, WriterBuilder};
use std::collections::{HashMap, HashSet};
Expand Down Expand Up @@ -163,7 +163,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();

Expand Down Expand Up @@ -313,13 +313,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: &timestamp,
timestamp: timestamp,
num_cores,
version: VERSION,
opts,
Expand Down