summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2009-10-05 15:09:18 -0400
committerEliot Horowitz <eliot@10gen.com>2009-10-05 15:09:18 -0400
commit27fd0a7a9fd84b1965f733848e9c38072ee8f7ee (patch)
treede4ba8e7ace434541fee017c0a65c382caf6fae4 /util
parent6b79e14d967d05c3cbb70bb1b597fba6b8666bf8 (diff)
downloadmongo-27fd0a7a9fd84b1965f733848e9c38072ee8f7ee.tar.gz
more ProgressMeter to public place
Diffstat (limited to 'util')
-rw-r--r--util/goodies.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/util/goodies.h b/util/goodies.h
index 45a4a7dc96b..4689e32ec4d 100644
--- a/util/goodies.h
+++ b/util/goodies.h
@@ -321,4 +321,46 @@ namespace mongo {
boost::thread_specific_ptr<int> _val;
};
+ class ProgressMeter {
+ public:
+ ProgressMeter( long long total , int secondsBetween = 3 , int checkInterval = 100 )
+ : _total( total ) , _secondsBetween( secondsBetween ) , _checkInterval( checkInterval ) ,
+ _done(0) , _hits(0) , _lastTime( time(0) ){
+ }
+
+ void hit( int n = 1 ){
+ _done += n;
+ _hits++;
+ if ( _hits % _checkInterval )
+ return;
+
+ int t = time(0);
+ if ( t - _lastTime < _secondsBetween )
+ return;
+
+ int per = (int)( ( (double)_done * 100.0 ) / (double)_total );
+ cout << "\t\t" << _done << "/" << _total << "\t" << per << "%" << endl;
+ _lastTime = t;
+ }
+
+ long long done(){
+ return _done;
+ }
+
+ long long hits(){
+ return _hits;
+ }
+
+ private:
+
+ long long _total;
+ int _secondsBetween;
+ int _checkInterval;
+
+ long long _done;
+ long long _hits;
+ int _lastTime;
+ };
+
+
} // namespace mongo