diff --git a/include/filestorm/utils/logger.h b/include/filestorm/utils/logger.h index c9e1375..e6c3d0b 100644 --- a/include/filestorm/utils/logger.h +++ b/include/filestorm/utils/logger.h @@ -8,6 +8,7 @@ #include #include +#include class ProgressBar { int total; @@ -20,6 +21,8 @@ class ProgressBar { UnitType unit_type; + std::map metas = {}; + public: ProgressBar(int total, const std::string label) : total(total), label(label) { unit_type = UnitType::Count; @@ -29,13 +32,20 @@ class ProgressBar { unit_type = UnitType::Time; print_bar(); } + ProgressBar(const std::string label) : total(0), label(label) {} - void clear_line(); + void clear_line(bool overwrite = true); void disable() { active = false; } void update(int current); + void update(std::chrono::seconds current) { update(current.count()); } bool is_active() { return active; } - void print_bar(); + void print_bar(bool clear = false); + void set_meta(const std::string &key, const std::string &value) { metas[key] = value; } + void get_meta(const std::string &key) { metas[key]; } + void clear_meta(const std::string &key) { metas.erase(key); } + void set_total(int total); + void set_total(std::chrono::seconds total); ProgressBar &operator++(); ProgressBar operator++(int); diff --git a/source/scenarios/aging.cpp b/source/scenarios/aging.cpp index c53b0d6..4643ef4 100644 --- a/source/scenarios/aging.cpp +++ b/source/scenarios/aging.cpp @@ -92,7 +92,15 @@ void AgingScenario::run() { Result result; ///////// LOGGER settings - ProgressBar bar(getParameter("iterations").get_int(), "Aging Scenario"); + + ProgressBar bar("Aging Scenario"); + if (getParameter("iterations").get_int() != -1) { + logger.warn("Iterations are set to {}", getParameter("iterations").get_int()); + bar.set_total(getParameter("iterations").get_int()); + } else { + logger.warn("Time is set to {}", getParameter("time").get_string()); + bar.set_total(std::chrono::duration_cast(max_time)); + } logger.set_progress_bar(&bar); while ((iteration < getParameter("iterations").get_int() || getParameter("iterations").get_int() == -1) @@ -351,7 +359,9 @@ void AgingScenario::run() { throw std::runtime_error("Null pointer found"); } iteration++; - bar.update(iteration); + bar.set_meta("extents", fmt::format("{}", tree.total_extents_count)); + bar.set_meta("f-count", fmt::format("{}", tree.all_files.size())); + bar.update(std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - start)); break; default: break; diff --git a/source/utils/logger.cpp b/source/utils/logger.cpp index d00fcd2..80b9dcb 100644 --- a/source/utils/logger.cpp +++ b/source/utils/logger.cpp @@ -2,21 +2,22 @@ FilestormLogger logger; -void ProgressBar::clear_line() { +void ProgressBar::clear_line(bool overwrite) { std::cout << "\r"; - for (int i = 0; i < width; i++) { - std::cout << " "; + if (overwrite) { + for (int i = 0; i < width; i++) { + std::cout << " "; + } + std::cout << "\r"; } - std::cout << "\r"; } void ProgressBar::update(int current) { this->current = current; - clear_line(); - print_bar(); + print_bar(true); } -void ProgressBar::print_bar() { +void ProgressBar::print_bar(bool clear) { if (!is_active()) { return; } @@ -42,15 +43,18 @@ void ProgressBar::print_bar() { } float progress = (float)current / total; std::string infos = ""; + for (auto meta : metas) { + infos += fmt::format("[{}={}]", meta.first, meta.second); + } if (unit_type == UnitType::Count) { std::chrono::duration remaining = std::chrono::duration((total - current) / (current / (elapsed / 1000.0))); double it_per_s = current / (elapsed / 1000.0); - infos = fmt::format("[{}/{}][{:.1f} it/s][{:.1f}s Remaining]", current, total, it_per_s, remaining.count()); - } else { + infos += fmt::format("[{}/{}][{:.1f} it/s][ Remaining]", current, total, it_per_s, fmt::format("{:%H:%M:%S}", remaining)); + } else if (unit_type == UnitType::Time) { std::chrono::duration done = std::chrono::duration(current); std::chrono::duration total_duration = std::chrono::duration(total); - infos = fmt::format("[{}/{}]", fmt::format("{:%H:%M:%S}", done), fmt::format("{:%H:%M:%S}", total_duration)); + infos += fmt::format("[{}/{}]", fmt::format("{:%H:%M:%S}", done), fmt::format("{:%H:%M:%S}", total_duration)); } std::string prefix_infos = fmt::format("{} {} %", label, (int)(progress * 100)); int bar_width = width - prefix_infos.size() - infos.size() - 2; @@ -62,6 +66,9 @@ void ProgressBar::print_bar() { for (int i = progress_width; i < bar_width; i++) { bar += " "; } + if (clear) { + clear_line(false); + } std::cout << prefix_infos << "[" << bar << "]" << infos; std::cout.flush(); if (current == total) { @@ -72,8 +79,7 @@ void ProgressBar::print_bar() { ProgressBar& ProgressBar::operator++() { current++; - clear_line(); - print_bar(); + print_bar(true); return *this; } @@ -81,4 +87,13 @@ ProgressBar ProgressBar::operator++(int) { ProgressBar temp = *this; ++*this; return temp; -} \ No newline at end of file +} + +void ProgressBar::set_total(int total) { + this->total = total; + unit_type = UnitType::Count; +} +void ProgressBar::set_total(std::chrono::seconds total) { + this->total = total.count(); + unit_type = UnitType::Time; +}