array('RATIO', "select round((a.cntr_value*100.0)/b.cntr_value,2) from master.dbo.sysperfinfo a, master.dbo.sysperfinfo b where a.counter_name = 'Buffer cache hit ratio' and b.counter_name='Buffer cache hit ratio base'", '=WarnCacheRatio'), 'prepared sql hit ratio' => array('RATIO', array('dbcc cachestats','Prepared',1,100), ''), 'adhoc sql hit ratio' => array('RATIO', array('dbcc cachestats','Adhoc',1,100), ''), 'IO', 'data reads' => array('IO', "select cntr_value from master.dbo.sysperfinfo where counter_name = 'Page reads/sec'"), 'data writes' => array('IO', "select cntr_value from master.dbo.sysperfinfo where counter_name = 'Page writes/sec'"), 'Data Cache', 'data cache size' => array('DATAC', "select cntr_value*8192 from master.dbo.sysperfinfo where counter_name = 'Total Pages' and object_name='SQLServer:Buffer Manager'", '' ), 'data cache blocksize' => array('DATAC', "select 8192",'page size'), 'Connections', 'current connections' => array('SESS', '=sp_who', ''), 'max connections' => array('SESS', "SELECT @@MAX_CONNECTIONS", ''), false ); function perf_mssql(&$conn) { if ($conn->dataProvider == 'odbc') { $this->sql1 = 'sql1'; //$this->explain = false; } $this->conn = $conn; } function Explain($sql,$partial=false) { $save = $this->conn->LogSQL(false); if ($partial) { $sqlq = $this->conn->qstr($sql.'%'); $arr = $this->conn->GetArray("select distinct sql1 from adodb_logsql where sql1 like $sqlq"); if ($arr) { foreach($arr as $row) { $sql = reset($row); if (crc32($sql) == $partial) break; } } } $s = '

Explain: '.htmlspecialchars($sql).'

'; $this->conn->Execute("SET SHOWPLAN_ALL ON;"); $sql = str_replace('?',"''",$sql); global $ADODB_FETCH_MODE; $save = $ADODB_FETCH_MODE; $ADODB_FETCH_MODE = ADODB_FETCH_NUM; $rs = $this->conn->Execute($sql); //adodb_printr($rs); $ADODB_FETCH_MODE = $save; if ($rs) { $rs->MoveNext(); $s .= ''; while (!$rs->EOF) { $s .= '\n"; ## NOTE CORRUPT tag is intentional!!!! $rs->MoveNext(); } $s .= '
Rows IO CPU     Plan
'.round($rs->fields[8],1).''.round($rs->fields[9],3).''.round($rs->fields[10],3).'
'.htmlspecialchars($rs->fields[0])."
'; $rs->NextRecordSet(); } $this->conn->Execute("SET SHOWPLAN_ALL OFF;"); $this->conn->LogSQL($save); $s .= $this->Tracer($sql); return $s; } function Tables() { global $ADODB_FETCH_MODE; $save = $ADODB_FETCH_MODE; $ADODB_FETCH_MODE = ADODB_FETCH_NUM; //$this->conn->debug=1; $s = ''; $rs1 = $this->conn->Execute("select distinct name from sysobjects where xtype='U'"); if ($rs1) { while (!$rs1->EOF) { $tab = $rs1->fields[0]; $tabq = $this->conn->qstr($tab); $rs2 = $this->conn->Execute("sp_spaceused $tabq"); if ($rs2) { $s .= ''; $rs2->Close(); } $rs1->MoveNext(); } $rs1->Close(); } $ADODB_FETCH_MODE = $save; return $s.'
tablenamesize_in_kindex sizereserved size
'.$tab.''.$rs2->fields[3].''.$rs2->fields[4].''.$rs2->fields[2].'
'; } function sp_who() { $arr = $this->conn->GetArray('sp_who'); return sizeof($arr); } function HealthCheck($cli=false) { $this->conn->Execute('dbcc traceon(3604)'); $html = adodb_perf::HealthCheck($cli); $this->conn->Execute('dbcc traceoff(3604)'); return $html; } } ?>