0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 01:21:03 +01:00
mongodb/jstests/libs/mongoebench.js
Max Hirschhorn a750bf210f SERVER-35537 Create mongoebench for running benchRun against mobile.
It take a JSON config file with a "pre" section for any setup logic and
an "ops" section for the operations that the benchRun workers should
execute repeatedly.
2018-07-10 01:39:36 -04:00

50 lines
1.6 KiB
JavaScript

"use strict";
var {runMongoeBench} = (function() {
/**
* Spawns a mongoebench process with the specified options.
*
* If a plain JavaScript object is specified as the 'config' parameter, then it is serialized to
* a file as a JSON string which is then specified as the config file for the mongoebench
* process.
*/
function runMongoeBench(config, options = {}) {
const args = ["mongoebench"];
if (typeof config === "object") {
const filename = MongoRunner.dataPath + "mongoebench_config.json";
writeFile(filename, tojson(config));
args.push(filename);
} else if (typeof config === "string") {
args.push(config);
} else {
throw new Error("'config' parameter must be a string or an object");
}
if (!options.hasOwnProperty("dbpath")) {
options.dbpath = MongoRunner.dataDir;
}
for (let key of Object.keys(options)) {
const value = options[key];
if (value === null || value === undefined) {
throw new Error(
"Value '" + value + "' for '" + key +
"' option is ambiguous; specify {flag: ''} to add --flag command line" +
" options'");
}
args.push("--" + key);
if (value !== "") {
args.push(value.toString());
}
}
const exitCode = _runMongoProgram(...args);
assert.eq(0, exitCode, "encountered an error in mongoebench");
}
return {runMongoeBench};
})();