diff options
author | Milena Ivanova <milena.ivanova@mongodb.com> | 2021-05-28 09:24:11 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-10-12 10:00:03 +0000 |
commit | 10bbd356ff484dd6bb921ad4efe54f4e97aab32b (patch) | |
tree | 029a0c03f40e98b90509dba8b08b89d2ff09a781 /src/mongo/db/stats | |
parent | b3107d73a2c58d7e016b834dae0acfd01c0db8d7 (diff) | |
download | mongo-10bbd356ff484dd6bb921ad4efe54f4e97aab32b.tar.gz |
SERVER-56602 Track usage of match expressions in serverStatus
(cherry picked from commit 98b4a0a2b2c4a230efe1c2ddc3da487a575d670d)
Diffstat (limited to 'src/mongo/db/stats')
-rw-r--r-- | src/mongo/db/stats/counters.cpp | 1 | ||||
-rw-r--r-- | src/mongo/db/stats/counters.h | 33 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/mongo/db/stats/counters.cpp b/src/mongo/db/stats/counters.cpp index 1cf3e4f4f72..2f9b070b888 100644 --- a/src/mongo/db/stats/counters.cpp +++ b/src/mongo/db/stats/counters.cpp @@ -314,4 +314,5 @@ AuthCounter authCounter; AggStageCounters aggStageCounters; DotsAndDollarsFieldsCounters dotsAndDollarsFieldsCounters; OperatorCountersExpressions operatorCountersExpressions; +OperatorCountersMatchExpressions operatorCountersMatchExpressions; } // namespace mongo diff --git a/src/mongo/db/stats/counters.h b/src/mongo/db/stats/counters.h index 397951bdd7b..18e39b1366a 100644 --- a/src/mongo/db/stats/counters.h +++ b/src/mongo/db/stats/counters.h @@ -363,4 +363,37 @@ private: }; extern OperatorCountersExpressions operatorCountersExpressions; + +/** + * Global counters for match expressions. + */ +class OperatorCountersMatchExpressions { +private: + struct MatchExprCounter { + MatchExprCounter(StringData name) : metric("operatorCounters.match." + name, &counter) {} + + Counter64 counter; + ServerStatusMetricField<Counter64> metric; + }; + +public: + void addMatchExprCounter(StringData name) { + operatorCountersMatchExprMap[name] = std::make_unique<MatchExprCounter>(name); + } + + void mergeCounters(StringMap<uint64_t>& toMerge) { + for (auto&& [name, cnt] : toMerge) { + if (auto it = operatorCountersMatchExprMap.find(name); + it != operatorCountersMatchExprMap.end()) { + it->second->counter.increment(cnt); + } + } + } + +private: + // Map of match expressions to the number of occurrences in queries. + StringMap<std::unique_ptr<MatchExprCounter>> operatorCountersMatchExprMap = {}; +}; + +extern OperatorCountersMatchExpressions operatorCountersMatchExpressions; } // namespace mongo |