Properly initialize file_per_thread_logger for rayon thread pool (#211)

* Properly initialize file_per_thread_logger for rayon thread pool
This commit is contained in:
Artur Jamro
2019-07-23 14:53:48 -07:00
committed by Dan Gohman
parent 1aff03a5b4
commit 794841b366
6 changed files with 47 additions and 5 deletions

View File

@@ -43,6 +43,7 @@ file-per-thread-logger = "0.1.1"
wabt = "0.8"
libc = "0.2.50"
errno = "0.2.4"
rayon = "1.1"
[workspace]

27
src/utils.rs Normal file
View File

@@ -0,0 +1,27 @@
pub fn init_file_per_thread_logger() {
use super::LOG_FILENAME_PREFIX;
file_per_thread_logger::initialize(LOG_FILENAME_PREFIX);
// Extending behavior of default spawner:
// https://docs.rs/rayon/1.1.0/rayon/struct.ThreadPoolBuilder.html#method.spawn_handler
// Source code says DefaultSpawner is implementation detail and
// shouldn't be used directly.
rayon::ThreadPoolBuilder::new()
.spawn_handler(|thread| {
let mut b = std::thread::Builder::new();
if let Some(name) = thread.name() {
b = b.name(name.to_owned());
}
if let Some(stack_size) = thread.stack_size() {
b = b.stack_size(stack_size);
}
b.spawn(|| {
file_per_thread_logger::initialize(LOG_FILENAME_PREFIX);
thread.run()
})?;
Ok(())
})
.build_global()
.unwrap();
}

View File

@@ -52,6 +52,10 @@ use wasmtime_debug::{emit_debugsections, read_debuginfo};
use wasmtime_environ::{Compiler, Cranelift, ModuleEnvironment, Tunables};
use wasmtime_obj::emit_module;
mod utils;
static LOG_FILENAME_PREFIX: &str = "wasm2obj.dbg.";
const USAGE: &str = "
Wasm to native object translation utility.
Takes a binary WebAssembly module into a native object file.
@@ -68,6 +72,7 @@ Options:
--target <TARGET> build for the target triple; default is the host machine
-g generate debug information
--version print the Cranelift version
-d, --debug enable debug output on stderr/stdout
";
#[derive(Deserialize, Debug, Clone)]
@@ -76,6 +81,7 @@ struct Args {
arg_output: String,
arg_target: Option<String>,
flag_g: bool,
flag_debug: bool,
}
fn read_wasm_file(path: PathBuf) -> Result<Vec<u8>, io::Error> {
@@ -95,6 +101,12 @@ fn main() {
})
.unwrap_or_else(|e| e.exit());
if args.flag_debug {
pretty_env_logger::init();
} else {
utils::init_file_per_thread_logger();
}
let path = Path::new(&args.arg_file);
match handle_module(
path.to_path_buf(),

View File

@@ -37,7 +37,6 @@ use cranelift_codegen::settings;
use cranelift_codegen::settings::Configurable;
use cranelift_native;
use docopt::Docopt;
use file_per_thread_logger;
use pretty_env_logger;
use std::error::Error;
use std::ffi::OsStr;
@@ -56,6 +55,8 @@ use wasmtime_wast::instantiate_spectest;
#[cfg(feature = "wasi-c")]
use wasmtime_wasi_c::instantiate_wasi_c;
mod utils;
static LOG_FILENAME_PREFIX: &str = "wasmtime.dbg.";
const USAGE: &str = "
@@ -203,7 +204,7 @@ fn main() {
if args.flag_debug {
pretty_env_logger::init();
} else {
file_per_thread_logger::initialize(LOG_FILENAME_PREFIX);
utils::init_file_per_thread_logger();
}
let isa_builder = cranelift_native::builder().unwrap_or_else(|_| {

View File

@@ -32,13 +32,14 @@ use cranelift_codegen::settings;
use cranelift_codegen::settings::Configurable;
use cranelift_native;
use docopt::Docopt;
use file_per_thread_logger;
use pretty_env_logger;
use std::path::Path;
use std::process;
use wasmtime_jit::Compiler;
use wasmtime_wast::WastContext;
mod utils;
static LOG_FILENAME_PREFIX: &str = "cranelift.dbg.";
const USAGE: &str = "
@@ -76,7 +77,7 @@ fn main() {
if args.flag_debug {
pretty_env_logger::init();
} else {
file_per_thread_logger::initialize(LOG_FILENAME_PREFIX);
utils::init_file_per_thread_logger();
}
let isa_builder = cranelift_native::builder().unwrap_or_else(|_| {

View File

@@ -19,7 +19,7 @@ lightbeam = { path = "../lightbeam", optional = true }
failure = { version = "0.1.3", default-features = false }
failure_derive = { version = "0.1.3", default-features = false }
indexmap = "1.0.2"
rayon = "1.0"
rayon = "1.1"
[features]
default = ["std"]