summaryrefslogtreecommitdiff
path: root/src/mongo/db/concurrency/lock_stats.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/concurrency/lock_stats.cpp')
-rw-r--r--src/mongo/db/concurrency/lock_stats.cpp182
1 files changed, 89 insertions, 93 deletions
diff --git a/src/mongo/db/concurrency/lock_stats.cpp b/src/mongo/db/concurrency/lock_stats.cpp
index c115244f369..809799299a7 100644
--- a/src/mongo/db/concurrency/lock_stats.cpp
+++ b/src/mongo/db/concurrency/lock_stats.cpp
@@ -34,125 +34,121 @@
namespace mongo {
- template<typename CounterType>
- LockStats<CounterType>::LockStats() {
- reset();
+template <typename CounterType>
+LockStats<CounterType>::LockStats() {
+ reset();
+}
+
+template <typename CounterType>
+void LockStats<CounterType>::report(BSONObjBuilder* builder) const {
+ // All indexing below starts from offset 1, because we do not want to report/account
+ // position 0, which is a sentinel value for invalid resource/no lock.
+ for (int i = 1; i < ResourceTypesCount; i++) {
+ _report(builder, resourceTypeName(static_cast<ResourceType>(i)), _stats[i]);
}
- template<typename CounterType>
- void LockStats<CounterType>::report(BSONObjBuilder* builder) const {
- // All indexing below starts from offset 1, because we do not want to report/account
- // position 0, which is a sentinel value for invalid resource/no lock.
- for (int i = 1; i < ResourceTypesCount; i++) {
- _report(builder, resourceTypeName(static_cast<ResourceType>(i)), _stats[i]);
- }
-
- _report(builder, "oplog", _oplogStats);
- }
-
- template<typename CounterType>
- void LockStats<CounterType>::_report(BSONObjBuilder* builder,
- const char* sectionName,
- const PerModeLockStatCounters& stat) const {
-
- std::unique_ptr<BSONObjBuilder> section;
-
- // All indexing below starts from offset 1, because we do not want to report/account
- // position 0, which is a sentinel value for invalid resource/no lock.
-
- // Num acquires
- {
- std::unique_ptr<BSONObjBuilder> numAcquires;
- for (int mode = 1; mode < LockModesCount; mode++) {
- const long long value = CounterOps::get(stat.modeStats[mode].numAcquisitions);
- if (value > 0) {
- if (!numAcquires) {
- if (!section) {
- section.reset(new BSONObjBuilder(builder->subobjStart(sectionName)));
- }
-
- numAcquires.reset(
- new BSONObjBuilder(section->subobjStart("acquireCount")));
+ _report(builder, "oplog", _oplogStats);
+}
+
+template <typename CounterType>
+void LockStats<CounterType>::_report(BSONObjBuilder* builder,
+ const char* sectionName,
+ const PerModeLockStatCounters& stat) const {
+ std::unique_ptr<BSONObjBuilder> section;
+
+ // All indexing below starts from offset 1, because we do not want to report/account
+ // position 0, which is a sentinel value for invalid resource/no lock.
+
+ // Num acquires
+ {
+ std::unique_ptr<BSONObjBuilder> numAcquires;
+ for (int mode = 1; mode < LockModesCount; mode++) {
+ const long long value = CounterOps::get(stat.modeStats[mode].numAcquisitions);
+ if (value > 0) {
+ if (!numAcquires) {
+ if (!section) {
+ section.reset(new BSONObjBuilder(builder->subobjStart(sectionName)));
}
- numAcquires->append(legacyModeName(static_cast<LockMode>(mode)), value);
+
+ numAcquires.reset(new BSONObjBuilder(section->subobjStart("acquireCount")));
}
+ numAcquires->append(legacyModeName(static_cast<LockMode>(mode)), value);
}
}
+ }
- // Num waits
- {
- std::unique_ptr<BSONObjBuilder> numWaits;
- for (int mode = 1; mode < LockModesCount; mode++) {
- const long long value = CounterOps::get(stat.modeStats[mode].numWaits);
- if (value > 0) {
- if (!numWaits) {
- if (!section) {
- section.reset(new BSONObjBuilder(builder->subobjStart(sectionName)));
- }
-
- numWaits.reset(
- new BSONObjBuilder(section->subobjStart("acquireWaitCount")));
+ // Num waits
+ {
+ std::unique_ptr<BSONObjBuilder> numWaits;
+ for (int mode = 1; mode < LockModesCount; mode++) {
+ const long long value = CounterOps::get(stat.modeStats[mode].numWaits);
+ if (value > 0) {
+ if (!numWaits) {
+ if (!section) {
+ section.reset(new BSONObjBuilder(builder->subobjStart(sectionName)));
}
- numWaits->append(legacyModeName(static_cast<LockMode>(mode)), value);
+
+ numWaits.reset(new BSONObjBuilder(section->subobjStart("acquireWaitCount")));
}
+ numWaits->append(legacyModeName(static_cast<LockMode>(mode)), value);
}
}
+ }
- // Total time waiting
- {
- std::unique_ptr<BSONObjBuilder> timeAcquiring;
- for (int mode = 1; mode < LockModesCount; mode++) {
- const long long value = CounterOps::get(stat.modeStats[mode].combinedWaitTimeMicros);
- if (value > 0) {
- if (!timeAcquiring) {
- if (!section) {
- section.reset(new BSONObjBuilder(builder->subobjStart(sectionName)));
- }
-
- timeAcquiring.reset(
- new BSONObjBuilder(section->subobjStart("timeAcquiringMicros")));
+ // Total time waiting
+ {
+ std::unique_ptr<BSONObjBuilder> timeAcquiring;
+ for (int mode = 1; mode < LockModesCount; mode++) {
+ const long long value = CounterOps::get(stat.modeStats[mode].combinedWaitTimeMicros);
+ if (value > 0) {
+ if (!timeAcquiring) {
+ if (!section) {
+ section.reset(new BSONObjBuilder(builder->subobjStart(sectionName)));
}
- timeAcquiring->append(legacyModeName(static_cast<LockMode>(mode)), value);
+
+ timeAcquiring.reset(
+ new BSONObjBuilder(section->subobjStart("timeAcquiringMicros")));
}
+ timeAcquiring->append(legacyModeName(static_cast<LockMode>(mode)), value);
}
}
+ }
- // Deadlocks
- {
- std::unique_ptr<BSONObjBuilder> deadlockCount;
- for (int mode = 1; mode < LockModesCount; mode++) {
- const long long value = CounterOps::get(stat.modeStats[mode].numDeadlocks);
- if (value > 0) {
- if (!deadlockCount) {
- if (!section) {
- section.reset(new BSONObjBuilder(builder->subobjStart(sectionName)));
- }
-
- deadlockCount.reset(
- new BSONObjBuilder(section->subobjStart("deadlockCount")));
+ // Deadlocks
+ {
+ std::unique_ptr<BSONObjBuilder> deadlockCount;
+ for (int mode = 1; mode < LockModesCount; mode++) {
+ const long long value = CounterOps::get(stat.modeStats[mode].numDeadlocks);
+ if (value > 0) {
+ if (!deadlockCount) {
+ if (!section) {
+ section.reset(new BSONObjBuilder(builder->subobjStart(sectionName)));
}
- deadlockCount->append(legacyModeName(static_cast<LockMode>(mode)), value);
+
+ deadlockCount.reset(new BSONObjBuilder(section->subobjStart("deadlockCount")));
}
+ deadlockCount->append(legacyModeName(static_cast<LockMode>(mode)), value);
}
}
}
+}
- template<typename CounterType>
- void LockStats<CounterType>::reset() {
- for (int i = 0; i < ResourceTypesCount; i++) {
- for (int mode = 0; mode < LockModesCount; mode++) {
- _stats[i].modeStats[mode].reset();
- }
- }
-
+template <typename CounterType>
+void LockStats<CounterType>::reset() {
+ for (int i = 0; i < ResourceTypesCount; i++) {
for (int mode = 0; mode < LockModesCount; mode++) {
- _oplogStats.modeStats[mode].reset();
+ _stats[i].modeStats[mode].reset();
}
}
+ for (int mode = 0; mode < LockModesCount; mode++) {
+ _oplogStats.modeStats[mode].reset();
+ }
+}
+
- // Ensures that there are instances compiled for LockStats for AtomicInt64 and int64_t
- template class LockStats<int64_t>;
- template class LockStats<AtomicInt64>;
+// Ensures that there are instances compiled for LockStats for AtomicInt64 and int64_t
+template class LockStats<int64_t>;
+template class LockStats<AtomicInt64>;
-} // namespace mongo
+} // namespace mongo