summaryrefslogtreecommitdiff
path: root/src/mongo/bson
diff options
context:
space:
mode:
authorEvan Broder <evan@stripe.com>2016-07-05 21:02:49 -0700
committerDavid Storch <david.storch@10gen.com>2017-01-26 18:35:29 -0500
commit94b37aac060bcc8b10c3eb41f178d84008136f9c (patch)
treef98c9f60273345ea880af48ab14ad7ac8ef167cd /src/mongo/bson
parent249eaae3e1b78ed5c4b6b7425145a23dc658fd75 (diff)
downloadmongo-94b37aac060bcc8b10c3eb41f178d84008136f9c.tar.gz
SERVER-4786 Allow specifying sample rate of slow queries
Adds a sampleRate parameter to the profile command, a value on the interval [0, 1] which indicates which fraction of operations should be randomly sampled for profiling and logging. This allows users to reduce their slowms threshold or increase their profiling level with less performance impact on the system. Closes #1099 Signed-off-by: David Storch <david.storch@10gen.com>
Diffstat (limited to 'src/mongo/bson')
-rw-r--r--src/mongo/bson/util/bson_extract.cpp12
-rw-r--r--src/mongo/bson/util/bson_extract.h15
2 files changed, 27 insertions, 0 deletions
diff --git a/src/mongo/bson/util/bson_extract.cpp b/src/mongo/bson/util/bson_extract.cpp
index 84c9cc92de6..8a453c02472 100644
--- a/src/mongo/bson/util/bson_extract.cpp
+++ b/src/mongo/bson/util/bson_extract.cpp
@@ -185,6 +185,18 @@ Status bsonExtractDoubleField(const BSONObj& object, StringData fieldName, doubl
return Status::OK();
}
+Status bsonExtractDoubleFieldWithDefault(const BSONObj& object,
+ StringData fieldName,
+ double defaultValue,
+ double* out) {
+ Status status = bsonExtractDoubleField(object, fieldName, out);
+ if (status == ErrorCodes::NoSuchKey) {
+ *out = defaultValue;
+ status = Status::OK();
+ }
+ return status;
+}
+
Status bsonExtractIntegerFieldWithDefault(const BSONObj& object,
StringData fieldName,
long long defaultValue,
diff --git a/src/mongo/bson/util/bson_extract.h b/src/mongo/bson/util/bson_extract.h
index cedc84cd01f..a4e2b90d82d 100644
--- a/src/mongo/bson/util/bson_extract.h
+++ b/src/mongo/bson/util/bson_extract.h
@@ -158,6 +158,21 @@ Status bsonExtractIntegerFieldWithDefault(const BSONObj& object,
long long* out);
/**
+ * Finds a double-precision floating point element named "fieldName" in "object".
+ *
+ * If a field named "fieldName" is present, and is a double, stores the value of the field into
+ * "*out". If no field named fieldName is present, sets "*out" to "defaultValue". In these cases,
+ * returns Status::OK().
+ *
+ * If "fieldName" is present more than once, behavior is undefined. If the found field is not a
+ * double, returns ErrorCodes::TypeMismatch.
+ */
+Status bsonExtractDoubleFieldWithDefault(const BSONObj& object,
+ StringData fieldName,
+ double defaultValue,
+ double* out);
+
+/**
* Finds a std::string element named "fieldName" in "object".
*
* If a field named "fieldName" is present, and is a string, stores the value of the field into