@doc>
A utility Class for performning perfomnace measurements
Instances of this class are created automatically by the system, and should
not be created directly.
(c) SAP AG 2003-2006. All rights reserved.
Class PerformanceMng;
<@doc>
Constructs and initializes an BaseChannel object
The unique channel identifier
constructor(id)
this.msg=[];
this.times=[];
//this.begin('begin measurements');
end
<@doc scope="private" >A collection of all massages
readonly property msgs = [];
<@doc scope="private" >A collection of all the time stamps
readonly property times = [];
<@doc scope="private" >A collection of all the records keys
readonly property keys = {};
<@doc scope="private">Gets the folder name
readonly property folderName = 'C:\\VCLogs\\';
<@doc scope="private">Gets the file name
readonly property fileName = (new Date()).getTime() + '__LOG';
<@doc scope="private" >Gets log counter
readonly property logCounter = 0;
<@doc >log output in the console
readonly property CONSOLE = 0x01;
<@doc >log output in the local directory of the user
readonly property FILE = 0x02;
<@doc scope="private" >Gets the log output device
readonly property outputDevice = 0x02 | 0x01 ;
<@doc scope="private" >Gets and Sets whether to activate the performance checks in the GML DOM
readonly property disabled = false;
<@doc scope="private" >Gets and Sets the statistics mode
readonly property statisticsMode = false;
///////////////////////////////////////////////////////////////////////
// METHODS
<@doc>
Sets the starting time of the performance measurment.
Important Notes:
Make sure that for each PTIMESTART call there is a corresponding PTIMEEND call.
The log is printed to the console and to the following folder C:\VCLogs so make sure that this folder exist on your machine.
Configure the security setting in your browser to allow ActiveX component, so the logs could be written to your local hard-drive.
Description to be printed to the log.
method begin(desc)
//if(this.disabled) return;
var caller = arguments.callee.caller;
var mName = caller && caller.name || 'Undefined';
var cName = caller && caller.Class && caller.Class.fullname || 'Undefined';
this.times.push({key:desc||(cName+' ' + mName), start:new Date()});
if (!this.statisticsMode){
var str = [];
str.push("");
this.msgs.push( str.join('') );
}
end
<@doc>
Sets the ending time of the performance measurment.
method end()
//if(this.disabled) return;
if (this.times.length == 0){
this.clear('PTIME WAS ENDED WITH ERRORS.');
return;
}
if (this.times.length == 1){
var record = this.times.pop();
var time = new Date() - record.start;
if(this.statisticsMode) {
var obj = this.keys[record.key];
if(!obj)
obj = this.keys[record.key] = {hits:0, total:0};
obj.hits++;
obj.total += time;
}else {
this.msgs.push("");
this.msgs.push("");
}
//this.log(true);
return;
}
var record = this.times.pop();
var time = new Date() - record.start;
if(this.statisticsMode) {
var obj = this.keys[record.key];
if(!obj)
obj = this.keys[record.key] = {hits:0, total:0};
obj.hits++;
obj.total += time;
}else {
this.msgs.push("");
this.msgs.push("");
}
end
<@doc>
Force end of the performance measurements
method forceEnd()
for(var i =0,len= this.times.length;i
Clears the data structures used by the performance functions.
method clear(msg)
this.msgs = [];
this.times = [];
this.keys = {};
if (msg ){
alert(msg);
}
end
<@doc>
Save the log into the local machine of the user.
method save(str)
//only available in dev time.
var activeXMsg = '#TEXT[YMSG_ACTIVEX]';
var noVcLogsMsg = '#TEXT[XMSG_PERF_PRN_LOG_DIRECTORY]';
#DEVTIME[
var path = this.folderName + this.fileName + (this.logCounter++) +'\.xml';
var FSO;
try {
FSO = new ActiveXObject("Scripting.FileSystemObject");
} catch (e) {
PROMPT(activeXMsg);
return;
}
try {
var stream = FSO.createTextFile(path, true);
stream.Write(str);
stream.Close();
} catch (e) {
PROMPT(noVcLogsMsg);
}
]
end
<@doc scope="private">
Prints the log to the selceted device.
method log()
var text = '';
if(this.statisticsMode) {
if( ISEMPTY(this.keys) ) {
this.print('No entries in the log.');
return;
}
var msgs = [];
msgs.push(" ");
msgs.push("************************** Statistics ***************************");
var maxLen = 0;
for(var i in this.keys) if(i.length>maxLen) maxLen = i.length;
maxLen += 10;
for(var i in this.keys) {
var key = this.keys[i];
var str = "key = "+ i;
for(var n =str.length; n';
}
this.print(text);
if( this.times.length != 0 ){
var msg = [];
msg.push("***********************************************************************" );
msg.push("THERE ARE STILL SOME TIME ENTRIES WHICH WERE NOT CONSIDERED");
msg.push("PLEASE CHECK IF THERE ARE PTIMEEND CALLS FOR EACH PTIMESTART CALLS, NO. OF ENTRIES LEFT IN THE STACK:" + PTIME.times.length );
msg.push("***********************************************************************" );
alert(msg.join('\n'));
}
this.clear();
end
method print(str)
if( this.isConsole()) WRITE(str);
if(this.isFile()){
this.save(str);
}
end
<@doc >
Sets the output device.
method setOutputDevice(device)
this.outputDevice = device;
end
// Under development
method convertFn ( func )
var fnName = func.name;
if(fnName && (fnName =='supercall' || fnName =='protocall') ){
return func;
}
return function (p1,p2, p3, p4 , p5, p6, p7,p8, p9){
$ENV.perfMng.begin('Checking function:' + fnName);
var res = func.call(this ,p1,p2, p3, p4 , p5, p6, p7,p8, p9);
$ENV.perfMng.end();
return res;
}
end
// Under development
method convertObj ( obj )
for (var id in obj){
if( typeof obj[id] == 'function'){
try{
obj[id] = this.convertFn(obj[id]);
}catch(e){
WRITE && WRITE('Function' + func.name+' could not be converted:' + e.description);
}
}
}
end
// Under development
method convertClass ( name )
var cls= CLASS(name);
if(!cls) {
alert('No class found');
return;
}
this.convertObj(cls.prototype);
end
<@doc >
Gets whether the output should be to the CONSOLE.
method isConsole()
return (this.outputDevice & this.CONSOLE) && WRITE ? true: false;
end
<@doc >
Gets whether the output should be to the file system.
method isFile()
return (this.outputDevice & this.FILE) ? true: false;
end