Вы находитесь на странице: 1из 1

YUI Library: Profiler 2008-2-19 v2.

5
Simple Use Case: Profiler Object Function Report Object YAHOO.tool.Profiler
When YAHOO.tool.getFunctionReport() is called, an object with the following properties is returned. Registration Methods
To use Profiler, register your target functions with the Member Type Description registerConstructor(string name,
YAHOO.tool.Profiler object and then call the function as avg float The average amount of time (in milliseconds) that the func owner) registers a constructor
you would normally: function took to execute. for profiling
registerFunction(string name,
var object = { calls int The number of times that the function was called. func owner) registers a function for
method: function(){ min float The average amount of time (in milliseconds) that the profiling
function took to execute. registerObject(string name, obj
} object, bool recurse) registers all
}; max float The average amount of time (in milliseconds) that the
methods on an object for profiling
function took to execute. unregisterConstructor(string
//register the function points float[] An array containing the actual execution times (in name) unregisters a constructor that
YAHOO.tool.Profiler.registerFunction( milliseconds) of the function. was previously registered
"object.method", object); unregisterFunction(string name)
Usage: YAHOO.registerObject()
unregisters a function that was
previously registered
//call the function unregisterObject(string name)
object.method(); YAHOO.tool.Profiler.registerObject(str name[, obj unregisters all methods on an object
that were previously registered
object[, bool recurse]])
Usage: YAHOO.registerFunction() Use registerObject to register all of the methods on an object (use YAHOO.tool.Profiler
YAHOO.tool.Profiler.registerFunction(str name[, registerFunction to register a single method). Reporting Methods
obj owner]) Arguments: getAverage(str name) returns the
Arguments: (1) name: A string containing the fully-qualified name of the object (e.g. average amount of time (in ms) the
function with the given name took to
(1) name: A string containing the fully-qualified name of the myobject or YAHOO.util.Dom). execute
(2) object: The object represented by the name. This argument may be getCallCount(str name) returns the
function (e.g. myobject.mymethod). Profiler knows to number of times that the given
extract everything after the last dot as the short function safely omitted if the name exists in the global scope. function was called
name. (3) recurse: Indicates if object properties should also be should also getMax(str name) returns the
maximum amount of time (in ms) the
(2) owner: The object that owns the function (e.g. myobject for have their methods registered. function with the given name took to
execute
myobject.mymethod). This argument may be safely omitted getMin(str name) returns the
if the name exists in the global scope. Solutions minimum amount of time (in ms) the
function with the given name took to
Note: Only functions that exist on objects can be profiled. Global functions are considered execute
properties of the window object, so they can be registered but functions declared inside of other The basic use case of Profiler is to register one or more functions, run
getFunctionReport(str name)
functions cannot be registered unless attached to an object. the application as you normally would, retrieve information about specific returns an object containing all
functions (or a complete report), and then unregister the functions (a information about a given function
including call count and average, min,
Usage: YAHOO.registerConstructor() necessary step to clean up memory if you wish to persist the browser and max calls times
session). getFullReport(func filter) returns an
YAHOO.tool.Profiler.registerConstructor(str object containing profiling information
//register the function for all registered functions
name[, obj owner])
YAHOO.tool.Profiler.registerFunction(
Arguments: "object.method", object);
Dependencies
(1) name: A string containing the fully-qualified name of the //call the function
constructor (e.g. YAHOO.widget.Menu). Profiler knows to object.method(); Profiler requires only the
extract everything after the last dot as the short constructor YAHOO Global Object.
//get specific function information
name. var calls =
(2) owner: The object that owns the function (e.g. YAHOO.tool.Profiler.getCallCount("object.method");
YAHOO.widget for YAHOO.widget.Menu). This argument var avg = YAHOO.tool.Profiler.getAverage("object.method");
may be safely omitted if the name exists in the global scope. var min = YAHOO.tool.Profiler.getMin("object.method");
var max = YAHOO.tool.Profiler.getMax("object.method");
Note: Only constructors that exist on objects can be profiled. Global functions are considered
properties of the window object, so they can be registered but functions declared inside of other //get all function information
functions cannot be registered unless attached to an object. var report =
YAHOO.tool.Profiler.getFunctionReport("object.method");

Вам также может понравиться