diff options
author | nehakhatri5 <neha.khatri@mongodb.com> | 2018-12-07 16:55:42 +1100 |
---|---|---|
committer | Alex Cameron <alex.cameron@10gen.com> | 2019-03-27 04:59:43 +0000 |
commit | 097c20d21c6e735f179bd14eb30d963d5f2a7a82 (patch) | |
tree | c6f2f85ea705a0858fb8c395859946739c6bc3f2 /src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp | |
parent | 79be33d4f24e8a38a42546b4f4e61885a8a3ce6d (diff) | |
download | mongo-097c20d21c6e735f179bd14eb30d963d5f2a7a82.tar.gz |
SERVER-38239 Added getOperationStatistics() API to fetch storage stats from WiredTigerslow-ops-backport
(cherry picked from commit ba3894493a94ed3c18458f391ff181d57475f010)
Diffstat (limited to 'src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp')
-rw-r--r-- | src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp index 7c954df00ab..383b5186d8e 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp @@ -665,4 +665,84 @@ Status WiredTigerUtil::exportTableToBSON(WT_SESSION* session, return Status::OK(); } +Status WiredTigerUtil::exportOperationStatsInfoToBSON(WT_SESSION* session, + const std::string& uri, + const std::string& config, + BSONObjBuilder* bob) { + invariant(session); + invariant(bob); + + // Map the statistics to a name and type desired for user consumption. There are two types of + // operation statistics - data and wait. + enum class Section { DATA, WAIT }; + static std::map<int, std::pair<StringData, Section>> statNameMap = { + {WT_STAT_SESSION_BYTES_READ, std::make_pair("bytesRead", Section::DATA)}, + {WT_STAT_SESSION_BYTES_WRITE, std::make_pair("bytesWritten", Section::DATA)}, + {WT_STAT_SESSION_LOCK_DHANDLE_WAIT, std::make_pair("handleLock", Section::WAIT)}, + {WT_STAT_SESSION_READ_TIME, std::make_pair("timeReadingMicros", Section::DATA)}, + {WT_STAT_SESSION_WRITE_TIME, std::make_pair("timeWritingMicros", Section::DATA)}, + {WT_STAT_SESSION_LOCK_SCHEMA_WAIT, std::make_pair("schemaLock", Section::WAIT)}, + {WT_STAT_SESSION_CACHE_TIME, std::make_pair("cache", Section::WAIT)}}; + + WT_CURSOR* c = nullptr; + const char* cursorConfig = config.empty() ? nullptr : config.c_str(); + int ret = session->open_cursor(session, uri.c_str(), nullptr, cursorConfig, &c); + if (ret != 0) { + return Status(ErrorCodes::CursorNotFound, + str::stream() << "unable to open cursor at URI " << uri << ". reason: " + << wiredtiger_strerror(ret)); + } + invariant(c); + ON_BLOCK_EXIT(c->close, c); + + BSONObjBuilder* dataSection = nullptr; + BSONObjBuilder* waitSection = nullptr; + const char* desc; + uint64_t value; + uint64_t key; + while (c->next(c) == 0 && c->get_key(c, &key) == 0) { + fassert(51035, c->get_value(c, &desc, nullptr, &value) == 0); + + StringData statName; + // Find the user consumable name for this statistic. + auto statIt = statNameMap.find(key); + invariant(statIt != statNameMap.end()); + statName = statIt->second.first; + + Section subs = statIt->second.second; + long long casted_val = _castStatisticsValue<long long>(value); + + // Add this statistic only if higher than zero. + if (casted_val > 0) { + // Gather the statistic into its own subsection in the BSONObj. + switch (subs) { + case Section::DATA: + if (!dataSection) + dataSection = new BSONObjBuilder(); + + dataSection->append(statName, casted_val); + break; + case Section::WAIT: + if (!waitSection) + waitSection = new BSONObjBuilder(); + + waitSection->append(statName, casted_val); + break; + default: + return Status(ErrorCodes::BadValue, + str::stream() << "Unexpected storage statistics type."); + } + } + } + + if (dataSection) + bob->append("data", dataSection->obj()); + if (waitSection) + bob->append("timeWaitingMicros", waitSection->obj()); + + // Reset the statistics so that the next fetch gives the recent values. + c->reset(c); + return Status::OK(); +} + } // namespace mongo |