Source for file perf-mysql.inc.php
Documentation is available at perf-mysql.inc.php
V5.04 13 Feb 2008 (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence. See License.txt.
Set tabs to 4 for best viewing.
Latest version is available at http://adodb.sourceforge.net
Library for basic performance monitoring and tuning
created datetime NOT NULL,
sql0 varchar(250) NOT NULL,
timer decimal(16,6) NOT NULL
'MyISAM cache hit ratio' =>
array('RATIO',
'InnoDB cache hit ratio' =>
array('RATIO',
'data cache hit ratio' =>
array('HIDE', # only if called
'sql cache hit ratio' =>
array('RATIO',
'data reads' =>
array('IO',
'Number of selects (Key_reads is not accurate)'),
'data writes' =>
array('IO',
'Number of inserts/updates/deletes * coef (Key_writes is not accurate)'),
'MyISAM data cache size' =>
array('DATAC',
array("show variables", 'key_buffer_size'),
'BDB data cache size' =>
array('DATAC',
array("show variables", 'bdb_cache_size'),
'InnoDB data cache size' =>
array('DATAC',
array("show variables", 'innodb_buffer_pool_size'),
'read buffer size' =>
array('CACHE',
array("show variables", 'read_buffer_size'),
'sort buffer size' =>
array('CACHE',
array("show variables", 'sort_buffer_size'),
'Size of sort buffer (per session)' ),
'table cache' =>
array('CACHE',
array("show variables", 'table_cache'),
'Number of tables to keep open'),
'current connections' =>
array('SESS',
array('show status','Threads_connected'),
'max connections' =>
array( 'SESS',
array("show variables",'max_connections'),
function Explain($sql,$partial=
false)
if (strtoupper(substr(trim($sql),0,6)) !==
'SELECT') return '<p>Unable to EXPLAIN non-select statement</p>';
$save =
$this->conn->LogSQL(false);
$sqlq =
$this->conn->qstr($sql.
'%');
$arr =
$this->conn->GetArray("select distinct sql1 from adodb_logsql where sql1 like $sqlq");
if (crc32($sql) ==
$partial) break;
$sqlq =
$this->conn->qstr($sql.
'%');
$sql =
$this->conn->GetOne("select sql1 from adodb_logsql where sql1 like $sqlq");
$rs =
$this->conn->Execute('EXPLAIN '.
$sql);
$s .=
rs2html($rs,false,false,false,false);
$this->conn->LogSQL($save);
$s .=
$this->Tracer($sql);
$rs =
$this->conn->Execute($this->tablesSQL);
$html =
rs2html($rs,false,false,false,false);
global $ADODB_FETCH_MODE;
$save =
$ADODB_FETCH_MODE;
$ADODB_FETCH_MODE =
ADODB_FETCH_NUM;
if ($this->conn->fetchMode !==
false) $savem =
$this->conn->SetFetchMode(false);
$rs =
$this->conn->Execute('show status');
if (isset
($savem)) $this->conn->SetFetchMode($savem);
$ADODB_FETCH_MODE =
$save;
global $ADODB_FETCH_MODE;
$save =
$ADODB_FETCH_MODE;
$ADODB_FETCH_MODE =
ADODB_FETCH_NUM;
if ($this->conn->fetchMode !==
false) $savem =
$this->conn->SetFetchMode(false);
$rs =
$this->conn->Execute('show status');
if (isset
($savem)) $this->conn->SetFetchMode($savem);
$ADODB_FETCH_MODE =
$save;
$val +=
$rs->fields[1]; break;
$val +=
$rs->fields[1]; break;
$val +=
$rs->fields[1]/
2;
// first find out type of table
global $ADODB_FETCH_MODE;
$save =
$ADODB_FETCH_MODE;
$ADODB_FETCH_MODE =
ADODB_FETCH_NUM;
if ($this->conn->fetchMode !==
false) $savem =
$this->conn->SetFetchMode(false);
$rs =
$this->conn->Execute('show table status');
if (isset
($savem)) $this->conn->SetFetchMode($savem);
$ADODB_FETCH_MODE =
$save;
return $this->DBParameter('MyISAM cache hit ratio').
' (MyISAM)';
return $this->DBParameter('InnoDB cache hit ratio').
' (InnoDB)';
return $type.
' not supported';
//Total number of queries = Qcache_inserts + Qcache_hits + Qcache_not_cached
$hits =
$this->_DBParameter(array("show status","Qcache_hits"));
$total =
$this->_DBParameter(array("show status","Qcache_inserts"));
$total +=
$this->_DBParameter(array("show status","Qcache_not_cached"));
if ($total) return round(($hits*
100)/
$total,2);
Use session variable to store Hit percentage, because MySQL
does not remember last value of SHOW INNODB STATUS hit ratio
# 1st query to SHOW INNODB STATUS
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
Buffer pool hit rate 1000 / 1000
# 2nd query to SHOW INNODB STATUS
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
No buffer pool activity since the last printout
global $ADODB_FETCH_MODE;
$save =
$ADODB_FETCH_MODE;
$ADODB_FETCH_MODE =
ADODB_FETCH_NUM;
if ($this->conn->fetchMode !==
false) $savem =
$this->conn->SetFetchMode(false);
$rs =
$this->conn->Execute('show innodb status');
if (isset
($savem)) $this->conn->SetFetchMode($savem);
$ADODB_FETCH_MODE =
$save;
if (!$rs ||
$rs->EOF) return 0;
$at =
strpos($stat,'Buffer pool hit rate');
$stat =
substr($stat,$at,200);
if (preg_match('!Buffer pool hit rate\s*([0-9]*) / ([0-9]*)!',$stat,$arr)) {
$val =
100*
$arr[1]/
$arr[2];
$_SESSION['INNODB_HIT_PCT'] =
$val;
if (isset
($_SESSION['INNODB_HIT_PCT'])) return $_SESSION['INNODB_HIT_PCT'];
$hits =
$this->_DBParameter(array("show status","Key_read_requests"));
$reqs =
$this->_DBParameter(array("show status","Key_reads"));
if ($reqs ==
0) return 0;
return round(($hits/
($reqs+
$hits))*
100,2);
* @see adodb_perf#optimizeTable
if ( !$conn) return false;
// May dont use __FUNCTION__ constant for BC (__FUNCTION__ Added in PHP 4.3.0)
ADOConnection::outp( sprintf( "<p>%s: '%s' using of undefined mode '%s'</p>", __CLASS__
, __FUNCTION__
, $mode));
return $conn->Execute( $sql) !==
false;
Documentation generated on Sun, 09 Mar 2008 23:52:47 -0300 by phpDocumentor 1.4.0