Skip to content

Commit

Permalink
Added a progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytm committed Oct 5, 2018
1 parent 9229309 commit 3efa87f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ failure = "0.1"
rand = "0.5"
data-encoding = "2.1"
regex-syntax = "0.6"
pbr = "1.0"
8 changes: 8 additions & 0 deletions src/bin/dbgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ use data_encoding::{DecodeError, DecodeKind, HEXLOWER_PERMISSIVE};
use failure::{Error, ResultExt};
use rand::{EntropyRng, Rng};
use structopt::StructOpt;
use pbr::ProgressBar;

use std::fs::{create_dir_all, read_to_string, File};
use std::io::BufWriter;
use std::path::PathBuf;
use std::process::exit;
use std::time::Duration;

#[derive(StructOpt, Debug)]
struct Args {
Expand Down Expand Up @@ -132,6 +134,9 @@ fn run() -> Result<(), Error> {
eprintln!("Using seed: {}", HEXLOWER_PERMISSIVE.encode(&seed));
let mut compiled = generator.compile(seed)?;

let mut pb = ProgressBar::new((args.files_count as u64) * (args.inserts_count as u64));
pb.set_max_refresh_rate(Some(Duration::from_millis(500)));

let num_digits = args.files_count.to_string().len();
for file_index in 1..=args.files_count {
let data_path = args.out_dir.join(format!(
Expand All @@ -145,8 +150,11 @@ fn run() -> Result<(), Error> {
compiled
.write_sql(&mut data_file, args.rows_count)
.with_context(|_| format!("failed to write to data file at {}", data_path.display()))?;
pb.inc();
}
}

pb.finish_println("Done!");

Ok(())
}

0 comments on commit 3efa87f

Please sign in to comment.