forked from M-Labs/artiq
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 is contained in:
parent
0443f83d5e
commit
cd7527b701
|
@ -1,11 +1,12 @@
|
||||||
use core::{mem, ptr};
|
use core::{mem, ptr};
|
||||||
use core::cell::RefCell;
|
use core::cell::{Cell, RefCell};
|
||||||
use log::{self, Log, LogLevel, LogMetadata, LogRecord, LogLevelFilter};
|
use log::{self, Log, LogLevel, LogMetadata, LogRecord, LogLevelFilter};
|
||||||
use log_buffer::LogBuffer;
|
use log_buffer::LogBuffer;
|
||||||
use clock;
|
use clock;
|
||||||
|
|
||||||
pub struct BufferLogger {
|
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 {}
|
unsafe impl Sync for BufferLogger {}
|
||||||
|
@ -15,7 +16,8 @@ static mut LOGGER: *const BufferLogger = ptr::null();
|
||||||
impl BufferLogger {
|
impl BufferLogger {
|
||||||
pub fn new(buffer: &'static mut [u8]) -> BufferLogger {
|
pub fn new(buffer: &'static mut [u8]) -> BufferLogger {
|
||||||
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 {
|
pub fn extract<R, F: FnOnce(&str) -> R>(&self, f: F) -> R {
|
||||||
f(self.buffer.borrow_mut().extract())
|
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 {
|
impl Log for BufferLogger {
|
||||||
|
@ -61,7 +71,10 @@ impl Log for BufferLogger {
|
||||||
writeln!(self.buffer.borrow_mut(),
|
writeln!(self.buffer.borrow_mut(),
|
||||||
"[{:12}us] {:>5}({}): {}",
|
"[{:12}us] {:>5}({}): {}",
|
||||||
clock::get_us(), record.level(), record.target(), record.args()).unwrap();
|
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}({}): {}",
|
println!("[{:12}us] {:>5}({}): {}",
|
||||||
clock::get_us(), record.level(), record.target(), record.args());
|
clock::get_us(), record.level(), record.target(), record.args());
|
||||||
}
|
}
|
||||||
|
|
|
@ -583,6 +583,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 addr = SocketAddr::new(IP_ANY, 1381);
|
||||||
let listener = TcpListener::bind(waiter, addr).expect("cannot bind socket");
|
let listener = TcpListener::bind(waiter, addr).expect("cannot bind socket");
|
||||||
listener.set_keepalive(true);
|
listener.set_keepalive(true);
|
||||||
|
|
Loading…
Reference in New Issue