Myna. Profiler

Stores execution times between begin() and end() functions

Detail

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.

Example

<%
$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
Summary
Myna. ProfilerStores execution times between begin() and end() functions
Functions
ProfilerConstructor function for Profiler class
calcAverages (deprecated)(deprecated) see detail
beginSets begin point for a given label.
endSets end point for a given label.
markSets a bookmark entry.
getAveragesArrayreturns an array of tasks with average execution time in milliseconds
getAveragesHtmlreturns <getTaskAverages> in an HTML table.
getAveragesTextreturns a text table of average times.
getSummaryArrayreturns an array of all the entries.
getSummaryHtmlreturns an HTML summary of all the entries.
getSummaryTextreturns a text summary of all the entries.
profileattaches profiling hooks to an object

Functions

Profiler

Myna.Profiler=function (start)

Constructor function for Profiler class

Parameters

startOptional, default new Date().getTime() Milliseconds since epoch to use as starting point.

Returns

Reference to Profiler instance

calcAverages (deprecated)

Myna.Profiler.prototype.calcAverages = function()

(deprecated) see detail

This function has been replaced by

begin

Myna.Profiler.prototype.begin = function(label,
time)

Sets begin point for a given label.

Parameters

labelstring label for this event
timeOptional, default new Date().getTime() Time to record for this entry

Returns

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

Detail

If an entry with this label was already pending, it is closed and a new entry is started.

Example

$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 ...
})

See

end

Myna.Profiler.prototype.end = function(label,
time)

Sets end point for a given label.

Parameters

labelstring label for this event
timeOptional, default new Date().getTime() Time to record for this entry

Detail

If no entry is pending for this label, one is created with the same time, and the entries isMark property is set to true;

mark

Myna.Profiler.prototype.mark=function(label)

Sets a bookmark entry.

Parameters

labelstring label for this event
timeOptional, default new Date().getTime() Time to record for this entry

Detail

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.

getAveragesArray

Myna.Profiler.prototype.getAveragesArray = function()

returns an array of tasks with average execution time in milliseconds

Note

This will only return entries with a “begin” and “end”.

See

getAveragesHtml

Myna.Profiler.prototype.getAveragesHtml = function()

returns <getTaskAverages> in an HTML table.

getAveragesText

Myna.Profiler.prototype.getAveragesText = function()

returns a text table of average times.

getSummaryArray

Myna.Profiler.prototype.getSummaryArray = function()

returns an array of all the entries.

Detail

Each entry is an object with begin and end proerties, and optionally isMark or isAverage properties.

getSummaryHtml

Myna.Profiler.prototype.getSummaryHtml = function()

returns an HTML summary of all the entries.

getSummaryText

Myna.Profiler.prototype.getSummaryText = function()

returns a text summary of all the entries.

profile

Myna.Profiler.prototype.profile = function(obj,
name,
logArgs)

attaches profiling hooks to an object

Parameters

objobject to profile
nameString.  Name of this object to use in profile logs
logArgsOptional, default false If true, log arguments to function in the profiler

Detail

This attaches “begin” and “end” profiling to every function in obj, and getters

Myna.Profiler=function (start)
Constructor function for Profiler class
Myna.Profiler.prototype.calcAverages = function()
(deprecated) see detail
Myna.Profiler.prototype.begin = function(label,
time)
Sets begin point for a given label.
Myna.Profiler.prototype.end = function(label,
time)
Sets end point for a given label.
Myna.Profiler.prototype.mark=function(label)
Sets a bookmark entry.
Myna.Profiler.prototype.getAveragesArray = function()
returns an array of tasks with average execution time in milliseconds
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.
Myna.Profiler.prototype.getSummaryHtml = function()
returns an HTML summary of all the entries.
Myna.Profiler.prototype.getSummaryText = function()
returns a text summary of all the entries.
Myna.Profiler.prototype.profile = function(obj,
name,
logArgs)
attaches profiling hooks to an object
Global instance of Myna.Profiler.