Methods
ASProf.profile("path.to.function");
Profiles a function. The parameter is a string evaluable to the function. Relative/absolute pathing, scope chain descending, and dot/slash notation are all valid.
ASProf.profileObject("path.to.object");
Profile all functions within an object. Like ASProf.profile, the parameter is a string evaluable to the object. This method is most useful for profiling the prototype object.
ASProf.begin("name");
Opens an inline code profile. The parameter is a unique string label. Note: must close with ASProf.end.
ASProf.end();
Closes an inline code profile opened by ASProf.begin.
ASProf.getFlatGraph();
Returns a string of the flat graph. The graph is based on that of gprof's. For information on reading the graph, please visit gprof's description
here.
Example
The example below demonstrates the various features of ASProf. The AClass constructor is profiled to count intances. Its prototype object is profiled to measure its methods’ execution times. An inline profile labeled "main" measures the lines that follow. Note that since profiles exist within "main", those timings are accounted for by the self time field of "main" in the flat graph. View a demo
here.
#include "ASProf.as"
_global.AClass = function() {};
AClass.prototype.loop = function() {
for (var i = 0; i < 10000; i++) {} // waste time
};
ASProf.profile("AClass");
ASProf.profileObject("AClass.prototype");
ASProf.begin("main");
aClassInstance = new AClass();
aClassInstance.loop();
ASProf.end();
trace(ASProf.getFlatGraph());
Flat profile:
Each sample counts as 0.001 seconds.
% cumulative self self total
time seconds seconds calls ms/call ms/call name
98.507 0.066 0.066 1 66 66 AClass.prototype.loop
1.492 0.067 0.001 1 1 67 main
0 0.067 0 1 0 0 AClass