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->EOF) { $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])." |
tablename | size_in_k | index size | reserved size |
'.$tab.' | '.$rs2->fields[3].' | '.$rs2->fields[4].' | '.$rs2->fields[2].' |