summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jstests/core/profile_options.js75
-rw-r--r--jstests/libs/config_files/set_profiling.json5
-rw-r--r--src/mongo/db/mongod_options.cpp74
3 files changed, 131 insertions, 23 deletions
diff --git a/jstests/core/profile_options.js b/jstests/core/profile_options.js
new file mode 100644
index 00000000000..0ba4a5b40c3
--- /dev/null
+++ b/jstests/core/profile_options.js
@@ -0,0 +1,75 @@
+var baseName = "jstests_core_profile_options";
+
+function removeOptionsAddedByFramework(getCmdLineOptsResult) {
+ // Remove options that we are not interested in checking, but that get set by the test
+ delete getCmdLineOptsResult.parsed.setParameter
+ delete getCmdLineOptsResult.parsed.storage
+ delete getCmdLineOptsResult.parsed.net
+ delete getCmdLineOptsResult.parsed.fastsync
+ delete getCmdLineOptsResult.parsed.security
+ return getCmdLineOptsResult;
+}
+
+function testGetCmdLineOpts(mongoRunnerConfig, expectedResult) {
+
+ // Start mongod with options
+ var mongod = MongoRunner.runMongod(mongoRunnerConfig);
+
+ // Get the parsed options
+ var getCmdLineOptsResult = mongod.adminCommand("getCmdLineOpts");
+ printjson(getCmdLineOptsResult);
+
+ // Remove options added by the test framework
+ getCmdLineOptsResult = removeOptionsAddedByFramework(getCmdLineOptsResult);
+
+ // Make sure the options are equal to what we expect
+ assert.docEq(getCmdLineOptsResult.parsed, expectedResult.parsed);
+
+ // Cleanup
+ MongoRunner.stopMongod(mongod.port);
+}
+
+jsTest.log("Testing \"profile\" command line option with profiling off");
+var expectedResult = {
+ "parsed" : {
+ "operationProfiling" : {
+ "mode" : "off"
+ }
+ }
+};
+testGetCmdLineOpts({ profile : "0" }, expectedResult);
+
+jsTest.log("Testing \"profile\" command line option with profiling slow operations on");
+var expectedResult = {
+ "parsed" : {
+ "operationProfiling" : {
+ "mode" : "slowOp"
+ }
+ }
+};
+testGetCmdLineOpts({ profile : "1" }, expectedResult);
+
+jsTest.log("Testing \"profile\" command line option with profiling all on");
+var expectedResult = {
+ "parsed" : {
+ "operationProfiling" : {
+ "mode" : "all"
+ }
+ }
+};
+testGetCmdLineOpts({ profile : "2" }, expectedResult);
+
+jsTest.log("Testing \"operationProfiling.mode\" config file option");
+expectedResult = {
+ "parsed" : {
+ "config" : "jstests/libs/config_files/set_profiling.json",
+ "operationProfiling" : {
+ "mode" : "all"
+ }
+ }
+};
+testGetCmdLineOpts({ config : "jstests/libs/config_files/set_profiling.json" }, expectedResult);
+
+
+
+print(baseName + " succeeded.");
diff --git a/jstests/libs/config_files/set_profiling.json b/jstests/libs/config_files/set_profiling.json
new file mode 100644
index 00000000000..944f0de1575
--- /dev/null
+++ b/jstests/libs/config_files/set_profiling.json
@@ -0,0 +1,5 @@
+{
+ "operationProfiling" : {
+ "mode" : "all"
+ }
+}
diff --git a/src/mongo/db/mongod_options.cpp b/src/mongo/db/mongod_options.cpp
index 7749f16760a..8cc97868cf1 100644
--- a/src/mongo/db/mongod_options.cpp
+++ b/src/mongo/db/mongod_options.cpp
@@ -706,6 +706,37 @@ namespace mongo {
}
}
+ if (params->count("profile")) {
+ int profilingMode;
+ Status ret = params->get("profile", &profilingMode);
+ if (!ret.isOK()) {
+ return ret;
+ }
+ std::string profilingModeString;
+ if (profilingMode == 0) {
+ profilingModeString = "off";
+ }
+ else if (profilingMode == 1) {
+ profilingModeString = "slowOp";
+ }
+ else if (profilingMode == 2) {
+ profilingModeString = "all";
+ }
+ else {
+ StringBuilder sb;
+ sb << "Bad value for profile: " << profilingMode
+ << ". Supported modes are: (0=off|1=slowOp|2=all)";
+ return Status(ErrorCodes::BadValue, sb.str());
+ }
+ ret = params->set("operationProfiling.mode", moe::Value(profilingModeString));
+ if (!ret.isOK()) {
+ return ret;
+ }
+ ret = params->remove("profile");
+ if (!ret.isOK()) {
+ return ret;
+ }
+ }
return Status::OK();
}
@@ -761,6 +792,26 @@ namespace mongo {
storageGlobalParams.dbpath.erase(storageGlobalParams.dbpath.size()-1);
}
#endif
+
+ if (params.count("operationProfiling.mode")) {
+ std::string profilingMode = params["operationProfiling.mode"].as<std::string>();
+ if (profilingMode == "off") {
+ serverGlobalParams.defaultProfile = 0;
+ }
+ else if (profilingMode == "slowOp") {
+ serverGlobalParams.defaultProfile = 1;
+ }
+ else if (profilingMode == "all") {
+ serverGlobalParams.defaultProfile = 2;
+ }
+ else {
+ StringBuilder sb;
+ sb << "Bad value for operationProfiling.mode: " << profilingMode
+ << ". Supported modes are: (off|slowOp|all)";
+ return Status(ErrorCodes::BadValue, sb.str());
+ }
+ }
+
if ( params.count("operationProfiling.slowOpThresholdMs")) {
serverGlobalParams.slowMS = params["operationProfiling.slowOpThresholdMs"].as<int>();
}
@@ -1001,29 +1052,6 @@ namespace mongo {
if (!params.count("replication.oplogSizeMB"))
replSettings.oplogSize = 5 * 1024 * 1024;
}
- if (params.count("profile")) {
- serverGlobalParams.defaultProfile = params["profile"].as<int>();
- }
- else {
- if (params.count("operationProfiling.mode")) {
- std::string profilingMode = params["operationProfiling.mode"].as<std::string>();
- if (profilingMode == "off") {
- serverGlobalParams.defaultProfile = 0;
- }
- else if (profilingMode == "slowOp") {
- serverGlobalParams.defaultProfile = 1;
- }
- else if (profilingMode == "all") {
- serverGlobalParams.defaultProfile = 2;
- }
- else {
- StringBuilder sb;
- sb << "Bad value for operationProfiling.mode: " << profilingMode
- << ". Supported modes are: (off|slowOp|all)";
- return Status(ErrorCodes::BadValue, sb.str());
- }
- }
- }
if (params.count("net.ipv6")) {
enableIPv6();
}