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/db/stats/top.cpp | |
parent | 01965cf52bce6976637ecb8f4a622aeb05ab256a (diff) | |
download | mongo-9c2ed42daa8fbbef4a919c21ec564e2db55e8d60.tar.gz |
SERVER-18579: Clang-Format - reformat code, no comment reflow
Diffstat (limited to 'src/mongo/db/stats/top.cpp')
-rw-r--r-- | src/mongo/db/stats/top.cpp | 188 |
1 files changed, 92 insertions, 96 deletions
diff --git a/src/mongo/db/stats/top.cpp b/src/mongo/db/stats/top.cpp index 903378e1834..f4f66d42a05 100644 --- a/src/mongo/db/stats/top.cpp +++ b/src/mongo/db/stats/top.cpp @@ -40,86 +40,84 @@ namespace mongo { - using std::endl; - using std::string; - using std::stringstream; - using std::vector; +using std::endl; +using std::string; +using std::stringstream; +using std::vector; namespace { - const auto getTop = ServiceContext::declareDecoration<Top>(); +const auto getTop = ServiceContext::declareDecoration<Top>(); -} // namespace +} // namespace - Top::UsageData::UsageData( const UsageData& older, const UsageData& newer ) { - // this won't be 100% accurate on rollovers and drop(), but at least it won't be negative - time = (newer.time >= older.time) ? (newer.time - older.time) : newer.time; - count = (newer.count >= older.count) ? (newer.count - older.count) : newer.count; - } - - Top::CollectionData::CollectionData( const CollectionData& older, const CollectionData& newer ) - : total( older.total, newer.total ), - readLock( older.readLock, newer.readLock ), - writeLock( older.writeLock, newer.writeLock ), - queries( older.queries, newer.queries ), - getmore( older.getmore, newer.getmore ), - insert( older.insert, newer.insert ), - update( older.update, newer.update ), - remove( older.remove, newer.remove ), - commands( older.commands, newer.commands ) { - - } - - // static - Top& Top::get(ServiceContext* service) { - return getTop(service); - } +Top::UsageData::UsageData(const UsageData& older, const UsageData& newer) { + // this won't be 100% accurate on rollovers and drop(), but at least it won't be negative + time = (newer.time >= older.time) ? (newer.time - older.time) : newer.time; + count = (newer.count >= older.count) ? (newer.count - older.count) : newer.count; +} - void Top::record( StringData ns, int op, int lockType, long long micros, bool command ) { - if ( ns[0] == '?' ) - return; +Top::CollectionData::CollectionData(const CollectionData& older, const CollectionData& newer) + : total(older.total, newer.total), + readLock(older.readLock, newer.readLock), + writeLock(older.writeLock, newer.writeLock), + queries(older.queries, newer.queries), + getmore(older.getmore, newer.getmore), + insert(older.insert, newer.insert), + update(older.update, newer.update), + remove(older.remove, newer.remove), + commands(older.commands, newer.commands) {} + +// static +Top& Top::get(ServiceContext* service) { + return getTop(service); +} - //cout << "record: " << ns << "\t" << op << "\t" << command << endl; - stdx::lock_guard<SimpleMutex> lk(_lock); +void Top::record(StringData ns, int op, int lockType, long long micros, bool command) { + if (ns[0] == '?') + return; - if ( ( command || op == dbQuery ) && ns == _lastDropped ) { - _lastDropped = ""; - return; - } + // cout << "record: " << ns << "\t" << op << "\t" << command << endl; + stdx::lock_guard<SimpleMutex> lk(_lock); - CollectionData& coll = _usage[ns]; - _record( coll, op, lockType, micros, command ); + if ((command || op == dbQuery) && ns == _lastDropped) { + _lastDropped = ""; + return; } - void Top::_record( CollectionData& c, int op, int lockType, long long micros, bool command ) { - c.total.inc( micros ); + CollectionData& coll = _usage[ns]; + _record(coll, op, lockType, micros, command); +} + +void Top::_record(CollectionData& c, int op, int lockType, long long micros, bool command) { + c.total.inc(micros); - if ( lockType > 0 ) - c.writeLock.inc( micros ); - else if ( lockType < 0 ) - c.readLock.inc( micros ); + if (lockType > 0) + c.writeLock.inc(micros); + else if (lockType < 0) + c.readLock.inc(micros); - switch ( op ) { + switch (op) { case 0: // use 0 for unknown, non-specific break; case dbUpdate: - c.update.inc( micros ); + c.update.inc(micros); break; case dbInsert: - c.insert.inc( micros ); + c.insert.inc(micros); break; case dbQuery: - if ( command ) - c.commands.inc( micros ); + if (command) + c.commands.inc(micros); else - c.queries.inc( micros ); + c.queries.inc(micros); break; case dbGetMore: - c.getmore.inc( micros ); + c.getmore.inc(micros); break; case dbDelete: - c.remove.inc( micros ); + c.remove.inc(micros); break; case dbKillCursors: break; @@ -133,62 +131,60 @@ namespace { break; default: log() << "unknown op in Top::record: " << op << endl; - } - - } - - void Top::collectionDropped( StringData ns ) { - stdx::lock_guard<SimpleMutex> lk(_lock); - _usage.erase(ns); - _lastDropped = ns.toString(); } +} - void Top::cloneMap(Top::UsageMap& out) const { - stdx::lock_guard<SimpleMutex> lk(_lock); - out = _usage; - } +void Top::collectionDropped(StringData ns) { + stdx::lock_guard<SimpleMutex> lk(_lock); + _usage.erase(ns); + _lastDropped = ns.toString(); +} - void Top::append( BSONObjBuilder& b ) { - stdx::lock_guard<SimpleMutex> lk( _lock ); - _appendToUsageMap( b, _usage ); - } +void Top::cloneMap(Top::UsageMap& out) const { + stdx::lock_guard<SimpleMutex> lk(_lock); + out = _usage; +} - void Top::_appendToUsageMap( BSONObjBuilder& b, const UsageMap& map ) const { - // pull all the names into a vector so we can sort them for the user +void Top::append(BSONObjBuilder& b) { + stdx::lock_guard<SimpleMutex> lk(_lock); + _appendToUsageMap(b, _usage); +} - vector<string> names; - for ( UsageMap::const_iterator i = map.begin(); i != map.end(); ++i ) { - names.push_back( i->first ); - } +void Top::_appendToUsageMap(BSONObjBuilder& b, const UsageMap& map) const { + // pull all the names into a vector so we can sort them for the user - std::sort( names.begin(), names.end() ); + vector<string> names; + for (UsageMap::const_iterator i = map.begin(); i != map.end(); ++i) { + names.push_back(i->first); + } - for ( size_t i=0; i<names.size(); i++ ) { - BSONObjBuilder bb( b.subobjStart( names[i] ) ); + std::sort(names.begin(), names.end()); - const CollectionData& coll = map.find(names[i])->second; + for (size_t i = 0; i < names.size(); i++) { + BSONObjBuilder bb(b.subobjStart(names[i])); - _appendStatsEntry( b, "total", coll.total ); + const CollectionData& coll = map.find(names[i])->second; - _appendStatsEntry( b, "readLock", coll.readLock ); - _appendStatsEntry( b, "writeLock", coll.writeLock ); + _appendStatsEntry(b, "total", coll.total); - _appendStatsEntry( b, "queries", coll.queries ); - _appendStatsEntry( b, "getmore", coll.getmore ); - _appendStatsEntry( b, "insert", coll.insert ); - _appendStatsEntry( b, "update", coll.update ); - _appendStatsEntry( b, "remove", coll.remove ); - _appendStatsEntry( b, "commands", coll.commands ); + _appendStatsEntry(b, "readLock", coll.readLock); + _appendStatsEntry(b, "writeLock", coll.writeLock); - bb.done(); - } - } + _appendStatsEntry(b, "queries", coll.queries); + _appendStatsEntry(b, "getmore", coll.getmore); + _appendStatsEntry(b, "insert", coll.insert); + _appendStatsEntry(b, "update", coll.update); + _appendStatsEntry(b, "remove", coll.remove); + _appendStatsEntry(b, "commands", coll.commands); - void Top::_appendStatsEntry( BSONObjBuilder& b, const char * statsName, const UsageData& map ) const { - BSONObjBuilder bb( b.subobjStart( statsName ) ); - bb.appendNumber( "time", map.time ); - bb.appendNumber( "count", map.count ); bb.done(); } +} +void Top::_appendStatsEntry(BSONObjBuilder& b, const char* statsName, const UsageData& map) const { + BSONObjBuilder bb(b.subobjStart(statsName)); + bb.appendNumber("time", map.time); + bb.appendNumber("count", map.count); + bb.done(); +} } |