4fd88cbe40ba14264d3d9ea31b166dab73c64691Nicholas C Zakas * The YUI JavaScript profiler.
4fd88cbe40ba14264d3d9ea31b166dab73c64691Nicholas C Zakas * @module profiler
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas //-------------------------------------------------------------------------
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas // Private Variables and Functions
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas //-------------------------------------------------------------------------
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas var container = {}, //Container object on which to put the original unprofiled methods.
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas report = {}, //Profiling information for functions
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas stopwatches = {}, //Additional stopwatch information
2d9dc67ae64e403844b913078658e45ed63cf0a0Nicholas C. Zakas /* (intentionally not documented)
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas * Creates a report object with the given name.
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas * @param {String} name The name to store for the report object.
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas * @return {Void}
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas * @method createReport
2d9dc67ae64e403844b913078658e45ed63cf0a0Nicholas C. Zakas /* (intentionally not documented)
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas * Called when a method ends execution. Marks the start and end time of the
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas * method so it can calculate how long the function took to execute. Also
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas * updates min/max/avg calculations for the function.
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas * @param {String} name The name of the function to mark as stopped.
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas * @param {int} duration The number of milliseconds it took the function to
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas * @return {Void}
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas * @method saveDataPoint
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas //get the function data
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas var functionData /*:Object*/ = report[name];
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas //just in case clear() was called
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas //increment the calls
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas //if it's already been called at least once, do more complex calculations
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas functionData.avg = ((functionData.avg*(functionData.calls-1))+duration)/functionData.calls;
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas functionData.min = Math.min(functionData.min, duration);
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas functionData.max = Math.max(functionData.max, duration);
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas //-------------------------------------------------------------------------
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas // Public Interface
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas //-------------------------------------------------------------------------
4fd88cbe40ba14264d3d9ea31b166dab73c64691Nicholas C Zakas * Profiles functions in JavaScript.
4fd88cbe40ba14264d3d9ea31b166dab73c64691Nicholas C Zakas * @class Profiler