4 V5.19 23-Apr-2014 (c) 2000-2014 John Lim (jlim#natsoft.com). All rights reserved.
5 Released under both BSD license and Lesser GPL library license.
6 Whenever there is any discrepancy between the two licenses,
7 the BSD license will take precedence. See License.txt.
8 Set tabs to 4 for best viewing.
10 Latest version is available at http://adodb.sourceforge.net
12 Library for basic performance monitoring and tuning
16 // security - hide paths
17 if (!defined('ADODB_DIR')) die();
20 MSSQL has moved most performance info to Performance Monitor
22 class perf_mssqlnative
extends adodb_perf
{
23 var $sql1 = 'cast(sql1 as text)';
24 var $createTableSQL = "CREATE TABLE adodb_logsql (
25 created datetime NOT NULL,
26 sql0 varchar(250) NOT NULL,
27 sql1 varchar(4000) NOT NULL,
28 params varchar(3000) NOT NULL,
29 tracer varchar(500) NOT NULL,
30 timer decimal(16,6) NOT NULL
33 var $settings = array(
35 'data cache hit ratio' => array('RATIO',
36 "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'",
38 'prepared sql hit ratio' => array('RATIO',
39 array('dbcc cachestats','Prepared',1,100),
41 'adhoc sql hit ratio' => array('RATIO',
42 array('dbcc cachestats','Adhoc',1,100),
45 'data reads' => array('IO',
46 "select cntr_value from master.dbo.sysperfinfo where counter_name = 'Page reads/sec'"),
47 'data writes' => array('IO',
48 "select cntr_value from master.dbo.sysperfinfo where counter_name = 'Page writes/sec'"),
51 'data cache size' => array('DATAC',
52 "select cntr_value*8192 from master.dbo.sysperfinfo where counter_name = 'Total Pages' and object_name='SQLServer:Buffer Manager'",
54 'data cache blocksize' => array('DATAC',
55 "select 8192",'page size'),
57 'current connections' => array('SESS',
60 'max connections' => array('SESS',
61 "SELECT @@MAX_CONNECTIONS",
68 function perf_mssqlnative(&$conn)
70 if ($conn->dataProvider
== 'odbc') {
72 //$this->explain = false;
77 function Explain($sql,$partial=false)
80 $save = $this->conn
->LogSQL(false);
82 $sqlq = $this->conn
->qstr($sql.'%');
83 $arr = $this->conn
->GetArray("select distinct sql1 from adodb_logsql where sql1 like $sqlq");
85 foreach($arr as $row) {
87 if (crc32($sql) == $partial) break;
92 $s = '<p><b>Explain</b>: '.htmlspecialchars($sql).'</p>';
93 $this->conn
->Execute("SET SHOWPLAN_ALL ON;");
94 $sql = str_replace('?',"''",$sql);
95 global $ADODB_FETCH_MODE;
97 $save = $ADODB_FETCH_MODE;
98 $ADODB_FETCH_MODE = ADODB_FETCH_NUM
;
99 $rs =& $this->conn
->Execute($sql);
101 $ADODB_FETCH_MODE = $save;
104 $s .= '<table bgcolor=white border=0 cellpadding="1" callspacing=0><tr><td nowrap align=center> Rows<td nowrap align=center> IO<td nowrap align=center> CPU<td align=left> Plan</tr>';
106 $s .= '<tr><td>'.round($rs->fields
[8],1).'<td>'.round($rs->fields
[9],3).'<td align=right>'.round($rs->fields
[10],3).'<td nowrap><pre>'.htmlspecialchars($rs->fields
[0])."</td></pre></tr>\n"; ## NOTE CORRUPT </td></pre> tag is intentional!!!!
111 $rs->NextRecordSet();
114 $this->conn
->Execute("SET SHOWPLAN_ALL OFF;");
115 $this->conn
->LogSQL($save);
116 $s .= $this->Tracer($sql);
120 function Tables($orderby='1')
122 global $ADODB_FETCH_MODE;
124 $save = $ADODB_FETCH_MODE;
125 $ADODB_FETCH_MODE = ADODB_FETCH_NUM
;
126 //$this->conn->debug=1;
127 $s = '<table border=1 bgcolor=white><tr><td><b>tablename</b></td><td><b>size_in_k</b></td><td><b>index size</b></td><td><b>reserved size</b></td></tr>';
128 $rs1 = $this->conn
->Execute("select distinct name from sysobjects where xtype='U'");
131 $tab = $rs1->fields
[0];
132 $tabq = $this->conn
->qstr($tab);
133 $rs2 = $this->conn
->Execute("sp_spaceused $tabq");
135 $s .= '<tr><td>'.$tab.'</td><td align=right>'.$rs2->fields
[3].'</td><td align=right>'.$rs2->fields
[4].'</td><td align=right>'.$rs2->fields
[2].'</td></tr>';
142 $ADODB_FETCH_MODE = $save;
143 return $s.'</table>';
148 $arr = $this->conn
->GetArray('sp_who');
152 function HealthCheck($cli=false)
155 $this->conn
->Execute('dbcc traceon(3604)');
156 $html = adodb_perf
::HealthCheck($cli);
157 $this->conn
->Execute('dbcc traceoff(3604)');