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:
@@ -43,6 +43,7 @@ file-per-thread-logger = "0.1.1"
|
|||||||
wabt = "0.8"
|
wabt = "0.8"
|
||||||
libc = "0.2.50"
|
libc = "0.2.50"
|
||||||
errno = "0.2.4"
|
errno = "0.2.4"
|
||||||
|
rayon = "1.1"
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
|
|
||||||
|
|||||||
27
src/utils.rs
Normal file
27
src/utils.rs
Normal 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();
|
||||||
|
}
|
||||||
@@ -52,6 +52,10 @@ use wasmtime_debug::{emit_debugsections, read_debuginfo};
|
|||||||
use wasmtime_environ::{Compiler, Cranelift, ModuleEnvironment, Tunables};
|
use wasmtime_environ::{Compiler, Cranelift, ModuleEnvironment, Tunables};
|
||||||
use wasmtime_obj::emit_module;
|
use wasmtime_obj::emit_module;
|
||||||
|
|
||||||
|
mod utils;
|
||||||
|
|
||||||
|
static LOG_FILENAME_PREFIX: &str = "wasm2obj.dbg.";
|
||||||
|
|
||||||
const USAGE: &str = "
|
const USAGE: &str = "
|
||||||
Wasm to native object translation utility.
|
Wasm to native object translation utility.
|
||||||
Takes a binary WebAssembly module into a native object file.
|
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
|
--target <TARGET> build for the target triple; default is the host machine
|
||||||
-g generate debug information
|
-g generate debug information
|
||||||
--version print the Cranelift version
|
--version print the Cranelift version
|
||||||
|
-d, --debug enable debug output on stderr/stdout
|
||||||
";
|
";
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, Clone)]
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
@@ -76,6 +81,7 @@ struct Args {
|
|||||||
arg_output: String,
|
arg_output: String,
|
||||||
arg_target: Option<String>,
|
arg_target: Option<String>,
|
||||||
flag_g: bool,
|
flag_g: bool,
|
||||||
|
flag_debug: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_wasm_file(path: PathBuf) -> Result<Vec<u8>, io::Error> {
|
fn read_wasm_file(path: PathBuf) -> Result<Vec<u8>, io::Error> {
|
||||||
@@ -95,6 +101,12 @@ fn main() {
|
|||||||
})
|
})
|
||||||
.unwrap_or_else(|e| e.exit());
|
.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);
|
let path = Path::new(&args.arg_file);
|
||||||
match handle_module(
|
match handle_module(
|
||||||
path.to_path_buf(),
|
path.to_path_buf(),
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ use cranelift_codegen::settings;
|
|||||||
use cranelift_codegen::settings::Configurable;
|
use cranelift_codegen::settings::Configurable;
|
||||||
use cranelift_native;
|
use cranelift_native;
|
||||||
use docopt::Docopt;
|
use docopt::Docopt;
|
||||||
use file_per_thread_logger;
|
|
||||||
use pretty_env_logger;
|
use pretty_env_logger;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
@@ -56,6 +55,8 @@ use wasmtime_wast::instantiate_spectest;
|
|||||||
#[cfg(feature = "wasi-c")]
|
#[cfg(feature = "wasi-c")]
|
||||||
use wasmtime_wasi_c::instantiate_wasi_c;
|
use wasmtime_wasi_c::instantiate_wasi_c;
|
||||||
|
|
||||||
|
mod utils;
|
||||||
|
|
||||||
static LOG_FILENAME_PREFIX: &str = "wasmtime.dbg.";
|
static LOG_FILENAME_PREFIX: &str = "wasmtime.dbg.";
|
||||||
|
|
||||||
const USAGE: &str = "
|
const USAGE: &str = "
|
||||||
@@ -203,7 +204,7 @@ fn main() {
|
|||||||
if args.flag_debug {
|
if args.flag_debug {
|
||||||
pretty_env_logger::init();
|
pretty_env_logger::init();
|
||||||
} else {
|
} else {
|
||||||
file_per_thread_logger::initialize(LOG_FILENAME_PREFIX);
|
utils::init_file_per_thread_logger();
|
||||||
}
|
}
|
||||||
|
|
||||||
let isa_builder = cranelift_native::builder().unwrap_or_else(|_| {
|
let isa_builder = cranelift_native::builder().unwrap_or_else(|_| {
|
||||||
|
|||||||
@@ -32,13 +32,14 @@ use cranelift_codegen::settings;
|
|||||||
use cranelift_codegen::settings::Configurable;
|
use cranelift_codegen::settings::Configurable;
|
||||||
use cranelift_native;
|
use cranelift_native;
|
||||||
use docopt::Docopt;
|
use docopt::Docopt;
|
||||||
use file_per_thread_logger;
|
|
||||||
use pretty_env_logger;
|
use pretty_env_logger;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process;
|
use std::process;
|
||||||
use wasmtime_jit::Compiler;
|
use wasmtime_jit::Compiler;
|
||||||
use wasmtime_wast::WastContext;
|
use wasmtime_wast::WastContext;
|
||||||
|
|
||||||
|
mod utils;
|
||||||
|
|
||||||
static LOG_FILENAME_PREFIX: &str = "cranelift.dbg.";
|
static LOG_FILENAME_PREFIX: &str = "cranelift.dbg.";
|
||||||
|
|
||||||
const USAGE: &str = "
|
const USAGE: &str = "
|
||||||
@@ -76,7 +77,7 @@ fn main() {
|
|||||||
if args.flag_debug {
|
if args.flag_debug {
|
||||||
pretty_env_logger::init();
|
pretty_env_logger::init();
|
||||||
} else {
|
} else {
|
||||||
file_per_thread_logger::initialize(LOG_FILENAME_PREFIX);
|
utils::init_file_per_thread_logger();
|
||||||
}
|
}
|
||||||
|
|
||||||
let isa_builder = cranelift_native::builder().unwrap_or_else(|_| {
|
let isa_builder = cranelift_native::builder().unwrap_or_else(|_| {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ lightbeam = { path = "../lightbeam", optional = true }
|
|||||||
failure = { version = "0.1.3", default-features = false }
|
failure = { version = "0.1.3", default-features = false }
|
||||||
failure_derive = { version = "0.1.3", default-features = false }
|
failure_derive = { version = "0.1.3", default-features = false }
|
||||||
indexmap = "1.0.2"
|
indexmap = "1.0.2"
|
||||||
rayon = "1.0"
|
rayon = "1.1"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["std"]
|
default = ["std"]
|
||||||
|
|||||||
Reference in New Issue
Block a user