Description

ASProf is a realtime profiler for Macromedia Flash MX.

Features

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.

Tips

Keep your profile initializations together so they can be block commented at the final release to free up ASProf’s processing overhead. You can also just comment the include line and all calls will be made to a null object thus doing nothing.

Built-in functions generally run under 1ms however profiling them may be useful to track how often they are getting called.

Profiling constructors may be useful for counting instance creations however a count occurs only when 'new' is used. So for instance, using [ ] to create an array will not affect the profile.

Set a time interval on getFlatGraph to view realtime updates however bear in mind that getFlatGraph's performance is relative to the number of profiles so try to keep the interval high.

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.
source
// include the file
#include "ASProf.as"
_global.AClass = function() {};
AClass.prototype.loop = function() {
   for (var i = 0; i < 10000; i++) {} // waste time
};
// setup for for profiling
ASProf.profile("AClass");
ASProf.profileObject("AClass.prototype");
// open inline profile
ASProf.begin("main");
aClassInstance = new AClass();
aClassInstance.loop();
ASProf.end(); // close “main”
trace(ASProf.getFlatGraph());
output
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