Stores execution times between begin() and end() functions
The Profiler class is for tracking execution time. More than one Myna.Profiler can be active at a time, but generally it is most convenient to use the global $profiler instance.
<%
$profiler.mark("Starting interesting section");
var num_loops=100,i=0;
$profiler.begin("Create " + num_loops +" encrypted passwords.");
for (; i < num_loops;++i){
$profiler.begin("Create encrypted password");
$lib.string.encryptPassword("NunyaBidness");
$profiler.end("Create encrypted password");
}
$profiler.end("Create " + num_loops +" encrypted passwords.");
$profiler.mark("All Done!");
$profiler.calcAverages();
%>
<%=$profiler.getSummaryHtml()%>
Displays HTML somewhat like this...
Label Elapsed Millis Elapsed Total Millis
$application import 10 758
Include file:/data/tomcat/webapps/myna/application.sjs 0 751
Runtime scripts included 760
Starting interesting section 763
Create 100 encrypted passwords. 237 1004
Create encrypted password (Avg of 100 entries) 2
All Done! 1004
| Myna. Profiler | Stores execution times between begin() and end() functions |
| Functions | |
| Profiler | Constructor function for Profiler class |
| calcAverages (deprecated) | (deprecated) see detail |
| begin | Sets begin point for a given label. |
| end | Sets end point for a given label. |
| mark | Sets a bookmark entry. |
| getAveragesArray | returns an array of tasks with average execution time in milliseconds |
| getAveragesHtml | returns <getTaskAverages> in an HTML table. |
| getAveragesText | returns a text table of average times. |
| getSummaryArray | returns an array of all the entries. |
| getSummaryHtml | returns an HTML summary of all the entries. |
| getSummaryText | returns a text summary of all the entries. |
Myna.Profiler=function ( start )
Constructor function for Profiler class
| start | Optional, default new Date().getTime() Milliseconds since epoch to use as starting point. |
Reference to Profiler instance
Myna.Profiler.prototype.calcAverages = function()
(deprecated) see detail
Myna.Profiler.prototype.begin = function( label, time )
Sets begin point for a given label.
| label | string label for this event |
| time | Optional, default new Date().getTime() Time to record for this entry |
A function that can be used to set the end time. This functions can be called with no parameters to set the end time to “now” or you can pass a millisecond timestamp to set a specific end time. This can be useful for asynchronous operations to make sure that correct entry is updated
If an entry with this label was already pending, it is closed and a new entry is started.
$profiler.begin("Doin' Stuff")
doStuff();
$profiler.end("Doin' Stuff")
var endFunction =$profiler.begin("Doin' Stuff Asynchronously")
var doStuffWithCallback(args,callback) {
callAsyncFunction()
}
var doStuffWithCallback(args,function(result){
// use encosed end function to set end time on the correct begin()
endFunction()
... handle result ...
})
Myna.Profiler.prototype.end = function( label, time )
Sets end point for a given label.
| label | string label for this event |
| time | Optional, default new Date().getTime() Time to record for this entry |
If no entry is pending for this label, one is created with the same time, and the entries isMark property is set to true;
Myna.Profiler.prototype.mark=function( label, time )
Sets a bookmark entry.
| label | string label for this event |
| time | Optional, default new Date().getTime() Time to record for this entry |
This is the same behavior as end when there is no begin. An entry is created with both begin and end set to time and the entry’s isMark property is set.
Myna.Profiler.prototype.getAveragesArray = function()
returns an array of tasks with average execution time in milliseconds
This will only return entries with a “begin” and “end”.
Myna.Profiler.prototype.getAveragesHtml = function()
returns <getTaskAverages> in an HTML table.
Myna.Profiler.prototype.getAveragesText = function()
returns a text table of average times.
Myna.Profiler.prototype.getSummaryArray = function()
returns an array of all the entries.
Each entry is an object with begin and end proerties, and optionally isMark or isAverage properties.
Constructor function for Profiler class
Myna.Profiler=function ( start )
(deprecated) see detail
Myna.Profiler.prototype.calcAverages = function()
Sets begin point for a given label.
Myna.Profiler.prototype.begin = function( label, time )
Sets end point for a given label.
Myna.Profiler.prototype.end = function( label, time )
Sets a bookmark entry.
Myna.Profiler.prototype.mark=function( label, time )
returns an array of tasks with average execution time in milliseconds
Myna.Profiler.prototype.getAveragesArray = function()
returns getTaskAverages in an HTML table.
Myna.Profiler.prototype.getAveragesHtml = function()
returns a text table of average times.
Myna.Profiler.prototype.getAveragesText = function()
returns an array of all the entries.
Myna.Profiler.prototype.getSummaryArray = function()
returns an HTML summary of all the entries.
Myna.Profiler.prototype.getSummaryHtml = function()
returns a text summary of all the entries.
Myna.Profiler.prototype.getSummaryText = function()