From 763d7caa4c70111b7cb3ef5733d2c3c697758c28 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 10 Aug 2020 14:38:23 +0800 Subject: [PATCH] Add percentage and throughput to tasks that matter --- Cargo.lock | 9 ++++++++- git-features/Cargo.toml | 3 +-- git-features/src/progress/mod.rs | 24 ++++++++++++++++++++++- git-odb/src/pack/bundle/write/mod.rs | 2 +- git-odb/src/pack/index/traverse/lookup.rs | 5 +++-- git-odb/src/pack/index/util.rs | 4 ++-- git-odb/src/pack/index/write/encode.rs | 4 ++-- git-odb/src/pack/index/write/mod.rs | 9 ++++++--- git-odb/src/pack/tree/from_offsets.rs | 4 ++-- git-odb/src/pack/tree/traverse/mod.rs | 11 +++++++++-- git-odb/src/pack/tree/traverse/resolve.rs | 4 ++-- src/plumbing/pretty.rs | 1 + src/shared.rs | 2 ++ 13 files changed, 62 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aee31cd9b78..879f2da5b89 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -622,7 +622,6 @@ dependencies = [ "crossbeam-channel", "crossbeam-utils", "ctrlc", - "log", "num_cpus", "once_cell", "prodash", @@ -757,6 +756,12 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" +[[package]] +name = "human_format" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86cce260d758a9aa3d7c4b99d55c815a540f8a37514ba6046ab6be402a157cb0" + [[package]] name = "humantime" version = "1.3.0" @@ -1123,11 +1128,13 @@ name = "prodash" version = "8.0.0" dependencies = [ "async-io", + "bytesize", "crosstermion", "dashmap", "futures-core", "futures-lite", "futures-util", + "human_format", "humantime 2.0.1", "log", "parking_lot 0.11.0", diff --git a/git-features/Cargo.toml b/git-features/Cargo.toml index 2400794f3c9..4fbef3c0dff 100644 --- a/git-features/Cargo.toml +++ b/git-features/Cargo.toml @@ -43,8 +43,7 @@ crc = "1.8.1" fastsha1 = { package = "sha-1", version = "0.9.1", optional = true } # progress -log = { version = "0.4.8", optional = true } -prodash = { version = "8.0.0", default-features = false } +prodash = { version = "8.0.0", default-features = false, features = ["unit-bytes", "unit-human"]} # interruptible ctrlc = { version = "3.1.4", optional = true, default-features = false, features = ['termination'] } diff --git a/git-features/src/progress/mod.rs b/git-features/src/progress/mod.rs index 03e5e146a31..41a127f20c8 100644 --- a/git-features/src/progress/mod.rs +++ b/git-features/src/progress/mod.rs @@ -1,7 +1,29 @@ use std::io; pub use prodash::progress::{Discard, DoOrDiscard, Either}; -pub use prodash::{unit, Progress}; +pub use prodash::{unit, Progress, Unit}; + +pub fn bytes() -> Unit { + unit::dynamic_and_mode(unit::Bytes, unit::display::Mode::with_throughput().and_percentage()) +} + +pub fn count(name: &'static str) -> Unit { + unit::dynamic_and_mode( + unit::Human::new( + { + let mut f = unit::human::Formatter::new(); + f.with_decimals(1); + f + }, + name, + ), + unit::display::Mode::with_throughput().and_percentage(), + ) +} + +pub fn steps() -> Unit { + unit::dynamic(unit::Range::new("steps")) +} /// A structure passing every 'read' call through to the contained Progress instance using `inc_by(bytes_read)`. pub struct Read { diff --git a/git-odb/src/pack/bundle/write/mod.rs b/git-odb/src/pack/bundle/write/mod.rs index 08eba112814..b11b75d4462 100644 --- a/git-odb/src/pack/bundle/write/mod.rs +++ b/git-odb/src/pack/bundle/write/mod.rs @@ -40,7 +40,7 @@ impl pack::Bundle { <

::SubProgress as Progress>::SubProgress: Send, { let mut read_progress = progress.add_child("read pack"); - read_progress.init(pack_size.map(|s| s as usize), Some("bytes".into())); + read_progress.init(pack_size.map(|s| s as usize), Some(progress::bytes())); let pack = progress::Read { reader: pack, progress: read_progress, diff --git a/git-odb/src/pack/index/traverse/lookup.rs b/git-odb/src/pack/index/traverse/lookup.rs index 4cc9f63b7b9..6d2a0d92b58 100644 --- a/git-odb/src/pack/index/traverse/lookup.rs +++ b/git-odb/src/pack/index/traverse/lookup.rs @@ -2,6 +2,7 @@ use super::{Error, Reducer, SafetyCheck}; use crate::pack::{self, data::decode, index, index::util}; use git_features::{ parallel::{self, in_parallel_if}, + progress, progress::Progress, }; use git_object::owned; @@ -39,7 +40,7 @@ impl index::File { let input_chunks = index_entries.chunks(chunk_size.max(chunk_size)); let reduce_progress = parking_lot::Mutex::new({ let mut p = root.add_child("Traversing"); - p.init(Some(self.num_objects() as usize), Some("objects".into())); + p.init(Some(self.num_objects() as usize), Some(progress::count("objects"))); p }); let state_per_thread = |index| { @@ -59,7 +60,7 @@ impl index::File { |entries: &[index::Entry], (cache, ref mut processor, buf, progress)| -> Result, Error> { - progress.init(Some(entries.len()), Some("entries".into())); + progress.init(Some(entries.len()), Some(progress::count("entries"))); let mut stats = Vec::with_capacity(entries.len()); let mut header_buf = [0u8; 64]; for index_entry in entries.iter() { diff --git a/git-odb/src/pack/index/util.rs b/git-odb/src/pack/index/util.rs index f3201f073cd..46ad60bba2a 100644 --- a/git-odb/src/pack/index/util.rs +++ b/git-odb/src/pack/index/util.rs @@ -1,12 +1,12 @@ use crate::pack; -use git_features::progress::Progress; +use git_features::progress::{self, Progress}; use std::{io, time::Instant}; pub(crate) fn index_entries_sorted_by_offset_ascending( idx: &pack::index::File, mut progress: impl Progress, ) -> Vec { - progress.init(Some(idx.num_objects as usize), Some("entries".into())); + progress.init(Some(idx.num_objects as usize), Some(progress::count("entries"))); let start = Instant::now(); let mut v = Vec::with_capacity(idx.num_objects as usize); diff --git a/git-odb/src/pack/index/write/encode.rs b/git-odb/src/pack/index/write/encode.rs index 0793bd017f0..21e8f4c372a 100644 --- a/git-odb/src/pack/index/write/encode.rs +++ b/git-odb/src/pack/index/write/encode.rs @@ -3,7 +3,7 @@ use crate::{ pack::index::{util::Count, V2_SIGNATURE}, }; use byteorder::{BigEndian, WriteBytesExt}; -use git_features::progress::Progress; +use git_features::progress::{self, Progress}; use git_object::owned; use std::{cmp::Ordering, io}; @@ -36,7 +36,7 @@ pub(crate) fn to_write( let needs_64bit_offsets = entries_sorted_by_oid.last().expect("at least one pack entry").offset > LARGE_OFFSET_THRESHOLD; let mut fan_out_be = [0u32; 256]; - progress.init(Some(4), Some("steps".into())); + progress.init(Some(4), Some(progress::steps())); let start = std::time::Instant::now(); let _info = progress.add_child("generating fan-out table"); diff --git a/git-odb/src/pack/index/write/mod.rs b/git-odb/src/pack/index/write/mod.rs index 9d51e269e59..a77768a6a0a 100644 --- a/git-odb/src/pack/index/write/mod.rs +++ b/git-odb/src/pack/index/write/mod.rs @@ -2,7 +2,10 @@ use crate::{ loose, pack, pack::tree::{traverse::Context, Tree}, }; -use git_features::{hash, progress::Progress}; +use git_features::{ + hash, + progress::{self, Progress}, +}; use git_object::{owned, HashKind}; use std::{convert::Infallible, convert::TryInto, io}; @@ -66,9 +69,9 @@ impl pack::index::File { let mut header_buf = [0u8; 16]; let indexing_start = std::time::Instant::now(); - root_progress.init(Some(4), Some("steps".into())); + root_progress.init(Some(4), Some(progress::steps())); let mut progress = root_progress.add_child("indexing"); - progress.init(entries.size_hint().1, Some("objects".into())); + progress.init(entries.size_hint().1, Some(progress::count("objects"))); let mut pack_entries_end: u64 = 0; for (eid, entry) in entries.enumerate() { diff --git a/git-odb/src/pack/tree/from_offsets.rs b/git-odb/src/pack/tree/from_offsets.rs index 842c7aea7a4..5af38a8800e 100644 --- a/git-odb/src/pack/tree/from_offsets.rs +++ b/git-odb/src/pack/tree/from_offsets.rs @@ -1,5 +1,5 @@ use crate::{pack, pack::index::access::PackOffset, pack::tree::Tree}; -use git_features::progress::Progress; +use git_features::progress::{self, Progress}; use quick_error::quick_error; use std::{ fs, io, @@ -47,7 +47,7 @@ impl Tree { ); let anticpiated_num_objects = if let Some(num_objects) = data_sorted_by_offsets.size_hint().1 { - progress.init(Some(num_objects), Some("objects".into())); + progress.init(Some(num_objects), Some(progress::count("objects"))); num_objects } else { 0 diff --git a/git-odb/src/pack/tree/traverse/mod.rs b/git-odb/src/pack/tree/traverse/mod.rs index a899123de98..f6547ed5752 100644 --- a/git-odb/src/pack/tree/traverse/mod.rs +++ b/git-odb/src/pack/tree/traverse/mod.rs @@ -3,7 +3,12 @@ use crate::{ pack::data::EntrySlice, pack::tree::{Item, Tree}, }; -use git_features::{interruptible::is_interrupted, parallel, parallel::in_parallel_if, progress::Progress}; +use git_features::{ + interruptible::is_interrupted, + parallel, + parallel::in_parallel_if, + progress::{self, Progress}, +}; use quick_error::quick_error; mod resolve; @@ -94,7 +99,9 @@ where P: Progress, { pub fn new(num_objects: u32, progress: &'a parking_lot::Mutex

) -> Self { - progress.lock().init(Some(num_objects as usize), Some("objects".into())); + progress + .lock() + .init(Some(num_objects as usize), Some(progress::count("objects"))); Reducer { item_count: 0, progress, diff --git a/git-odb/src/pack/tree/traverse/resolve.rs b/git-odb/src/pack/tree/traverse/resolve.rs index 4cda9f4e4ee..41d2263155c 100644 --- a/git-odb/src/pack/tree/traverse/resolve.rs +++ b/git-odb/src/pack/tree/traverse/resolve.rs @@ -2,7 +2,7 @@ use crate::{ pack::{self, data::EntrySlice, tree::traverse::Context, tree::traverse::Error}, zlib, }; -use git_features::progress::Progress; +use git_features::progress::{self, Progress}; use std::{cell::RefCell, collections::BTreeMap}; pub(crate) fn deltas( @@ -32,7 +32,7 @@ where }; // Traverse the tree breadth first and loose the data produced for the base as it won't be needed anymore. - progress.init(None, Some("objects".into())); + progress.init(None, Some(progress::count("objects"))); // each node is a base, and its children always start out as deltas which become a base after applying them. // These will be pushed onto our stack until all are processed diff --git a/src/plumbing/pretty.rs b/src/plumbing/pretty.rs index f8f377a87b1..9169eaf5eb7 100644 --- a/src/plumbing/pretty.rs +++ b/src/plumbing/pretty.rs @@ -223,6 +223,7 @@ fn prepare_and_run( title: "gitoxide".into(), frames_per_second: crate::shared::DEFAULT_FRAME_RATE, stop_if_empty_progress: !progress_keep_open, + throughput: true, ..Default::default() }, ) diff --git a/src/shared.rs b/src/shared.rs index ab17ca45d9c..51526547c90 100644 --- a/src/shared.rs +++ b/src/shared.rs @@ -19,6 +19,7 @@ pub fn setup_line_renderer( output_is_terminal, colored: output_is_terminal && crosstermion::color::allowed(), timestamp: true, + throughput: true, hide_cursor, ..prodash::render::line::Options::default() }, @@ -44,6 +45,7 @@ pub fn setup_line_renderer_range( colored: output_is_terminal && crosstermion::color::allowed(), timestamp: true, hide_cursor, + throughput: true, ..prodash::render::line::Options::default() }, )