summaryrefslogtreecommitdiff
path: root/src/mongo/db/curop.cpp
diff options
context:
space:
mode:
authorXuerui Fa <xuerui.fa@mongodb.com>2020-02-07 15:19:58 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-02-07 22:53:35 +0000
commitfd1e712a1407181e1105b4767205a42bbf463bbd (patch)
treece8f422421c628d557d52e6aabed8ab7776819fd /src/mongo/db/curop.cpp
parentb11d1174d98481c497d26728d0fa21e54192b712 (diff)
downloadmongo-fd1e712a1407181e1105b4767205a42bbf463bbd.tar.gz
SERVER-43069: Condition logging for slow ops on sample rate
create mode 100644 src/mongo/util/log_with_sampling.h create mode 100644 src/mongo/util/log_with_sampling_test.cpp
Diffstat (limited to 'src/mongo/db/curop.cpp')
-rw-r--r--src/mongo/db/curop.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/mongo/db/curop.cpp b/src/mongo/db/curop.cpp
index de89c4b5789..1ac7a4c71c1 100644
--- a/src/mongo/db/curop.cpp
+++ b/src/mongo/db/curop.cpp
@@ -53,6 +53,7 @@
#include "mongo/rpc/metadata/impersonated_user_metadata.h"
#include "mongo/util/hex.h"
#include "mongo/util/log.h"
+#include "mongo/util/log_with_sampling.h"
#include "mongo/util/net/socket_utils.h"
#include "mongo/util/str.h"
#include <mongo/db/stats/timer_stats.h>
@@ -421,12 +422,8 @@ bool CurOp::completeAndLogOperation(OperationContext* opCtx,
boost::optional<size_t> responseLength,
boost::optional<long long> slowMsOverride,
bool forceLog) {
- // Log the operation if it is eligible according to the current slowMS and sampleRate settings.
- const bool shouldLogOp = (forceLog || shouldLog(component, logger::LogSeverity::Debug(1)));
const long long slowMs = slowMsOverride.value_or(serverGlobalParams.slowMS);
- const auto client = opCtx->getClient();
-
// Record the size of the response returned to the client, if applicable.
if (responseLength) {
_debug.responseLength = *responseLength;
@@ -436,14 +433,19 @@ bool CurOp::completeAndLogOperation(OperationContext* opCtx,
_end = curTimeMicros64();
_debug.executionTimeMicros = durationCount<Microseconds>(elapsedTimeExcludingPauses());
+ const auto executionTimeMillis = _debug.executionTimeMicros / 1000;
+
if (_debug.isReplOplogFetching) {
- oplogGetMoreStats.recordMillis(_debug.executionTimeMicros / 1000);
+ oplogGetMoreStats.recordMillis(executionTimeMillis);
}
- const bool shouldSample =
- client->getPrng().nextCanonicalDouble() < serverGlobalParams.sampleRate;
+ bool shouldLogSlowOp, shouldSample;
+
+ // Log the operation if it is eligible according to the current slowMS and sampleRate settings.
+ std::tie(shouldLogSlowOp, shouldSample) = shouldLogSlowOpWithSampling(
+ opCtx, component, Milliseconds(executionTimeMillis), Milliseconds(slowMs));
- if (shouldLogOp || (shouldSample && _debug.executionTimeMicros > slowMs * 1000LL)) {
+ if (forceLog || shouldLogSlowOp) {
auto lockerInfo = opCtx->lockState()->getLockerInfo(_lockStatsBase);
if (_debug.storageStats == nullptr && opCtx->lockState()->wasGlobalLockTaken() &&
opCtx->getServiceContext()->getStorageEngine()) {