Skip to content

Commit

Permalink
Add percentage and throughput to tasks that matter
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Aug 10, 2020
1 parent 0a2ea35 commit 763d7ca
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 20 deletions.
9 changes: 8 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions git-features/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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'] }
Expand Down
24 changes: 23 additions & 1 deletion git-features/src/progress/mod.rs
Original file line number Diff line number Diff line change
@@ -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<R, P> {
Expand Down
2 changes: 1 addition & 1 deletion git-odb/src/pack/bundle/write/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl pack::Bundle {
<<P as Progress>::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,
Expand Down
5 changes: 3 additions & 2 deletions git-odb/src/pack/index/traverse/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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| {
Expand All @@ -59,7 +60,7 @@ impl index::File {
|entries: &[index::Entry],
(cache, ref mut processor, buf, progress)|
-> Result<Vec<decode::Outcome>, 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() {
Expand Down
4 changes: 2 additions & 2 deletions git-odb/src/pack/index/util.rs
Original file line number Diff line number Diff line change
@@ -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<pack::index::Entry> {
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);
Expand Down
4 changes: 2 additions & 2 deletions git-odb/src/pack/index/write/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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");

Expand Down
9 changes: 6 additions & 3 deletions git-odb/src/pack/index/write/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions git-odb/src/pack/tree/from_offsets.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -47,7 +47,7 @@ impl<T> Tree<T> {
);

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
Expand Down
11 changes: 9 additions & 2 deletions git-odb/src/pack/tree/traverse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -94,7 +99,9 @@ where
P: Progress,
{
pub fn new(num_objects: u32, progress: &'a parking_lot::Mutex<P>) -> 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,
Expand Down
4 changes: 2 additions & 2 deletions git-odb/src/pack/tree/traverse/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T, F, P, MBFN, S, E>(
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/plumbing/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ fn prepare_and_run<T: Send + 'static>(
title: "gitoxide".into(),
frames_per_second: crate::shared::DEFAULT_FRAME_RATE,
stop_if_empty_progress: !progress_keep_open,
throughput: true,
..Default::default()
},
)
Expand Down
2 changes: 2 additions & 0 deletions src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
},
Expand All @@ -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()
},
)
Expand Down

0 comments on commit 763d7ca

Please sign in to comment.