/*Copyright 2007 by StatspackAnalyzer.com.  All Rights Reserved.*/

function clear_screen(){
	document.getElementById('placeholder').style.display="";
	document.getElementById('placeholder').innerHTML='<H2>Results will display here ...</H2>';

	document.getElementById('oracledatabaseinfo').style.display="none";
	document.getElementById('oracledatabaseinfo').innerHTML='';
	
	document.getElementById('oraclestorageperformance').style.display="none";
	document.getElementById('oraclestorageperformance').innerHTML='';

	document.getElementById('oracletop5timedevents1').style.display="none";
	document.getElementById('oracletop5timedevents1').innerHTML='';

	document.getElementById('oracletop5timedevents2').style.display="none"
	document.getElementById('oracletop5timedevents2').innerHTML='';

	document.getElementById('oracletablespace1').style.display="none"
	document.getElementById('oracletablespace1').innerHTML='';
	
	document.getElementById('oracletablespace2').style.display="none"
	document.getElementById('oracletablespace2').innerHTML='';

	document.getElementById('oracleloadprofile1').style.display="none"
	document.getElementById('oracleloadprofile1').innerHTML='';
	
	document.getElementById('oracleloadprofile2').style.display="none"
	document.getElementById('oracleloadprofile2').innerHTML='';

	document.getElementById('oracleinstanceefficiency1').style.display="none"
	document.getElementById('oracleinstanceefficiency1').innerHTML='';
	
	document.getElementById('oracleinstanceefficiency2').style.display="none"
	document.getElementById('oracleinstanceefficiency2').innerHTML='';	
	
	document.getElementById('oraclewaitevents1').style.display="none"
	document.getElementById('oraclewaitevents1').innerHTML='';
	
	document.getElementById('oraclewaitevents2').style.display="none"
	document.getElementById('oraclewaitevents2').innerHTML='';	
	
	document.getElementById('oracleinstanceactivitystats1').style.display="none"
	document.getElementById('oracleinstanceactivitystats1').innerHTML='';
	
	document.getElementById('oracleinstanceactivitystats2').style.display="none"
	document.getElementById('oracleinstanceactivitystats2').innerHTML='';	
	
	document.getElementById('oraclesqlorderedby').style.display="none"
	document.getElementById('oraclesqlorderedby').innerHTML='';		
	
	document.getElementById('oraclelatchactivity1').style.display="none"
	document.getElementById('oraclelatchactivity1').innerHTML='';
	
	document.getElementById('oraclelatchactivity2').style.display="none"
	document.getElementById('oraclelatchactivity2').innerHTML='';	
	
	document.getElementById('oraclebufferpooladvisory').style.display="none"
	document.getElementById('oraclebufferpooladvisory').innerHTML='';
	
	document.getElementById('oraclepgamemoryadvisory').style.display="none"
	document.getElementById('oraclepgamemoryadvisory').innerHTML='';
	
	document.getElementById('oraclesharedpooladvisory').style.display="none"
	document.getElementById('oraclesharedpooladvisory').innerHTML='';
	
	document.getElementById('oracleparameters1').style.display="none"
	document.getElementById('oracleparameters1').innerHTML='';
	
	document.getElementById('oracleparameters2').style.display="none"
	document.getElementById('oracleparameters2').innerHTML='';	
	
	return 0;
}

function error_message(error){
	if(error==1)	  document.getElementById('placeholder').innerHTML='<H2>Error 1: Please paste your statspack or AWR report into the text area.</H2>';
	else if(error==2) document.getElementById('placeholder').innerHTML='<H2>Error 2: Snapshots span an instance shutdown and are invalid.<BR>Please submit another statspack report.</H2>';
	else if(error==3) document.getElementById('placeholder').innerHTML='<H2>Error 3: Statspack Analyzer cannot currently process html reports.<BR>We apologize for the inconvenience. Please resubmit in plain text.</H2>';
	else if(error==4) document.getElementById('placeholder').innerHTML='<H2>Error 4: Oracle is reporting an error.<BR>Please correct error and generate new statspack report.</H2>';
	else if(error==5) document.getElementById('placeholder').innerHTML='<H2>Error 5: This statspack report appears to have wrapped text or non-standard formatting. Please email for more information.</H2>';
	else 	    	  document.getElementById('placeholder').innerHTML='<H2>Error 6: Statspack Analyzer is having trouble processing this statspack report.  Please email for more information.</H2>';
}

