diff options
Diffstat (limited to 'db/stats/counters.h')
-rw-r--r-- | db/stats/counters.h | 77 |
1 files changed, 51 insertions, 26 deletions
diff --git a/db/stats/counters.h b/db/stats/counters.h index 2704464..b5cad85 100644 --- a/db/stats/counters.h +++ b/db/stats/counters.h @@ -21,6 +21,7 @@ #include "../jsobj.h" #include "../../util/message.h" #include "../../util/processinfo.h" +#include "../../util/concurrency/spin_lock.h" namespace mongo { @@ -30,28 +31,33 @@ namespace mongo { */ class OpCounters { public: - + OpCounters(); - AtomicUInt * getInsert(){ return _insert; } - AtomicUInt * getQuery(){ return _query; } - AtomicUInt * getUpdate(){ return _update; } - AtomicUInt * getDelete(){ return _delete; } - AtomicUInt * getGetMore(){ return _getmore; } - AtomicUInt * getCommand(){ return _command; } - - void gotInsert(){ _insert[0]++; } - void gotQuery(){ _query[0]++; } - void gotUpdate(){ _update[0]++; } - void gotDelete(){ _delete[0]++; } - void gotGetMore(){ _getmore[0]++; } - void gotCommand(){ _command[0]++; } + AtomicUInt * getInsert() { return _insert; } + AtomicUInt * getQuery() { return _query; } + AtomicUInt * getUpdate() { return _update; } + AtomicUInt * getDelete() { return _delete; } + AtomicUInt * getGetMore() { return _getmore; } + AtomicUInt * getCommand() { return _command; } + + void incInsertInWriteLock(int n) { _insert->x += n; } + void gotInsert() { _insert[0]++; } + void gotQuery() { _query[0]++; } + void gotUpdate() { _update[0]++; } + void gotDelete() { _delete[0]++; } + void gotGetMore() { _getmore[0]++; } + void gotCommand() { _command[0]++; } void gotOp( int op , bool isCommand ); - BSONObj& getObj(){ return _obj; } + BSONObj& getObj(); + private: BSONObj _obj; + + // todo: there will be a lot of cache line contention on these. need to do something + // else eventually. AtomicUInt * _insert; AtomicUInt * _query; AtomicUInt * _update; @@ -59,14 +65,16 @@ namespace mongo { AtomicUInt * _getmore; AtomicUInt * _command; }; - + extern OpCounters globalOpCounters; + extern OpCounters replOpCounters; + class IndexCounters { public: IndexCounters(); - - void btree( char * node ){ + + void btree( char * node ) { if ( ! _memSupported ) return; if ( _sampling++ % _samplingrate ) @@ -74,28 +82,28 @@ namespace mongo { btree( _pi.blockInMemory( node ) ); } - void btree( bool memHit ){ + void btree( bool memHit ) { if ( memHit ) _btreeMemHits++; else _btreeMemMisses++; _btreeAccesses++; } - void btreeHit(){ _btreeMemHits++; _btreeAccesses++; } - void btreeMiss(){ _btreeMemMisses++; _btreeAccesses++; } - + void btreeHit() { _btreeMemHits++; _btreeAccesses++; } + void btreeMiss() { _btreeMemMisses++; _btreeAccesses++; } + void append( BSONObjBuilder& b ); - + private: ProcessInfo _pi; bool _memSupported; int _sampling; int _samplingrate; - + int _resets; long long _maxAllowed; - + long long _btreeMemMisses; long long _btreeMemHits; long long _btreeAccesses; @@ -108,7 +116,7 @@ namespace mongo { FlushCounters(); void flushed(int ms); - + void append( BSONObjBuilder& b ); private: @@ -130,4 +138,21 @@ namespace mongo { map<string,long long> _counts; // TODO: replace with thread safe map mongo::mutex _mutex; }; + + class NetworkCounter { + public: + NetworkCounter() : _bytesIn(0), _bytesOut(0), _requests(0), _overflows(0) {} + void hit( long long bytesIn , long long bytesOut ); + void append( BSONObjBuilder& b ); + private: + long long _bytesIn; + long long _bytesOut; + long long _requests; + + long long _overflows; + + SpinLock _lock; + }; + + extern NetworkCounter networkCounter; } |