Use the ThreadId to name cretonne.dbg in unnamed threads.
Don't use a single cretonne.dbg log file when there are multiple unnamed threads logging. They will clobber each other.
This commit is contained in:
@@ -9,7 +9,6 @@
|
|||||||
/// The output will appear in files named `cretonne.dbg.*`, where the suffix is named after the
|
/// The output will appear in files named `cretonne.dbg.*`, where the suffix is named after the
|
||||||
/// thread doing the logging.
|
/// thread doing the logging.
|
||||||
|
|
||||||
use std::ascii::AsciiExt;
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
@@ -72,18 +71,20 @@ pub fn writeln_with_format_args(args: fmt::Arguments) -> io::Result<()> {
|
|||||||
|
|
||||||
/// Open the tracing file for the current thread.
|
/// Open the tracing file for the current thread.
|
||||||
fn open_file() -> io::BufWriter<File> {
|
fn open_file() -> io::BufWriter<File> {
|
||||||
let file = match thread::current().name() {
|
let curthread = thread::current();
|
||||||
None => File::create("cretonne.dbg"),
|
let tmpstr;
|
||||||
Some(name) => {
|
|
||||||
let mut path = "cretonne.dbg.".to_owned();
|
let mut path = "cretonne.dbg.".to_owned();
|
||||||
for ch in name.chars() {
|
path.extend(
|
||||||
if ch.is_ascii() && ch.is_alphanumeric() {
|
match curthread.name() {
|
||||||
path.push(ch);
|
Some(name) => name.chars(),
|
||||||
|
// The thread is unnamed, so use the thread ID instead.
|
||||||
|
None => {
|
||||||
|
tmpstr = format!("{:?}", curthread.id());
|
||||||
|
tmpstr.chars()
|
||||||
}
|
}
|
||||||
}
|
}.filter(|ch| ch.is_alphanumeric() || *ch == '-' || *ch == '_'),
|
||||||
File::create(path)
|
);
|
||||||
}
|
let file = File::create(path).expect("Can't open tracing file");
|
||||||
}.expect("Can't open tracing file");
|
|
||||||
io::BufWriter::new(file)
|
io::BufWriter::new(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user