improve progressbar
This commit is contained in:
parent
4caabf923a
commit
7e1e39e592
|
@ -88,6 +88,7 @@ std::map<uint64_t, Files> Dedup::hash(std::multimap<uint64_t, std::shared_ptr<Fi
|
||||||
|
|
||||||
std::cout << progressBar;
|
std::cout << progressBar;
|
||||||
}
|
}
|
||||||
|
std::cout << "\n";
|
||||||
|
|
||||||
Log::info << "Hashing done after: " << (int) (progressBar.getDuration().count() / 1000) << "s ";
|
Log::info << "Hashing done after: " << (int) (progressBar.getDuration().count() / 1000) << "s ";
|
||||||
return filesizes;
|
return filesizes;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "progressbar.h"
|
#include "progressbar.h"
|
||||||
|
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
|
|
||||||
const uint_fast8_t ProgressBar::BARLENGTH = 50;
|
const uint_fast8_t ProgressBar::BARLENGTH = 50;
|
||||||
|
@ -18,17 +20,20 @@ std::chrono::duration<uint64_t, std::milli> ProgressBar::getDuration() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& str, const ProgressBar& pb) {
|
std::ostream& operator<<(std::ostream& str, const ProgressBar& pb) {
|
||||||
double progressd = pb.currentBytes / (double) pb.maxBytes;
|
double progress = (pb.currentBytes / (double) pb.maxBytes);
|
||||||
uint64_t progressi = (progressd * 10000.0);
|
|
||||||
|
|
||||||
auto usedtime = pb.getDuration();
|
auto usedtime = pb.getDuration();
|
||||||
std::chrono::duration<uint64_t, std::ratio<60>> eta = std::chrono::duration_cast<std::chrono::minutes>((usedtime / (double) pb.currentBytes) * pb.maxBytes);
|
std::chrono::duration<uint64_t, std::ratio<60>> eta = std::chrono::duration_cast<std::chrono::minutes>((usedtime / (double) pb.currentBytes) * pb.maxBytes);
|
||||||
|
|
||||||
|
// speed
|
||||||
|
double speed = (pb.currentBytes / (double) usedtime.count()); // B/ms
|
||||||
|
speed /= 1000; // B/s
|
||||||
|
uint64_t bytespersecond = (int) speed; // floor
|
||||||
|
|
||||||
// generate bar
|
// generate bar
|
||||||
str << "[";
|
str << "\r[";
|
||||||
for(uint_fast8_t i = 0; i < ProgressBar::BARLENGTH; ++i) {
|
for(uint_fast8_t i = 0; i < ProgressBar::BARLENGTH; ++i) {
|
||||||
if( (i / (double) ProgressBar::BARLENGTH) < progressd ) {
|
if( (i / (double) ProgressBar::BARLENGTH) < progress ) {
|
||||||
str << '#';
|
str << '#';
|
||||||
} else {
|
} else {
|
||||||
str << ' ';
|
str << ' ';
|
||||||
|
@ -36,9 +41,10 @@ std::ostream& operator<<(std::ostream& str, const ProgressBar& pb) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// print info
|
// print info
|
||||||
str << "] " << (progressi / 100.0f) << "% " << pb.currentFiles << '/' << pb.maxFiles << " Files "
|
str << "] " << std::setprecision(2) << std::setfill('0') << std::fixed << std::setw(5) << (progress * 100) << "% "
|
||||||
<< FileSize(pb.currentBytes) << '/' << FileSize(pb.maxBytes) << " ETA: " << eta.count()
|
<< std::setprecision(6) << std::defaultfloat
|
||||||
<< "s \r" << std::flush;
|
<< FileSize(pb.currentBytes) << '/' << FileSize(pb.maxBytes) << " " << pb.currentFiles << '/' << pb.maxFiles << " Files "
|
||||||
|
<< FileSize(bytespersecond) << "/s ETA: " << eta.count() << "s " << std::flush;
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue