Skip to content

Commit 7578c1e

Browse files
committed
Tidy various logging uses
1 parent 37b737c commit 7578c1e

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

timely/src/dataflow/scopes/child.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ where
135135
let path = self.addr_for_child(index);
136136

137137
let type_name = std::any::type_name::<T2>();
138-
let progress_logging = self.log_register().as_ref().and_then(|l| l.get(&format!("timely/progress/{type_name}")));
139-
let summary_logging = self.log_register().as_ref().and_then(|l| l.get(&format!("timely/summary/{type_name}")));
138+
let progress_logging = self.logger_for(&format!("timely/progress/{type_name}"));
139+
let summary_logging = self.logger_for(&format!("timely/summary/{type_name}"));
140140

141141
let subscope = RefCell::new(SubgraphBuilder::new_from(path, identifier, self.logging(), summary_logging, name));
142142
let result = {

timely/src/progress/subgraph.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::cell::RefCell;
1010
use std::collections::BinaryHeap;
1111
use std::cmp::Reverse;
1212

13-
use crate::logging::{TimelyLogger as Logger, TimelyProgressEventBuilder};
13+
use crate::logging::TimelyLogger as Logger;
1414
use crate::logging::TimelySummaryLogger as SummaryLogger;
1515

1616
use crate::scheduling::Schedule;
@@ -182,13 +182,9 @@ where
182182
// The `None` argument is optional logging infrastructure.
183183
let type_name = std::any::type_name::<TInner>();
184184
let reachability_logging =
185-
worker.log_register()
186-
.as_ref()
187-
.and_then(|l|
188-
l.get::<reachability::logging::TrackerEventBuilder<TInner>>(&format!("timely/reachability/{type_name}"))
189-
.map(|logger| reachability::logging::TrackerLogger::new(self.identifier, logger))
190-
);
191-
let progress_logging = worker.log_register().as_ref().and_then(|l| l.get::<TimelyProgressEventBuilder<TInner>>(&format!("timely/progress/{type_name}")));
185+
worker.logger_for(&format!("timely/reachability/{type_name}"))
186+
.map(|logger| reachability::logging::TrackerLogger::new(self.identifier, logger));
187+
let progress_logging = worker.logger_for(&format!("timely/progress/{type_name}"));
192188
let (tracker, scope_summary) = builder.build(reachability_logging);
193189

194190
let progcaster = Progcaster::new(worker, Rc::clone(&self.path), self.identifier, self.logging.clone(), progress_logging);

timely/src/worker.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,14 @@ pub trait AsWorker : Scheduler {
202202
fn peek_identifier(&self) -> usize;
203203
/// Provides access to named logging streams.
204204
fn log_register(&self) -> Option<::std::cell::RefMut<crate::logging_core::Registry>>;
205+
/// Acquires a logger by name, if the log register exists and the name is registered.
206+
///
207+
/// For a more precise understanding of why a result is `None` one can use the direct functions.
208+
fn logger_for<CB: timely_container::ContainerBuilder>(&self, name: &str) -> Option<timely_logging::Logger<CB>> {
209+
self.log_register().and_then(|l| l.get(name))
210+
}
205211
/// Provides access to the timely logging stream.
206-
fn logging(&self) -> Option<crate::logging::TimelyLogger> { self.log_register().and_then(|l| l.get("timely").map(Into::into)) }
212+
fn logging(&self) -> Option<crate::logging::TimelyLogger> { self.logger_for("timely").map(Into::into) }
207213
}
208214

209215
/// A `Worker` is the entry point to a timely dataflow computation. It wraps a `Allocate`,
@@ -579,8 +585,7 @@ impl<A: Allocate> Worker<A> {
579585
T: Refines<()>,
580586
F: FnOnce(&mut Child<Self, T>)->R,
581587
{
582-
let logging = self.logging.as_ref().map(|l| l.borrow_mut()).and_then(|l| l.get("timely").map(Into::into));
583-
self.dataflow_core("Dataflow", logging, Box::new(()), |_, child| func(child))
588+
self.dataflow_core("Dataflow", self.logging(), Box::new(()), |_, child| func(child))
584589
}
585590

586591
/// Construct a new dataflow with a (purely cosmetic) name.
@@ -603,8 +608,7 @@ impl<A: Allocate> Worker<A> {
603608
T: Refines<()>,
604609
F: FnOnce(&mut Child<Self, T>)->R,
605610
{
606-
let logging = self.logging.as_ref().map(|l| l.borrow_mut()).and_then(|l| l.get("timely").map(Into::into));
607-
self.dataflow_core(name, logging, Box::new(()), |_, child| func(child))
611+
self.dataflow_core(name, self.logging(), Box::new(()), |_, child| func(child))
608612
}
609613

610614
/// Construct a new dataflow with specific configurations.
@@ -643,8 +647,8 @@ impl<A: Allocate> Worker<A> {
643647
let identifier = self.new_identifier();
644648

645649
let type_name = std::any::type_name::<T>();
646-
let progress_logging = self.logging.as_ref().map(|l| l.borrow_mut()).and_then(|l| l.get(&format!("timely/progress/{}", type_name)).map(Into::into));
647-
let summary_logging = self.logging.as_ref().map(|l| l.borrow_mut()).and_then(|l| l.get(&format!("timely/summary/{}", type_name)).map(Into::into));
650+
let progress_logging = self.logger_for(&format!("timely/progress/{}", type_name));
651+
let summary_logging = self.logger_for(&format!("timely/summary/{}", type_name));
648652
let subscope = SubgraphBuilder::new_from(addr, identifier, logging.clone(), summary_logging, name);
649653
let subscope = RefCell::new(subscope);
650654

0 commit comments

Comments
 (0)