Function Monitor

FunMon2.js

static FunctionMonitor

version 2.1

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

Object Index

Property Index

Method Index

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

Metric

Object representing a function metric. Object is private and should not be directly referenced.

Properties

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

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

Returns

sName as String: The name of the function.

getIsRegistered

Returns a bit indicating whether the specified function is registered.

Syntax

b = getIsRegistered( sName, oWindow, sClass )

Parameters

Returns

b as boolean: Bit indicating whether the specified function is registered.

getMetrics

Returns collected metrics for the specified function in a formatted hierarchy.

Syntax

sTxt = getMetrics( sName )

Parameters

Returns

sTxt as String: string representing the collected metrics.

getObject

Returns a function or object from a given string and window reference.

Syntax

v = getObject( sFunctionPath, oWindow )

Parameters

Returns

v as variant: Returns a function or object pointer.

getWindowName

Returns a name for the specified window object. Method is private and should not be directly referenced.

Syntax

sName = getWindowName( oWindow )

Parameters

Returns

sName as String: Window name.

makeMetric

Returns a new Metric object. Method is private and should not be directly referenced.

Syntax

void makeMetric( )

printArguments

Returns a pseudo construct of the argument list, including values. Method is private and should not be directly referenced.

Syntax

sConstruct = printArguments( aArgs )

Parameters

Returns

sConstruct as String: String representing the argument construct.

register

Registers a function to be monitored.

Syntax

void register( sName, oWindow, sClass )

Parameters

traceRoute

Returns the call stack for the specified function. Method is private and should not be directly referenced.

Syntax

sTrace = traceRoute( fFunction )

Parameters

Returns

sTrace as String: String value representing the stack trace.

unregister

Unregisters a monitored function.

Syntax

void unregister( sName, oWindow, sClass )

Parameters

unregisterAll

Unregisters all monitored functions.

Syntax

void unregisterAll( )