From acc5e53b32597adc749fe990ff7eed713e0168be Mon Sep 17 00:00:00 2001 From: whitequark Date: Sat, 12 Nov 2016 18:28:29 +0000 Subject: [PATCH] runtime: print microsecond timestamps in debug messages. --- artiq/runtime.rs/src/clock.rs | 7 +++++++ artiq/runtime.rs/src/logger.rs | 10 ++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/artiq/runtime.rs/src/clock.rs b/artiq/runtime.rs/src/clock.rs index 3c203a196..40e56eea9 100644 --- a/artiq/runtime.rs/src/clock.rs +++ b/artiq/runtime.rs/src/clock.rs @@ -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); diff --git a/artiq/runtime.rs/src/logger.rs b/artiq/runtime.rs/src/logger.rs index d09995bf7..e01248da2 100644 --- a/artiq/runtime.rs/src/logger.rs +++ b/artiq/runtime.rs/src/logger.rs @@ -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> @@ -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()); } } }