summaryrefslogtreecommitdiff
path: root/src/mongo/db/concurrency/lock_state.cpp
diff options
context:
space:
mode:
authorXiangyu Yao <xiangyu.yao@mongodb.com>2018-09-04 15:42:43 -0400
committerXiangyu Yao <xiangyu.yao@mongodb.com>2018-09-07 23:13:42 -0400
commitb5ca922655a1d0a438c39c38b2c4434016069cb7 (patch)
tree514a178784e763803db5cad8d72c56fc77518a91 /src/mongo/db/concurrency/lock_state.cpp
parenta8fe1d82c3c5484c7e8a6402a34bc45ea11d06f1 (diff)
downloadmongo-b5ca922655a1d0a438c39c38b2c4434016069cb7.tar.gz
SERVER-26854 LockStats for sub-operations should not include wait time for previous operations
Diffstat (limited to 'src/mongo/db/concurrency/lock_state.cpp')
-rw-r--r--src/mongo/db/concurrency/lock_state.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/mongo/db/concurrency/lock_state.cpp b/src/mongo/db/concurrency/lock_state.cpp
index 47fd8a408b8..e526931d785 100644
--- a/src/mongo/db/concurrency/lock_state.cpp
+++ b/src/mongo/db/concurrency/lock_state.cpp
@@ -538,7 +538,8 @@ ResourceId LockerImpl::getWaitingResource() const {
return ResourceId();
}
-void LockerImpl::getLockerInfo(LockerInfo* lockerInfo) const {
+void LockerImpl::getLockerInfo(LockerInfo* lockerInfo,
+ const boost::optional<SingleThreadedLockStats> lockStatsBase) const {
invariant(lockerInfo);
// Zero-out the contents
@@ -562,11 +563,19 @@ void LockerImpl::getLockerInfo(LockerInfo* lockerInfo) const {
lockerInfo->waitingResource = getWaitingResource();
lockerInfo->stats.append(_stats);
+
+ // lockStatsBase is a snapshot of lock stats taken when the sub-operation starts. Only
+ // sub-operations have lockStatsBase.
+ if (lockStatsBase)
+ // Adjust the lock stats by subtracting the lockStatsBase. No mutex is needed because
+ // lockStatsBase is immutable.
+ lockerInfo->stats.subtract(*lockStatsBase);
}
-boost::optional<Locker::LockerInfo> LockerImpl::getLockerInfo() const {
+boost::optional<Locker::LockerInfo> LockerImpl::getLockerInfo(
+ const boost::optional<SingleThreadedLockStats> lockStatsBase) const {
Locker::LockerInfo lockerInfo;
- getLockerInfo(&lockerInfo);
+ getLockerInfo(&lockerInfo, lockStatsBase);
return std::move(lockerInfo);
}