Loading TOC...

MarkLogic Server 11.0 Product Documentation
prof.eval

prof.eval(
   javascript as String,
   [vars as Object],
   [options as Object?]
) as Sequence

Summary

Evaluate a string as JavaScript for profiling. An ObjectNode will be prepended to any output produced by evaluating the string. If profiling is not enabled for the App Server, this function will throw a PROF-PROFILEALLOW exception.

Parameters
javascript The Javascript string to be evaluated. If the Javascript string contains double quotes ("), surround the string with single quotes (').
vars The external variable values for this evaluation. This can either be a sequence of map:map objects, or a sequence of even length, alternating QNames and items.

Each key in the map(s) is a string representing the name of the parameter in Clark notation: "{namespaceURI}localname". The function xdmp.keyFromQName is a convenient way to generate these keys. Each entry in the map is the value of the corresponding external variable.

Alternatively, the alternating sequence should contain QName and item pairs that specify a variable name and value for an external variable.

options The options object. The default value is null.

Required Privileges

Either http://marklogic.com/xdmp/privileges/profile-my-requests or http://marklogic.com/xdmp/privileges/profile-any-requests is required for prof:eval (the profile-my-requests privilege is suffient because the resulting request is always run by the same user who initiated the call, but the profile-any-requests privilege will also work).

Usage Notes

The Sequnce returned by this function contains the profiling report as the first item, followed by any items returned by the evaluated JavaScript code.

See Also

Example

var query = " function isPrime(num) { \
  xdmp.log(num); \
  for (var count = 2; count < num; count++) \
    if (num % count == 0) return false;\
  return true;\
};\
\
var total = 0;\
for (var i = 2; i < 10000; i++) {\
  if (isPrime(i)) {\
    total++\
  }\
};\
total;"
prof.eval(query);
=> {"nodes":[{"id":1, "callFrame":{"functionName":"(root)", "scriptId":0, "url":"", ... }
1229

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.