diff --git a/abstutil/src/time.rs b/abstutil/src/time.rs index 389fd0671e..66414f9ee5 100644 --- a/abstutil/src/time.rs +++ b/abstutil/src/time.rs @@ -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, stack: Vec, + + 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 { diff --git a/convert_osm/src/main.rs b/convert_osm/src/main.rs index 3cab91c785..5af865d155 100644 --- a/convert_osm/src/main.rs +++ b/convert_osm/src/main.rs @@ -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(); } diff --git a/editor/src/ui.rs b/editor/src/ui.rs index a46385caff..6e979ffeb9 100644 --- a/editor/src/ui.rs +++ b/editor/src/ui.rs @@ -231,8 +231,7 @@ impl PluginsPerMap { impl PerMapUI { pub fn new(flags: SimFlags, kml: &Option) -> (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 { diff --git a/halloween/src/main.rs b/halloween/src/main.rs index 03c1acf47a..059f81e95e 100644 --- a/halloween/src/main.rs +++ b/halloween/src/main.rs @@ -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), diff --git a/headless/src/main.rs b/headless/src/main.rs index df1079cf06..cc1e058f25 100644 --- a/headless/src/main.rs +++ b/headless/src/main.rs @@ -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)), diff --git a/precompute/src/main.rs b/precompute/src/main.rs index dbf33774d6..a02792dd48 100644 --- a/precompute/src/main.rs +++ b/precompute/src/main.rs @@ -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(); }