clear to end of line properly in Timer, using termion

This commit is contained in:
Dustin Carlino 2019-03-11 14:01:06 -07:00
parent 92bf86454c
commit 899718bf48
7 changed files with 54 additions and 23 deletions

View File

@ -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"

View File

@ -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();
print!(
"\rReading {}: {}/{} MB... {}",
self.path,
prettyprint_usize(self.processed_bytes / 1024 / 1024),
prettyprint_usize(self.total_bytes / 1024 / 1024),
prettyprint_time(elapsed_seconds(self.started_at))
);
clear_current_line();
if done {
println!();
// 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!(
"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))
);
stdout().flush().unwrap();
}
}

View File

@ -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)
);
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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