Skip to content
This repository has been archived by the owner on Jul 11, 2019. It is now read-only.

Commit

Permalink
0.10.3: Implement --joblog-8601 Parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
mmstick committed Jan 16, 2017
1 parent b5e61d5 commit c25d34a
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "parallel"
version = "0.10.2"
version = "0.10.3"
authors = ["Michael Aaron Murphy <mmstickman@gmail.com>"]
license = "MIT"
description = "Command-line CPU load balancer for executing jobs in parallel"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ operates:
- **-h**, **--help**: Prints the manual for the application (recommended to pipe it to `less`).
- **-j**, **--jobs**: Defines the number of jobs/threads to run in parallel.
- **--joblog**: Logs job statistics to a designated file as they are completed.
- **--joblog-8601**: Writes the start time in the ISO 8601 format: `YYYY-MM-DD hh:mm:ss`
- **--memfree**: Defines the minimum amount of memory available before starting the next job.
- **-n**, **--max-args**: Groups up to a certain number of arguments together in the same command line.
- **--num-cpu-cores**: Prints the number of CPU cores in the system and exits.
Expand Down
3 changes: 3 additions & 0 deletions src/arguments/man.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ OPTIONS
--joblog:
Logs job statistics to a designated file as they are completed.
--joblog-8601:
Writes the start time in the ISO 8601 format: `YYYY-MM-DD hh:mm:ss`
--memfree:
Defines the minimum amount of memory available before starting the next job.
Expand Down
4 changes: 3 additions & 1 deletion src/arguments/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub const DRY_RUN: u16 = 64;
pub const SHELL_QUOTE: u16 = 128;
pub const ETA: u16 = 256;
pub const JOBLOG: u16 = 512;
pub const JOBLOG_8601: u16 = 1024;

/// `Args` is a collection of critical options and arguments that were collected at
/// startup of the application.
Expand Down Expand Up @@ -142,6 +143,7 @@ impl Args {
index += 1;
self.flags |= JOBLOG;
},
"joblog-8601" => self.flags |= JOBLOG_8601,
"jobs" => {
let val = arguments.get(index).ok_or(ParseErr::JobsNoValue)?;
self.ncores = jobs::parse(val)?;
Expand Down Expand Up @@ -172,7 +174,7 @@ impl Args {
},
"verbose" => self.flags |= VERBOSE_MODE,
"version" => {
println!("MIT/Rust Parallel 0.10.1\n");
println!("MIT/Rust Parallel 0.10.3\n");
exit(0);
},
"tmpdir" | "tempdir" => {
Expand Down
1 change: 1 addition & 0 deletions src/execute/exec_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ impl ExecCommands {
runtime: runtime.num_nanoseconds().unwrap_or(0) as u64,
exit_value: exit_value,
signal: signal,
flags: self.flags,
command: command_buffer.clone(),
}));
}
Expand Down
1 change: 1 addition & 0 deletions src/execute/exec_inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl ExecInputs {
runtime: runtime.num_nanoseconds().unwrap_or(0) as u64,
exit_value: exit_value,
signal: signal,
flags: flags,
command: input.clone(),
}));
}
Expand Down
57 changes: 36 additions & 21 deletions src/execute/job_log.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use arguments::JOBLOG_8601;
use misc::NumToA;
use std::fs::File;
use std::io::{Write, BufWriter};
use time::Timespec;
use time::{at, Timespec};

