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

Commit

Permalink
0.10.2: Quick Fix
Browse files Browse the repository at this point in the history
Removed unnecessary println's that were used for debugging.
  • Loading branch information
mmstick committed Jan 14, 2017
1 parent 7dc92f6 commit 9ba7f41
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 23 deletions.
15 changes: 11 additions & 4 deletions 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.1"
version = "0.10.2"
authors = ["Michael Aaron Murphy <mmstickman@gmail.com>"]
license = "MIT"
description = "Command-line CPU load balancer for executing jobs in parallel"
Expand Down
6 changes: 3 additions & 3 deletions src/execute/child.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ use super::pipe::disk::output as pipe_output;
use super::pipe::disk::State;

pub fn handle_child(mut child: Child, output: &Sender<State>, flags: u16, job_id: usize, input: String,
has_timeout: bool, timeout: Duration, base: &str) -> (Timespec, Timespec, i32, i32)
has_timeout: bool, timeout: Duration, base: &str, buffer: &mut [u8]) -> (Timespec, Timespec, i32, i32)
{
let start_time = get_time();
if has_timeout && child.wait_timeout(timeout).unwrap().is_none() {
let _ = child.kill();
pipe_output(&mut child, job_id, input, output, flags & QUIET_MODE != 0, base);
pipe_output(&mut child, job_id, input, output, flags & QUIET_MODE != 0, base, buffer);
(start_time, get_time(), -1, 15)
} else {
pipe_output(&mut child, job_id, input, output, flags & QUIET_MODE != 0, base);
pipe_output(&mut child, job_id, input, output, flags & QUIET_MODE != 0, base, buffer);
match child.wait() {
Ok(status) => match status.code() {
Some(exit) => (start_time, get_time(), exit, 0),
Expand Down
5 changes: 3 additions & 2 deletions src/execute/exec_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ impl ExecCommands {
let has_timeout = self.timeout != Duration::from_millis(0);
let mut input = String::with_capacity(64);
let mut id_buffer = [0u8; 64];

let mut job_buffer = [0u8; 64];
let mut total_buffer = [0u8; 64];
let truncate = self.num_inputs.numtoa(10, &mut total_buffer);
let job_total = &total_buffer[0..truncate];


while let Some(job_id) = self.inputs.try_next(&mut input) {
if self.flags & VERBOSE_MODE != 0 {
verbose::processing_task(&stdout, job_id+1, self.num_inputs, &input);
Expand All @@ -61,7 +62,7 @@ impl ExecCommands {
let (start_time, end_time, exit_value, signal) = match command.exec(command_buffer) {
Ok(child) => {
handle_child(child, &self.output_tx, self.flags, job_id, input.clone(), has_timeout, self.timeout,
&self.tempdir)
&self.tempdir, &mut job_buffer)
},
Err(cmd_err) => {
let mut stderr = stderr.lock();
Expand Down
7 changes: 4 additions & 3 deletions src/execute/exec_inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ impl ExecInputs {
let stdout = io::stdout();
let stderr = io::stderr();

let has_timeout = self.timeout != Duration::from_millis(0);
let mut input = String::with_capacity(64);
let has_timeout = self.timeout != Duration::from_millis(0);
let mut input = String::with_capacity(64);
let mut id_buffer = [0u8; 64];

while let Some(job_id) = self.inputs.try_next(&mut input) {
if flags & arguments::VERBOSE_MODE != 0 {
Expand All @@ -46,7 +47,7 @@ impl ExecInputs {
let (start_time, end_time, exit_value, signal) = match command::get_command_output(&input, flags) {
Ok(child) => {
handle_child(child, &self.output_tx, flags, job_id, input.clone(), has_timeout, self.timeout,
&self.tempdir)
&self.tempdir, &mut id_buffer)
},
Err(why) => {
let mut stderr = stderr.lock();
Expand Down
4 changes: 2 additions & 2 deletions src/execute/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ pub mod disk {
/// Sends messages received by a `Child` process's standard output and error and sends them
/// to be handled by the grouped output channel.
pub fn output(child: &mut Child, job_id: usize, name: String, output_tx: &Sender<State>, quiet: bool,
base: &str)
base: &str, buffer: &mut [u8])
{
let (_, stdout_path, stderr_path) = filepaths::new_job(base, job_id);
let (_, stdout_path, stderr_path) = filepaths::new_job(base, job_id, buffer);
let mut stdout_file = File::create(stdout_path).expect("unable to create job stdout file");
let mut stderr_file = File::create(stderr_path).expect("unable to create job stderr file");

Expand Down
2 changes: 1 addition & 1 deletion src/execute/receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub fn receive_messages(input_rx: Receiver<State>, args: Args, base: &str, proce
// A buffer for converting job ID's into a byte array representation of a string.
let mut id_buffer = [0u8; 64];
// Generates the stdout and stderr paths, along with a truncation value to truncate the job ID from the paths.
let (truncate_size, mut stdout_path, mut stderr_path) = filepaths::new_job(base, counter);
let (truncate_size, mut stdout_path, mut stderr_path) = filepaths::new_job(base, counter, &mut id_buffer);
// If the joblog parameter was passed, open the file for writing.
let mut joblog = args.joblog.map(|path| {
job_counter = 0;
Expand Down
13 changes: 7 additions & 6 deletions src/filepaths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@ pub fn base() -> Option<PathBuf> {
})
}

pub fn new_job(base: &str, id: usize) -> (usize, String, String) {
let id = id.to_string();
pub fn new_job(base: &str, id: usize, buffer: &mut [u8]) -> (usize, String, String) {
let mut stdout = String::from(base) + "/stdout_";
let mut stderr = String::from(base) + "/stderr_";
let truncate_value = stdout.len();
stdout.push_str(&id);
stderr.push_str(&id);
println!("stdout: '{}'", stdout);
let length = id.numtoa(10, buffer);
for byte in &buffer[0..length] {
stdout.push(*byte as char);
stderr.push(*byte as char);
}
(truncate_value, stdout, stderr)
}

pub fn next_job_path(id: usize, truncate: usize, buffer: &mut [u8; 64], stdout: &mut String, stderr: &mut String) {
pub fn next_job_path(id: usize, truncate: usize, buffer: &mut [u8], stdout: &mut String, stderr: &mut String) {
stdout.truncate(truncate);
stderr.truncate(truncate);
let length = id.numtoa(10, buffer);
Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ fn main() {
exit(1);
}
};
println!("base_path: '{}'", base_path);

let mut unprocessed_path = base.clone();
let mut processed_path = base.clone();
Expand Down

0 comments on commit 9ba7f41

Please sign in to comment.