slight improvements to Timer API and output

This commit is contained in:
Dustin Carlino 2018-10-30 15:10:58 -07:00
parent 4a1d2c8bb6
commit 8a1ee5c32b
6 changed files with 24 additions and 19 deletions

View File

@ -38,10 +38,7 @@ impl Progress {
if self.processed_items == self.total_items {
let elapsed = elapsed_seconds(self.started_at);
let line = format!(
"{}: {}/{}... {}s",
self.label, self.processed_items, self.total_items, elapsed
);
let line = format!("{} ({})... {}s", self.label, self.total_items, elapsed);
// TODO blank till end of current line
println!("\r{}", line);
return Some((elapsed, line));
@ -70,6 +67,8 @@ enum StackEntry {
pub struct Timer {
results: Vec<String>,
stack: Vec<StackEntry>,
outermost_name: String,
}
struct TimerSpan {
@ -80,14 +79,19 @@ struct TimerSpan {
}
impl Timer {
pub fn new() -> Timer {
Timer {
pub fn new(name: String) -> Timer {
let mut t = Timer {
results: Vec::new(),
stack: Vec::new(),
}
outermost_name: name.clone(),
};
t.start(&name);
t
}
pub fn done(self) {
pub fn done(mut self) {
let stop_name = self.outermost_name.clone();
self.stop(&stop_name);
assert!(self.stack.is_empty());
println!("");
for line in self.results {

View File

@ -7,13 +7,11 @@ use structopt::StructOpt;
fn main() {
let flags = Flags::from_args();
let mut timer = abstutil::Timer::new();
timer.start("converting OSM");
let mut timer = abstutil::Timer::new(format!("generate {}", flags.output));
let map = convert(&flags, &mut timer);
println!("writing to {}", flags.output);
timer.start("saving map");
abstutil::write_binary(&flags.output, &map).expect("serializing map failed");
timer.stop("saving map");
timer.stop("converting OSM");
timer.done();
}

View File

@ -231,8 +231,7 @@ impl PluginsPerMap {
impl PerMapUI {
pub fn new(flags: SimFlags, kml: &Option<String>) -> (PerMapUI, PluginsPerMap) {
let mut timer = abstutil::Timer::new();
timer.start("PerMapUI setup");
let mut timer = abstutil::Timer::new("setup PerMapUI");
let (map, control_map, sim) =
sim::load(flags.clone(), Some(sim::Tick::from_seconds(30)), &mut timer);
@ -251,7 +250,6 @@ impl PerMapUI {
let neighborhood_summary =
plugins::neighborhood_summary::NeighborhoodSummary::new(&map, &draw_map, &mut timer);
timer.stop("PerMapUI setup");
timer.done();
let state = PerMapUI {

View File

@ -37,7 +37,11 @@ struct UI {
impl UI {
fn new(flags: Flags) -> UI {
let map = Map::new(&flags.load_map, RoadEdits::new(), &mut Timer::new()).unwrap();
let map = Map::new(
&flags.load_map,
RoadEdits::new(),
&mut Timer::new("load map for Halloween"),
).unwrap();
UI {
canvas: Canvas::new(),
draw_map: DrawMap::new(map),

View File

@ -38,7 +38,7 @@ fn main() {
// TODO not the ideal way to distinguish what thing we loaded
let load = flags.sim_flags.load.clone();
let mut timer = Timer::new();
let mut timer = Timer::new("setup headless");
let (map, control_map, mut sim) = sim::load(
flags.sim_flags,
Some(sim::Tick::from_seconds(30)),

View File

@ -15,12 +15,13 @@ fn main() {
log::set_logger(&LOG_ADAPTER).unwrap();
let flags = SimFlags::from_args();
let mut timer = Timer::new();
timer.start("precompute map");
let mut timer = Timer::new(format!(
"precompute {} with {}",
flags.load, flags.edits_name
));
let (map, _, _) = sim::load(flags, None, &mut timer);
timer.start("save map");
map.save();
timer.stop("save map");
timer.stop("precompute map");
timer.done();
}