Measuring Service Performance
The Scriptframe stores the overall script execution time as a property but how can I measure and check the actual invocation time for a particular service (one script may contain multiple requests?)
The LiveConnect capability within the Rhino scripting engine allows the Java System class to be utilized. This must be prefixed via Packages.java.lang.System. The currentTimeMillis() method can be used to get the current time in milliseconds (elapsed milliseconds since midnight, January 1, 1970 UTC). Running this before and after the http.send() allows the service invocation time to be measured and then logged/checked as required.
var t0 = Packages.java.lang.System.currentTimeMillis();
http.send(myXMLRequestObject);
var t1 = Packages.java.lang.System.currentTimeMillis();
var elapsed = t1 - t0;
// Write a general message to the log
Scriptframe.info("Invocation time:" + elapsed + " ms.");
// Write a custom property to facilitate custom reporting.
Scriptframe.logProperty(“invocationTimeMs”,elapsed);
// Invocation should take less than 500 ms
// Otherwise fail the test
Scriptframe.assertTrue(elapsed < 500);
The logProperty() statement will write a line similar to the following to the Scriptframe log file:
<LogEntry CronId='2007-08-16T16:49:00_1' Script='myScript'
Status='COMPLETED_OK' Start='2007-08-16T16:49:01'>
...
<Property Name='invocationTimeMs'>265</Property>
...
</LogEntry>
The log file log.xml is considered to be user data and is located under:
{MagooClient Install Dir}/data/scripts/Scriptframe
The custom timing data can be added as a column to the HTML or CSV reports by modifying the associated stylesheets. These are located in the samples/Scriptframe directory under the MagooClient installation directory:
These stylesheets already contain processing instructions for the default 'totalElapsedMs' property which is always written to the log file by the Scriptframe on script completion. The associated 'Property' custom template should be extended using the 'totalElapsedMs' stylesheet code as an example