Skip to content
This repository has been archived by the owner on Jun 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #183 from darrenldl/dev
Browse files Browse the repository at this point in the history
Deps requirements update, updated progress reporting for encode stdin mode
  • Loading branch information
darrenldl committed Apr 30, 2019
2 parents f7e9aa2 + c59a718 commit 0c25cce
Show file tree
Hide file tree
Showing 13 changed files with 182 additions and 119 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@

- Bumped major version as this may break backward compatibility

- Switched to using tilde requirements for dependencies

- This is to ensure build stability for users who install blkar via crates.io, as `Cargo.lock` is not currently published along with the package on crates.io
- Updated progress reporting code
- Encode stdin mode now reports current rate and time used during encoding, and shows normal progress stats at the end

## 6.0.1

- Minor fixes for rescue and decode mode help messages
Expand Down
69 changes: 38 additions & 31 deletions Cargo.lock

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ path = "src/lib.rs"
doc = false

[dependencies]
reed-solomon-erasure = { version = "3.1", features = ["pure-rust"] }
sha-1 = "0.8.1"
sha2 = "0.8.0"
blake2_c = "0.3"
rand = "0.6.1"
smallvec = "0.6"
nom = "4.0"
chrono = "0.4"
clap = "2.30.0"
ctrlc = "3.1"
reed-solomon-erasure = { version = "~ 3.1.1", features = ["pure-rust"] }
sha-1 = "~ 0.8.1"
sha2 = "~ 0.8.0"
blake2_c = "~ 0.3.3"
rand = "~ 0.6.1"
smallvec = "~ 0.6.9"
nom = "~ 4.2.3"
chrono = "~ 0.4.6"
clap = "~ 2.33.0"
ctrlc = "~ 3.1.2"

[dev-dependencies]
quickcheck = "0.8"
quickcheck = "~ 0.8.2"
4 changes: 2 additions & 2 deletions src/block_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ impl ProgressReport for ScanStats {
self.bytes_processed
}