function create_report(DATA_BUNDLE){
	
	var db_info           = DATA_BUNDLE[0];
	var load_profile      = DATA_BUNDLE[1];
	var inst_efficiency   = DATA_BUNDLE[2];
	var top_event 	      = DATA_BUNDLE[3];
	var wait_event 	      = DATA_BUNDLE[4];
	var sql_data 	      = DATA_BUNDLE[5];
	var instance_activity = DATA_BUNDLE[6];
	var tablespace_io     = DATA_BUNDLE[7];
	var buffer_pool       = DATA_BUNDLE[8];
	var pga_memory        = DATA_BUNDLE[9];
	var latch_activity    = DATA_BUNDLE[10];
	var shared_pool       = DATA_BUNDLE[11];
	var init_param        = DATA_BUNDLE[12];
	var MI        	      = DATA_BUNDLE[13];
		
	var a,x,y,z,temp,temp2;
	
	x = 0;
	
	var db_block_size = init_param[MI.dbblocksize].value;	

	if(db_info.version<9010) db_info.cache = comma(Math.round(db_info.cache * db_block_size / 1024 / 1024));
	
	document.getElementById('placeholder').style.display="none";
	
	/********************************************************************************/
	/*			   Database Information					*/
	/********************************************************************************/	
	
	document.getElementById('oracledatabaseinfo').style.display="";
	document.getElementById('oracledatabaseinfo').innerHTML=
	'<TABLE width="100%" cellpadding="3" cellspacing="0">'+
	'<TR><TD colspan="3"><H2>Database Info</H2></TD><TD align="right" colspan="4"><i>'+new Date()+'</i></TD></TR>'+
	'<TR bgcolor="#000000"><TD class="black1"><b>DB ID</b></TD><TD align="right" class="black1"><b>Instance</b></TD><TD align="right" class="black1"><b>Release</b></TD><TD align="right" class="black1"><b>RAC</b></TD><TD align="right" class="black1"><b>Host</b></TD>'+
	'<TR bgcolor="#c0c0c0"><TD class="chart7"><b>'+db_info.id+'</TD><TD align="right" class="chart7"><b>'+db_info.instance+'</TD><TD align="right" class="chart7"><b>'+db_info.release+'</TD><TD align="right" class="chart7"><b>'+db_info.rac+'</TD><TD align="right" class="chart0"><b>'+db_info.host+'</TD>'+
	'<TR><TD>&nbsp;</TD></TR>'+
	'<TR><TD><b>Elapsed:</b></TD><TD>'+comma(Math.round(100*(db_info.elapsed/60))/100)+' (min)</TD><TD align="right">'+comma(db_info.elapsed)+' (sec)</TD></TR>'+
	'<TR><TD><b>DB Time:</b></TD><TD>'+comma(Math.round(100*(db_info.dbtime/60))/100)+' (min)</TD><TD align="right">'+comma(db_info.dbtime)+' (sec)</TD></TR>'+
	'<TR><TD><b>Cache:</b></TD><TD>'+db_info.cache+' MB</TD></TR>'+
	'<TR><TD><b>Block Size:</b></TD><TD>'+comma(db_block_size)+' bytes</TD></TR>'+
	'<TR><TD><b>Transactions:</b></TD><TD>'+load_profile.trans+' per second</TD></TR>'+
	'<TR><TD>&nbsp;</TD></TR></TABLE>';
	
	/********************************************************************************/
	/*			   Performance Summary					*/
	/********************************************************************************/	
	
	x = 0;
	
	var seq_reads = (MI.sequential>=0)? noComma(wait_event[MI.sequential].waits):0;
	var seq_read_time = (MI.sequential>=0)? noComma(wait_event[MI.sequential].total):0;
	if(seq_reads>0){
		var seq_reads_persec = Math.round(100*seq_reads/db_info.elapsed)/100;
		var seq_reads_avgwait = Math.round(100*(seq_read_time/seq_reads)*1000)/100;
	}
	else{
		var seq_reads_persec = 0;
		var seq_reads_avgwait = 0;
	}
	
	x = 0;

	var scat_reads = (MI.scattered>=0)? noComma(wait_event[MI.scattered].waits):0;
	var scat_read_time = (MI.scattered>=0)? noComma(wait_event[MI.scattered].total):0;
	if(scat_reads>0){
		var scat_reads_persec = Math.round(100*scat_reads/db_info.elapsed)/100;
		var scat_reads_avgwait  = Math.round(100*(scat_read_time/scat_reads)*1000)/100;
	}
	else{
		var scat_reads_persec = 0;
		var scat_reads_avgwait  = 0;
	}
	
/*	document.getElementById('oraclestorageperformance').style.display="";
	document.getElementById('oraclestorageperformance').innerHTML=
	'<TABLE width="100%">'+
	'<TR><TD colspan="2" width="320"><H2>Performance Summary</H2></TD></TR>'+
	'<TR><TD><b>Physical reads:</b></TD><TD align="left">'+load_profile.reads+' reads per second </TD><TD>('+Math.round(100*load_profile.reads*db_block_size/1024/1024)/100+' MB/sec)</TD></TR>'+
	'<TR><TD><b>Physical writes:</b></TD><TD align="left">'+load_profile.writes+' writes per second </TD><TD>('+Math.round(100*load_profile.writes*db_block_size/1024/1024)/100+' MB/sec)</TD></TR>'+
	'<TR><TD><b>Sequential reads:</b></TD><TD align="left">'+Math.round(100*seq_reads/db_info.elapsed)/100+' waits per second </TD><TD>('+Math.round(100*(seq_read_time/seq_reads)*1000)/100+' ms avg)</TD></TR>'+
	'<TR><TD><b>Scattered reads:</b></TD><TD align="left">'+Math.round(100*scat_reads/db_info.elapsed)/100+' waits per second </TD><TD>('+Math.round(100*(scat_read_time/scat_reads)*1000)/100+' ms avg)</TD></TR>'+
	'<TR><TD><b>Tablespace reads:</b></TD><TD align="left">'+tablespace_io[0].total_rps+' per second </TD><TD>&nbsp;</TD></TR>'+
	'<TR><TD><b>Tablespace writes:</b></TD><TD align="left">'+tablespace_io[0].total_wps+' per second </TD><TD>&nbsp;</TD></TR></TABLE></td></tr>';	
*/

	document.getElementById('oraclestorageperformance').style.display="";
	document.getElementById('oraclestorageperformance').innerHTML=
	'<TABLE width="100%" cellpadding="3" cellspacing="0">'+
	'<TR><TD colspan="5" class="chart6"><H2>Performance Summary</H2></TD></TR>'+
	'<TR><TD class="chart8" width="180">Physical Reads:</TD><TD align="right">'+comma(load_profile.reads)+'/sec</TD><TD width="50">&nbsp;</TD><TD>MB per second:</TD><TD align="right" class="chart4">'+Math.round(100*load_profile.reads*db_block_size/1024/1024)/100+' MB/sec</TD><TD width="100">&nbsp;</TD></TR>'+
	'<TR><TD class="chart8">Physical Writes:</TD><TD align="right">'+comma(load_profile.writes)+'/sec</TD><TD width="50">&nbsp;</TD><TD>MB per second:</TD><TD align="right" class="chart4">'+Math.round(100*load_profile.writes*db_block_size/1024/1024)/100+' MB/sec</TD><TD>&nbsp;</TD></TR>'+
	//'<TR><TD class="chart8">&nbsp;</TD><TD align="right">&nbsp;</TD><TD width="50">&nbsp;</TD><TD>&nbsp;</TD><TD align="right" class="chart4">&nbsp;</TD><TD>&nbsp;</TD></TR>'+
	'<TR><TD class="chart8">Single-block Reads:</TD><TD align="right">'+comma(seq_reads_persec)+'/sec</TD><TD width="50">&nbsp;</TD><TD>Avg wait:</TD><TD align="right" class="chart4">'+seq_reads_avgwait+' ms</TD><TD>&nbsp;</TD></TR>'+
	'<TR><TD class="chart8">Multi-block Reads:</TD><TD align="right">'+comma(scat_reads_persec)+'/sec</TD><TD width="50">&nbsp;</TD><TD>Avg wait:</TD><TD align="right" class="chart4">'+scat_reads_avgwait+' ms</TD><TD>&nbsp;</TD></TR>'+
	'<TR><TD class="chart7">Tablespace Reads:</TD><TD align="right" class="chart6">'+comma(tablespace_io[0].total_rps)+'/sec</TD><TD width="50" class="chart6">&nbsp;</TD><TD class="chart6">Writes:</TD><TD align="right" class="chart5">'+comma(tablespace_io[0].total_wps)+'/sec</TD><TD>&nbsp;</TD></TR>'+
	'<TR><TD>&nbsp;</TD></TR></TABLE>';
	
	/********************************************************************************/
	/*			  	Top 5 Events					*/
	/********************************************************************************/

	var top5_html = '';
	var key = ['CPU time','db file scattered read','db file sequential read','enqueue','message from client','control file sequential read','control file parallel write','direct path read','direct path write','log file parallel write','log file sync','log file single write','free buffer wait','buffer busy waits','db file parallel write','db file single write','log buffer space','log file sequential read','log file switch (archiving needed)','log file switch (checkpoint incomplete)','global cache cr request','global cr request waits','buffer busy global cache','global cache null to x','global cache null to s','message to client'];
	var length = key.length;
	for(x = 0; x < 5; x++){
		for(y=0;y<length;y++){
			if(top_event[x].name.match(key[y])){
				temp = getComment('top',y,top_event[x].percent).split('|');
				y = length;
			}
			else{
				temp = getComment('top',26,0).split('|');
			}
		}
		top5_html+='<TR bgcolor="#C0C0C0"><TD class="bottom"><b>'+top_event[x].name+'</TD><TD align="right" class="bottom"><b>'+top_event[x].percent+'%</TD></TR>'+
		'<TR bgcolor="#FFFFFF" valign="top"><TD class="chart7">'+temp[0]+'</TD><TD align="left" class="chart0">'+temp[1]+'</TD></TR>';
	}
	
	document.getElementById('oracletop5timedevents1').style.display="";
	document.getElementById('oracletop5timedevents2').style.display="none";
	
	var top5_collapsed = 
		'<TABLE width="100%" cellpadding="3" cellspacing="0" class="clickable" onclick="javascript:showhide(0)">'+
		'<TR><TD colspan="2"><H2>Top 5 Events</H2></TD></TR>'+
		'<TR bgcolor="#000000"><TD class="black1"><b>Event</b></TD><TD class="black1" align="right"><b>Percentage of Total Timed Events</b></TD></TR>'+
		'<TR bgcolor="#C0C0C0"><TD width="240" class="chart6"><b>'+top_event[0].name+'</TD><TD align="right" class="chart6"><b>'+top_event[0].percent+'%</TD></TR>'+
		'<TR bgcolor="#C0C0C0"><TD class="chart6"><b>'+top_event[1].name+'</TD><TD align="right" class="chart6"><b>'+top_event[1].percent+'%</TD></TR>'+
		'<TR bgcolor="#C0C0C0"><TD class="chart6"><b>'+top_event[2].name+'</TD><TD align="right" class="chart6"><b>'+top_event[2].percent+'%</TD></TR>'+
		'<TR bgcolor="#C0C0C0"><TD class="chart6"><b>'+top_event[3].name+'</TD><TD align="right" class="chart6"><b>'+top_event[3].percent+'%</TD></TR>'+
		'<TR bgcolor="#C0C0C0"><TD class="chart6"><b>'+top_event[4].name+'</TD><TD align="right" class="chart6"><b>'+top_event[4].percent+'%</TD></TR>'+
		'<TR><TD>&nbsp;</TD></TR></TABLE>';
		
	var top5_expanded =
		'<TABLE width="100%" cellpadding="3" cellspacing="0" class="clickable" onclick="javascript:showhide(1)">'+
		'<TR><TD colspan="2"><H2>Top 5 Events</H2></TD></TR>'+
		'<TR bgcolor="#000000"><TD class="black1"><b>Event</b></TD><TD class="black1" align="right"><b>Percentage of Total Timed Events</b></TD></TR>'+
		top5_html+
		'<TR><TD>&nbsp;</TD></TR></TABLE>';
	
	document.getElementById('oracletop5timedevents1').innerHTML=top5_collapsed;
	document.getElementById('oracletop5timedevents2').innerHTML=top5_expanded;
	
	/********************************************************************************/
	/*			      Tablespace IO Stats				*/
	/********************************************************************************/
	
	temp =  tablespace_io[0].total_reads+tablespace_io[0].total_writes;
	
	if(temp>0){
		/****** Make sorted arrays ******/
		var tablespace_io_time = new Array();
		var tablespace_io_reads = new Array();
		var tablespace_io_writes = new Array();
		
		/****** Copy original array to new arrays ******/
		for(x=0;x<tablespace_io.length;x++){
			/****** Save total reads and writes in every entry ******/
			tablespace_io[x].total_reads = tablespace_io[0].total_reads;
			tablespace_io[x].total_writes = tablespace_io[0].total_writes;
			tablespace_io_time[x] = tablespace_io[x];
			tablespace_io_reads[x] = tablespace_io[x];
			tablespace_io_writes[x] = tablespace_io[x];
		}
		
		/****** Sort new arrays ******/
		tablespace_io_time.sort(tableSort1);
		tablespace_io_reads.sort(tableSort2);
		tablespace_io_writes.sort(tableSort3);
							
		var tablespace_html = '';
		var tablespace_alt = '';
		length = tablespace_io.length;
		var color;
		var percent_reads;
		var percent_total;
		x = 0;
		while(x<length){
			color = "#e9e9e9";
			if(!(x%2)) color = "#C0C0C0";
			percent_reads = Math.round(100*tablespace_io[x].reads/(tablespace_io[x].reads+tablespace_io[x].writes));
			percent_total = Math.round(10000*(tablespace_io[x].reads+tablespace_io[x].writes)/(tablespace_io[0].total_reads+tablespace_io[0].total_writes))/100;
			if(percent_total>.4){
				tablespace_html+='<TR bgcolor='+color+'><TD class="chart7" style="cursor:pointer;">'+tablespace_io[x].name+'</TD><TD align="right" class="chart7">'+comma(tablespace_io[x].rps)+'</TD><TD align="right" class="chart7">'+tablespace_io[x].avg+'</TD><TD align="right" class="chart7">'+tablespace_io[x].blks+'</TD><TD align="right" class="chart7">'+comma(tablespace_io[x].wps)+'</TD><TD align="right" class="chart7">'+percent_reads+'%</TD><TD align="right" class="chart7">'+percent_total+'%</TD></TR>';	
				tablespace_alt+='<TR bgcolor='+color+'><TD class="chart7">'+tablespace_io[x].name+'</TD><TD align="right" class="chart7" style="cursor:pointer;">'+comma(tablespace_io[x].time)+'</TD><TD align="right" class="chart7">'+comma(tablespace_io[x].rps)+'</TD><TD align="right" class="chart7">'+tablespace_io[x].avg+'</TD><TD align="right" class="chart7">'+tablespace_io[x].blks+'</TD><TD align="right" class="chart7">'+comma(tablespace_io[x].wps)+'</TD><TD align="right" class="chart7">'+percent_reads+'%</TD><TD align="right" class="chart7">'+percent_total+'%</TD></TR>';	
			}
			else x = length;
			x++;
		}

		document.getElementById('oracletablespace1').style.display="";
		document.getElementById('oracletablespace1').innerHTML=
		'<TABLE width="100%" cellpadding="3" cellspacing="0" onclick="javascript:showhide(2)">'+
		'<TR><TD colspan="7"><a name="tablespaceio"></a><H2>Tablespace I/O Stats</H2></TD></TR>'+
		'<TR bgcolor="#000000"><TD class="black1" width="200"><b>Tablespace</b></TD><TD align="right" class="black1" style="cursor:pointer;"><b>Read/s</b></TD><TD align="right" class="black1"><b>Av Rd(ms)</b></TD><TD align="right" class="black1"><b>Blks/Rd</b></TD><TD align="right" class="black1"><b>Writes/s</b></TD><TD align="right" class="black1"><b>Read%</b></TD><TD align="right" class="black1"><b>% Total IO</b></TD></TR>'+
		tablespace_html+
		'<TR><TD>&nbsp;</TD></TR></TABLE>';
		
		document.getElementById('oracletablespace2').style.display="none";
		document.getElementById('oracletablespace2').innerHTML=
		'<TABLE width="100%" cellpadding="3" cellspacing="0" onclick="javascript:showhide(3)">'+
		'<TR><TD colspan="8"><a name="tablespaceio"></a><H2>Tablespace I/O Stats</H2></TD></TR>'+
		'<TR bgcolor="#000000"><TD class="black1" width="134"><b>Tablespace</b></TD><TD align="right" class="black1" style="cursor:pointer;" width="60"><b>Wait (s)</b></TD><TD align="right" class="black1"><b>Read/s</b></TD><TD align="right" class="black1"><b>Av Rd(ms)</b></TD><TD align="right" class="black1"><b>Blks/Rd</b></TD><TD align="right" class="black1"><b>Writes/s</b></TD><TD align="right" class="black1"><b>Read%</b></TD><TD align="right" class="black1"><b>% Total IO</b></TD></TR>'+
		tablespace_alt+
		'<TR><TD>&nbsp;</TD></TR></TABLE>';		
	}

	/********************************************************************************/
	/*			   	 Load Profile 					*/
	/********************************************************************************/	
	
	var loadProfile_html = '';
	
	document.getElementById('oracleloadprofile1').style.display="";
	document.getElementById('oracleloadprofile1').innerHTML=	
		'<TABLE width="100%" cellpadding="3" cellspacing="0">'+
		'<TR><TD colspan="5" class="chart6"><H2>Load Profile</H2></TD></TR>'+
		'<TR><TD class="chart8" width="180">Logical reads:</TD><TD align="right" width="80">'+comma(load_profile.logreads)+'/s</TD><TD width="50">&nbsp;</TD><TD>Parses:</TD><TD class="chart4" align="right">'+load_profile.parses+'/s</TD><TD width="100">&nbsp;</TD></TR>'+
		'<TR><TD class="chart8">Physical reads:</TD><TD align="right">'+comma(load_profile.reads)+'/s</TD><TD>&nbsp;</TD><TD>Hard parses:</TD><TD class="chart4" align="right">'+load_profile.hardparses+'/s</TD><TD>&nbsp;</TD></TR>'+
		'<TR><TD class="chart8">Physical writes:</TD><TD align="right">'+comma(load_profile.writes)+'/s</TD><TD>&nbsp;</TD><TD>Transactions:</TD><TD class="chart4" align="right">'+load_profile.trans+'/s</TD><TD>&nbsp;</TD></TR>'+
		'<TR><TD class="chart7">Rollback per transaction:</TD><TD align="right" class="chart6">'+load_profile.rollback+'%</TD><TD class="chart6">&nbsp;</TD><TD class="chart6">Buffer Nowait:</TD><TD class="chart5" align="right">'+inst_efficiency.buffernowait+'%</TD><TD>&nbsp;</TD></TR>'+
		'</TABLE>';

	/****** Save all Top 5 Timed Events to string ******/
	var top5names = '';
	for(x=0;x<5;x++) top5names+=top_event[x].name+' ';
	
	var optimizer_cost_model = init_param[MI.costmodel].value;
	var session_cached_cursors = init_param[MI.sessioncached].value;
	var cursor_sharing = init_param[MI.cursorsharing].value;
		
	if(db_info.version>=9010){
		var library_cache      	    = (MI.librarycache)? parseInt(latch_activity[MI.librarycache].waittime):0;
		var library_cache_lock 	    = (MI.lock)? 	 parseInt(latch_activity[MI.lock].waittime):0;
		var library_cache_pin  	    = (MI.pin)? 	 parseInt(latch_activity[MI.pin].waittime):0;
		var library_cache_load_lock = (MI.loadlock)? 	 parseInt(latch_activity[MI.loadlock].waittime):0;		
		
		var total_library	    = library_cache + library_cache_lock + library_cache_pin + library_cache_load_lock;

		var shared_pool_latch 	    = (MI.shared)? latch_activity[MI.shared].waittime:0;
		
		var parse_count_total 	    = (MI.totalparse)? noComma(instance_activity[MI.totalparse].total,1):0;
		var parse_count_hard 	    = (MI.hardparse)? noComma(instance_activity[MI.hardparse].total,1):0;
		var cursor_cached_hits	    = (MI.cursorcachehits)? noComma(instance_activity[MI.cursorcachehits].total,1):0;
		
		var session_cached_cursors  = init_param[MI.sessioncached].value;
		var cursor_sharing	    = init_param[MI.cursorsharing].value;
		var optimizer_cost_model    = init_param[MI.costmodel].value;
		
		var pct_library_cache = Math.round(100*(library_cache / db_info.dbtime) * 100)/100;
		var pct_total_library = Math.round(100*(total_library / db_info.dbtime) * 100)/100;
		var pct_shared_pool   = Math.round(100*(shared_pool_latch / db_info.dbtime) * 100)/100;
		var pct_hard_parse    = Math.round(100*(parse_count_hard / parse_count_total) * 100)/100;
		var pct_session_cached= Math.round(100*(cursor_cached_hits / parse_count_total) * 100)/100;
	}
	else{
		var pct_library_cache = 0;
		var pct_total_library = 0;
	}
	
	y = (tablespace_io_writes.length<5)? tablespace_io_writes.length:5; //If tablespace has less than 5 rows, make y = number of rows

	/****** Read top 5 tablespaces by writes ******/
	var topWrites = '';
	for(x=0;x<y;x++) if(tablespace_io_writes[x].avg>6.9) topWrites+=tablespace_io_writes[x].name+', ';
	topWrites=topWrites.substring(0,topWrites.length-2)+'.';

	/****** Read top 3 tablespaces by reads ******/
	var topReads = '';
	for(x=0;x<y;x++) topReads+=tablespace_io_reads[x].name+', ';
	topReads=topReads.substring(0,topReads.length-2)+'.';
	
	load_profile.parseAlert = 0;
	
	x = 0;

	/****** High Buffer Contention ******/
	if((top5names.match('buffer busy waits')&&top5names.match('cache buffers LRU'))||(inst_efficiency.buffernowait<98&&top5names.match('cache buffers LRU')))  
	x++, loadProfile_html+='<TR><TD>'+getComment('load',0)+'</TD></TR>';
	
	if((top5names.match('buffer busy waits')&&top5names.match('cache buffers chain'))||(inst_efficiency.buffernowait<98&&top5names.match('cache buffers chain')))  	
	x++, loadProfile_html+='<TR><TD>'+getComment('load',1)+'</TD></TR>';
	
	if(top5names.match('buffer busy waits')&&(top5names.match('db file sequential read')||top5names.match('db file scattered read')))
	x++, loadProfile_html+='<TR><TD>'+getComment('load',2)+'</TD></TR>';

	/****** High Logical Reads ******/
	if(load_profile.logreads>20000&&top5names.match('CPU time'))
	x++, loadProfile_html+='<TR><TD>'+getComment('load',3,comma(load_profile.logreads))+'</TD></TR>';
	
	/****** Optimizer Cost Model ******/
	if(load_profile.logreads>20000&&optimizer_cost_model=='cpu'&&db_info.version>=10100&&!top5names.match('CPU time'))
	x++, loadProfile_html+='<TR><TD>'+getComment('load',4)+'</TD></TR>';

	/****** High Physical Reads ******/
	if(load_profile.reads>500&&(top5names.match('db file sequential read')||top5names.match('db file scattered read'))){
	x++, loadProfile_html+='<TR><TD>'+getComment('load',5,comma(load_profile.reads),topReads)+'</TD></TR>';
	
		/****** Average Disk Read Speed ******/
		if(topReads!='.')
		x++, loadProfile_html+='<TR><TD>'+getComment('load',6,topReads)+'</TD></TR>';	
	}

	/****** High Physical Writes ******/
	if(load_profile.writes>100||top5names.match('db file parallel write')){
	x++, loadProfile_html+='<TR><TD>'+getComment('load',7,comma(load_profile.writes))+'</TD></TR>';

		/****** Long IO Times ******/
		if(topWrites!='.')
		x++, loadProfile_html+='<TR><TD>'+getComment('load',8,topWrites)+'</TD></TR>';
	}

	/****** High Hard Parses ******/
	if(pct_total_library>5||pct_shared_pool>3||pct_hard_parse>10){
	x++, loadProfile_html+='<TR><TD>'+getComment('load',10,comma(parse_count_hard))+'</TD></TR>';
	
		load_profile.parseAlert = 1;

		/****** Cursor Sharing = "Exact" ******/
		if(cursor_sharing=='exact')
		x++, loadProfile_html+='<TR><TD>'+getComment('load',11)+'</TD></TR>';
	}
	
	/****** High Soft Parses ******/
	if(pct_library_cache>3&&pct_session_cached<=10&&session_cached_cursors<=50){
		x++, loadProfile_html+='<TR><TD>'+getComment('load',12)+'</TD></TR>';
		load_profile.parseAlert = 1;
	}

	/****** High Rollbacks per transaction ******/
	if(load_profile.rollback>5)
	x++, loadProfile_html+='<TR><TD>'+getComment('load',13,comma(load_profile.rollback))+'</TD></TR>';

	document.getElementById('oracleloadprofile2').style.display="";
	document.getElementById('oracleloadprofile2').innerHTML=	
		'<TABLE width="100%" cellpadding="3" cellspacing="0">'+
		'<TR><TD><b>'+x+' Recommendations:</b></TD></TR>'+
		loadProfile_html+
		'<TR><TD>&nbsp;</TD></TR></TABLE>';		

	/********************************************************************************/
	/*			      Instance Efficiency 				*/
	/********************************************************************************/

	var efficiency_html = '';
	
	efficiency_html=	
		'<TABLE width="100%" cellpadding="3" cellspacing="0">'+
		'<TR><TD colspan="5" class="chart6"><H2>Instance Efficiency</H2></TD></TR>'+
		'<TR><TD class="chart8" width="180">Buffer Hit:</TD><TD align="right" width="80">'+inst_efficiency.bufferhit+'%</TD><TD width="50">&nbsp;</TD><TD>In-memory Sort:</TD><TD class="chart4" align="right">'+inst_efficiency.inmemorysort+'%</TD><TD width="100">&nbsp;</TD></TR>';

	/****** Show Memory Usage and Memory for SQL if available ******/
	if(inst_efficiency.memoryusage!='?') efficiency_html+= 
		'<TR><TD class="chart8">Library Hit:</TD><TD align="right">'+inst_efficiency.libraryhit+'%</TD><TD>&nbsp;</TD><TD>Latch Hit:</TD><TD class="chart4" align="right">'+inst_efficiency.latchhit+'%</TD><TD>&nbsp;</TD></TR>'+
		'<TR><TD class="chart7">Memory Usage:</TD><TD align="right" class="chart6">'+inst_efficiency.memoryusage+'%</TD><TD class="chart6">&nbsp;</TD><TD class="chart6">Memory for SQL:</TD><TD align="right" class="chart5">'+inst_efficiency.memoryforsql+'%</TD><TD>&nbsp;</TD></TR>'+
		'</TABLE>';

	/****** If not available, close box after Library Hit and Latch Hit ******/
	else efficiency_html+= 
		'<TR><TD class="chart7">Library Hit:</TD><TD align="right" class="chart6">'+inst_efficiency.libraryhit+'%</TD><TD class="chart6">&nbsp;</TD><TD class="chart6">Latch Hit:</TD><TD align="right" class="chart5">'+inst_efficiency.latchhit+'%</TD><TD>&nbsp;</TD></TR>'+
		'</TABLE';

	document.getElementById('oracleinstanceefficiency1').style.display="";	
	document.getElementById('oracleinstanceefficiency1').innerHTML = efficiency_html;
	
	var instEfficiency_html = '';
	x = 0;
	
	var sorts_disk =   (MI.disksorts)?   parseFloat(instance_activity[MI.disksorts].persec):0;
	var sorts_memory = (MI.memorysorts)? parseFloat(instance_activity[MI.memorysorts].persec):0;
	var pct_sorts_disk = Math.round((sorts_disk/(sorts_disk+sorts_memory))*10000)/100;
		
	/****** Low Buffer Hit Percentage ******/
	if(inst_efficiency.bufferhit<90)
	x++, instEfficiency_html+='<TR><TD>'+getComment('efficiency',0,inst_efficiency.bufferhit)+'</TD></TR>';

	/****** Low Library Hit Percentage ******/
	if(inst_efficiency.libraryhit<90)
	x++, instEfficiency_html+='<TR><TD>'+getComment('efficiency',1,inst_efficiency.libraryhit)+'</TD></TR>';
	
	/****** High Disk Sorts ******/
	if(inst_efficiency.inmemorysort<99||sorts_disk>.5)
	x++, instEfficiency_html+='<TR><TD>'+getComment('efficiency',2,pct_sorts_disk)+'</TD></TR>';

	/****** Low Latch Hit Percentage ******/
	if(inst_efficiency.latchhit<95)
	x++, instEfficiency_html+='<TR><TD>'+getComment('efficiency',3,inst_efficiency.latchhit)+'</TD></TR>';
	
	/****** High Shared Pool Memory Usage ******/
	if(inst_efficiency.memoryusage>90){
	x++, instEfficiency_html+='<TR><TD>'+getComment('efficiency',4,inst_efficiency.memoryusage)+'</TD></TR>';
	
		/****** High Memory For SQL ******/
		if(inst_efficiency.memoryforsql>70)
		x++, instEfficiency_html+='<TR><TD>'+getComment('efficiency',5,inst_efficiency.memoryusage,inst_efficiency.memoryforsql)+'</TD></TR>';	
	}
	
	/****** Shared Pool Advisory ******/
	if(shared_pool.esttimesaved>5)
	x++, instEfficiency_html+='<TR><TD>'+getComment('efficiency',6,shared_pool.estobjects,shared_pool.esttimesaved)+'</TD></TR>';
	
	document.getElementById('oracleinstanceefficiency2').style.display="";
	document.getElementById('oracleinstanceefficiency2').innerHTML=	
		'<TABLE width="100%" cellpadding="3" cellspacing="0">'+
		'<TR><TD><b>'+x+' Recommendations:</b></TD></TR>'+
		instEfficiency_html+
		'<TR><TD>&nbsp;</TD></TR></TABLE>';	
		
	/********************************************************************************/
	/*			     	  SQL Statistics	  			*/
	/********************************************************************************/

	if(sql_data.length){

			var SQL_data_html = '<TABLE width="100%" cellpadding="3" cellspacing="0"><TR><TD><H2>SQL Statements</H2></TD></TR><TR><TD><B>Summary:</B></TD></TR><TR><TD>&nbsp;</TD></TR>';
		SQL_data_html += '<TR><TD width = "40"><B>Hash Value</B></TD><TD width = "40"><B>Buffer Gets</B></TD><TD><B>Physical Reads</B></TD><TD><B>Executions</B></TD><TD><B>Parse Calls</B></TD><TD><B>Rows Processed</B></TD><TD><B>Shareable Mem</B></TD><TD><B>Version Count</B></TD><TD><B>CPU Time</B></TD><TD><B>Elapsed</B></TD><TD><B>Gets per exec</B></TD><TD><B>Reads per exec</B></TD><TD><B>Rows per exec</B></TD><TD><B>Cpu per exec</B></TD><TD><B>Elap per exec</B></TD><TD><B>%gets</B></TD><TD><B>%reads</B></TD><TD><B>%db</B></TD><TD><B>%cpu</B></TD><TD><B>%elap</B></TD><TD><B>%parses</B></TD><TD><B>%share</B></TD><TD><B>%exec</B></TD></TR>';

		color = "#FFFFFF";
		i = 0;

		for(i=0;i<sql_data.length;i++){
			//dbSQL[i].phys_reads_per_min =   Math.round(100*dbSQL[i].phys_reads/minutes_in_report)/100;
			//dbSQL[i].gets_per_min = 	Math.round(100*dbSQL[i].gets/minutes_in_report)/100;
			//dbSQL[i].executions_per_min =   Math.round(100*dbSQL[i].executions/minutes_in_report)/100;		
			//dbSQL[i].pct_total_exec = 	Math.round(10000*dbSQL[i].executions/total_executions)/100;

			if(i%2) color = "#FFFFFF";
			else color = "#F5F5FF";

			SQL_data_html+='<TR bgcolor='+color+'><TD>'+
				sql_data[i].hash+'</TD><TD>'+
				sql_data[i].gets+'</TD><TD>'+
				sql_data[i].phys_reads+'</TD><TD>'+
				sql_data[i].executions+'</TD><TD>'+
				sql_data[i].parse_calls+'</TD><TD>'+
				sql_data[i].rows_processed+'</TD><TD>'+
				sql_data[i].shareable_mem+'</TD><TD>'+
				sql_data[i].version_count+'</TD><TD>'+
				sql_data[i].cpu_time+'</TD><TD>'+
				sql_data[i].elap_time+'</TD><TD>'+
				sql_data[i].gets_per_exec+'</TD><TD>'+
				sql_data[i].reads_per_exec+'</TD><TD>'+
				sql_data[i].rows_per_exec+'</TD><TD>'+
				sql_data[i].cpu_per_exec+'</TD><TD>'+
				sql_data[i].elap_per_exec+'</TD><TD>'+
				sql_data[i].pct_total_gets+'</TD><TD>'+
				sql_data[i].pct_total_reads+'</TD><TD>'+
				sql_data[i].pct_total_dbtime+'</TD><TD>'+
				sql_data[i].pct_total_cpu+'</TD><TD>'+
				sql_data[i].pct_total_elap+'</TD><TD>'+
				sql_data[i].pct_total_parses+'</TD><TD>'+
				sql_data[i].pct_total_shareable+'</TD><TD>'+
				sql_data[i].pct_total_exec+'</TD></TR><TR bgcolor='+color+'><TD colspan="23"><font color="#CCCCCC">'+
				sql_data[i].SQL_statement+'</font></TD></TR>';
		}
		SQL_data_html+='</TABLE>'

		document.getElementById('oraclesqlorderedby').style.display="";
		document.getElementById('oraclesqlorderedby').innerHTML=	
			'<TABLE width="100%" cellpadding="3" cellspacing="0">'+
			'<TR><TD><H2>SQL Statistics</H2></TD></TR>'+
			'<TR><TD><a href="javascript:sql_print()">Click here to see all SQL data</a></TD></TR>'+
			'<TR><TD>&nbsp;</TD></TR></TABLE>';		

		global_SQL_data = SQL_data_html;
	}

	/********************************************************************************/
	/*			           Wait Events					*/
	/********************************************************************************/	

	var waitevents_html = '';
	var waitEvents_output = '';
	length = wait_event.length;
	x = 0;
	y = 0;
	while(x < length && x < 10){
	
		color = "#e9e9e9";
		if(!(x%2)) color = "#C0C0C0";
		waitevents_html += '<TR bgcolor='+color+'><TD class="chart7">'+wait_event[x].name+'</TD><TD align="right" class="chart7">'+wait_event[x].waits+'</TD><TD align="right" class="chart7">'+wait_event[x].total+'</TD><TD align="right" class="chart7">'+wait_event[x].avg+'</TD><TD align="right" class="chart0">'+wait_event[x].pertxn+'</TD></TR>';	
		
			/****** High Free Buffer Waits ******/
			if(wait_event[x].name.match('free buffer waits')&&noComma(wait_event[x].avg)>5)
			y++, waitEvents_output+='<TR><TD>'+getComment('wait',0,wait_event[x].avg)+'</TD></TR>';

			/****** High Latch Free Waits ******/
			else if(wait_event[x].name.match('latch free  ')&&noComma(wait_event[x].pertxn)>1)
			y++, waitEvents_output+='<TR><TD>'+getComment('wait',1,wait_event[x].pertxn)+'</TD></TR>';	

			/****** High Log Buffer Space Waits ******/
			else if(wait_event[x].name.match('log buffer space')&&noComma(wait_event[x].pertxn)>1)
			y++, waitEvents_output+='<TR><TD>'+getComment('wait',2,wait_event[x].pertxn)+'</TD></TR>';	

			/****** High Log File Switch Waits ******/
			else if(wait_event[x].name.match('log file switch completion')&&noComma(wait_event[x].avg)>5)
			y++, waitEvents_output+='<TR><TD>'+getComment('wait',3,wait_event[x].avg)+'</TD></TR>';	

			/****** High Log File Sync Waits ******/
			else if(wait_event[x].name.match('log file sync')&&noComma(wait_event[x].pertxn)>1)
			y++, waitEvents_output+='<TR><TD>'+getComment('wait',4,wait_event[x].pertxn)+'</TD></TR>';

			/****** High SQL*Net message from client ******/
			else if(wait_event[x].name.match('message from client')&&noComma(wait_event[x].avg)>5)
			y++, waitEvents_output+='<TR><TD>'+getComment('wait',5,wait_event[x].avg)+'</TD></TR>';		

			/****** High db file sequential read waits ******/
			else if(wait_event[x].name.match('db file sequential read')&&noComma(wait_event[x].avg)>5)
			y++, waitEvents_output+='<TR><TD>'+getComment('wait',6,wait_event[x].avg)+'</TD></TR>';		

			/****** High db file scattered read waits ******/
			else if(wait_event[x].name.match('db file scattered read')&&noComma(wait_event[x].avg)>5)
			y++, waitEvents_output+='<TR><TD>'+getComment('wait',7,wait_event[x].avg)+'</TD></TR>';	

			/****** High Buffer Busy Waits ******/
			else if(wait_event[x].name.match('buffer busy waits')&&noComma(wait_event[x].avg)>5)
			y++, waitEvents_output+='<TR><TD>'+getComment('wait',8,wait_event[x].avg)+'</TD></TR>';		

			/****** High Buffer Busy Waits ******/
			else if(wait_event[x].name.match('buffer busy waits')&&noComma(wait_event[x].pertxn)>1)
			y++, waitEvents_output+='<TR><TD>'+getComment('wait',9,wait_event[x].pertxn)+'</TD></TR>';		

			/****** High Enqueue Waits ******/
			else if(wait_event[x].name.match('enqueue')&&noComma(wait_event[x].avg)>5)
			y++, waitEvents_output+='<TR><TD>'+getComment('wait',10,wait_event[x].avg)+'</TD></TR>';	

			/****** High Enqueue Waits ******/
			else if(wait_event[x].name.match('enqueue')&&noComma(wait_event[x].pertxn)>1)
			y++, waitEvents_output+='<TR><TD>'+getComment('wait',11,wait_event[x].pertxn)+'</TD></TR>';
		
		x++;
	}
	document.getElementById('oraclewaitevents1').style.display="";
	document.getElementById('oraclewaitevents1').innerHTML=	
		'<TABLE width="100%" cellpadding="3" cellspacing="0">'+
		'<TR><TD colspan="5"><H2>Wait Events</H2></TD></TR>'+
		'<TR bgcolor="#000000"><TD class="black1"><b>Event</b></TD><TD align="right" class="black1"><b>Waits</b></TD><TD align="right" class="black1"><b>Wait Time (s)</b></TD><TD align="right" class="black1" width="110"><b>Avg Wait (ms)</b></TD><TD align="right" class="black1"><b>Waits/txn</b></TD></TR>'+
		waitevents_html+
		'</TABLE>';

	document.getElementById('oraclewaitevents2').style.display="";
	document.getElementById('oraclewaitevents2').innerHTML=	
		'<TABLE width="100%" cellpadding="3" cellspacing="0">'+
		'<TR><TD><b>'+y+' Recommendations:</b></TD></TR>'+
		waitEvents_output+
		'<TR><TD>&nbsp;</TD></TR></TABLE>';

	/********************************************************************************/
	/*			      Instance Activity Stats				*/
	/********************************************************************************/

	var stats_html = '';
	var instanceActivity_output = '';
	
	key = ['SQL\\*\\Net roundtrips to\/from client','consistent gets  ','consistent gets - examination','db block changes','execute count','physical reads  ','physical reads direct  ','physical writes  ','physical writes direct  ','redo writes','sorts \\(disk\\)','table fetch continued row','table scans \\(long tables\\)','table scans \\(short tables\\)','workarea executions - onepass','session cursor cache hits','parse count \\(hard\\)','parse count \\(total\\)','sorts \\(memory\\)'];

	var key_length = key.length;
	length = instance_activity.length;
	
	a = 0;
	x = 0;
	y = 0;
	z = 0;
		
	while(x < length){
		color = "#e9e9e9";
		if(!(a%2)) color = "#C0C0C0";
		temp = instance_activity[x].name;
		for(y=0;y<key_length;y++){
			if(temp.match(key[y])){

				stats_html += '<TR bgcolor='+color+'><TD class="chart7">'+instance_activity[x].name+'</TD><TD align="right" class="chart7">'+instance_activity[x].total+'</TD><TD align="right" class="chart7">'+instance_activity[x].persec+'</TD><TD align="right" class="chart0">'+instance_activity[x].pertxn+'</TD></TR>';	
				y=key_length;
				a++;
				
				/****** High SQL Roundtrips ******/
				if(instance_activity[x].name.match('roundtrips to\/from client')&&noComma(instance_activity[x].persec)>50)
				z++, instanceActivity_output+='<TR><TD>'+getComment('stats',0,instance_activity[x].persec)+'</TD></TR>';

				/****** High Consistent Gets Examination ******/
				if(instance_activity[x].name.match('consistent gets - examination')&&noComma(instance_activity[x].persec)>1000)
				z++, instanceActivity_output+='<TR><TD>'+getComment('stats',1,instance_activity[x].persec)+'</TD></TR>';

				/****** High DB Block Changes ******/
				if(instance_activity[x].name.match('db block changes')&&noComma(instance_activity[x].persec)>50)
				z++, instanceActivity_output+='<TR><TD>'+getComment('stats',2,instance_activity[x].persec)+'</TD></TR>';

				/****** High Physical Reads ******/
				if(instance_activity[x].name.match('physical reads  ')&&noComma(instance_activity[x].persec)>1000)
				z++, instanceActivity_output+='<TR><TD>'+getComment('stats',3,instance_activity[x].persec)+'</TD></TR>';

				/****** High Physical Writes ******/
				if(instance_activity[x].name.match('physical writes  ')&&noComma(instance_activity[x].persec)>50)
				z++, instanceActivity_output+='<TR><TD>'+getComment('stats',4,instance_activity[x].persec)+'</TD></TR>';

				/****** High Disk Sorts ******/
				if(instance_activity[x].name.match('sorts \\(disk\\)')&&noComma(instance_activity[x].total)>0)
				z++, instanceActivity_output+='<TR><TD>'+getComment('stats',5,instance_activity[x].total)+'</TD></TR>';

				/****** High Table Fetch Continued Row ******/
				if(instance_activity[x].name.match('table fetch continued row')&&noComma(instance_activity[x].total)>1000)
				z++, instanceActivity_output+='<TR><TD>'+getComment('stats',6,instance_activity[x].total)+'</TD></TR>';

				/****** High Full Table Scans (long) ******/
				if(instance_activity[x].name.match('long tables')&&noComma(instance_activity[x].persec)>.5)
				z++, instanceActivity_output+='<TR><TD>'+getComment('stats',7,instance_activity[x].persec)+'</TD></TR>';

				/****** High Full Table Scans (short) ******/
				if(instance_activity[x].name.match('short tables')&&noComma(instance_activity[x].persec)>.5)
				z++, instanceActivity_output+='<TR><TD>'+getComment('stats',8,instance_activity[x].persec)+'</TD></TR>';

				/****** High Onepass Workarea Executions ******/
				if(instance_activity[x].name.match('workarea executions - onepass')&&noComma(instance_activity[x].total)>50)
				z++, instanceActivity_output+='<TR><TD>'+getComment('stats',9,instance_activity[x].total)+'</TD></TR>';
								
			}
		}
		x++;
	}
	
	document.getElementById('oracleinstanceactivitystats1').style.display="";
	document.getElementById('oracleinstanceactivitystats1').innerHTML=	
		'<TABLE width="100%" cellpadding="3" cellspacing="0">'+
		'<TR><TD colspan="4"><H2>Instance Activity Stats</H2></TD></TR>'+
		'<TR bgcolor="#000000"><TD class="black1"><b>Statistic</b></TD><TD align="right" class="black1"><b>Total</b></TD><TD align="right" class="black1"><b>per Second</b></TD><TD align="right" class="black1" width="110"><b>per Trans</b></TD></TR>'+		
		stats_html+
		'</TABLE>';

	document.getElementById('oracleinstanceactivitystats2').style.display="";
	document.getElementById('oracleinstanceactivitystats2').innerHTML=	
		'<TABLE width="100%" cellpadding="3" cellspacing="0">'+
		'<TR><TD><b>'+z+' Recommendations:</b></TD></TR>'+
		instanceActivity_output+
		'<TR><TD>&nbsp;</TD></TR></TABLE>';		

	/********************************************************************************/
	/*			          Latch Activity				*/
	/********************************************************************************/
		
	var latch_html = '';
	var latchActivity_output = '';
	length = latch_activity.length;
	a = 0;
	x = 0;
	y = 0;
	
	while(x < length){
		color = "#e9e9e9";
		if(!(a%2)) color = "#C0C0C0";
		if((db_info.version>=9010&&latch_activity[x].waittime>0&&latch_activity[x].getmiss>0.0)||(db_info.version<9010&&latch_activity[x].getmiss>0.1)){
			latch_html += '<TR bgcolor='+color+'><TD class="chart7">'+latch_activity[x].name+'</TD><TD align="right" class="chart7">'+latch_activity[x].getreq+'</TD><TD align="right" class="chart7">'+latch_activity[x].getmiss+'</TD><TD align="right" class="chart7">'+latch_activity[x].nowaitmiss+'</TD><TD align="right" class="chart0">'+latch_activity[x].waittime+'</TD></TR>';	
			a++;
			
			/****** High Cache Buffer Chain Waits ******/
			if(latch_activity[x].name.match('cache buffers chains'))
			y++, latchActivity_output+='<TR><TD>'+getComment('latch',0,latch_activity[x].getmiss)+'</TD></TR>';
			
			/****** High Cache Buffer LRU Chain Waits ******/
			if(latch_activity[x].name.match('cache buffers lru chain'))
			y++, latchActivity_output+='<TR><TD>'+getComment('latch',1,latch_activity[x].getmiss)+'</TD></TR>';
			
			/****** High Library Cache Waits ******/
			if(latch_activity[x].name.match('library cache  '))
			y++, latchActivity_output+='<TR><TD>'+getComment('latch',2,latch_activity[x].getmiss)+'</TD></TR>';
			
			/****** High Redo Allocation Misses ******/
			if(latch_activity[x].name.match('redo allocation'))
			y++, latchActivity_output+='<TR><TD>'+getComment('latch',3,latch_activity[x].getmiss)+'</TD></TR>';
			
			/****** High Redo Copy Latches ******/
			if(latch_activity[x].name.match('redo copy'))
			y++, latchActivity_output+='<TR><TD>'+getComment('latch',4,latch_activity[x].getmiss)+'</TD></TR>';
			
			/****** High Row Cache Object Latches ******/
			if(latch_activity[x].name.match('row cache objects'))
			y++, latchActivity_output+='<TR><TD>'+getComment('latch',5,latch_activity[x].getmiss)+'</TD></TR>';
		}
		x++;
	}
	if(latch_html!=''){
		document.getElementById('oraclelatchactivity1').style.display="";
		document.getElementById('oraclelatchactivity1').innerHTML=	
			'<TABLE width="100%" cellpadding="3" cellspacing="0">'+
			'<TR><TD colspan="4"><H2>Latch Activity</H2></TD></TR>'+
			'<TR bgcolor="#000000"><TD class="black1"><b>Latch</b></TD><TD align="right" class="black1"><b>Get Requests</b></TD><TD align="right" class="black1"><b>% Get Miss</b></TD><TD align="right" class="black1"><b>% NoWait Miss</b></TD><TD align="right" class="black1" width="110"><b>Wait Time (s)</b></TD></TR>'+
			latch_html+
			'</TABLE>';

		document.getElementById('oraclelatchactivity2').style.display="";
		document.getElementById('oraclelatchactivity2').innerHTML=	
			'<TABLE width="100%" cellpadding="3" cellspacing="0">'+
			'<TR><TD><b>'+y+' Recommendations:</b></TD></TR>'+
			latchActivity_output+
			'<TR><TD>&nbsp;</TD></TR></TABLE>';			
	}
	
	/********************************************************************************/
	/*			      Buffer Pool Advisory				*/
	/********************************************************************************/

	/****** Calculate percent decrease in physical disk reads ******/
	temp = Math.round(10000-(10000*buffer_pool.double/buffer_pool.current))/100;

	/****** Display message if difference is greater than 5% ******/
	if(temp>5){	
		document.getElementById('oraclebufferpooladvisory').style.display="";
		document.getElementById('oraclebufferpooladvisory').innerHTML=	
			'<TABLE width="100%" cellpadding="3" cellspacing="0">'+
			'<TR><TD colspan="2" class="chart6"><H2>Buffer Pool Advisory</H2></TD></TR>'+
			'<TR><TD class="chart8">Current:</TD><TD align="right" class="chart4">'+comma(buffer_pool.current)+' disk reads</TD><TD width="200">&nbsp;</TD></TR>'+
			'<TR><TD class="chart8">Optimized:</TD><TD align="right" class="chart4">'+comma(buffer_pool.double)+' disk reads</TD><TD>&nbsp;</TD></TR>'+
			'<TR><TD class="chart7">Improvement:</TD><TD align="right" class="chart5">'+temp+'% fewer</TD><TD>&nbsp;</TD></TR>'+
			'</TABLE>'+
			'<TABLE width="100%" cellpadding="3" cellspacing="0">'+
			'<TR><TD>'+getComment('buffer',0,comma(buffer_pool.current),comma(buffer_pool.double),temp)+'</TD></TR>'+
			'<TR><TD>&nbsp;</TD></TR></TABLE>';
	}
	
	/********************************************************************************/
	/*			      PGA Memory Advisory				*/
	/********************************************************************************/
	
	//temp = Math.round((1000*pga_memory.double/pga_memory.current)-1000)/100;
	temp = pga_memory.double - pga_memory.current;
	
	if(temp>5){	
		document.getElementById('oraclepgamemoryadvisory').style.display="";
		document.getElementById('oraclepgamemoryadvisory').innerHTML=	
			'<TABLE width="100%" cellpadding="3" cellspacing="0">'+
			'<TR><TD colspan="2" class="chart6"><H2>PGA Memory Advisory</H2></TD></TR>'+
			'<TR><TD class="chart8">Current:</TD><TD align="right" class="chart4">'+pga_memory.current+'% cache hit</TD><TD width="200">&nbsp;</TD></TR>'+
			'<TR><TD class="chart8">Optimized:</TD><TD align="right" class="chart4">'+pga_memory.double+'% cache hit</TD><TD>&nbsp;</TD></TR>'+
			'<TR><TD class="chart7">Improvement:</TD><TD align="right" class="chart5">'+temp+'% more</TD><TD>&nbsp;</TD></TR>'+
			'</TABLE>'+
			'<TABLE width="100%" cellpadding="3" cellspacing="0">'+
			'<TR><TD>'+getComment('pga',0,pga_memory.current,pga_memory.double,temp)+'</TD></TR>'+
			'<TR><TD>&nbsp;</TD></TR></TABLE>';
	}	
	
	/********************************************************************************/
	/*			      Shared Pool Advisor				*/
	/********************************************************************************/
	
	//temp = Math.round((100*shared_pool.doubleobjects/shared_pool.currentobjects)-100);
	//temp2 = Math.round(100*((100*shared_pool.doubletime/shared_pool.currenttime)-100))/100;
	
		if(shared_pool.esttimesaved>5){
		document.getElementById('oraclesharedpooladvisory').style.display="";
		document.getElementById('oraclesharedpooladvisory').innerHTML=	
			'<TABLE width="100%" cellpadding="3" cellspacing="0">'+
			'<TR><TD colspan="3" class="chart6"><a name="sharedpooladvisory"></a><H2>Shared Pool Advisor</H2></TD></TR>'+
			'<TR><TD class="chart8">Current:</TD><TD align="right">'+comma(shared_pool.currentobjects)+' cached objects</TD><TD align="right" class="chart4">'+comma(shared_pool.currenttime)+' seconds saved</TD><TD width="200">&nbsp;</TD></TR>'+
			'<TR><TD class="chart8">Optimized:</TD><TD align="right">'+comma(shared_pool.doubleobjects)+' cached objects</TD><TD align="right" class="chart4">'+comma(shared_pool.doubletime)+' seconds saved</TD><TD>&nbsp;</TD></TR>'+
			'<TR><TD class="chart7">Improvement:</TD><TD align="right" class="chart6">'+shared_pool.estobjects+'% more</TD><TD align="right" class="chart5">'+shared_pool.esttimesaved+'% more</TD><TD>&nbsp;</TD></TR>'+
			'</TABLE>'+
			'<TABLE width="100%" cellpadding="3" cellspacing="0">'+
			'<TR><TD>'+getComment('shared',0,comma(shared_pool.currentobjects),shared_pool.estobjects,shared_pool.esttimesaved)+'</TD></TR>'+
			'<TR><TD>&nbsp;</TD></TR></TABLE>';
	}
	
	/********************************************************************************/
	/*			       init.ora Parameters				*/
	/********************************************************************************/
	
	var parameters_html = '';
	var initParam_output = '';

	key = ['buffer_pool_keep','db_16k_cache_size','db_32k_cache_size','db_block_size','db_cache_size','db_file_multiblock_read_count','db_keep_cache_size','hash_area_size','hash_join_enabled','mts_servers','optimizer_index_caching','optimizer_index_cost_adj','optimizer_mode','parallel_automatic_tuning','pga_aggregate_target','query_rewrite_enabled','shared_pool_size','shared_servers','sort_area_size','workarea_size_policy','session_cached_cursors','cursor_sharing','_optimizer_cost_model','dblink_encrypt_login','db_block_buffers','global_context_pool_size','log_archive_start','log_parallelism','max_enabled_roles','max_rollback_segments','mts_circuits','mts_dispatchers','mts_listener_address','mts_max_dispatchers','mts_max_servers','mts_multiple_listeners','mts_service','mts_sessions','optimizer_max_permutations','oracle_trace_collection_path','oracle_trace_collection_size','oracle_trace_enable','oracle_trace_facility_name','oracle_trace_facility_path','partition_view_enabled','plsql_compiler_flags','row_locking','serializable','transaction_auditing','undo_suppress_errors'];

	key_length = key.length;
	length = init_param.length;
	
	a = 0;
	x = 0;
	y = 0;
	z = 0;
	
	while(x < length){
		temp = init_param[x].name;
		for(y=0;y<key_length;y++){
			if(temp.match(key[y])){
				color = "#e9e9e9";
				if(!(a%2)) color = "#C0C0C0";
				parameters_html += '<TR><TD class="chart7" bgcolor='+color+'>'+init_param[x].name+'</TD><TD align="right" class="chart5" bgcolor='+color+'>'+byteFormat(init_param[x].value)+'</TD><TD>&nbsp;</TD></TR>';	//byteFormat takes number of blocks and formats into Byte size incorrectly when reading db_block_buffers 
				y=key_length;
				a++
			}
		}
		x++;
	}	
	
	
	document.getElementById('oracleparameters1').style.display="";
	document.getElementById('oracleparameters1').innerHTML=	
		'<TABLE width="100%" cellpadding="3" cellspacing="0">'+
		'<TR><TD colspan="2" class="chart6"><H2>Init.ora Parameters</H2></TD><TD width="200">&nbsp;</TD></TR>'+
		'<TR><TD class="black1" bgcolor="#000000"><b>Parameter</b></TD><TD align="right" class="black1" bgcolor="#000000"><b>Value</b></TD><TD width="200">&nbsp;</TD></TR>'+
		parameters_html+
		'</TABLE>';
		
	var obsoleteParam = '';
	x = 0;
	if(MI.obsolete[0]){
		while(x<MI.obsolete.length) obsoleteParam+=init_param[MI.obsolete[x++]].name+', ';
		obsoleteParam=obsoleteParam.substring(0,obsoleteParam.length-2);
	}
	
	/****** Not Using Large Blocksizes ******/
	if(!MI.db16kcachesize&&!MI.db32kcachesize&&init_param[MI.dbblocksize].value<16384&&top5names.match('db file sequential read')&&db_info.version>=9010)		
	z++, initParam_output+='<TR><TD>'+getComment('param',0,0)+'</TD></TR>';

	/****** Small DB Cache ******/
	if(MI.dbcachesize&&init_param[MI.dbcachesize].value<536870912&&top5names.match('buffer busy waits'))
	z++, initParam_output+='<TR><TD>'+getComment('param',1,byteFormat(init_param[MI.dbcachesize].value))+'</TD></TR>';

	/****** DB File Multiblock Read Count ******/
	if(MI.dbmultiblockreadcount&&init_param[MI.dbmultiblockreadcount].value==16&&db_info.version<10100&&top5names.match('db file scattered read'))
	z++, initParam_output+='<TR><TD>'+getComment('param',2,0)+'</TD></TR>';

	/****** KEEP Pool ******/
	if((!MI.dbkeepcachesize&&db_info.version>=9010)||(!MI.bufferpoolkeep&&db_info.version<9010))
	z++, initParam_output+='<TR><TD>'+getComment('param',3,0)+'</TD></TR>';
	
	/****** Hash Area Size ******/
	if(MI.hashareasize&&init_param[MI.hashareasize].value<1048576&&!MI.pgaaggregatetarget&&!MI.mtsservers&&!MI.sharedservers)
	z++, initParam_output+='<TR><TD>'+getComment('param',4,byteFormat(init_param[MI.hashareasize].value))+'</TD></TR>';

	/****** Hash Joins ******/
	if(MI.hashjoinenabled&&init_param[MI.hashjoinenabled].value.match('false'))
	z++, initParam_output+='<TR><TD>'+getComment('param',5,0)+'</TD></TR>';

	/****** Multi-threaded Server with PGA Aggregate Target ******/
	if((MI.mtsservers||MI.sharedservers)&&MI.pgaaggregatetarget&&db_info.version<10100)
	z++, initParam_output+='<TR><TD>'+getComment('param',6,0)+'</TD></TR>';

	/****** Multi-threaded Server ******/
	if(MI.mtsservers||MI.sharedservers)
	z++, initParam_output+='<TR><TD>'+getComment('param',7,0)+'</TD></TR>';	

	/****** Optimizer Index Caching ******/
	if(!MI.optimizerindexcaching)
	z++, initParam_output+='<TR><TD>'+getComment('param',8,0)+'</TD></TR>';	

	/****** Optimizer Index Caching ******/
	if(MI.optimizerindexcaching&&init_param[MI.optimizerindexcaching].value==0)
	z++, initParam_output+='<TR><TD>'+getComment('param',9,0)+'</TD></TR>';	

	/****** Optimizer Index Cost Adj ******/
	if(MI.optimizerindexcostadj&&init_param[MI.optimizerindexcostadj].value==100)
	z++, initParam_output+='<TR><TD>'+getComment('param',10,0)+'</TD></TR>';		

	/****** Optimizer Index Cost Adj ******/
	if(!MI.optimizerindexcostadj&&MI.optimizerindexcaching)
	z++, initParam_output+='<TR><TD>'+getComment('param',11,0)+'</TD></TR>';	
	
	/****** Optimizer Mode ******/
	if(MI.optimizermode&&((init_param[MI.optimizermode].value.match('choose')&&db_info.version<10100)||(init_param[MI.optimizermode].value.match('all_rows')&&db_info.version>=10100)))
	z++, initParam_output+='<TR><TD>'+getComment('param',12,0)+'</TD></TR>';	

	/****** Parallel Automatic Tuning ******/
	if(MI.parallelautomatictuning&&init_param[MI.parallelautomatictuning].value.match('true')&&db_info.version<10100)
	z++, initParam_output+='<TR><TD>'+getComment('param',13,0)+'</TD></TR>';	

	/****** Default Sort Area Size ******/
	if(!MI.pgaaggregatetarget&&MI.sortareasize&&init_param[MI.sortareasize].value==65536)
	z++, initParam_output+='<TR><TD>'+getComment('param',14,0)+'</TD></TR>';	
	
	/****** PGA Aggregate Target ******/
	if(MI.pgaaggregatetarget&&init_param[MI.pgaaggregatetarget].value>2147483648)
	z++, initParam_output+='<TR><TD>'+getComment('param',15,byteFormat(init_param[MI.pgaaggregatetarget].value))+'</TD></TR>';
	
	/****** Query Rewrite Enabled ******/
	if(MI.queryrewriteenabled&&init_param[MI.queryrewriteenabled].value.match('false'))
	z++, initParam_output+='<TR><TD>'+getComment('param',16,0)+'</TD></TR>';		
	
	/****** Small Shared Pool ******/
	if(MI.sharedpoolsize&&init_param[MI.sharedpoolsize].value<102400)
	z++, initParam_output+='<TR><TD>'+getComment('param',17,byteFormat(init_param[MI.sharedpoolsize].value))+'</TD></TR>';	

	/****** Large Shared Pool ******/
	if(MI.sharedpoolsize&&init_param[MI.sharedpoolsize].value>209715200&&!load_profile.parseAlert&&shared_pool.esttimesaved<=5)
	z++, initParam_output+='<TR><TD>'+getComment('param',18,byteFormat(init_param[MI.sharedpoolsize].value))+'</TD></TR>';		
	
	/****** Small Sort Area Size ******/
	if(MI.sortareasize&&init_param[MI.sortareasize].value<512000&&init_param[MI.sortareasize].value!=65536&&!MI.pgaaggregatetarget&&!MI.mtsservers&&!MI.sharedservers)
	z++, initParam_output+='<TR><TD>'+getComment('param',19,byteFormat(init_param[MI.sortareasize].value))+'</TD></TR>';	
	
	/****** Sort Area Size and PGA Aggregate Target ******/
	if(MI.sortareasize&&MI.pgaaggregatetarget&&MI.workareasizepolicy&&init_param[MI.workareasizepolicy].value.match('auto')&&!MI.mtsservers&&!MI.sharedservers)
	z++, initParam_output+='<TR><TD>'+getComment('param',20,0)+'</TD></TR>';	
	
	/****** Obsolete Parameters ******/
	if(MI.obsolete[0])	
	z++, initParam_output+='<TR><TD>'+getComment('param',21,obsoleteParam)+'</TD></TR>';

	document.getElementById('oracleparameters2').style.display="";
	document.getElementById('oracleparameters2').innerHTML=	
		'<TABLE width="100%" cellpadding="3" cellspacing="0">'+
		'<TR><TD><b>'+z+' Recommendations:</b></TD></TR>'+
		initParam_output+
		'<TR><TD>&nbsp;</TD></TR></TABLE>';	
	
}

