/**
* The YUI JavaScript profiler.
* @module profiler
*/
//-------------------------------------------------------------------------
// Private Variables and Functions
//-------------------------------------------------------------------------
var container = {}, //Container object on which to put the original unprofiled methods.
report = {}, //Profiling information for functions
stopwatches = {}, //Additional stopwatch information
WATCH_STARTED = 0,
WATCH_STOPPED = 1,
WATCH_PAUSED = 2,
//shortcuts
L = Y.Lang;
/* (intentionally not documented)
* Creates a report object with the given name.
* @param {String} name The name to store for the report object.
* @return {Void}
* @method createReport
* @private
*/
function createReport(name){
calls: 0,
max: 0,
min: 0,
avg: 0,
points: []
};
}
/* (intentionally not documented)
* Called when a method ends execution. Marks the start and end time of the
* method so it can calculate how long the function took to execute. Also
* @param {String} name The name of the function to mark as stopped.
* @param {int} duration The number of milliseconds it took the function to
* execute.
* @return {Void}
* @method saveDataPoint
* @private
* @static
*/
//get the function data
//just in case clear() was called
if (!functionData){
}
//increment the calls
//if it's already been called at least once, do more complex calculations
} else {
}
}
//-------------------------------------------------------------------------
// Public Interface
//-------------------------------------------------------------------------
/**
* Profiles functions in JavaScript.
* @class Profiler
* @static
*/
Y.Profiler = {
//-------------------------------------------------------------------------
// Utility Methods
//-------------------------------------------------------------------------
/**
* Removes all report data from the profiler.
* @param {String} name (Optional) The name of the report to clear. If
* omitted, then all report data is cleared.
* @return {Void}
* @method clear
* @static
*/
delete stopwatches[name];
} else {
report = {};
stopwatches = {};
}
},
/**
* @method getOriginal
* @static
*/
getOriginal: function(name){
},
/**
* Instruments a method to have profiling calls.
* @param {String} name The name of the report for the function.
* @param {Function} method The function to instrument.
* @return {Function} An instrumented version of the function.
* @method instrument
* @static
*/
//create instrumented version of function
var newMethod = function () {
var start = new Date(),
stop = new Date();
return retval;
};
//copy the function properties over
//assign prototype and flag as being profiled
newMethod.__yuiProfiled = true;
//store original method
//create the report
//return the new method
return newMethod;
},
//-------------------------------------------------------------------------
// Stopwatch Methods
//-------------------------------------------------------------------------
/**
* Pauses profiling information for a given name.
* @param {String} name The name of the data point.
* @return {Void}
* @method pause
* @static
*/
var now = new Date(),
}
},
/**
* Start profiling information for a given name. The name cannot be the name
* of a registered function or object. This is used to start timing for a
* particular block of code rather than instrumenting the entire function.
* @param {String} name The name of the data point.
* @return {Void}
* @method start
* @static
*/
throw new Error("Cannot use '" + name + "' for profiling through start(), name is already in use.");
} else {
//create report if necessary
}
//create stopwatch object if necessary
if (!stopwatches[name]){
stopwatches[name] = {
start: 0,
total: 0
};
}
}
}
},
/**
* Stops profiling information for a given name.
* @param {String} name The name of the data point.
* @return {Void}
* @method stop
* @static
*/
var now = new Date(),
if (stopwatch){
}
//reset stopwatch information
}
},
//-------------------------------------------------------------------------
// Reporting Methods
//-------------------------------------------------------------------------
/**
* Returns the average amount of time (in milliseconds) that the function
* with the given name takes to execute.
* @param {String} name The name of the function whose data should be returned.
* If an object type method, it should be 'constructor.prototype.methodName';
* a normal object method would just be 'object.methodName'.
* @return {float} The average time it takes the function to execute.
* @method getAverage
* @static
*/
},
/**
* Returns the number of times that the given function has been called.
* @param {String} name The name of the function whose data should be returned.
* @return {int} The number of times the function was called.
* @method getCallCount
* @static
*/
},
/**
* Returns the maximum amount of time (in milliseconds) that the function
* with the given name takes to execute.
* @param {String} name The name of the function whose data should be returned.
* If an object type method, it should be 'constructor.prototype.methodName';
* a normal object method would just be 'object.methodName'.
* @return {float} The maximum time it takes the function to execute.
* @method getMax
* @static
*/
},
/**
* Returns the minimum amount of time (in milliseconds) that the function
* with the given name takes to execute.
* @param {String} name The name of the function whose data should be returned.
* If an object type method, it should be 'constructor.prototype.methodName';
* a normal object method would just be 'object.methodName'.
* @return {float} The minimum time it takes the function to execute.
* @method getMin
* @static
*/
},
/**
* Returns an object containing profiling data for a single function.
* The object has an entry for min, max, avg, calls, and points).
* @return {Object} An object containing profile data for a given function.
* @method getFunctionReport
* @static
* @deprecated Use getReport() instead.
*/
},
/**
* Returns an object containing profiling data for a single function.
* The object has an entry for min, max, avg, calls, and points).
* @return {Object} An object containing profile data for a given function.
* @method getReport
* @static
*/
},
/**
* Returns an object containing profiling data for all of the functions
* that were profiled. The object has an entry for each function and
* returns all information (min, max, average, calls, etc.) for each
* function.
* @return {Object} An object containing all profile data.
* @method getFullReport
* @static
*/
if (L.isFunction(filter)) {
var fullReport = {};
}
}
return fullReport;
}
},
//-------------------------------------------------------------------------
// Profiling Methods
//-------------------------------------------------------------------------
/**
* Sets up a constructor for profiling, including all properties and methods on the prototype.
* @param {string} name The fully-qualified name of the function including namespace information.
* @param {Object} owner (Optional) The object that owns the function (namespace or containing object).
* @return {Void}
* @method registerConstructor
* @static
*/
},
/**
* Sets up a function for profiling. It essentially overwrites the function with one
* that has instrumentation data. This method also creates an entry for the function
* in the profile report. The original function is stored on the container object.
* @param {String} name The full name of the function including namespacing. This
* is the name of the function that is stored in the report.
* @param {Object} owner (Optional) The object that owns the function. If the function
* isn't global then this argument is required. This could be the namespace that
* the function belongs to or the object on which it's
* a method.
* @param {Boolean} registerPrototype (Optional) Indicates that the prototype should
* also be instrumented. Setting to true has the same effect as calling
* registerConstructor().
* @return {Void}
* @method registerFunction
* @static
*/
registerFunction : function(name /*:String*/, owner /*:Object*/, registerPrototype /*:Boolean*/) /*:Void*/{
//figure out the function name without namespacing
//if owner isn't an object, try to find it from the name
}
//get the method and prototype
//see if the method has already been registered
//replace the function with the profiling one
/*
* Store original function information. We store the actual
* function as well as the owner and the name used to identify
* the function so it can be restored later.
*/
//register prototype if necessary
if (registerPrototype) {
}
}
},
/**
* Sets up an object for profiling. It takes the object and looks for functions.
* When a function is found, registerMethod() is called on it. If set to recrusive
* mode, it will also setup objects found inside of this object for profiling,
* using the same methodology.
* @param {String} name The name of the object to profile (shows up in report).
* @param {Object} owner (Optional) The object represented by the name.
* @param {Boolean} recurse (Optional) Determines if subobject methods are also profiled.
* @return {Void}
* @method registerObject
* @static
*/
//get the object
//save the object
if (prop != "constructor" && prop != "superclass"){ //don't do constructor or superclass, it's recursive
}
}
}
},
/**
* Removes a constructor function from profiling. Reverses the registerConstructor() method.
* @param {String} name The full name of the function including namespacing. This
* is the name of the function that is stored in the report.
* @return {Void}
* @method unregisterFunction
* @static
*/
//see if the method has been registered
this.unregisterFunction(name, true);
}
},
/**
* Removes function from profiling. Reverses the registerFunction() method.
* @param {String} name The full name of the function including namespacing. This
* is the name of the function that is stored in the report.
* @return {Void}
* @method unregisterFunction
* @static
*/
//see if the method has been registered
//check to see if you should unregister the prototype
if (unregisterPrototype){
}
//get original data
//delete extra information
//replace instrumented function
//delete supporting information
}
},
/**
* Unregisters an object for profiling. It takes the object and looks for functions.
* When a function is found, unregisterMethod() is called on it. If set to recrusive
* mode, it will also unregister objects found inside of this object,
* using the same methodology.
* @param {String} name The name of the object to unregister.
* @param {Boolean} recurse (Optional) Determines if subobject methods should also be
* unregistered.
* @return {Void}
* @method unregisterObject
* @static
*/
//get the object
}
}
}
}
};