Skip to content

Commit

Permalink
dbcopy: print timeofday when the table copy is started
Browse files Browse the repository at this point in the history
  • Loading branch information
franku committed Feb 27, 2020
1 parent 5dceb8b commit 992f934
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
4 changes: 3 additions & 1 deletion core/src/dird/dbcopy/database_import_mysql.cc
Expand Up @@ -104,7 +104,9 @@ void DatabaseImportMysql::RunQuerySelectAllRows(

Progress progress(db_, t.table_name, limit_amount_of_rows_);

std::cout << "--> copying..." << std::endl;
std::cout << progress.TimeOfDay() << std::endl;
std::cout << "--> copying " << progress.FullAmount() << " rows..."
<< std::endl;

std::string query{"SELECT `"};
for (const auto& col : t.column_descriptions) {
Expand Down
18 changes: 13 additions & 5 deletions core/src/dird/dbcopy/progress.cc
Expand Up @@ -56,7 +56,7 @@ Progress::Progress(BareosDb* db,
}

if (a.is_valid) {
if (a.amount > limit_amount_of_rows_) {
if (limit_amount_of_rows_ && a.amount > limit_amount_of_rows_) {
// commandline parameter
a.amount = limit_amount_of_rows_;
}
Expand All @@ -78,8 +78,6 @@ bool Progress::Increment()
state_.amount = state_.amount != 0 ? state_.amount - 1 : 0;
if ((state_.amount % 10000) != 0) { return false; }

state_.ratio =
Ratio::num - (state_.amount * Ratio::num) / (full_amount_ * Ratio::den);

state_.start = system_clock::now();

Expand All @@ -93,6 +91,9 @@ bool Progress::Increment()

state_.eta = system_clock::now() + remaining_time;

state_.ratio =
Ratio::num - (state_.amount * Ratio::num) / (full_amount_ * Ratio::den);

bool changed =
(state_.ratio != state_old_.ratio) || (state_.eta != state_old_.eta);

Expand All @@ -101,10 +102,17 @@ bool Progress::Increment()
return changed;
}

std::string Progress::Eta() const
static std::string FormatTime(time_point<system_clock> tp)
{
std::ostringstream oss;
std::time_t time = system_clock::to_time_t(state_.eta);
std::time_t time = system_clock::to_time_t(tp);
oss << std::put_time(std::localtime(&time), "%F %T");
return oss.str();
}

std::string Progress::Eta() const { return FormatTime(state_.eta); }

std::string Progress::TimeOfDay() const
{
return FormatTime(system_clock::now());
}
4 changes: 3 additions & 1 deletion core/src/dird/dbcopy/progress.h
Expand Up @@ -50,14 +50,16 @@ class Progress {

using Ratio = std::ratio<100, 1>;

std::size_t FullAmount() const { return state_.amount; }
std::size_t Rate() const { return state_.ratio; }

std::string TimeOfDay() const;
std::string Eta() const;

private:
ProgressState state_;
ProgressState state_old_;
std::size_t full_amount_{};
bool suppress_first_output_{true};
bool is_valid_{false};
};

Expand Down

0 comments on commit 992f934

Please sign in to comment.