function byteFormat(num){
	if(num%1024) 	    return comma(num);
	if(num>=1073741824) return comma(Math.round(100*num/1073741824)/100)+'GB';
	if(num>=1048576)    return comma(Math.round(100*num/1048576)/100)+'MB';
	if(num>8192) 	    return comma(Math.round(100*num/1024)/100)+'KB';
	if(num<=8192) 	    return comma(num);
	return num;

}

function tableSort1(a,b){
	if(a.time < b.time) return 1;
	if(a.time > b.time) return -1;
	return 0;
}

function tableSort2(a,b){
	if(a.reads < b.reads) return 1;
	if(a.reads > b.reads) return -1;
	return 0;
}

function tableSort3(a,b){
	if(a.writes < b.writes) return 1;
	if(a.writes > b.writes) return -1;
	return 0;
}

function showhide(x){
	if(x==0){
		document.getElementById('oracletop5timedevents1').style.display="none"
		document.getElementById('oracletop5timedevents2').style.display="";
	}
	if(x==1){
		document.getElementById('oracletop5timedevents1').style.display="";
		document.getElementById('oracletop5timedevents2').style.display="none"
	}
	if(x==2){
		document.getElementById('oracletablespace1').style.display="none"
		document.getElementById('oracletablespace2').style.display="";
	}
	if(x==3){
		document.getElementById('oracletablespace1').style.display="";
		document.getElementById('oracletablespace2').style.display="none"
	}		
}

