Files
mongo/jstests/libs/profiler.js
Charlie Swanson 584ca76de9 SERVER-22541 Manage aggregation cursors on global cursor manager.
Moves registration of aggregation cursors to the global cursor manager.
This simplifies the logic for acquiring locks and resolving view
namespaces within the getMore and killCursors commands.
2017-03-15 11:03:44 -04:00

33 lines
1.3 KiB
JavaScript

// Provides convenience methods for confirming system.profile content.
// Retrieve latest system.profile entry.
function getLatestProfilerEntry(inputDb, filter) {
if (filter === null) {
filter = {};
}
var cursor = inputDb.system.profile.find(filter).sort({$natural: -1});
assert(
cursor.hasNext(),
"could not find any entries in the profile collection matching filter: " + tojson(filter));
return cursor.next();
}
// Returns a string representing the wire protocol used for commands run on the given connection.
// This string matches the system.profile "protocol" field when commands are profiled.
function getProfilerProtocolStringForCommand(conn) {
if ("opQueryOnly" === conn.getClientRPCProtocols()) {
return "op_query";
}
return "op_command";
}
// Throws an assertion if the profiler does not contain exactly one entry matching <filter>.
// Optional arguments <errorMsgFilter> and <errorMsgProj> limit profiler output if this asserts.
function profilerHasSingleMatchingEntryOrThrow(inputDb, filter, errorMsgFilter, errorMsgProj) {
assert.eq(inputDb.system.profile.find(filter).itcount(),
1,
"Expected exactly one op matching: " + tojson(filter) + " in profiler " +
tojson(inputDb.system.profile.find(errorMsgFilter, errorMsgProj).toArray()));
}