diff options
author | Jordi Olivares Provencio <jordi.olivares-provencio@mongodb.com> | 2022-07-07 12:41:02 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-07-07 13:19:21 +0000 |
commit | 0f8bfc630081c7688bbc8072c4380d854f0e1c58 (patch) | |
tree | 0219b50a0f89fbd288b0a5b2e5ac7a9566a94db8 | |
parent | dcaa06adce903997e4a499822efc1ced9891f476 (diff) | |
download | mongo-0f8bfc630081c7688bbc8072c4380d854f0e1c58.tar.gz |
SERVER-67102 Avoid unnecessary string copies for metrics
4 files changed, 26 insertions, 26 deletions
diff --git a/src/mongo/db/stats/resource_consumption_metrics.cpp b/src/mongo/db/stats/resource_consumption_metrics.cpp index 24d36012f2c..1fccd04fc66 100644 --- a/src/mongo/db/stats/resource_consumption_metrics.cpp +++ b/src/mongo/db/stats/resource_consumption_metrics.cpp @@ -239,7 +239,7 @@ inline void ResourceConsumption::MetricsCollector::_doIfCollecting(Func&& func) func(); } -void ResourceConsumption::MetricsCollector::incrementOneDocRead(std::string uri, +void ResourceConsumption::MetricsCollector::incrementOneDocRead(StringData uri, size_t docBytesRead) { _doIfCollecting([&]() { LOGV2_DEBUG(6523900, @@ -251,7 +251,7 @@ void ResourceConsumption::MetricsCollector::incrementOneDocRead(std::string uri, }); } -void ResourceConsumption::MetricsCollector::incrementOneIdxEntryRead(std::string uri, +void ResourceConsumption::MetricsCollector::incrementOneIdxEntryRead(StringData uri, size_t bytesRead) { _doIfCollecting([&]() { LOGV2_DEBUG(6523901, @@ -284,7 +284,7 @@ void ResourceConsumption::MetricsCollector::incrementSorterSpills(size_t spills) } void ResourceConsumption::MetricsCollector::incrementDocUnitsReturned( - std::string ns, DocumentUnitCounter docUnits) { + StringData ns, DocumentUnitCounter docUnits) { _doIfCollecting([&]() { LOGV2_DEBUG(6523904, 1, @@ -295,7 +295,7 @@ void ResourceConsumption::MetricsCollector::incrementDocUnitsReturned( }); } -void ResourceConsumption::MetricsCollector::incrementOneDocWritten(std::string uri, +void ResourceConsumption::MetricsCollector::incrementOneDocWritten(StringData uri, size_t bytesWritten) { _doIfCollecting([&] { LOGV2_DEBUG(6523905, @@ -308,7 +308,7 @@ void ResourceConsumption::MetricsCollector::incrementOneDocWritten(std::string u }); } -void ResourceConsumption::MetricsCollector::incrementOneIdxEntryWritten(std::string uri, +void ResourceConsumption::MetricsCollector::incrementOneIdxEntryWritten(StringData uri, size_t bytesWritten) { _doIfCollecting([&] { LOGV2_DEBUG(6523906, @@ -344,7 +344,7 @@ bool ResourceConsumption::MetricsCollector::endScopedCollecting() { return wasCollecting; } -void ResourceConsumption::MetricsCollector::incrementOneCursorSeek(std::string uri) { +void ResourceConsumption::MetricsCollector::incrementOneCursorSeek(StringData uri) { _doIfCollecting([&] { LOGV2_DEBUG(6523907, 1, diff --git a/src/mongo/db/stats/resource_consumption_metrics.h b/src/mongo/db/stats/resource_consumption_metrics.h index bd132dcaf26..9acba648b1e 100644 --- a/src/mongo/db/stats/resource_consumption_metrics.h +++ b/src/mongo/db/stats/resource_consumption_metrics.h @@ -344,13 +344,13 @@ public: * This should be called once per document read with the number of bytes read for that * document. This is a no-op when metrics collection is disabled on this operation. */ - void incrementOneDocRead(std::string uri, size_t docBytesRead); + void incrementOneDocRead(StringData uri, size_t docBytesRead); /** * This should be called once per index entry read with the number of bytes read for that * entry. This is a no-op when metrics collection is disabled on this operation. */ - void incrementOneIdxEntryRead(std::string uri, size_t idxEntryBytesRead); + void incrementOneIdxEntryRead(StringData uri, size_t idxEntryBytesRead); /** * Increments the number of keys sorted for a query operation. This is a no-op when metrics @@ -367,7 +367,7 @@ public: /** * Increments the number of document units returned in the command response. */ - void incrementDocUnitsReturned(std::string ns, DocumentUnitCounter docUnitsReturned); + void incrementDocUnitsReturned(StringData ns, DocumentUnitCounter docUnitsReturned); /** * This should be called once per document written with the number of bytes written for that @@ -375,13 +375,13 @@ public: * function should not be called when the operation is a write to the oplog. The metrics are * only for operations that are not oplog writes. */ - void incrementOneDocWritten(std::string uri, size_t docBytesWritten); + void incrementOneDocWritten(StringData uri, size_t docBytesWritten); /** * This should be called once per index entry written with the number of bytes written for * that entry. This is a no-op when metrics collection is disabled on this operation. */ - void incrementOneIdxEntryWritten(std::string uri, size_t idxEntryBytesWritten); + void incrementOneIdxEntryWritten(StringData uri, size_t idxEntryBytesWritten); /** * This should be called once every time the storage engine successfully does a cursor seek. @@ -389,7 +389,7 @@ public: * only be called once. If the seek does not find anything, this function should not be * called. */ - void incrementOneCursorSeek(std::string uri); + void incrementOneCursorSeek(StringData uri); private: // Privatize copy constructors to prevent callers from accidentally copying when this is diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp index 69c422c27d5..8ba1dbd61bf 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp @@ -768,7 +768,7 @@ public: invariantWTOK(wiredTigerCursorInsert(_opCtx, _cursor), _cursor->session); auto& metricsCollector = ResourceConsumption::MetricsCollector::get(_opCtx); - metricsCollector.incrementOneIdxEntryWritten(std::string(_cursor->uri), item.size); + metricsCollector.incrementOneIdxEntryWritten(_cursor->uri, item.size); return Status::OK(); } @@ -836,7 +836,7 @@ public: invariantWTOK(wiredTigerCursorInsert(_opCtx, _cursor), _cursor->session); auto& metricsCollector = ResourceConsumption::MetricsCollector::get(_opCtx); - metricsCollector.incrementOneIdxEntryWritten(std::string(_cursor->uri), keyItem.size); + metricsCollector.incrementOneIdxEntryWritten(_cursor->uri, keyItem.size); // Don't copy the key again if dups are allowed. if (!_dupsAllowed) @@ -888,7 +888,7 @@ public: invariantWTOK(wiredTigerCursorInsert(_opCtx, _cursor), _cursor->session); auto& metricsCollector = ResourceConsumption::MetricsCollector::get(_opCtx); - metricsCollector.incrementOneIdxEntryWritten(std::string(_cursor->uri), keyItem.size); + metricsCollector.incrementOneIdxEntryWritten(_cursor->uri, keyItem.size); _previousKeyString.resetFromBuffer(newKeyString.getBuffer(), newKeyString.getSize()); return Status::OK(); @@ -1110,7 +1110,7 @@ protected: invariantWTOK(ret, c->session); auto& metricsCollector = ResourceConsumption::MetricsCollector::get(_opCtx); - metricsCollector.incrementOneCursorSeek(std::string(c->uri)); + metricsCollector.incrementOneCursorSeek(c->uri); _cursorAtEof = false; @@ -1569,7 +1569,7 @@ Status WiredTigerIdIndex::_insert(OperationContext* opCtx, int ret = WT_OP_CHECK(wiredTigerCursorInsert(opCtx, c)); auto& metricsCollector = ResourceConsumption::MetricsCollector::get(opCtx); - metricsCollector.incrementOneIdxEntryWritten(std::string(c->uri), keyItem.size); + metricsCollector.incrementOneIdxEntryWritten(c->uri, keyItem.size); if (ret != WT_DUPLICATE_KEY) { return wtRCToStatus(ret, c->session, [this]() { @@ -1628,7 +1628,7 @@ Status WiredTigerIndexUnique::_insert(OperationContext* opCtx, // Account for the actual key insertion, but do not attempt account for the complexity of any // previous duplicate key detection, which may perform writes. auto& metricsCollector = ResourceConsumption::MetricsCollector::get(opCtx); - metricsCollector.incrementOneIdxEntryWritten(std::string(c->uri), keyItem.size); + metricsCollector.incrementOneIdxEntryWritten(c->uri, keyItem.size); // It is possible that this key is already present during a concurrent background index build. if (ret != WT_DUPLICATE_KEY) { @@ -1666,7 +1666,7 @@ void WiredTigerIdIndex::_unindex(OperationContext* opCtx, invariantWTOK(ret, c->session); auto& metricsCollector = ResourceConsumption::MetricsCollector::get(opCtx); - metricsCollector.incrementOneIdxEntryWritten(std::string(c->uri), keyItem.size); + metricsCollector.incrementOneIdxEntryWritten(c->uri, keyItem.size); return; } @@ -1680,7 +1680,7 @@ void WiredTigerIdIndex::_unindex(OperationContext* opCtx, invariantWTOK(ret, c->session); auto& metricsCollector = ResourceConsumption::MetricsCollector::get(opCtx); - metricsCollector.incrementOneCursorSeek(std::string(c->uri)); + metricsCollector.incrementOneCursorSeek(c->uri); WT_ITEM old; invariantWTOK(c->get_value(c, &old), c->session); @@ -1703,7 +1703,7 @@ void WiredTigerIdIndex::_unindex(OperationContext* opCtx, // The RecordId matches, so remove the entry. if (id == idInIndex) { invariantWTOK(WT_OP_CHECK(wiredTigerCursorRemove(opCtx, c)), c->session); - metricsCollector.incrementOneIdxEntryWritten(std::string(c->uri), keyItem.size); + metricsCollector.incrementOneIdxEntryWritten(c->uri, keyItem.size); return; } @@ -1730,7 +1730,7 @@ void WiredTigerIndexUnique::_unindex(OperationContext* opCtx, // Account for the first removal attempt, but do not attempt to account for the complexity of // any subsequent removals and insertions when the index's keys are not fully-upgraded. auto& metricsCollector = ResourceConsumption::MetricsCollector::get(opCtx); - metricsCollector.incrementOneIdxEntryWritten(std::string(c->uri), item.size); + metricsCollector.incrementOneIdxEntryWritten(c->uri, item.size); if (ret != WT_NOTFOUND) { invariantWTOK(ret, c->session); @@ -1808,7 +1808,7 @@ Status WiredTigerIndexStandard::_insert(OperationContext* opCtx, ret = WT_OP_CHECK(wiredTigerCursorInsert(opCtx, c)); auto& metricsCollector = ResourceConsumption::MetricsCollector::get(opCtx); - metricsCollector.incrementOneIdxEntryWritten(std::string(c->uri), keyItem.size); + metricsCollector.incrementOneIdxEntryWritten(c->uri, keyItem.size); // If the record was already in the index, we return OK. This can happen, for example, when // building a background index while documents are being written and reindexed. @@ -1837,7 +1837,7 @@ void WiredTigerIndexStandard::_unindex(OperationContext* opCtx, invariantWTOK(ret, c->session); auto& metricsCollector = ResourceConsumption::MetricsCollector::get(opCtx); - metricsCollector.incrementOneIdxEntryWritten(std::string(c->uri), item.size); + metricsCollector.incrementOneIdxEntryWritten(c->uri, item.size); } } // namespace mongo diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp index a6c9626d2a5..c8eb7935176 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp @@ -2294,7 +2294,7 @@ boost::optional<Record> WiredTigerRecordStoreCursorBase::seekExact(const RecordI invariantWTOK(seekRet, c->session); auto& metricsCollector = ResourceConsumption::MetricsCollector::get(_opCtx); - metricsCollector.incrementOneCursorSeek(std::string(c->uri)); + metricsCollector.incrementOneCursorSeek(c->uri); WT_ITEM value; invariantWTOK(c->get_value(c, &value), c->session); @@ -2337,7 +2337,7 @@ boost::optional<Record> WiredTigerRecordStoreCursorBase::seekNear(const RecordId invariantWTOK(ret, c->session); auto& metricsCollector = ResourceConsumption::MetricsCollector::get(_opCtx); - metricsCollector.incrementOneCursorSeek(std::string(c->uri)); + metricsCollector.incrementOneCursorSeek(c->uri); RecordId curId = getKey(c); |