function comma(num)
{
	var x,x1,x2,rgx;
	num+='';		//convert number to string
	x = num.split('.');
	x1 = x[0];
	x2 = x.length>1 ? '.' +x [1] : '';
	rgx = /(\d+)(\d{3})/;
	while(rgx.test(x1))	x1 = x1.replace(rgx, '$1' + ',' + '$2');
	return x1+x2;
}

function sql_print(){
	var newWin = window.open('','printable','width=800,height=600,scrollbars=1,resizable=1,menubar=1,toolbar=1,status=1');
	newWin.document.open();
	newWin.document.write('<html><head><title>Statspack Analyzer</title><style type="text/css"><!-- @import url("css/styles.css");--></style></head><body>'+global_SQL_data);
	newWin.document.close();
}

function getComment(sec,indx,val,val2,val3){

	/*******************Load Profile*****************/
	/************************************************/
	var LP = new Array();
	
	/****** High Buffer Contention ******/
	LP[0]='You have <b>high contention for LRU latches</b>, which are necessary to move blocks in and out of the buffer cache.  You may want to consider setting the hidden Oracle parameter <a href="http://www.dba-oracle.com/m_cache_buffers_lru_chain.htm" target="_blank">_db_block_lru_latches</a> with the assistance of Oracle Support.';
	LP[1]='You have a <b>high buffer wait</b> coupled with a high occurrence of <b>cache buffers chains</b> latches.  This can be caused by contention for hot block updates within the buffer.  Identify the data block (using <a href="http://www.dba-oracle.com/art_builder_data_buffer_par.htm" target="_blank">v$bh</a> or <a href="http://www.dba-oracle.com/art_builder_bbw.htm" target="_blank">v$system_event</a>) and reduce contention by increasing freelists or freelist groups on the object.';
	LP[2]='It appears you have a large amount of waiting on both the <b>physical I/O</b> layer and in the <b>SGA</b>.  You may want to consider tuning your SQL using broad brush techniques in order to encourage index use.  In a well tuned system, you may want to consider moving to <a href="http://www.superssd.com/products_sub.htm" target="blank" class="style1">solid state disk </a> in order to decrease the amount of waiting Oracle must do for disk resources.';

	/****** High Logical IO ******/
	LP[3]='Your database has relatively high <B>logical I/O</B> at '+val+' reads per second.  Logical Reads includes data block reads from both memory and disk.  High LIO is sometimes associated with high CPU activity.  CPU bottlenecks occur when the CPU run queue exceeds the number of CPUs on the database server, and this can be seen by looking at the &quot;r&quot; column in the vmstat UNIX/Linux utility or within the Windows performance manager.  Consider tuning your application to reduce unnecessary data buffer touches (<a href="http://www.rampant-books.com/book_2005_1_awr_proactive_tuning.htm" target="blank">SQL Tuning</a> or <a href="http://www.dba-oracle.com/oracle_news/2006_03_17_test_10g_logical_io_plsql_faster.htm" target="blank">PL/SQL bulking</a>), using <a href="http://www.dba-oracle.com/t_hardware_scalability_testing.htm" target="blank">faster CPUs</a> or adding <a href="http://www.dba-oracle.com/oracle10g_tuning/t_cpu_constrained_bottleneck.htm" target="blank">more CPUs</a> to your system.';

	/****** Optimizer Cost Model ******/
	LP[4]='Consider unsetting your <b>CPU-based optimizer costing</b> (the 10g default, a change from 9i).  CPU costing is best if you see CPU in your Top 5 Timed Events in your STATSPACK/AWR report, and the 10g default of _optimizer_cost_model=cpu will try to minimize CPU by invoking more full scans, especially in tablespaces with large blocksizes.  To return to your 9i CBO I/O-based costing, set the hidden parameter _optimizer_cost_model=io';

	/****** High Physical Reads ******/
	LP[5]='You are performing more than '+val+' <B>disk reads</B> per second.  High disk latency can be caused by <a href="http://www.dba-oracle.com/t_oraclerac_io_slow.htm" target="blank">too-few physical disk spindles</a>.  Compare your read times across multiple datafiles to see which datafiles are slower than others.  Disk read times may be improved if <a href="http://www.dba-oracle.com/m_average_read_time.htm" target="blank">contention is reduced</a> on the datafile, even though read times may be high due to the file residing on a slow disk. You should identify whether the SQL accessing the file can be tuned, as well as the underlying characteristics of the <a href="http://www.dba-oracle.com/oracle10g_tuning/t_server_bottlenecks.htm" target="blank">hardware devices</a>.';
	
	/****** Average Disk Read Speed ******/
	LP[6]='Check your <b>average disk read speed</b> later in this report and ensure that it is under 7ms.  Assuming that the SQL is optimized, the only remaining solutions are the addition of RAM for the data buffers or a switch to <a href="http://www.superssd.com/benefits.htm" target="blank" class="style1">solid state disks</a>. Give careful consideration these tablespaces with high read I/O: '+val;

	/****** High Physical Writes ******/
	LP[7]='You are performing more than '+val+' <B>disk writes</B> per second.  Check to ensure that you are using <a href="http://www.dba-oracle.com/oracle_tips_mount_options.htm" target="blank">direct I/O</a> (non buffer) on your database and perform an IO balance and an IO timing analysis to determine if a disk or array is undergoing IO related stress, and verify your <a href="http://www.dba-oracle.com/t_ault_109_lgwr_utlestat_lru.htm" target="blank">DBWR optimization</a>.  Check you average disk read speed later in this report and ensure that it is under 7 milliseconds.  If not, consider <a href="http://www.superssd.com/benefits.htm" target="blank" class="style1">SSD </a> for faster physical reads.';

	/****** Long IO Times ******/
	LP[8]='<b>Long I/O times</b> are occuring when using the following tablespaces: '+val+' Consider placing these tablespace&acute;s datafiles on <a href="http://www.superssd.com/products_sub.htm" target="blank" class="style1">solid state disk</a> for faster disk access.';

	/****** High Parses ******/
	LP[9]='You are performing more than '+val+' <B>SQL parses</B> per second.  A parse is the process of executing your SQL, checking for proper security authorization, checking for the existence of tables, columns, and other referenced objects, and generating an execution plan. Your <a href="http://www.dba-oracle.com/m_parses.htm" target="blank">high parses</a> suggest that your system has many incoming unique SQL statements or that your SQL is not reentrant (i.e. literal values in the WHERE clause, not using bind variables).  Confirm that the '+val+' parses per second is reasonable and consider setting <a href="http://www.dba-oracle.com/t_cusror_sharing.htm" target="blank">cursor_sharing=force</a> if warranted.  Setting cursor_sharing=force can cause <a href="http://www.dba-oracle.com/art_dbazine_911_pt7.htm" target="blank">dramatic performance improvements</a> for systems with ad-hoc query tools such as Crystal Reports or Business Objects.';

	/****** High Hard Parses ******/
	LP[10]='You have more than '+val+' <B>unique SQL statements</B> entering your shared pool, with the resulting overhead of continuous RAM allocation and freeing within the shared pool.  A <a href="http://www.dba-oracle.com/t_hard_vs_soft_parse_parsing.htm" target="blank">hard parse</a> is expensive because each incoming SQL statement must be re-loaded into the shared pool; with the associated overhead involved in shared pool RAM allocation and memory management.  Once loaded, the SQL must then be completely re-checked for syntax & semantics and an executable generated.  <a href="http://www.dba-oracle.com/m_parses.htm" target="blank">Excessive hard parsing</a> can occur when your shared_pool_size is too small (and reentrant SQL is paged out) or when you have non-reusable SQL statements without host variables.  See the cursor_sharing parameter for an easy way to make SQL reentrant and remember that you should always use host variables in you SQL so that they can be reentrant.';
	
	/****** Cursor Sharing = "Exact" ******/
	LP[11]='Set the <b>cursor_sharing</b> parameter for an easy way to make SQL reentrant and remember that you should always use host variables in you SQL so that they can be reentrant.';

	/****** High Soft Parses ******/
	LP[12]='You have a large number of <b>soft parses</b> that are not being cached by your user’s sessions.  This behavior may be unavoidable depending on your SQL usage; however, if the code being executed against this database uses individual queries multiple times in a single session, the issue can be alleviated by setting the session cached cursors parameter.  Consider benchmarking and testing an increase of the SESSION_CACHED_CURSORS parameter.';

	/****** High Rollbacks ******/
	LP[13]='You may have an application issue causing excessive <B>rollbacks</B> with '+val+'% rollbacks per transaction.  Due to Oracle&acute;s assumption of a commit, the rollback process is very expensive and should only be used when necessary.  You can identify the specific SQL and user session that is executing the rollbacks by querying the <a href="http://www.dba-oracle.com/oracle10g_tuning/t_sql_top_sessions.htm" target="blank">v$sesstat view</a>.<br>Remember that some applications may automatically perform rollback operations (commit-then-rollback or rollback-then-exit) after each commit. If this is the case, speak with your application developers to find out if there is a way to disable this. While these "empty rollbacks" do not incur performance expense, it will case this metric to appear very high.';
	

	/*******************Instance Efficiency*****************/
	/*******************************************************/
	var IE = new Array();
	
	/****** Low Buffer Hit Percentage ******/
	IE[0]='Your <B>Buffer Hit ratio</B> is '+val+'%.  The <a href="http://www.dba-oracle.com/m_data_buffer_hit_ratio.htm" target="blank">buffer hit ratio</a> measures the probability that a data block will be in the buffer cache upon a re-read of the data block.  If your database has a large number of frequently referenced table rows (a large working set), then investigate increasing your db_cache_size. For specific recommendations, see the output from the data buffer cache advisory utility (using the <a href="http://www.dba-oracle.com/oracle_tips_data_cache_advice.htm" target="blank">v$db_cache_advice</a> utility).  Also, a low buffer hit ratio is normal for applications that do not frequently re-read the same data blocks.  Moving to <a href="http://www.superssd.com" target="blank" class="style1">SSD </a> will alleviate the need for a large data buffer cache.';

	/****** Low Library Hit Percentage ******/
	IE[1]='Your <B>Library Hit ratio</B> is '+val+'%.  A <a href="http://www.dba-oracle.com/m_library_cache_hit_ratio.htm" target="blank">low library cache hit percentage</a> could mean SQL is prematurely aging out of the shared pool as the shared pool may be small or that <a href="http://www.dba-oracle.com/oracle10g_tuning/t_instance_efficiency_percentage.htm" target="blank">unsharable SQL</a> is being used. In addition, compare it with the soft parse ratio. If they are both low, then investigate whether there is a parsing issue.  Since you never know in-advance how many SQL statements need to be cached, the Oracle DBA must set shared_pool_size large enough to prevent excessive re-parsing of SQL.';

	/****** High Disk Sorts ******/	
	IE[2]='You have more than '+val+'% of sorts being <B>sorted to disk</B>, which can result in a significant delay due to the physical writes and reads.  You can see the impact of this later in the report as reads and writes on the temporary tablespace.  If the <a href="http://www.dba-oracle.com/art_tuning4.htm" target="">sorts to disk</a> are not large, increasing the pga_aggregate_target may allow Oracle to perform the sort in memory.  If the application sorts are large and you must perform <a href="http://www.dba-oracle.com/oracle10g_tuning/t_server_bottlenecks.htm" target="blank">disk sorts</a>, moving the temporary tablespace to <a href="http://www.superssd.com" target="blank" class="style1">SSD </a> will improve large sort performance.';
	
	/****** Low Latch Hit Percentage ******/
	IE[3]='Your <B>latch hit percentage</B> is '+val+'%, below the recommended value of 99%.  Investigate the specific latches in your latch activity section and tune to reduce library cache contention.';
	
	/****** High Shared Pool Memory Usage ******/
	IE[4]='Your shared pool maybe filled with non-reusable SQL with '+val+'% <B>memory usage</b>.  The Oracle <a href="http://www.dba-oracle.com/m_shared_pool.htm" target="blank">shared pool</a> contains Oracle&acute;s library cache, which is responsible for collecting, parsing, interpreting, and executing all of the SQL statements that go against the Oracle database. You can check the <a href="http://www.dba-oracle.com/oracle10g_tuning/t_dba_hist_librarycache.htm" target="blank">dba_hist_librarycache</a> table in Oracle10g to see your historical library cache RAM usage.';

	/****** High Memory For SQL ******/
	IE[5]='Your Shared Pool Memory Usage is '+val+'% and "<b>% Memory for SQL w/exec>1</b>" is '+val2+'%.  Your shared pool size might need increasing by adjusting your shared_pool_size parameter.  If server memory is available, allocate more RAM to the shared pool.';

	/****** Shared Pool Advisory ******/
	IE[6]='<b>Shared pool statistics</b> indicate that you may improve upon this statistic with a larger shared pool.  Please consult the <a href="#sharedpooladvisory">Shared Pool Advisory</a> for details.';
	

	/*******************Top 5 Timed Events*****************/		//definitions are on two lines, separated by | character
	/******************************************************/		
	var T5 = new Array();		

	/****** CPU Time ******/
	T5[0] =
	'CPU time is the amount of time that the Oracle database spent processing SQL statements, parsing statements, or managing the buffer cache.'+
	'|If this is the main timed event, tuning SQL statements and/or increasing server CPU resources will provide the greatest performance improvement.';
	
	/****** DB File Scattered Read ******/
	T5[1] =
	'The scattered read events occur when Oracle reads multiple blocks of a table or index. Look at the <u><a href="#tablespaceio">tablespace IO section</a></u> of the report for tablespaces with more than 2 average blocks per read, high response time, and a large percentage of the total IO. Improving the response time of these tables with <a href="http://www.superssd.com" target="blank" class="style1">faster storage </a> will help reduce this wait event and speed up the database. Full table scan of a data tables can cause these events.'+
	'|Moving the data files with largest amount of time spent waiting on multi-block reads to faster storage can significantly reduce the amount of time spent waiting on this event.  By reducing the time spent waiting on this event, the database performance could increase '+Math.round(((1/(1-(val/100)))-1)*100)+'%.';
	
	/****** DB File Sequential Read ******/
	T5[2] =
	'The sequential read event occurs when Oracle reads single blocks of a table or index. Look at the <u><a href="#tablespaceio">tablespace IO section</a></u> of the report for tablespaces with less than 2 average blocks per read, high response time, and a large percentage of the total IO. Improving the response time of these tables with <a href="http://www.superssd.com" target="blank" class="style1">faster storage </a> will help reduce this wait event and speed up the database.'+
	'|Moving the data files with the largest amount of time spend waiting on single-block reads to faster storage can significantly reduce the amount of time spent waiting on this event.  By reducing the time spent waiting on this event, the database performance could increase '+Math.round(((1/(1-(val/100)))-1)*100)+'%.';
	
	/****** Enqueue ******/
	T5[3] =
	'High enqueue waits are related to Oracle internal locks.'+
	'|Investigate by querying the v$lock, v$transaction and v$session views to drill-in and see the exact queries that are causing the locks.';
	
	/****** SQL*Net Message From Client ******/
	T5[4] =
	'This event occurs when DB is idle and waiting on the client process. This is a very prevalent wait in an OLTP system, as the client process waits for user input.'+
	'|If the user is not the source of these waits, client side software or the network may be causing a bottleneck. If you expect this event due to waiting on the user and response time is still a concern, then you may subtract the percent of time that this event is consuming from the wait events. Addressing the other wait events will generate a disproportionate gain to the end user than its wait percentage would suggest.';
	
	/****** Control File Sequential Read ******/
	T5[5] =
	'The control file sequential read Oracle metric indicates the process is waiting for blocks to be read from a control file.'+
	'|This happens in many cases. For example, you can see a &quot;control file sequential read&quot; when you are making a backup of the controlfiles, sharing information (between instances) from the controlfile, reading other blocks from the controlfiles, and most importantly, when you are reading the header block for a data file.';
	
	/****** Control File Parallel Write ******/
	T5[6] =
	'This wait is caused by waiting on writes to the control files.'+
	'|Moving the control files on to <a href="http://www.superssd.com" target="blank" class="style1">solid state disks </a> can help alleviate this wait.';
	
	/****** Direct Path Read ******/
	T5[7] =
	'Reads that skip the database buffer cause this wait event. If there are many sorts and hashes taking place, then slow access to the TEMP space can cause this.'+
	'|Check the top IO tablespaces below. If the list includes the TEMP space, then there is a good chance that moving the TEMP space to <a href="http://www.superssd.com" target="blank" class="style1">solid state disks </a> can help reduce this event.';
	
	/****** Direct Path Write ******/
	T5[8] =
	'Writes that skip the database buffer cause this wait event. If there are many sorts and hashes taking place, then slow access to the TEMP space can cause this.'+
	'|Check the top IO tablespaces below. If the list includes the TEMP space, then there is a good chance that moving the TEMP space to <a href="http://www.superssd.com" target="blank" class="style1">solid state disks </a> can help reduce this event.';
	
	/****** Log File Parallel Write ******/
	T5[9] =
	'This event occurs when Oracle is waiting for the completion of writes to the redo log files.'+
	'|Moving some or all copies of your redo logs logs to <a href="http://www.superssd.com" target="blank" class="style1">solid state disks </a> can reduce the amount of time spent waiting for this event.';
	
	/****** Log File Sync ******/
	T5[10] =
	'This event is caused by waiting for the LGWR to post after a session performs a commit.  This can be tuned by reducing the number of commits.'+
	'|Moving some or all copies of your redo logs logs to <a href="http://www.superssd.com" target="blank" class="style1">solid state disks </a> can reduce the amount of time spent waiting for this event.';
	
	/****** Log File Single Write ******/
	T5[11] =
	'This event occurs when Oracle is waiting for the completion of writes to the redo log files.'+
	'|Moving some or all copies of your redo logs to <a href="http://www.superssd.com" target="blank" class="style1">solid state disks </a> can reduce the amount of time spent waiting for this event.';
	
	/****** Free Buffer Wait ******/
	T5[12] =
	'This wait occurs when a session needs a free buffer and cannot find one. This can be caused by a slow DBWR process that cannot quickly flush dirty blocks from the buffer cache.'+
	'|Moving the files that receive the majority of the writes to <a href="http://www.superssd.com" target="blank" class="style1">solid state disks </a> can help to alleviate the wait event. If poor I/O write capacity does not cause this wait, you can tune your instance by increasing the buffer cache.';
	
	/****** Buffer Busy Waits ******/
	T5[13] =
	'The primary cause of these waits is contention for a block that is being used in an non-sharable way (so that a read/write cannot be performed until the process that is using it is complete).'+
	'|Decrease this event by increasing the free lists for the offending file, reducing the number of rows in a block (to reduce the contention for a block), or increasing the speed of the disk system (especially in cases where a slow DBWR process is causing some of the contention.)';
	
	/****** DB File Parallel Write ******/
	T5[14] =
	'The DBWR process produces this wait event as it writes dirty blocks to the datafiles. This event can cause poor read performance, and the writes may interfere with reads from the data files.'+
	'|Moving the tables that are experiencing the highest write activity to <a href="http://www.superssd.com" target="blank" class="style1">solid state disks </a> may help to alleviate this wait event.';
	
	/****** DB File Single Write ******/
	T5[15] =
	'This wait event occurs during checkpoints as data file headers are updated.'+
	'|You can alleviate this wait by reducing the number of data files or checkpoints.  If the checkpoints and data files are required, then <a href="http://www.superssd.com" target="blank" class="style1">solid state disks </a> can help alleviate this event.';
	
	/****** Log Buffer Space ******/
	T5[16] =
	'This wait event occurs when an application generates redo information faster than it can be written to the log files. Contention on the disks where the log files are stored can cause this event.'+
	'|Alleviate this event by moving the log files to a storage device with a high bandwidth, such as <a href="http://www.superssd.com/benefits.htm" target="blank" class="style1">solid state disks </a>.';
	
	/****** Log File Sequential Read ******/
	T5[17] = 
	'This wait event often appears when the ARCH process waits to read from the redo log files.'+
	'|Increasing the number of redo log groups or increasing the performance of the archive storage can help alleviate this event.  If the archive storage device is not the bottleneck, placing all of the redo log groups onto <a href="http://www.superssd.com" target="blank" class="style1">solid state disks </a> can help alleviate this event.';
	
	/****** Log File Switch (archiving needed) ******/
	T5[18] = 
	'This wait event often appears when the ARCH process cannot archive the redo logs as fast as the LGWR process creates them.'+
	'|To help alleviate this event, focus on increasing the performance of the archive storage.';
	
	/****** Log File Switch (checkpoint incomplete) ******/
	T5[19] = 
	'Log file switch (checkpoint incomplete) occurs when a log file switch needs to take place, but the checkpoint for the log file to be switched has not completed.'+
	'|Alleviate this wait by increasing the size of the redo logs or by increasing the number of log groups. Alternatively, increase the speed of completing checkpoints by improving the write speed to the data files. You can accomplish this by moving the data files with the highest write activity to <a href="http://www.superssd.com" target="blank" class="style1">solid state disks </a>.';
	
	/****** Global Cache CR Request ******/
	T5[20] =
	'Waits for this event are caused when a local instance of RAC needs a buffer in a remote instance.'+
	'|In some cases, you can tune this event by increasing the speed of the high-speed interconnect. Alternatively, you can alleviate this wait event by reducing the buffer cache size of each of the servers in a RAC cluster to make it less likely for the remote instance to contain a buffer that the local instance requires. This setup is only recommended if the most accessed table spaces can be moved to <a href="http://www.superssd.com" target="blank" class="style1">solid state disks </a>, where the access time to the storage is significantly faster than the high-speed interconnect.';
	
	/****** Global CR Request Wait ******/
	T5[21] = 
	'Waits for event are caused when a local instance of RAC needs a buffer in a remote instance.'+
	'|In some cases, you can tune this event by increasing the speed of the high-speed interconnect. Alternatively, you can alleviate this wait event by reducing the buffer cache size of each of the servers in a RAC cluster to make it less likely for the remote instance to contain a buffer that the local instance requires. This setup is only recommended if the most accessed table spaces can be moved to <a href="http://www.superssd.com" target="blank" class="style1">solid state disks </a>, where the access time to the storage is significantly faster than the high-speed interconnect.';
	
	/****** Buffer Busy Global Cache ******/
	T5[22] = 
	'This wait occurs when a local instance wants to modify a buffer that a remote instance has cached. This event may point to a bottleneck in the high speed interconnect.'+
	'|Attack this wait by employing <a href="http://www.superssd.com" target="blank" class="style1">solid state disks </a> for the most active tables (for writes) in the database and by lowering the buffer cache. This approach increases overall throughput because the penalty for physical IO to a solid state disk is lower than the penalty for fetching a block from the remote instance.';
	
	/****** Global Cache Null to x ******/
	T5[23] = 
	'This wait occurs when a session wants to modify a block that is either resident in a remote instance buffer cache or is outside the GCS and requires a physical read from disk.'+
	'|A faster IO system, such as a <a href="http://www.superssd.com" target="blank" class="style1">solid state disk </a>, can help improve the physical IO time.';
	
	/****** Global Cache Null to s ******/
	T5[24] = 
	'This wait occurs when a session wants to read a block that is either resident in a remote instance buffer cache or is outside the GCS and requires a physical read from disk.'+
	'|A faster IO system, such as a <a href="http://www.superssd.com" target="blank" class="style1">solid state disk </a>, can help improve the physical IO time.';
	
	/****** SQL*Net Message To Client ******/
	T5[25] = 
	'This wait event is generated by waiting for a response from a client after a message is sent.'+
	'|This could point to a network bottleneck or inadequate client computing resources.';

	T5[26] = 
	'Other  | &nbsp;';


	/**********************Wait Events*********************/
	/******************************************************/
	var WE = new Array();
	
	/****** Free Buffer Avg Wait Time ******/	
	WE[0]='You have high <B>free buffer wait time</B> of '+val+' milliseconds.  Free buffer waits commonly happen when your application is insert intensive (among many other factors), and Oracle requests a new block from the <a href="http://www.dba-oracle.com/oracle_tips_freelists.htm" target="blank">freelist</a>.  With a free buffer wait, Oracle requests RAM heap space for the new block but no space is available within the data buffer cache region.  The remedy is tuning your data buffer cache which might include using <a href="http://www.dba-oracle.com/oracle_tips_hardware_oracle_performance.htm" target="blank">faster disks</a>, rebuilding with <a href="http://www.dba-oracle.com/art_so_blocksize.htm" target="blank">larger blocksizes</a>, <a href="http://www.dba-oracle.com/t_ault_109_lgwr_utlestat_lru.htm" target="blank">tuning your DBWR process</a>, segregating hot tables into separate data buffers (using the <a href="http://www.dba-oracle.com/art_dbazine_9i_multiblock.htm" target="blank">multiple blocksize</a> feature), <a href="http://www.dba-oracle.com/art_otn_cbo.htm" target="blank">optimizing your SQL</a> to reduce data block requests (using highly-selective <a href="http://www.dba-oracle.com/t_function_based_indexes.htm" target="blank">function-based indexes</a> or <a href="http://www.dba-oracle.com/art_mv.htm" target="blank">materialized views</a>) or by increasing the speed of your back-end disks.  You can also optimize your db_cache_size and moving the hot objects to high-speed <a href="http://www.superssd.com" target="blank" class="style1">solid state disks </a>.';

	/****** Latch Free Waits/Txn ******/
	WE[1]='You have high <B>latch free waits</B> of '+val+' per transaction.  The latch free wait occurs when the process is waiting for a latch held by another process. Check the later section for the specific latch waits.  Latch free waits are usually due to SQL without bind variables, but buffer chains and redo generation can also cause them.';
	
	/****** Log Buffer Space Waits/Txn ******/
	WE[2]='You have a high value for <B>log buffer space waits</B> at '+val+' per transaction.  If your log_buffer is too small then high log buffer space waits will be seen during high DML periods (redo generation). Consider moving your redo log data files to <a href="http://www.superssd.com" target="blank" class="style1">solid state disk </a> or increase the size of your redo log buffer (<a href="http://www.dba-oracle.com/t_log_buffer_optimal_size.htm" target="blank">log_buffer</a>).';
	
	/****** Log File Switch Completion Avg Wait Time ******/
	WE[3]='You have a high value for <B>log file switch waits</B> at '+val+' milliseconds.  If you have a large SGA full of dirty buffers and small redo log files, a log switch must wait for DBWR to write dirty buffers to disk before continuing. Consider allocating <a href="http://www.dba-oracle.com/m_redo_log_space_requests.htm" target="blank">larger online redo log</a> files or move your redo logs to faster disk with <a href="http://www.superssd.com" target="blank" class="style1">SSD </a>.';
	
	/****** High Log File Sync Waits ******/
	WE[4]='You have a high value for <B>log file sync waits</B> at '+val+' per transaction.  Check to ensure that your application does frequent commits and consider moving your redo log files to faster <a href="http://www.superssd.com" target="blank" class="style1">SSD </a> disk.  Also consider <a href="http://www.dba-oracle.com/t_log_buffer_optimal_size.htm" target="blank">increasing your log_buffer size</a>.';
	
	/****** High SQL*Net message from client ******/
	WE[5]='Your average wait time for <B>SQL*Net message from client</B> events is '+val+' milliseconds.  Check your application to see if it might benefit from bulk collection (using PL/SQL &quot;forall&quot; or &quot;<a href="http://www.dba-oracle.com/t_10g_pl_sql_performance.htm" target="blank">bulk collect</a>&quot; operators.  In addition, optimize your <a href="http://www.dba-oracle.com/art_builder_tns.htm" target="blank">TNS settings</a> in your tnsnames.ora file and investigate consolidating your Oracle requests into larger TNS packets.';
	
	/****** High db file sequential read waits ******/
	WE[6]='Your average wait time for <B>db file sequential read</B> is '+val+' milliseconds, which is very slow.  The sequential read event occurs when Oracle reads single blocks of a table or index. Index reads or single block reads typically cause this event.  In addition, check to ensure that you are using non-buffered <a href="http://www.dba-oracle.com/oracle_tips_direct_io.htm" target="blank">direct I/O</a>.  If these steps fail to reduce your disk wait times, moving some of your datafiles to <a href="http://www.dba-oracle.com/disk_i_o_speed_comparison.htm" target="blank">solid state disk</a> will reduce the amount of time spent waiting for this event.';
	
	/****** High db file scattered read waits ******/
	WE[7]='Your average wait time for <B>db file scattered read</B> is '+val+' milliseconds, which is very slow.  The scattered read events occur when Oracle reads multiple blocks of a table or index (a full table scan of fast full index scan).  Full-table scans may indicate missing indexes.  Check for missing indexes and verify that you have optimized your <a href="http://www.dba-oracle.com/t_db_file_multiblock_read_count.htm" target="blank">db_file_multiblock_read_count</a>.  If these steps fail to reduce your disk wait times, moving some of your datafiles to <a href="http://www.dba-oracle.com/t_oraclerac_moving_to_ssd.htm" target="blank">solid state disk</a> will reduce the amount of time spent waiting for scattered disk reads.';
	
	/****** High Buffer Busy Waits ******/
	WE[8]='You have excessive <B>buffer busy waits</B> at '+val+' milliseconds.  <a href="http://www.dba-oracle.com/art_builder_bbw.htm" target="blank">Buffer busy waits</a> are most commonly caused by segment header contention and can be remedied by increasing the value of the tables &amp; index <a href="http://www.dba-oracle.com/t_ault_109_lgwr_utlestat_lru.htm" target="blank">freelists or freelist_groups</a> parameters, tuning your database writer (DBWR process, or by using Automatic Segment Storage Management (<a href="http://www.dba-oracle.com/oracle10g_tuning/t_assm_performance.htm" target="blank">ASSM</a>) in the tablespace definition.  Using super-fast <a href="http://www.superssd.com/benefits.htm" target="blank" class="style1">SSD </a> can dramatically reduce wait times for other reads and in some cases lessen the buffer busy waits.';
	
	/****** High Buffer Busy Waits ******/
	WE[9]='You have excessive <B>buffer busy waits</B> with '+val+' per transaction.  <a href="http://www.dba-oracle.com/art_builder_bbw.htm" target="blank">Buffer busy waits</a> are most commonly caused by segment header contention and can be remedied by increasing the value of the tables & index <a href="http://www.dba-oracle.com/t_ault_109_lgwr_utlestat_lru.htm" target="blank">freelists or freelist_groups</a> parameters, tuning your database writer (DBWR process, or by using Automatic Segment Storage Management (<a href="http://www.dba-oracle.com/oracle10g_tuning/t_assm_performance.htm" target="blank">ASSM</a>) in the tablespace definition.  Using super-fast <a href="http://www.superssd.com,benefits.htm" target="blank" class="style1">SSD </a> can dramatically reduce wait times for other reads and in some cases lessen the buffer busy waits.';
	
	/****** High Enqueue Waits ******/
	WE[10]='You have excessive <B>enqueue wait times</B> at '+val+' milliseconds.  Oracle locks protect shared resources and allow access to those resources via a queuing mechanism. A large amount of time spent waiting for <a href="http://www.dba-oracle.com/m_enqueue_requests.htm" target="blank">enqueue events</a> can be caused by various problems, such as waiting for individual row locks or waiting for exclusive locks on a table.  Ensure that you are using locally-managed tables (if you see enqueue ST waits) and review your settings for INITRANS and MAXTRANS n(if you have enqueue TX waits).  If you see enqueue TX waits, check for DML locks and ensure that all foreign keys are indexed.';
	
	/****** High Enqueue Waits ******/
	WE[11]='You have excessive <a href="http://www.dba-oracle.com/m_enqueue_waits_per_txn.htm" target="blank"><B>enqueue wait times</B></a> with '+val+' per transaction.  Oracle locks protect shared resources and allow access to those resources via a queuing mechanism. A large amount of time spent waiting for <a href="http://www.dba-oracle.com/m_enqueue_requests.htm" target="blank">enqueue events</a> can be caused by various problems, such as waiting for individual row locks or waiting for exclusive locks on a table.  Ensure that you are using locally-managed tables (if you see enqueue ST waits) and review your settings for INITRANS and MAXTRANS n(if you have enqueue TX waits).  If you see enqueue TX waits, check for DML locks and ensure that all foreign keys are indexed.';


	/*******************Instance Activity Stats*****************/
	/***********************************************************/
	var IA = new Array();
	
	/****** High SQL Roundtrips ******/
	IA[0]='You have high network activity with '+val+' <B>SQL*Net roundtrips to/from client</B> per second, which is a high amount of traffic.  Review your application to reduce the number of calls to Oracle by encapsulating data requests into larger pieces (i.e. make a single SQL request to populate all online screen items).  In addition, check your application to see if it might benefit from <a href="http://www.dba-oracle.com/oracle_news/2004_1_29_collections_cursors_bulk_binds_and_FORALL.htm" target="blank">bulk collection</a> by using PL/SQL &quot;<a href="http://www.dba-oracle.com/oracle_news/2004_1_31_plsqlL_bulk_binds_FORALL.htm" target="blank">forall</a>&quot; or &quot;bulk collect&quot; operators.';
	
	/****** High Consistent Gets Examination ******/
	IA[1]='You have '+val+' <B>consistent gets examination</B> per second.  "Consistent gets - examination" is different than regular consistent gets. It is used to read undo blocks for consistent read purposes, but also for the first part of an index read and hash cluster I/O.  To reduce disk reads, you may consider moving your indexes to a large blocksize tablespace.  Because index splitting and spawning are controlled at the block level, a <a href="http://www.dba-oracle.com/oracle_tips_intelligent_10g_DBA_maintenance.htm" target="blank">larger blocksize</a> will result in a flatter index tree structure.';
	
	/****** High DB Block Changes ******/
	IA[2]='You have high update activity with '+val+' <B>db block changes</B> per second.  The <a href="http://www.dba-oracle.com/m_db_block_changes.htm" target="blank">DB block changes</a> are a rough indication of total database work. This statistic indicates (on a per-transaction level) the rate at which buffers are being dirtied and you may want to optimize your <a href="http://www.dba-oracle.com/t_ault_109_lgwr_utlestat_lru.htm" target="blank">database writer</a> (DBWR) process.  You can determine which sessions and SQL statements have the <a href="http://www.dba-oracle.com/oracle10g_tuning/t_sql_top_sessions.htm" target="blank">highest db block changes</a> by querying the v$session and v$sessatst views.';
	
	/****** High Physical Reads ******/
	IA[3]='You have high <B>disk reads</B> with '+val+' per second.  Reduce disk reads by increasing your data buffer size or speed up your disk read speed by moving to <a href="http://www.superssd.com" target="blank" class="style1">SSD </a> storage.  You can <a href="http://www.dba-oracle.com/art_orafaq_awr_disk_reads.htm" target="blank">monitor your physical disk reads</a> by hour of the day using AWR to see when the database has the highest disk activity.';
	
	/****** High Physical Writes ******/
	IA[4]='You have high <B>disk write</B> activity with '+val+' per second.  You should drill-down and <a href="http://www.dba-oracle.com/oracle_tips_top_session.htm" target="blank">identify the sessions</a> that are performing the disk writes as they can cause locking contention within Oracle.  Also investigate moving your high-write datafiles to a <a href="http://www.dba-oracle.com/tips_oracle_db_cache_size.htm" target="blank">smaller data buffer</a> to improve the speed of the <a href="http://www.dba-oracle.com/art_otn_auto_tuning_10g.htm" target="blank">database writer process</a>.  In addition, you can dramatically improve your disk write speed by up to 300 times by moving the high-write datafiles to <a href="http://www.dba-oracle.com/t_oraclerac_ssd_findings.htm" target="blank">solid-state disk</a>.';
	
	/****** High Disk Sorts ******/
	IA[5]='You have '+val+' <B>disk sorts</B> during this period.  Disk sorts are very expensive and <a href="http://www.dba-oracle.com/art_tuning4.htm" target="blank">increasing your PGA</a> (sort_area_size or pga_aggregate_target) may allow you to perform these sorts in RAM.';
	
	/****** High Table Fetch Continued Row ******/
	IA[6]='You have '+val+' <B>table fetch continued row</B> actions during this period.  Migrated/chained rows always cause double the I/O for a row fetch and &quot;table fetch continued row&quot; (chained row fetch) happens when we fetch BLOB/CLOB columns (if the avg_row_len > db_block_size), when we have tables with > 255 columns, and when PCTFREE is too small.  You may need to reorganize the affected tables with the dbms_redefintion utility and re-set your PCTFREE parameters to prevent future row chaining.';
	
	/****** High Full Table Scans (long) ******/
	IA[7]='You have '+val+' <B>long table full-table scans</B> per second.  This might indicate missing indexes, and you can run plan9i.sql to identify the specific tables and investigate the SQL to see if an <a href="http://www.dba-oracle.com/t_plan9i_sql_full_table_scans.htm" target="blank">index scan</a> might result in faster execution.  If your large table full table scans are legitimate, look at optimizing your <a href="http://www.dba-oracle.com/t_db_file_multiblock_read_count.htm" target="blank">db_file_multiblock_read_count</a> parameter.';
	
	/****** High Full Table Scans (short) ******/
	IA[8]='You have high <B>small table full-table scans</B>, at '+val+' per second.  Verify that your <a href="http://www.dba-oracle.com/bp/teaser_sga_keep_pool.htm" target="blank">KEEP pool</a> is sized properly to cache frequently referenced tables and indexes.  Moving frequently-referenced tables and indexes to <a href="http://www.superssd.com" target="blank" class="style1">SSD </a> will significantly increase the speed of <a href="http://www.dba-oracle.com/oracle_tips_cache_small_fts.htm" target="blank">small-table full-table scans</a>.';
	
	/****** High Onepass Workarea Executions ******/
	IA[9]='You have excessive onepass PGA <B>workarea executions</B> with '+val+' non-optimal executions during this elapsed period.  It?s better to have "workarea executions - optimal", and you might consider optimizing your <a href="http://www.dba-oracle.com/art_dbazine_9i_sga.htm" target="blank">pga_aggregate_target</a> parameter.';


	/*******************Tablespace IO Stats*****************/
	/*******************************************************/
	var IO = new Array();
	
	IO[0]='The above tablespace(s) marked with <font color="red"><B>&raquo;</B></font> have a slow response time.  These tablespaces might have <a href="http://www.dba-oracle.com/art_orafaq_awr_disk_reads.htm" target="blank">disk enqueues</a>, or excessive read-write head movement or <a href="http://www.dba-oracle.com/art_dbazine_disk.htm" target="blank">disk channel contention</a> might be causing the tablespace delay.  Consider distributing the frequently-referenced objects to a less-busy disk or moving the tablespace to a faster storage device such as <a href="http://www.dba-oracle.com/oracle_tips_SSD.htm" target="blank">SSD</a>.';


	/*******************Latch Activity*****************/
	/**************************************************/
	var LA = new Array();
	
	/****** High Cache Buffer Chain Waits ******/
	LA[0]='You have high <B>cache buffer chain latches</B> with '+val+'% get miss.  See MetaLink about increasing the hidden parameter _db_block_hash_buckets.';
	
	/****** High Cache Buffer LRU Chain Waits ******/
	LA[1]='You have a high value for <B>cache buffer LRU chain waits</B> with '+val+'% get miss, and you need to reduce the length of the hash chains for popular data blocks in your RAM buffer.   Investigate the specific data blocks that are experiencing the latches and reduce the popularity of the data block by spreading the rows across more data blocks by reorganizing with a higher value for PCTFREE.';
	
	/****** High Library Cache Waits ******/
	LA[2]='You have high <B>library cache waits</B> with '+val+'% get miss.  Consider pinning your frequently-used packages in the library cache with dbms_shared_pool.keep.';
	
	/****** High Redo Allocation Misses ******/
	LA[3]='You have high <B>redo allocation misses</B> with '+val+'% get miss.  The redo allocation latch controls the allocation of space for redo entries in the redo log buffer (as defined by the log_buffer parameter).  The redo allocation latch is a serialization latch that enforces the sequence of entries in the log buffer.  A process can only write a redo entry after the redo allocation latch, which is why it&acute;s a will-to-wait latch. Investigate increasing your log_buffer parameter.';
	
	/****** High Redo Copy Latches ******/
	LA[4]='You have high <B>redo copy latches</B> with '+val+'% get miss.  Check MetaLink for increasing the hidden parameter _log_simultaneous_copies.';

	/****** High Row Cache Object Latches ******/
	LA[5]='You have high <B>row cache object latches</B> with '+val+'% get miss.  The row cache objects is a serialization latch that protects the access to the data dictionary cache in the SGA. When loading, referencing and freeing objects in the data dictionary cache you will need to get this latch.  <a href="http://www.oracle.com/technology/oramag/oracle/03-mar/o23expert.html" target="blank">Rich Niemiec</a> notes: The row cache objects latch contention usually means there is contention in the data dictionary. This problem may also be a symptom of excessive parsing of SQL statements that depend on public synonyms. Increasing the shared pool usually solves this latch problem. You usually increase the shared pool for a library cache latch problem well before this one is a problem.';


	/*******************Buffer Pool Advisory*****************/
	/********************************************************/
	var BP = new Array();
	
	BP[0]='The Oracle buffer cache advisory utility indicates '+val+' disk reads during the sample interval.  Oracle estimates that doubling the data buffer size (by increasing db_cache_size) will reduce disk reads to '+val2+', a '+val3+'% decrease.';
	
	
	/*******************PGA Memory Advisory*****************/
	/*******************************************************/
	var PGA = new Array();
	
	PGA[0]='The PGA advisory utility indicates '+val+'% PGA cache hit ratio during the sample interval.  Oracle estimates that doubling the PGA size (by increasing pga_aggregate_target) will increase the PGA cache hit ratio to '+val2+'%, a '+val3+'% increase.';
	
	
	/*******************Shared Pool Advisory*****************/
	/********************************************************/
	var SP = new Array();
	
	SP[0]='The Oracle shared pool advisory utility indicates '+val+' cached memory objects during the sample interval.  Oracle estimates that doubling the shared pool size (by increasing shared_pool_size) will allow for '+val2+'% more cached objects and will increase estimated time saved by '+val3+'%.';
	
	
	/*******************Init.ora Parameters*****************/
	/*******************************************************/
	var IP = new Array();
	
	/****** Large Blocksizes ******/
	IP[0]='You are not using <B>large blocksizes</B> for your index tablespaces.  <a href="http://www.dba-oracle.com/art_so_blocksize.htm" target="blank">Oracle research proves</a> that indexes will build flatter tree structures in larger blocksizes.';

	/****** Small DB Cache ******/
	IP[1]='Your <B>db_cache_size</B> is '+val+', and this may be too small to fully cache your working set of frequently referenced tables and indexes.  To see if an increase is right for you, see the <a href="http://www.dba-oracle.com/oracle_tips_data_cache_advice.htm" target="blank">v$db_cache_advice utility</a>.';

	/****** DB File Multiblock Read Count ******/
	IP[2]='You have the default value for <B>db_file_multiblock_read_count</B> at 16.  The CBO uses this parameter to determine the cost of a full-table scan.  The default value is sometimes too large, and you can <a href="http://www.dba-oracle.com/t_db_file_multiblock_read_count.htm" target="blank">run scripts</a> to determine the optimal setting. If full-table scans are unavoidable, you may consider placing those tables on <a href="http://www.superssd.com" target="blank" class="style1">SSD </a>.';

	/****** KEEP Pool ******/
	IP[3]='You are not using your <B>KEEP pool</B> to cache frequently referenced tables and indexes.  This may cause <a href="http://www.dba-oracle.com/oracle_tips_cache_small_fts.htm" target="blank">unnecessary I/O</a>.  When configured properly, the KEEP pool guarantees full caching of popular tables and indexes.  Remember, an average buffer get is often 100 times faster than a disk read.  Any table or index that consumes > 10% of the data buffer, or tables & indexes that have > 50% of their blocks residing in the data buffer should be cached into the KEEP pool.  You can fully automate this process <a href="http://www.dba-oracle.com/t_script_automate_keep_pool_tables_indexes.htm" target="blank">using scripts</a>.';

	/****** Hash Area Size ******/
	IP[4]='You have an unusually <B>small hash_area_size</B> of '+val+'.  Setting a <a href="http://www.dba-oracle.com/tips_oracle_hash_area_size.htm" target="blank">larger hash_area_size</a> (or enabling pga_aggregate_target) may improve SQL performance.';

	/****** Hash Joins ******/
	IP[5]='You do not have <B>hash joins</B> enabled.  <a href="http://www.dba-oracle.com/tips_oracle_hash_joins.htm" target="blank">Hash joins</a> are a powerful alternative to nested loop joins.';
	
	/****** Multi-threaded Server with PGA Aggregate Target ******/
	IP[6]='If the Multi-threaded server is being used, the <B>pga_aggregate_target</B> setting would be ignored in all versions except Oracle10g.  See <a href="http://www.dba-oracle.com/art_so_undocumented_pga_parameters.htm" target="blank">pga_aggregate_target details</a> for more.';

	/****** Multi-threaded Server ******/
	IP[7]='You are using the <B>Multi-threaded Server</B> (Shared Server).  <a href="http://www.dba-oracle.com/t_mts_multithreaded_servers_shared.htm" target="blank">Oracle states</a> that connections with the MTS are slower than a dedicated server, and you may consider switching to dedicated database connections.';
	
	/****** Optimizer Index Caching ******/
	IP[8]='Consider setting your <B>optimizer_index_caching</B> parameter to assist the cost-based optimizer. Set the value of <a href="http://www.dba-oracle.com/art_so_optimizer_index_caching.htm" target="blank">optimizer_index_caching</a> to the average percentage of index segments in the data buffer at any time, which you can estimate from the v$bh view.';
	
	/****** Optimizer Index Caching ******/
	IP[9]='Consider setting your <B>optimizer_index_caching</B> parameter to the approximate percentage of index blocks in your data buffer to assist the cost-based optimizer.  Set the value of <a href="http://www.dba-oracle.com/art_so_optimizer_index_caching.htm" target="blank">optimizer_index_caching</a> to the average percentage of index segments in the data buffer at any time, which you can estimate from the v$bh view.';
	
	/****** Optimizer Index Cost Adj ******/
	IP[10]='You have the default value of <B>optimizer_index_cost_adj</B> of 100.  Consider <a href="http://www.remote-dba.net/oracle_10g_tuning/t_oracle_optimizer_index_cost_adj.htm" target="blank">lowering your optimizer_index_cost_adj</a> according to the relative costs of index vs. full-scan I/O.';

	/****** Optimizer Index Cost Adj ******/
	IP[11]='You have not set your <B>optimizer_index_cost_adj</B> parameter.  The optimizer_index_cost_adj parameter is an initialization parameter that can be very useful for SQL tuning. It is a numeric parameter with values from zero to 10,000 and a default value of 100. You can also enable it at the session level by using the alter session set optimizer_index_cost_adj = nn syntax. The default value of 100 is too high for many databases.';

	/****** Optimizer Mode ******/
	IP[12]='You are using the <B>default optimizer mode</B> and you may consider setting it to <a href="http://www.remote-dba.net/pl_sql/t_oracle_sql_first_all_rows_rule.htm" target="blank">first_rows or first_rows_n</a> if you have an online transaction processing system.';
	
	/****** Parallel Automatic Tuning ******/
	IP[13]='You have enabled <B>system-level parallel query</B>.  This can influence the cost-based optimizer to favor full-table scans over index access.  Consider using parallel hints instead, or invoking parallelism at the session level.  See <a href="http://www.dba-oracle.com/art_builder_sql_parm.htm" target="blank">parallel automatic tuning</a>.';
	
	/****** Default Sort Area Size ******/
	IP[14]='You are using the <B>default sort_area_size</B>, which is usually too small.  Examine your statistics for high disk sorts and low hash joins and <a href="http://www.dba-oracle.com/p_sort_area_size.htm" target="blank">re-set sort_area_size</a> or <a href="http://www.dba-oracle.com/art_so_undocumented_pga_parameters.htm" target="blank">enable pga_aggregate_target</a>.';

	/****** PGA Aggregate Target ******/
	IP[15]='Your <B>pga_aggregate_target</B> is '+val+'. You may have over-allocated your PGA region.  No RAM sort may use more than 5% of pga_aggregate_target or _pga_max_size, whichever is smaller. This means that no task may use more than 2GB for sorting or hash joins. Consider increasing _pga_max_size if you are experiencing high disk sorts or low hash joins. For more information, see <a href="http://www.dba-oracle.com/art_so_undocumented_pga_parameters.htm" target="blank">pga_aggregate_target details</a>.';
	
	/****** Query Rewrite Enabled ******/
	IP[16]='You have not enabled <B>Materialized Views</B> and <B>Function-based indexes</B>, which are very powerful features that require you to <a href="http://www.dba-oracle.com/t_query_rewrite_integrity_trusted.htm" target="blank">set query_rewrite_integrity and query_rewrite_enabled</a>.';

	/****** Small Shared Pool ******/
	IP[17]='Your <B>shared pool</B> is set at '+val+' and may not be large enough to hold your working set of frequently re-used SQL.  For further details, see the <a href="http://www.dba-oracle.com/t_ault_105_mts_sga_cache.htm" target="blank">shared pool advisory</a>.';
	
	/****** Large Shared Pool ******/
	IP[18]='Your <B>shared pool</B> is set at '+val+', which is an unusually large value.  Allocating excessive shared pool resource can adversely impact Oracle performance.  For further details, see the <a href="http://www.dba-oracle.com/t_ault_105_mts_sga_cache.htm" target="blank">shared pool advisory</a>.';
	
	/****** Small Sort Area Size ******/
	IP[19]='You have an unusually <B>small sort_area_size</B> of '+val+'.  Examine your statistics for high disk sorts and low hash joins and <a href="http://www.dba-oracle.com/p_sort_area_size.htm" target="blank">re-set sort_area_size</a> or <a href="http://www.dba-oracle.com/art_so_undocumented_pga_parameters.htm" target="blank">enable pga_aggregate_target</a>.';

	/****** Sort Area Size and PGA Aggregate Target ******/
	IP[20]='Oracle ignores your <B>sort_area_size</B> when <B>pga_aggregate_target</B> is set and when <B>workarea_size_policy = auto</B>, unless you are using a specialized feature such as the MTS. If dedicated server connections are used, Oracle ignores the sort_area_size parameter. For more information see <a href="http://www.dba-oracle.com/art_so_undocumented_pga_parameters.htm" target="blank">pga_aggregate_target details</a>.';

	/****** Obsolete Parameters ******/
	IP[21]='You currently have <b>obsolete parameters</b> set. These parameters are: <i>'+val+'</i>. Oracle classifies non-current parameters as either depreciated or obsolete. Depreciated parameters will prevent your database from starting up, whereas obsolete parameters will simply display a warning and may be ignored.';

	if(sec=='load') 	return(LP[indx]);
	if(sec=='efficiency') 	return(IE[indx]);
	if(sec=='top') 		return(T5[indx]);
	if(sec=='wait') 	return(WE[indx]);
	if(sec=='stats') 	return(IA[indx]);
	if(sec==5) 		return(IO[indx]);
	if(sec=='latch') 	return(LA[indx]);
	if(sec=='buffer') 	return(BP[indx]);
	if(sec=='pga')		return(PGA[indx]);
	if(sec=='shared')	return(SP[indx]);
	if(sec=='param') 	return(IP[indx]);
}