Open the stdout-file once (#419)

Co-authored-by: Dominik Maier <domenukk@gmail.com>
This commit is contained in:
s1341 2021-12-16 12:12:40 +02:00 committed by GitHub
parent abfdb619a8
commit d93f97309a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -111,6 +111,13 @@ where
println!("spawning on cores: {:?}", self.cores); println!("spawning on cores: {:?}", self.cores);
#[cfg(feature = "std")]
let stdout_file = if let Some(filename) = self.stdout_file {
Some(File::create(filename).unwrap())
} else {
None
};
// Spawn clients // Spawn clients
let mut index = 0_u64; let mut index = 0_u64;
for (id, bind_to) in core_ids.iter().enumerate().take(num_cores) { for (id, bind_to) in core_ids.iter().enumerate().take(num_cores) {
@ -132,8 +139,7 @@ where
std::thread::sleep(std::time::Duration::from_millis(index * 100)); std::thread::sleep(std::time::Duration::from_millis(index * 100));
#[cfg(feature = "std")] #[cfg(feature = "std")]
if let Some(filename) = self.stdout_file { if let Some(file) = stdout_file {
let file = File::create(filename).unwrap();
dup2(file.as_raw_fd(), libc::STDOUT_FILENO)?; dup2(file.as_raw_fd(), libc::STDOUT_FILENO)?;
dup2(file.as_raw_fd(), libc::STDERR_FILENO)?; dup2(file.as_raw_fd(), libc::STDERR_FILENO)?;
} }