diff options
author | Brandon Diamond <brandon@10gen.com> | 2011-10-13 11:34:58 -0400 |
---|---|---|
committer | Brandon Diamond <brandon@10gen.com> | 2011-10-13 11:37:30 -0400 |
commit | 983d18b904300a4780b05d7190449f1399effc42 (patch) | |
tree | cfdb95a2d07722b2d5d7a635241be89dfa0dcadf | |
parent | b9a31adaf216643f687a3a70cf96530e11785b5e (diff) | |
download | mongo-983d18b904300a4780b05d7190449f1399effc42.tar.gz |
SERVER-2495: Added units to ProgressMeter
mongodump/restore and bsondump will now indicate the correct unit
in progress meter output. Dump emits units "objects" whereas restore
emits units "bytes" (as we do not know the total # of objects)
-rw-r--r-- | tools/dump.cpp | 2 | ||||
-rw-r--r-- | tools/tool.cpp | 1 | ||||
-rw-r--r-- | util/goodies.h | 25 |
3 files changed, 25 insertions, 3 deletions
diff --git a/tools/dump.cpp b/tools/dump.cpp index 562b5b14d6a..e02d725196d 100644 --- a/tools/dump.cpp +++ b/tools/dump.cpp @@ -110,6 +110,7 @@ public: uassert(10262, errnoWithPrefix("couldn't open file"), f); ProgressMeter m( conn( true ).count( coll.c_str() , BSONObj() , QueryOption_SlaveOk ) ); + m.setUnits("objects"); doCollection(coll, f, &m); @@ -251,6 +252,7 @@ public: FilePtr f (fopen(outfile.string().c_str(), "wb")); ProgressMeter m( nsd->stats.nrecords * 2 ); + m.setUnits("objects"); Writer w( f , &m ); diff --git a/tools/tool.cpp b/tools/tool.cpp index 346a335fd0f..dc08625a545 100644 --- a/tools/tool.cpp +++ b/tools/tool.cpp @@ -470,6 +470,7 @@ namespace mongo { char * buf = buf_holder.get(); ProgressMeter m( fileLength ); + m.setUnits( "bytes" ); while ( read < fileLength ) { size_t amt = fread(buf, 1, 4, file); diff --git a/util/goodies.h b/util/goodies.h index d345c62642a..34108200230 100644 --- a/util/goodies.h +++ b/util/goodies.h @@ -159,12 +159,13 @@ namespace mongo { class ProgressMeter : boost::noncopyable { public: - ProgressMeter( unsigned long long total , int secondsBetween = 3 , int checkInterval = 100 ) { + ProgressMeter( unsigned long long total , int secondsBetween = 3 , int checkInterval = 100 , const char * units = NULL ) : _units(units) { reset( total , secondsBetween , checkInterval ); } ProgressMeter() { _active = 0; + _units = NULL; } // typically you do ProgressMeterHolder @@ -194,7 +195,7 @@ namespace mongo { */ bool hit( int n = 1 ) { if ( ! _active ) { - cout << "warning: hit on in-active ProgressMeter" << endl; + cout << "warning: hit an inactive ProgressMeter" << endl; return false; } @@ -209,12 +210,23 @@ namespace mongo { if ( _total > 0 ) { int per = (int)( ( (double)_done * 100.0 ) / (double)_total ); - cout << "\t\t" << _done << "/" << _total << "\t" << per << "%" << endl; + cout << "\t\t" << _done << "/" << _total << "\t" << per << "%"; + + if ( _units ) { + cout << "\t(" << _units << ")" << endl; + } + else { + cout << endl; + } } _lastTime = t; return true; } + void setUnits( const char * units ) { + _units = units; + } + void setTotalWhileRunning( unsigned long long total ) { _total = total; } @@ -230,6 +242,11 @@ namespace mongo { return ""; stringstream buf; buf << _done << "/" << _total << " " << (_done*100)/_total << "%"; + + if ( _units ) { + buf << "\t(" << _units << ")" << endl; + } + return buf.str(); } @@ -247,6 +264,8 @@ namespace mongo { unsigned long long _done; unsigned long long _hits; int _lastTime; + + const char * _units; }; // e.g.: |