mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 03:35:51 +03:00
clear to end of line properly in Timer, using termion
This commit is contained in:
parent
92bf86454c
commit
899718bf48
@ -13,3 +13,4 @@ rand_xorshift = "0.1.1"
|
||||
serde = "1.0.87"
|
||||
serde_derive = "1.0"
|
||||
serde_json = "1.0"
|
||||
termion = "1.5.1"
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::time::prettyprint_time;
|
||||
use crate::time::{clear_current_line, prettyprint_time};
|
||||
use crate::{elapsed_seconds, prettyprint_usize, MultiMap, Timer, PROGRESS_FREQUENCY_SECONDS};
|
||||
use bincode;
|
||||
use serde::de::DeserializeOwned;
|
||||
@ -225,16 +225,23 @@ impl Read for FileWithProgress {
|
||||
let done = self.processed_bytes == self.total_bytes && bytes == 0;
|
||||
if elapsed_seconds(self.last_printed_at) >= PROGRESS_FREQUENCY_SECONDS || done {
|
||||
self.last_printed_at = Instant::now();
|
||||
clear_current_line();
|
||||
if done {
|
||||
// TODO Not seeing this case happen!
|
||||
println!(
|
||||
"Read {} ({})... {}",
|
||||
self.path,
|
||||
prettyprint_usize(self.total_bytes / 1024 / 1024),
|
||||
prettyprint_time(elapsed_seconds(self.started_at))
|
||||
);
|
||||
} else {
|
||||
print!(
|
||||
"\rReading {}: {}/{} MB... {}",
|
||||
"Reading {}: {}/{} MB... {}",
|
||||
self.path,
|
||||
prettyprint_usize(self.processed_bytes / 1024 / 1024),
|
||||
prettyprint_usize(self.total_bytes / 1024 / 1024),
|
||||
prettyprint_time(elapsed_seconds(self.started_at))
|
||||
);
|
||||
if done {
|
||||
println!();
|
||||
} else {
|
||||
stdout().flush().unwrap();
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ use procfs;
|
||||
use std::collections::HashMap;
|
||||
use std::io::{stdout, Write};
|
||||
use std::time::Instant;
|
||||
use termion;
|
||||
|
||||
pub fn elapsed_seconds(since: Instant) -> f64 {
|
||||
let dt = since.elapsed();
|
||||
@ -47,14 +48,14 @@ impl Progress {
|
||||
prettyprint_usize(self.total_items),
|
||||
prettyprint_time(elapsed)
|
||||
);
|
||||
// TODO blank till end of current line
|
||||
println!("\r{}", line);
|
||||
clear_current_line();
|
||||
println!("{}", line);
|
||||
return Some((elapsed, line));
|
||||
} else if elapsed_seconds(self.last_printed_at) >= PROGRESS_FREQUENCY_SECONDS {
|
||||
self.last_printed_at = Instant::now();
|
||||
// TODO blank till end of current line
|
||||
clear_current_line();
|
||||
print!(
|
||||
"\r{}: {}/{}... {}",
|
||||
"{}: {}/{}... {}",
|
||||
self.label,
|
||||
prettyprint_usize(self.processed_items),
|
||||
prettyprint_usize(self.total_items),
|
||||
@ -110,6 +111,11 @@ impl Timer {
|
||||
// Log immediately, but also repeat at the end, to avoid having to scroll up and find
|
||||
// interesting debug stuff.
|
||||
pub fn note(&mut self, line: String) {
|
||||
// Interrupt the start_iter with a newline.
|
||||
if let Some(StackEntry::Progress(_)) = self.stack.last() {
|
||||
println!();
|
||||
}
|
||||
|
||||
println!("{}", line);
|
||||
self.notes.push(line);
|
||||
}
|
||||
@ -396,3 +402,12 @@ impl MeasureMemory {
|
||||
fn process_used_memory_mb() -> usize {
|
||||
(procfs::Process::myself().unwrap().stat.vsize / 1024 / 1024) as usize
|
||||
}
|
||||
|
||||
pub(crate) fn clear_current_line() {
|
||||
let (terminal_width, _) = termion::terminal_size().unwrap();
|
||||
print!(
|
||||
"{}{}",
|
||||
termion::clear::CurrentLine,
|
||||
termion::cursor::Left(terminal_width)
|
||||
);
|
||||
}
|
||||
|
@ -20,3 +20,8 @@
|
||||
- first: all the maps fully convert and display in some form; all tests pass or are disabled
|
||||
- slowly hone away at problems currently with errors printed (like bad pl shift angles)
|
||||
- eventually: every intersection has at least a turn, minimum lengths enforced, etc
|
||||
|
||||
## Code to release
|
||||
|
||||
- tmp_gfx as a 2D-with-camera glium sample
|
||||
- ezgui
|
||||
|
@ -1,10 +0,0 @@
|
||||
# Profiling
|
||||
|
||||
apt-get install google-perftools libgoogle-perftools-dev
|
||||
|
||||
Follow Usage from https://crates.io/crates/cpuprofiler
|
||||
|
||||
Run editor or headless with --enable_profiler
|
||||
google-pprof --no_strip_temp ../target/debug/editor profile
|
||||
google-pprof --no_strip_temp ../target/release/headless profile
|
||||
top30 --cum
|
@ -10,3 +10,14 @@ Debug OpenGL calls:
|
||||
apitrace trace --api gl ../target/debug/editor ../data/raw_maps/montlake.abst
|
||||
qapitrace editor.trace
|
||||
apitrace dump editor.trace
|
||||
|
||||
## Profiling
|
||||
|
||||
apt-get install google-perftools libgoogle-perftools-dev
|
||||
|
||||
Follow Usage from https://crates.io/crates/cpuprofiler
|
||||
|
||||
Run editor or headless with --enable_profiler
|
||||
google-pprof --no_strip_temp ../target/debug/editor profile
|
||||
google-pprof --no_strip_temp ../target/release/headless profile
|
||||
top30 --cum
|
||||
|
@ -23,6 +23,7 @@
|
||||
- https://www.seattle.gov/transportation/projects-and-programs/programs/neighborhood-street-fund / https://www.seattle.gov/neighborhoods/programs-and-services/your-voice-your-choice
|
||||
- https://commuteseattle.com/
|
||||
- https://www.theurbanist.org/
|
||||
- https://humantransit.org/2019/03/notes-on-simcity-at-30.html
|
||||
|
||||
## Similar projects
|
||||
|
||||
@ -64,6 +65,7 @@ Seattlites with opinions and ideas:
|
||||
### Games
|
||||
|
||||
SimCity, Cities: Skylines
|
||||
https://steamcommunity.com/sharedfiles/filedetails/?id=583429740
|
||||
|
||||
### Open source urban planning
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user