diff options
author | Eliot Horowitz <eliot@10gen.com> | 2012-04-27 12:12:46 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2012-05-07 10:35:36 -0400 |
commit | 798548691180ea5c7b35ead49361b4def3c82fac (patch) | |
tree | 900ab112af969db39f8ad1784fef3013c92e1990 /src/mongo/db/lockstat.cpp | |
parent | a412d552b19299faadc967fe1f4d91cb1bd36dde (diff) | |
download | mongo-798548691180ea5c7b35ead49361b4def3c82fac.tar.gz |
move lockstat to its own file
Diffstat (limited to 'src/mongo/db/lockstat.cpp')
-rw-r--r-- | src/mongo/db/lockstat.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/mongo/db/lockstat.cpp b/src/mongo/db/lockstat.cpp new file mode 100644 index 00000000000..4bc34d35ecb --- /dev/null +++ b/src/mongo/db/lockstat.cpp @@ -0,0 +1,62 @@ +// lockstat.cpp + +#include "mongo/pch.h" +#include "lockstat.h" +#include "mongo/db/jsobj.h" + +namespace mongo { + + BSONObj LockStat::report() const { + BSONObjBuilder x; + BSONObjBuilder y; + x.append("R", (long long) timeLocked[0]); + x.append("W", (long long) timeLocked[1]); + if( timeLocked[2] || timeLocked[3] ) { + x.append("r", (long long) timeLocked[2]); + x.append("w", (long long) timeLocked[3]); + } + y.append("R", (long long) timeAcquiring[0]); + y.append("W", (long long) timeAcquiring[1]); + if( timeAcquiring[2] || timeAcquiring[3] ) { + y.append("r", (long long) timeAcquiring[2]); + y.append("w", (long long) timeAcquiring[3]); + } + return BSON( + "timeLocked" << x.obj() << + "timeAcquiring" << y.obj() + ); + } + + unsigned LockStat::mapNo(char type) { + switch( type ) { + case 'R' : return 0; + case 'W' : return 1; + case 'r' : return 2; + case 'w' : return 3; + default: ; + } + fassert(16146,false); + return 0; + } + + LockStat::Acquiring::Acquiring(LockStat& _ls, char t) : ls(_ls) { + type = mapNo(t); + dassert( type < N ); + } + + // note: we have race conditions on the following += + // hmmm.... + + LockStat::Acquiring::~Acquiring() { + ls.timeAcquiring[type] += tmr.micros(); + if( type == 1 ) + ls.W_Timer.reset(); + } + + void LockStat::unlocking(char tp) { + unsigned type = mapNo(tp); + if( type == 1 ) + timeLocked[type] += W_Timer.micros(); + } + +} |