From ba37eb579c54e45ff9cae3772235121fed3132cb Mon Sep 17 00:00:00 2001 From: Frank Ueberschar Date: Sun, 9 Feb 2020 21:49:24 +0100 Subject: [PATCH] dbcopy: print the percentage of progress of each table --- core/src/dird/dbcopy/database_import_mysql.cc | 12 ++++-------- core/src/dird/dbcopy/progress.cc | 5 +++-- core/src/dird/dbcopy/progress.h | 1 + 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/core/src/dird/dbcopy/database_import_mysql.cc b/core/src/dird/dbcopy/database_import_mysql.cc index ee775b3d827..2b14d2a4d70 100644 --- a/core/src/dird/dbcopy/database_import_mysql.cc +++ b/core/src/dird/dbcopy/database_import_mysql.cc @@ -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; @@ -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; } @@ -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; } diff --git a/core/src/dird/dbcopy/progress.cc b/core/src/dird/dbcopy/progress.cc index 50b0be969b7..d9518763771 100644 --- a/core/src/dird/dbcopy/progress.cc +++ b/core/src/dird/dbcopy/progress.cc @@ -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; @@ -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; } diff --git a/core/src/dird/dbcopy/progress.h b/core/src/dird/dbcopy/progress.h index 3533da09e2e..3d5a3678d3c 100644 --- a/core/src/dird/dbcopy/progress.h +++ b/core/src/dird/dbcopy/progress.h @@ -53,6 +53,7 @@ class Progress { private: ProgressState state_new; ProgressState state_old; + std::size_t full_amount_{}; bool changed_{}; bool is_valid{};