forked from M-Labs/artiq
1
0
Fork 0

runtime: print microsecond timestamps in debug messages.

This commit is contained in:
whitequark 2016-11-12 18:28:29 +00:00
parent dca3fb5c96
commit acc5e53b32
2 changed files with 13 additions and 4 deletions

View File

@ -12,6 +12,13 @@ pub fn init() {
}
}
pub fn get_us() -> u64 {
unsafe {
csr::timer0::update_value_write(1);
(INIT - csr::timer0::value_read()) / (FREQ / 1_000_000)
}
}
pub fn get_ms() -> u64 {
unsafe {
csr::timer0::update_value_write(1);

View File

@ -2,6 +2,7 @@ use core::{mem, ptr};
use core::cell::RefCell;
use log::{self, Log, LogMetadata, LogRecord, LogLevelFilter};
use log_buffer::LogBuffer;
use clock;
pub struct BufferLogger {
buffer: RefCell<LogBuffer<&'static mut [u8]>>
@ -57,10 +58,11 @@ impl Log for BufferLogger {
fn log(&self, record: &LogRecord) {
if self.enabled(record.metadata()) {
use core::fmt::Write;
writeln!(self.buffer.borrow_mut(), "{:>5}({}): {}",
record.level(), record.target(), record.args()).unwrap();
println!("{:>5}({}): {}",
record.level(), record.target(), record.args());
writeln!(self.buffer.borrow_mut(),
"[{:12}us] {:>5}({}): {}",
clock::get_us(), record.level(), record.target(), record.args()).unwrap();
println!("[{:12}us] {:>5}({}): {}",
clock::get_us(), record.level(), record.target(), record.args());
}
}
}