forked from M-Labs/artiq
1
0
Fork 0

runtime: print trace level log messages to UART during startup.

There's no way to retrieve them otherwise if the startup kernel
hangs.

This commit was mistakenly removed in 88ad054.
This commit is contained in:
whitequark 2016-11-23 13:49:19 +00:00
parent b9588ddf03
commit 739da9f1b3
2 changed files with 19 additions and 4 deletions

View File

@ -1,11 +1,12 @@
use core::{mem, ptr};
use core::cell::RefCell;
use core::cell::{Cell, RefCell};
use log::{self, Log, LogLevel, LogMetadata, LogRecord, LogLevelFilter};
use log_buffer::LogBuffer;
use clock;
pub struct BufferLogger {
buffer: RefCell<LogBuffer<&'static mut [u8]>>
buffer: RefCell<LogBuffer<&'static mut [u8]>>,
trace_to_uart: Cell<bool>
}
unsafe impl Sync for BufferLogger {}
@ -15,7 +16,8 @@ static mut LOGGER: *const BufferLogger = ptr::null();
impl BufferLogger {
pub fn new(buffer: &'static mut [u8]) -> BufferLogger {
BufferLogger {
buffer: RefCell::new(LogBuffer::new(buffer))
buffer: RefCell::new(LogBuffer::new(buffer)),
trace_to_uart: Cell::new(true)
}
}
@ -48,6 +50,14 @@ impl BufferLogger {
pub fn extract<R, F: FnOnce(&str) -> R>(&self, f: F) -> R {
f(self.buffer.borrow_mut().extract())
}
pub fn disable_trace_to_uart(&self) {
if self.trace_to_uart.get() {
trace!("disabling tracing to UART; all further trace messages \
are sent to core log only");
self.trace_to_uart.set(false)
}
}
}
impl Log for BufferLogger {
@ -61,7 +71,10 @@ impl Log for BufferLogger {
writeln!(self.buffer.borrow_mut(),
"[{:12}us] {:>5}({}): {}",
clock::get_us(), record.level(), record.target(), record.args()).unwrap();
if record.level() <= LogLevel::Info {
// Printing to UART is really slow, so avoid doing that when we have an alternative
// route to retrieve the debug messages.
if self.trace_to_uart.get() || record.level() <= LogLevel::Info {
println!("[{:12}us] {:>5}({}): {}",
clock::get_us(), record.level(), record.target(), record.args());
}

View File

@ -590,6 +590,8 @@ pub fn thread(waiter: Waiter, spawner: Spawner) {
}
}
BufferLogger::with_instance(|logger| logger.disable_trace_to_uart());
let addr = SocketAddr::new(IP_ANY, 1381);
let listener = TcpListener::bind(waiter, addr).expect("cannot bind socket");
listener.set_keepalive(true);