// Each `JobLog` consists of a single job's statistics ready to be written to the job log file.
pub struct JobLog {
Expand All @@ -15,6 +16,8 @@ pub struct JobLog {
pub exit_value: i32,
/// The `signal` contains a non-zero value if the job was killed by a signal
pub signal: i32,
/// Contains the configuration parameters for the joblog
pub flags: u16,
/// The actual `command` that was executed for this job
pub command: String
}
Expand All @@ -30,29 +33,37 @@ impl JobLog {
let _ = joblog.write(b" ");
}

// 2: StartTime in seconds, with up to two decimal places
let bytes_written = self.start_time.sec.numtoa(10, id_buffer);
let _ = joblog.write(&id_buffer[0..bytes_written]);
let _ = joblog.write(b".");
let decimal = (self.start_time.nsec % 1_000_000_000) / 1_000_000;
if decimal == 0 {
let _ = joblog.write(b"000");
// 2: StartTime
if self.flags & JOBLOG_8601 != 0 {
// ISO 8601 representation of the time
let tm = at(self.start_time);
let message = format!("{}-{:02}-{:02} {:02}:{:02}:{:02} ", 1900+tm.tm_year, 1+tm.tm_mon,
tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
let _ = joblog.write(message.as_bytes());

} else {
let bytes_written = decimal.numtoa(10, id_buffer);
match bytes_written {
1 => { let _ = joblog.write(b"00"); },
2 => { let _ = joblog.write(b"0"); },
_ => (),
};
// Represented in seconds, with two decimal places
let bytes_written = self.start_time.sec.numtoa(10, id_buffer);
let _ = joblog.write(&id_buffer[0..bytes_written]);
}
for _ in 0..16-(bytes_written+4) {
let _ = joblog.write(b" ");
let _ = joblog.write(b".");
let decimal = (self.start_time.nsec % 1_000_000_000) / 1_000_000;
if decimal == 0 {
let _ = joblog.write(b"000");
} else {
let bytes_written = decimal.numtoa(10, id_buffer);
match bytes_written {
1 => { let _ = joblog.write(b"00"); },
2 => { let _ = joblog.write(b"0"); },
_ => (),
};
let _ = joblog.write(&id_buffer[0..bytes_written]);
}
let _ = joblog.write(b" ");
}

// 3: Runtime in seconds, with up to three decimal places.
let bytes_written = (self.runtime / 1_000_000_000).numtoa(10, id_buffer);
for _ in 0..10-(bytes_written + 4) {
for _ in 0..6-bytes_written {
let _ = joblog.write(b" ");
}
let _ = joblog.write(&id_buffer[0..bytes_written]);
Expand Down Expand Up @@ -92,16 +103,20 @@ impl JobLog {
}

/// Creates the column headers in the first line of the job log file
pub fn create(file: &mut File, padding: usize) {
pub fn create(file: &mut File, padding: usize, flags: u16) {
let mut joblog = BufWriter::new(file);

// Sequence column is at least 10 chars long, counting space separator.
let id_column_resize = if padding < 10 { 0 } else { padding - 10 };
let _ = joblog.write(b"Sequence ");
for _ in 0..id_column_resize { let _ = joblog.write(b" "); }

// StartTime column is always 17 chars long
let _ = joblog.write(b"StartTime(s) ");
if flags & JOBLOG_8601 != 0 {
let _ = joblog.write(b"StartTime(ISO-8601) ");
} else {
let _ = joblog.write(b"StartTime(s) ");
}


// Remaining columns, with the runtim column left-padded.
let _ = joblog.write(b"Runtime(s) ExitVal Signal Command\n");
Expand Down
4 changes: 3 additions & 1 deletion src/execute/receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ pub fn receive_messages(input_rx: Receiver<State>, args: Args, base: &str, proce
let stdout = io::stdout();
let stderr = io::stderr();

// Store the flags value outside of the `args` structure
let flags = args.flags;
// Keeps track of which job is currently allowed to print to standard output/error.
let mut counter = 0;
// In the event that the joblog parameter was passed, a counter will be needed for jobs.
Expand Down Expand Up @@ -107,7 +109,7 @@ pub fn receive_messages(input_rx: Receiver<State>, args: Args, base: &str, proce
if id_pad_length < 10 { id_pad_length = 10; }
let _ = fs::remove_file(&path);
let mut file = fs::OpenOptions::new().create(true).write(true).open(path).unwrap();
job_log::create(&mut file, id_pad_length);
job_log::create(&mut file, id_pad_length, flags);
file
});

Expand Down

0 comments on commit c25d34a

Please sign in to comment.