Skip to content

Commit

Permalink
dbcopy: print the percentage of progress of each table
Browse files Browse the repository at this point in the history
  • Loading branch information
franku committed Feb 27, 2020
1 parent 45434d2 commit ba37eb5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
12 changes: 4 additions & 8 deletions core/src/dird/dbcopy/database_import_mysql.cc
Expand Up @@ -87,7 +87,6 @@ struct ResultHandlerContext {
column_descriptions;
RowData& row_data;
DatabaseExport& exporter;
uint64_t row_counter{};
BareosDb* db{};
bool is_restore_object{};
Progress& progress;
Expand Down Expand Up @@ -226,12 +225,11 @@ int DatabaseImportMysql::ResultHandlerCopy(void* ctx, int fields, char** row)

r->exporter.CopyRow(r->row_data);

// if (!(++r->row_counter % 1)) {
r->progress.Advance(1);
// if (r->progress.IntegralChange()) {
std::cout << r->progress.Rate() << "%" << std::endl;
// }
//}

if (r->progress.IntegralChange()) {
std::cout << r->progress.Rate() << "%" << std::endl;
}
return 0;
}

Expand All @@ -241,7 +239,5 @@ int DatabaseImportMysql::ResultHandlerCompare(void* ctx, int fields, char** row)
FillRowWithDatabaseResult(r, fields, row);

r->exporter.CompareRow(r->row_data);

if (!(++r->row_counter % 10000)) { std::cout << "." << std::flush; }
return 0;
}
5 changes: 3 additions & 2 deletions core/src/dird/dbcopy/progress.cc
Expand Up @@ -52,6 +52,7 @@ Progress::Progress(BareosDb* db, const std::string& table_name)
}

if (a.is_valid) {
full_amount_ = a.amount;
state_old.start = steady_clock::now();
state_old.amount = a.amount;
is_valid = true;
Expand All @@ -66,11 +67,11 @@ void Progress::Advance(std::size_t increment)
state_new.start = steady_clock::now();

state_new.ratio =
(state_new.amount * Ratio::num) / (Ratio::den * state_old.amount);
(state_new.amount * Ratio::num) / (full_amount_ * Ratio::den);

auto duration = state_new.start - state_old.start;

if (state_new.ratio != state_old.ratio) { changed_ = true; }
changed_ = state_new.ratio != state_old.ratio;

state_old = state_new;
}
1 change: 1 addition & 0 deletions core/src/dird/dbcopy/progress.h
Expand Up @@ -53,6 +53,7 @@ class Progress {
private:
ProgressState state_new;
ProgressState state_old;
std::size_t full_amount_{};
bool changed_{};

bool is_valid{};
Expand Down

0 comments on commit ba37eb5

Please sign in to comment.