fe9e354325d6e42f7f7d66b75567b0adb7b74277NicholasYUI.add('profiler', function(Y) {
fe9e354325d6e42f7f7d66b75567b0adb7b74277Nicholas
4fd88cbe40ba14264d3d9ea31b166dab73c64691Nicholas C Zakas /**
4fd88cbe40ba14264d3d9ea31b166dab73c64691Nicholas C Zakas * The YUI JavaScript profiler.
4fd88cbe40ba14264d3d9ea31b166dab73c64691Nicholas C Zakas * @module profiler
4fd88cbe40ba14264d3d9ea31b166dab73c64691Nicholas C Zakas */
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas //-------------------------------------------------------------------------
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas // Private Variables and Functions
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas //-------------------------------------------------------------------------
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
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas WATCH_STARTED = 0,
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas WATCH_STOPPED = 1,
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas WATCH_PAUSED = 2,
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas //shortcuts
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas L = Y.Lang;
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas
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
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas * @private
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas */
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas function createReport(name){
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas report[name] = {
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas calls: 0,
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas max: 0,
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas min: 0,
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas avg: 0,
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas points: []
4e10ce0fb16d86c41fc11c6105715c493055383dNicholas C. Zakas };
4e10ce0fb16d86c41fc11c6105715c493055383dNicholas C. Zakas return report[name];
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas }
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas
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 * execute.
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas * @return {Void}
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas * @method saveDataPoint
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas * @private
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas * @static
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas */
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas function saveDataPoint(name, duration){
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas //get the function data
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas var functionData /*:Object*/ = report[name];
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas //just in case clear() was called
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas if (!functionData){
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas functionData = createReport(name);
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas }
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas //increment the calls
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas functionData.calls++;
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas functionData.points.push(duration);
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas //if it's already been called at least once, do more complex calculations
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas if (functionData.calls > 1) {
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 } else {
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas functionData.avg = duration;
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas functionData.min = duration;
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas functionData.max = duration;
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas }
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas }
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas //-------------------------------------------------------------------------
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas // Public Interface
e9ee71cc3e50c936d1f244bb111ef0524037b397Nicholas C. Zakas //-------------------------------------------------------------------------
4fd88cbe40ba14264d3d9ea31b166dab73c64691Nicholas C Zakas
4fd88cbe40ba14264d3d9ea31b166dab73c64691Nicholas C Zakas /**
4fd88cbe40ba14264d3d9ea31b166dab73c64691Nicholas C Zakas * Profiles functions in JavaScript.
4fd88cbe40ba14264d3d9ea31b166dab73c64691Nicholas C Zakas * @class Profiler
4fd88cbe40ba14264d3d9ea31b166dab73c64691Nicholas C Zakas * @static
4fd88cbe40ba14264d3d9ea31b166dab73c64691 Error!

 

There was an error!

null

java.lang.NullPointerException