fn total_units(&self) -> u64 {
self.total_bytes
fn total_units(&self) -> Option<u64> {
Some(self.total_bytes)
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/check_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ impl ProgressReport for Stats {
}

fn units_so_far(&self) -> u64 {
(self.meta_or_par_blocks_decoded
self.meta_or_par_blocks_decoded
+ self.data_or_par_blocks_decoded
+ self.blocks_decode_failed
+ self.okay_blank_blocks) as u64
+ self.okay_blank_blocks
}

fn total_units(&self) -> u64 {
self.total_blocks as u64
fn total_units(&self) -> Option<u64> {
Some(self.total_blocks)
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/decode_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,8 @@ impl ProgressReport for HashStats {
self.bytes_processed
}

fn total_units(&self) -> u64 {
self.total_bytes
fn total_units(&self) -> Option<u64> {
Some(self.total_bytes)
}
}

Expand Down Expand Up @@ -499,8 +499,8 @@ impl ProgressReport for Stats {
+ blocks_decode_failed) as u64
}

fn total_units(&self) -> u64 {
self.total_blocks as u64
fn total_units(&self) -> Option<u64> {
Some(self.total_blocks)
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/encode_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub struct Stats {
pub data_padding_bytes: usize,
pub in_file_size: u64,
pub out_file_size: u64,
total_data_blocks: u32,
total_data_blocks: Option<u64>,
start_time: f64,
end_time: f64,
json_printer: Arc<JSONPrinter>,
Expand Down Expand Up @@ -231,8 +231,8 @@ impl Stats {
parity_blocks_written: 0,
data_padding_bytes: 0,
total_data_blocks: match required_len {
Some(len) => calc_data_chunk_count(param.version, len) as u32,
None => 0,
Some(len) => Some(calc_data_chunk_count(param.version, len)),
None => None,
},
in_file_size: 0,
out_file_size: 0,
Expand Down Expand Up @@ -262,8 +262,8 @@ impl ProgressReport for Stats {
self.data_blocks_written as u64
}

fn total_units(&self) -> u64 {
self.total_data_blocks as u64
fn total_units(&self) -> Option<u64> {
self.total_data_blocks
}
}

Expand Down
154 changes: 102 additions & 52 deletions src/progress_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ pub trait ProgressReport {

fn units_so_far(&self) -> u64;

fn total_units(&self) -> u64;
fn total_units(&self) -> Option<u64>;

fn set_start_time(&mut self) {
*self.start_time_mut() = time_utils::get_time_now(time_utils::TimeMode::UTC);
Expand Down Expand Up @@ -284,9 +284,14 @@ where
let units_so_far = stats.units_so_far();
let total_units = stats.total_units();

let percent = helper::calc_percent(units_so_far, total_units);
let progress_complete = match total_units {
None => pretend_finish,
Some(total_units) => {
let percent = helper::calc_percent(units_so_far, total_units);

let progress_complete = percent == 100 || pretend_finish;
percent == 100 || pretend_finish
}
};

if ((verbose_while_active && !progress_complete) || (verbose_when_done && progress_complete))
&& !(context.finish_printed && progress_complete)
Expand Down Expand Up @@ -363,72 +368,111 @@ fn make_message(
start_time: f64,
end_time: f64,
units_so_far: u64,
total_units: u64,
total_units: Option<u64>,
elements: &[ProgressElement],
) -> String {
fn make_string_for_element(
percent: usize,
percent: Option<usize>,
cur_rate: f64,
avg_rate: f64,
unit: String,
time_used: f64,
time_left: f64,
time_left: Option<f64>,
element: &ProgressElement,
) -> String {
) -> Option<String> {
use self::ProgressElement::*;
match *element {
Percentage => format!("{:3}%", percent),
ProgressBar => helper::make_progress_bar(percent),
CurrentRateShort => format!("cur : {}", helper::make_readable_rate(cur_rate, unit)),
CurrentRateLong => format!(
Percentage => match percent {
None => None,
Some(percent) => Some(format!("{:3}%", percent)),
},
ProgressBar => match percent {
None => None,
Some(percent) => Some(helper::make_progress_bar(percent)),
},
CurrentRateShort => Some(format!(
"cur : {}",
helper::make_readable_rate(cur_rate, unit)
)),
CurrentRateLong => Some(format!(
"Current rate : {}",
helper::make_readable_rate(cur_rate, unit)
),
AverageRateShort => format!("avg : {}", helper::make_readable_rate(avg_rate, unit)),
AverageRateLong => format!(
)),
AverageRateShort => Some(format!(
"avg : {}",
helper::make_readable_rate(avg_rate, unit)
)),
AverageRateLong => Some(format!(
"Average rate : {}",
helper::make_readable_rate(avg_rate, unit)
),
)),
TimeUsedShort => {
let (hour, minute, second) = time_utils::seconds_to_hms(time_used as i64);
format!("used : {:02}:{:02}:{:02}", hour, minute, second)
Some(format!("used : {:02}:{:02}:{:02}", hour, minute, second))
}
TimeUsedLong => {
let (hour, minute, second) = time_utils::seconds_to_hms(time_used as i64);
format!("Time elapsed : {:02}:{:02}:{:02}", hour, minute, second)
}
TimeLeftShort => {
let (hour, minute, second) = time_utils::seconds_to_hms(time_left as i64);
format!("left : {:02}:{:02}:{:02}", hour, minute, second)
}
TimeLeftLong => {
let (hour, minute, second) = time_utils::seconds_to_hms(time_left as i64);
format!("Time remaining : {:02}:{:02}:{:02}", hour, minute, second)
Some(format!(
"Time elapsed : {:02}:{:02}:{:02}",
hour, minute, second
))
}
TimeLeftShort => match time_left {
None => None,
Some(time_left) => {
let (hour, minute, second) = time_utils::seconds_to_hms(time_left as i64);
Some(format!("left : {:02}:{:02}:{:02}", hour, minute, second))
}
},
TimeLeftLong => match time_left {
None => None,
Some(time_left) => {
let (hour, minute, second) = time_utils::seconds_to_hms(time_left as i64);
Some(format!(
"Time remaining : {:02}:{:02}:{:02}",
hour, minute, second
))
}
},
}
}

let units_remaining = if total_units >= units_so_far {
total_units - units_so_far
} else {
0
};
let percent = helper::calc_percent(units_so_far, total_units);
let cur_time = time_utils::get_time_now(time_utils::TimeMode::UTC);
let time_used = if percent < 100 {
f64_max(cur_time - start_time, 0.1)
} else {
f64_max(end_time - start_time, 0.1)
};
let time_since_last_report = f64_max(cur_time - context.last_report_time, 0.1);
let avg_rate = units_so_far as f64 / time_used;
let cur_rate = (units_so_far - context.last_reported_units) as f64 / time_since_last_report;
let cur_rate = if cur_rate <= 0.001 {
0.000000001
0.000_000_001
} else {
cur_rate
};
let time_left = units_remaining as f64 / cur_rate;
let (percent, time_left) = match total_units {
None => (None, None),
Some(total_units) => {
let percent = helper::calc_percent(units_so_far, total_units);

let units_remaining = if total_units >= units_so_far {
total_units - units_so_far
} else {
0
};

let time_left = units_remaining as f64 / cur_rate;

(Some(percent), Some(time_left))
}
};
let time_used = match percent {
None => f64_max(cur_time - start_time, 0.1),
Some(percent) => {
if percent < 100 {
f64_max(cur_time - start_time, 0.1)
} else {
f64_max(end_time - start_time, 0.1)
}
}
};
let avg_rate = units_so_far as f64 / time_used;

let mut res = String::with_capacity(150);
if context.verbosity_settings.json_enabled {
res.push_str(&format!(
Expand All @@ -441,11 +485,13 @@ fn make_message(
to_camelcase("units so far"),
units_so_far
));
res.push_str(&format!(
",\"{}\": {} ",
to_camelcase("total units"),
total_units
));
if let Some(total_units) = total_units {
res.push_str(&format!(
",\"{}\": {} ",
to_camelcase("total units"),
total_units
))
};
res.push_str(&format!(
",\"{}\": {} ",
to_camelcase("cur per sec"),
Expand All @@ -461,23 +507,27 @@ fn make_message(
to_camelcase("time used"),
time_used
));
res.push_str(&format!(
",\"{}\": {} ",
to_camelcase("time left"),
time_left
));
if let Some(time_left) = time_left {
res.push_str(&format!(
",\"{}\": {} ",
to_camelcase("time left"),
time_left
))
};
} else {
for e in elements.iter() {
res.push_str(&make_string_for_element(
if let Some(s) = make_string_for_element(
percent,
cur_rate,
avg_rate,
context.unit.clone(),
time_used,
time_left,
e,
));
res.push_str(" ");
) {
res.push_str(&s);
res.push_str(" ");
}
}
}
res
Expand Down
4 changes: 2 additions & 2 deletions src/repair_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ impl ProgressReport for Stats {
self.meta_blocks_decoded + self.data_or_par_blocks_decoded + self.blocks_decode_failed
}

fn total_units(&self) -> u64 {
self.total_blocks
fn total_units(&self) -> Option<u64> {
Some(self.total_blocks)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/rescue_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ impl ProgressReport for Stats {
self.bytes_processed
}

fn total_units(&self) -> u64 {
self.total_bytes
fn total_units(&self) -> Option<u64> {
Some(self.total_bytes)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/show_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ impl ProgressReport for Stats {
self.bytes_processed
}

fn total_units(&self) -> u64 {
self.total_bytes
fn total_units(&self) -> Option<u64> {
Some(self.total_bytes)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/sort_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ impl ProgressReport for Stats {
+ self.okay_blank_blocks) as u64
}

fn total_units(&self) -> u64 {
self.total_blocks as u64
fn total_units(&self) -> Option<u64> {
Some(self.total_blocks)
}
}

Expand Down

0 comments on commit 0c25cce

Please sign in to comment.