summaryrefslogtreecommitdiff
path: root/src/mongo/db/lockstate.cpp
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2012-06-12 00:49:13 -0400
committerEliot Horowitz <eliot@10gen.com>2012-06-12 01:52:26 -0400
commitf58ba6e38cb3e3f62d6cbacdfd646364b005a17e (patch)
treed4268a953f11d4c2389f7a075ebf7890a02bc230 /src/mongo/db/lockstate.cpp
parentea5f7a757789ba0ddaf9dfcab4fac8ab4050ae43 (diff)
downloadmongo-f58ba6e38cb3e3f62d6cbacdfd646364b005a17e.tar.gz
SERVER-4328 - db and global lock and acquisition time for read and write
Diffstat (limited to 'src/mongo/db/lockstate.cpp')
-rwxr-xr-xsrc/mongo/db/lockstate.cpp39
1 files changed, 37 insertions, 2 deletions
diff --git a/src/mongo/db/lockstate.cpp b/src/mongo/db/lockstate.cpp
index 511d4d163b9..2dac730c0c8 100755
--- a/src/mongo/db/lockstate.cpp
+++ b/src/mongo/db/lockstate.cpp
@@ -34,7 +34,8 @@ namespace mongo {
_nestableCount(0),
_otherCount(0),
_otherLock(NULL),
- _scopedLk(NULL)
+ _scopedLk(NULL),
+ _lockPending(false)
{
}
@@ -50,6 +51,10 @@ namespace mongo {
return _threadState == 'r' || _threadState == 'R';
}
+ bool LockState::hasAnyWriteLock() const {
+ return _threadState == 'w' || _threadState == 'W';
+ }
+
bool LockState::isLocked( const StringData& ns ) {
char db[MaxDatabaseNameLen];
nsToDatabase(ns.data(), db);
@@ -68,7 +73,7 @@ namespace mongo {
return false;
}
- void LockState::locked( char newState ) {
+ void LockState::lockedStart( char newState ) {
_threadState = newState;
}
void LockState::unlocked() {
@@ -88,6 +93,11 @@ namespace mongo {
return "?";
}
+ BSONObj LockState::reportState() {
+ BSONObjBuilder b;
+ reportState( b );
+ return b.obj();
+ }
/** Note: this is is called by the currentOp command, which is a different
thread. So be careful about thread safety here. For example reading
@@ -120,6 +130,7 @@ namespace mongo {
BSONObj o = b.obj();
if( !o.isEmpty() )
res.append("locks", o);
+ res.append( "waitingForLock" , _lockPending );
}
void LockState::Dump() {
@@ -204,5 +215,29 @@ namespace mongo {
_otherLock = 0;
}
+ LockStat* LockState::getRelevantLockStat() {
+ if ( _otherLock )
+ return &_otherLock->stats;
+
+ if ( isRW() )
+ return Lock::globalLockStat();
+
+ if ( _whichNestable )
+ return Lock::nestableLockStat( _whichNestable );
+ fassertFailed( 16337 );
+ }
+
+
+ Acquiring::Acquiring( Lock::ScopedLock* lock, LockState& ls )
+ : _lock( lock ), _ls( ls ){
+ _ls._lockPending = true;
+ }
+
+ Acquiring::~Acquiring() {
+ _ls._lockPending = false;
+ LockStat* stat = _ls.getRelevantLockStat();
+ stat->recordAcquireTimeMicros( _ls.threadState(), _lock->acquireFinished( stat ) );
+ }
+
}