diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 00:22:50 -0400 |
---|---|---|
committer | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 10:56:02 -0400 |
commit | 9c2ed42daa8fbbef4a919c21ec564e2db55e8d60 (patch) | |
tree | 3814f79c10d7b490948d8cb7b112ac1dd41ceff1 /src/mongo/util/progress_meter.cpp | |
parent | 01965cf52bce6976637ecb8f4a622aeb05ab256a (diff) | |
download | mongo-9c2ed42daa8fbbef4a919c21ec564e2db55e8d60.tar.gz |
SERVER-18579: Clang-Format - reformat code, no comment reflow
Diffstat (limited to 'src/mongo/util/progress_meter.cpp')
-rw-r--r-- | src/mongo/util/progress_meter.cpp | 104 |
1 files changed, 51 insertions, 53 deletions
diff --git a/src/mongo/util/progress_meter.cpp b/src/mongo/util/progress_meter.cpp index df065285a54..50575aff98a 100644 --- a/src/mongo/util/progress_meter.cpp +++ b/src/mongo/util/progress_meter.cpp @@ -30,7 +30,7 @@ #define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault #include "mongo/platform/basic.h" -#undef MONGO_PCH_WHITELISTED // needed for log.h +#undef MONGO_PCH_WHITELISTED // needed for log.h #include "mongo/util/progress_meter.h" @@ -40,64 +40,62 @@ using namespace std; namespace mongo { - void ProgressMeter::reset( unsigned long long total , int secondsBetween , int checkInterval) { - _total = total; - _secondsBetween = secondsBetween; - _checkInterval = checkInterval; - - _done = 0; - _hits = 0; - _lastTime = (int)time(0); - - _active = 1; +void ProgressMeter::reset(unsigned long long total, int secondsBetween, int checkInterval) { + _total = total; + _secondsBetween = secondsBetween; + _checkInterval = checkInterval; + + _done = 0; + _hits = 0; + _lastTime = (int)time(0); + + _active = 1; +} + + +bool ProgressMeter::hit(int n) { + if (!_active) { + warning() << "hit an inactive ProgressMeter" << endl; + return false; } + _done += n; + _hits++; + if (_hits % _checkInterval) + return false; - bool ProgressMeter::hit( int n ) { - if ( ! _active ) { - warning() << "hit an inactive ProgressMeter" << endl; - return false; - } - - _done += n; - _hits++; - if ( _hits % _checkInterval ) - return false; - - int t = (int) time(0); - if ( t - _lastTime < _secondsBetween ) - return false; - - if ( _total > 0 ) { - int per = (int)( ( (double)_done * 100.0 ) / (double)_total ); - LogstreamBuilder out = log(); - out << " " << _name << ": " << _done; - - if (_showTotal) { - out << '/' << _total << ' ' << per << '%'; - } - - if ( ! _units.empty() ) { - out << " (" << _units << ")"; - } - out << endl; + int t = (int)time(0); + if (t - _lastTime < _secondsBetween) + return false; + + if (_total > 0) { + int per = (int)(((double)_done * 100.0) / (double)_total); + LogstreamBuilder out = log(); + out << " " << _name << ": " << _done; + + if (_showTotal) { + out << '/' << _total << ' ' << per << '%'; } - _lastTime = t; - return true; - } - - string ProgressMeter::toString() const { - if ( ! _active ) - return ""; - stringstream buf; - buf << _name << ": " << _done << '/' << _total << ' ' << (_done*100)/_total << '%'; - - if ( ! _units.empty() ) { - buf << " (" << _units << ")" << endl; + + if (!_units.empty()) { + out << " (" << _units << ")"; } - - return buf.str(); + out << endl; } + _lastTime = t; + return true; +} +string ProgressMeter::toString() const { + if (!_active) + return ""; + stringstream buf; + buf << _name << ": " << _done << '/' << _total << ' ' << (_done * 100) / _total << '%'; + if (!_units.empty()) { + buf << " (" << _units << ")" << endl; + } + + return buf.str(); +} } |