Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a Duration offset to logging times #337

Merged
merged 1 commit into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions logging/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl<Id: Clone+'static> Registry<Id> {
name: &str,
action: F) -> Option<Box<dyn Any>>
{
let logger = Logger::<T, Id>::new(self.time.clone(), self.id.clone(), action);
let logger = Logger::<T, Id>::new(self.time.clone(), Duration::default(), self.id.clone(), action);
self.insert_logger(name, logger)
}

Expand Down Expand Up @@ -89,6 +89,7 @@ impl<Id> Flush for Registry<Id> {
pub struct Logger<T, E> {
id: E,
time: Instant, // common instant used for all loggers.
offset: Duration, // offset to allow re-calibration.
action: Rc<RefCell<dyn FnMut(&Duration, &mut Vec<(Duration, E, T)>)>>, // action to take on full log buffers.
buffer: Rc<RefCell<Vec<(Duration, E, T)>>>, // shared buffer; not obviously best design.
}
Expand All @@ -98,6 +99,7 @@ impl<T, E: Clone> Clone for Logger<T, E> {
Logger {
id: self.id.clone(),
time: self.time,
offset: self.offset.clone(),
action: self.action.clone(),
buffer: self.buffer.clone(),
}
Expand All @@ -106,13 +108,14 @@ impl<T, E: Clone> Clone for Logger<T, E> {

impl<T, E: Clone> Logger<T, E> {
/// Allocates a new shareable logger bound to a write destination.
pub fn new<F>(time: Instant, id: E, action: F) -> Self
pub fn new<F>(time: Instant, offset: Duration, id: E, action: F) -> Self
where
F: FnMut(&Duration, &mut Vec<(Duration, E, T)>)+'static
{
Logger {
id,
time,
offset,
action: Rc::new(RefCell::new(action)),
buffer: Rc::new(RefCell::new(Vec::with_capacity(1024))),
}
Expand Down Expand Up @@ -148,7 +151,7 @@ impl<T, E: Clone> Logger<T, E> {
where I: IntoIterator, I::Item: Into<T>
{
let mut buffer = self.buffer.borrow_mut();
let elapsed = self.time.elapsed();
let elapsed = self.time.elapsed() + self.offset;
for event in events {
buffer.push((elapsed.clone(), self.id.clone(), event.into()));
if buffer.len() == buffer.capacity() {
Expand Down
1 change: 1 addition & 0 deletions timely/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ where
let mut logger = BatchLogger::new(writer);
result = Some(crate::logging_core::Logger::new(
::std::time::Instant::now(),
::std::time::Duration::default(),
events_setup,
move |time, data| logger.publish_batch(time, data)
));
Expand Down