Files
mongo/jstests/core/profile2.js
David Storch 1574457c5f SERVER-19566 convert OP_QUERY profiler entries to look like the find command
Includes the following changes to profiler entries for queries:

-- The query field will contain find command parameters, e.g.
{find: <coll>, filter: {...}}.
-- Renames 'nscanned' to 'keysExamined' and 'nscannedObjects' to 'docsExamined'.
-- Renames 'scanAndOrder' to 'hasSortStage'.
-- Removes the top-level ntoreturn and ntoskip fields. Skip, limit, and
batchSize info will be present in the 'query' field instead.
2015-09-03 16:06:13 -04:00

80 lines
2.9 KiB
JavaScript

// Tests that large queries and updates are properly profiled.
// Special db so that it can be run in parallel tests.
var coll = db.getSisterDB("profile2").profile2;
assert.commandWorked(coll.getDB().runCommand({profile: 0}));
coll.drop();
coll.getDB().system.profile.drop();
assert.commandWorked(coll.getDB().runCommand({profile: 2}));
var str = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
var hugeStr = str;
while (hugeStr.length < 2*1024*1024){
hugeStr += str;
}
// Test query with large string element.
coll.find({a: hugeStr}).itcount();
var results = coll.getDB().system.profile.find().toArray();
assert.eq(1, results.length);
var result = results[0];
assert(result.hasOwnProperty('ns'));
assert(result.hasOwnProperty('millis'));
assert(result.hasOwnProperty('query'));
assert.eq('string', typeof(result.query));
// String value is truncated.
assert(result.query.match(/filter: { a: "a+\.\.\." } }$/));
assert.commandWorked(coll.getDB().runCommand({profile: 0}));
coll.getDB().system.profile.drop();
assert.commandWorked(coll.getDB().runCommand({profile: 2}));
// Test update with large string element in query portion.
assert.writeOK(coll.update({a: hugeStr}, {}));
var results = coll.getDB().system.profile.find().toArray();
assert.eq(1, results.length);
var result = results[0];
assert(result.hasOwnProperty('ns'));
assert(result.hasOwnProperty('millis'));
assert(result.hasOwnProperty('query'));
assert.eq('string', typeof(result.query));
assert(result.query.match(/^{ a: "a+\.\.\." }$/)); // String value is truncated.
assert.commandWorked(coll.getDB().runCommand({profile: 0}));
coll.getDB().system.profile.drop();
assert.commandWorked(coll.getDB().runCommand({profile: 2}));
// Test update with large string element in update portion.
assert.writeOK(coll.update({}, {a: hugeStr}));
var results = coll.getDB().system.profile.find().toArray();
assert.eq(1, results.length);
var result = results[0];
assert(result.hasOwnProperty('ns'));
assert(result.hasOwnProperty('millis'));
assert(result.hasOwnProperty('updateobj'));
assert.eq('string', typeof(result.updateobj));
assert(result.updateobj.match(/^{ a: "a+\.\.\." }$/)); // String value is truncated.
assert.commandWorked(coll.getDB().runCommand({profile: 0}));
coll.getDB().system.profile.drop();
assert.commandWorked(coll.getDB().runCommand({profile: 2}));
// Test query with many elements in query portion.
var doc = {};
for (var i = 0; i < 100 * 1000; ++i) {
doc["a" + i] = 1;
}
coll.find(doc).itcount();
var results = coll.getDB().system.profile.find().toArray();
assert.eq(1, results.length);
var result = results[0];
assert(result.hasOwnProperty('ns'));
assert(result.hasOwnProperty('millis'));
assert(result.hasOwnProperty('query'));
assert.eq('string', typeof(result.query));
// Query object itself is truncated.
assert(result.query.match(/filter: { a0: 1\.0, a1: .*\.\.\.$/));
assert.commandWorked(coll.getDB().runCommand({profile: 0}));