static FunctionMonitor
version 2.0
A library for monitoring function calls.
See Implement FunctionMonitor for an example of implementating the script on a page. This class resides in the global namespace. This class does not participate in another library.
Index
Example Index
- Implement FunctionMonitor: Implement this package on a Web page.
- Monitor a Function: Register a function to be monitored.
- Monitor a Function With Window Reference: Register a function to be monitored using a window reference. This is used for referencing functions in other frames, or when monitoring functions where the this reference is needed. Note that the Object.prototype syntax must be present to monitor a prototyped function. While the windowRef parameter can be used to register a function on a specific script object defined within a hash, that function registration cannot later be removed.
- Stop Monitoring a Function: Unregister a function from being monitored.
- Stop monitoring a Function With Window Reference: Unregister a function from being monitored using a window reference.
Object Index
- private FunctionStore (internal): Object representing a stored function reference.
- private Metric (internal): Object representing a function metric.
Property Index
- public can_trace: Bit indicating whether function stacks should be traced.
- private function_index: Reverse lookup array of monitored functions.
- private functions: Array of monitored functions.
- public hold_max: Bit indicating whether stored values should not be overwritten if new values are less than the stored values.
- public stack_len: Maximum number of records to store before overwriting previous values.
- public version: The version of the class.
Method Index
- private _pack (internal): Collapses the functions and function_index arrays.
- public clearMetrics: Clears stored metrics.
- private dispatch (internal): Receives function calls, invokes the original function, and monitors the execution time.
- public getAllMetrics: Returns all collected metrics in a formatted hierarchy.
- private getFunctionName (internal): Returns the name of a function based on the string representation of the whole function.
- public getMetrics: Returns collected metrics for the specified function in a formatted hierarchy.
- private makeMetric (internal): Returns a new Metric object.
- public register: Registers a function to be monitored.
- private traceRoute (internal): Returns the call stack for the specified function.
- public unregister: Unregisters a monitored function.
Examples
Implement FunctionMonitor
Implement this package on a Web page.
Example Code
<script type = "text/javascript" src = "FunMon2.js"></script>
Monitor a Function
Register a function to be monitored.
Syntax
FunctionMonitor.register(sName);
Example Code
function MonitorThis(){
// Some code
}
FunctionMonitor.register("MonitorThis");Monitor a Function With Window Reference
Register a function to be monitored using a window reference. This is used for referencing functions in other frames, or when monitoring functions where the this reference is needed. Note that the Object.prototype syntax must be present to monitor a prototyped function. While the windowRef parameter can be used to register a function on a specific script object defined within a hash, that function registration cannot later be removed.
Syntax
FunctionMonitor.register(sName, vWindow, sClass);
Example Code
function ObjectClass(){
this.name = "test object";
}
ObjectClass.prototype.doAction = function(){
alert(this.name);
// do something
}
var oObj = new ObjectClass();
FunctionMonitor.register("doAction",window,"ObjectClass");
oObj.doAction();Stop Monitoring a Function
Unregister a function from being monitored.
Syntax
FunctionMonitor.unregister(sName);
Example Code
function MonitorThis(){
// Some code
}
// where FunctionMonitor.register was previously used
FunctionMonitor.unregister("MonitorThis");Stop monitoring a Function With Window Reference
Unregister a function from being monitored using a window reference.
Syntax
FunctionMonitor.register(sName, vWindow, sClass);
Example Code
function ObjectClass(){
this.name = "test object";
}
ObjectClass.prototype.doAction = function(){
alert(this.name);
// do something
}
// where FunctionMonitor.register was previously used
FunctionMonitor.unregister("doAction",window,"ObjectClass");Objects
FunctionStore
Object representing a stored function reference. Object is private and should not be directly referenced.
Properties
- name as String: Name of the function
- classRef as String: Name of the parent or prototype class.
- refName as String: Name of the window reference.
- ref as object: Pointer to the window reference.
- fp as function: Pointer to the original function.
- index as int: Index into the reverse function map.
- metrics as array: Array of collected Metric objects.
- stackCount as int: Current marker into the metric stack.
Metric
Object representing a function metric. Object is private and should not be directly referenced.
Properties
- start as int: Start time of the metric in milliseconds.
- stop as int: Stop time of the metric in milliseconds.
- valOffset as int: Difference between function execution time and internal execution time in milliseconds.
- route as String: String representing the function trace.
- monStatus as int: Integer identifying the stat the variant object identifier.
- duration as int: Not used.
- caller as function: Pointer to the caller of the this monitored instance.
- parentName as String: Not used.
Properties
can_trace
Bit indicating whether function stacks should be traced.
Syntax
boolean = FunctionMonitor.can_trace
FunctionMonitor.can_trace = boolean
Default Value
function_index
Reverse lookup array of monitored functions. Property is private and should not be directly referenced.
Syntax
array = FunctionMonitor.function_index
functions
Array of monitored functions. Property is private and should not be directly referenced.
Syntax
array = FunctionMonitor.functions
hold_max
Bit indicating whether stored values should not be overwritten if new values are less than the stored values.
Syntax
boolean = FunctionMonitor.hold_max
FunctionMonitor.hold_max = boolean
Default Value
stack_len
Maximum number of records to store before overwriting previous values.
Syntax
int = FunctionMonitor.stack_len
FunctionMonitor.stack_len = int
Default Value
version
The version of the class.
Syntax
String = FunctionMonitor.version
Methods
_pack
Collapses the functions and function_index arrays. Method is private and should not be directly referenced.
Syntax
void _pack(
)
clearMetrics
Clears stored metrics.
Syntax
void clearMetrics(
)
dispatch
Receives function calls, invokes the original function, and monitors the execution time. Method is private and should not be directly referenced.
Syntax
v = dispatch(
sStoreName, vThis, aArgs
)
Parameters
- sStoreName as String : Internal lookup name for a monitored function.
- vThis as variant : Pointer to the
- aArgs as array : Arguments passed to the function.
Returns
v as variant: Returns the value returned by the monitored function.
getAllMetrics
Returns all collected metrics in a formatted hierarchy.
Syntax
sTxt = getAllMetrics(
)
Returns
sTxt as String: string representing the collected metrics.
getFunctionName
Returns the name of a function based on the string representation of the whole function. Method is private and should not be directly referenced.
Syntax
sName = getFunctionName(
sFunction
)
Parameters
- sFunction as String : String representation of a function.
Returns
sName as String: The name of the function.
getMetrics
Returns collected metrics for the specified function in a formatted hierarchy.
Syntax
sTxt = getMetrics(
sName
)
Parameters
- sName as String : name of the monitored function
Returns
sTxt as String: string representing the collected metrics.
makeMetric
Returns a new Metric object. Method is private and should not be directly referenced.
Syntax
void makeMetric(
)
register
Registers a function to be monitored.
Syntax
void register(
sName, oWindow, sClass
)
Parameters
- sName as String : name of the monitored function
- oWindow as object (optional): object reference to a browser window.
- sClass as String (optional): name of the class prototype to which the function belongs.
traceRoute
Returns the call stack for the specified function. Method is private and should not be directly referenced.
Syntax
sTrace = traceRoute(
fFunction
)
Parameters
- fFunction as function : Reference to the function being invoked.
Returns
sTrace as String: String value representing the stack trace.
unregister
Unregisters a monitored function.
Syntax
void unregister(
sName, oWindow, sClass
)
Parameters
- sName as String : name of the monitored function
- oWindow as object (optional): object reference to a browser window.
- sClass as String (optional): name of the class prototype to which the function belongs.