mirror of
https://github.com/ACSPRI/queXS
synced 2024-04-02 12:12:16 +00:00
Merged from McMasterReports branch
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
|
||||
V5.08 6 Apr 2009 (c) 2000-2009 John Lim (jlim#natsoft.com). 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.
|
||||
@@ -22,6 +22,10 @@ include_once(ADODB_DIR.'/tohtml.inc.php');
|
||||
define( 'ADODB_OPT_HIGH', 2);
|
||||
define( 'ADODB_OPT_LOW', 1);
|
||||
|
||||
global $ADODB_PERF_MIN;
|
||||
$ADODB_PERF_MIN = 0.05; // log only if >= minimum number of secs to run
|
||||
|
||||
|
||||
// returns in K the memory of current process, or 0 if not known
|
||||
function adodb_getmem()
|
||||
{
|
||||
@@ -62,37 +66,31 @@ function adodb_microtime()
|
||||
}
|
||||
|
||||
/* sql code timing */
|
||||
function& adodb_log_sql(&$connx,$sql,$inputarr)
|
||||
function adodb_log_sql(&$connx,$sql,$inputarr)
|
||||
{
|
||||
$perf_table = adodb_perf::table();
|
||||
$connx->fnExecute = false;
|
||||
$t0 = microtime();
|
||||
$rs =& $connx->Execute($sql,$inputarr);
|
||||
$t1 = microtime();
|
||||
$a0 = microtime(true);
|
||||
$rs = $connx->Execute($sql,$inputarr);
|
||||
$a1 = microtime(true);
|
||||
|
||||
if (!empty($connx->_logsql) && (empty($connx->_logsqlErrors) || !$rs)) {
|
||||
global $ADODB_LOG_CONN;
|
||||
|
||||
if (!empty($ADODB_LOG_CONN)) {
|
||||
$conn = &$ADODB_LOG_CONN;
|
||||
$conn = $ADODB_LOG_CONN;
|
||||
if ($conn->databaseType != $connx->databaseType)
|
||||
$prefix = '/*dbx='.$connx->databaseType .'*/ ';
|
||||
else
|
||||
$prefix = '';
|
||||
} else {
|
||||
$conn =& $connx;
|
||||
$conn = $connx;
|
||||
$prefix = '';
|
||||
}
|
||||
|
||||
$conn->_logsql = false; // disable logsql error simulation
|
||||
$dbT = $conn->databaseType;
|
||||
|
||||
$a0 = split(' ',$t0);
|
||||
$a0 = (float)$a0[1]+(float)$a0[0];
|
||||
|
||||
$a1 = split(' ',$t1);
|
||||
$a1 = (float)$a1[1]+(float)$a1[0];
|
||||
|
||||
$time = $a1 - $a0;
|
||||
|
||||
if (!$rs) {
|
||||
@@ -113,9 +111,9 @@ function& adodb_log_sql(&$connx,$sql,$inputarr)
|
||||
}
|
||||
if (isset($_SERVER['HTTP_HOST'])) {
|
||||
$tracer .= '<br>'.$_SERVER['HTTP_HOST'];
|
||||
if (isset($_SERVER['PHP_SELF'])) $tracer .= $_SERVER['PHP_SELF'];
|
||||
if (isset($_SERVER['PHP_SELF'])) $tracer .= htmlspecialchars($_SERVER['PHP_SELF']);
|
||||
} else
|
||||
if (isset($_SERVER['PHP_SELF'])) $tracer .= '<br>'.$_SERVER['PHP_SELF'];
|
||||
if (isset($_SERVER['PHP_SELF'])) $tracer .= '<br>'.htmlspecialchars($_SERVER['PHP_SELF']);
|
||||
//$tracer .= (string) adodb_backtrace(false);
|
||||
|
||||
$tracer = (string) substr($tracer,0,500);
|
||||
@@ -165,7 +163,13 @@ function& adodb_log_sql(&$connx,$sql,$inputarr)
|
||||
if ($dbT == 'db2') $arr['f'] = (float) $arr['f'];
|
||||
$isql = "insert into $perf_table (created,sql0,sql1,params,tracer,timer) values( $d,?,?,?,?,?)";
|
||||
}
|
||||
$ok = $conn->Execute($isql,$arr);
|
||||
|
||||
global $ADODB_PERF_MIN;
|
||||
if ($errN != 0 || $time >= $ADODB_PERF_MIN) {
|
||||
$ok = $conn->Execute($isql,$arr);
|
||||
} else
|
||||
$ok = true;
|
||||
|
||||
$conn->debug = $saved;
|
||||
|
||||
if ($ok) {
|
||||
@@ -173,7 +177,7 @@ function& adodb_log_sql(&$connx,$sql,$inputarr)
|
||||
} else {
|
||||
$err2 = $conn->ErrorMsg();
|
||||
$conn->_logsql = true; // enable logsql error simulation
|
||||
$perf =& NewPerfMonitor($conn);
|
||||
$perf = NewPerfMonitor($conn);
|
||||
if ($perf) {
|
||||
if ($perf->CreateLogTable()) $ok = $conn->Execute($isql,$arr);
|
||||
} else {
|
||||
@@ -227,7 +231,7 @@ class adodb_perf {
|
||||
var $maxLength = 2000;
|
||||
|
||||
// Sets the tablename to be used
|
||||
function table($newtable = false)
|
||||
static function table($newtable = false)
|
||||
{
|
||||
static $_table;
|
||||
|
||||
@@ -254,7 +258,7 @@ processes 69293
|
||||
|
||||
*/
|
||||
// Algorithm is taken from
|
||||
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/example__obtaining_raw_performance_data.asp
|
||||
// http://social.technet.microsoft.com/Forums/en-US/winservergen/thread/414b0e1b-499c-411e-8a02-6a12e339c0f1/
|
||||
if (strncmp(PHP_OS,'WIN',3)==0) {
|
||||
if (PHP_VERSION == '5.0.0') return false;
|
||||
if (PHP_VERSION == '5.0.1') return false;
|
||||
@@ -262,14 +266,33 @@ processes 69293
|
||||
if (PHP_VERSION == '5.0.3') return false;
|
||||
if (PHP_VERSION == '4.3.10') return false; # see http://bugs.php.net/bug.php?id=31737
|
||||
|
||||
@$c = new COM("WinMgmts:{impersonationLevel=impersonate}!Win32_PerfRawData_PerfOS_Processor.Name='_Total'");
|
||||
if (!$c) return false;
|
||||
static $FAIL = false;
|
||||
if ($FAIL) return false;
|
||||
|
||||
$objName = "winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\CIMV2";
|
||||
$myQuery = "SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name = '_Total'";
|
||||
|
||||
try {
|
||||
@$objWMIService = new COM($objName);
|
||||
if (!$objWMIService) {
|
||||
$FAIL = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
$info[0] = -1;
|
||||
$info[1] = 0;
|
||||
$info[2] = 0;
|
||||
$info[3] = 0;
|
||||
foreach($objWMIService->ExecQuery($myQuery) as $objItem) {
|
||||
$info[0] = $objItem->PercentProcessorTime();
|
||||
}
|
||||
|
||||
} catch(Exception $e) {
|
||||
$FAIL = true;
|
||||
echo $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
|
||||
$info[0] = $c->PercentProcessorTime;
|
||||
$info[1] = 0;
|
||||
$info[2] = 0;
|
||||
$info[3] = $c->TimeStamp_Sys100NS;
|
||||
//print_r($info);
|
||||
return $info;
|
||||
}
|
||||
|
||||
@@ -332,27 +355,26 @@ Committed_AS: 348732 kB
|
||||
{
|
||||
$info = $this->_CPULoad();
|
||||
if (!$info) return false;
|
||||
|
||||
if (empty($this->_lastLoad)) {
|
||||
sleep(1);
|
||||
$this->_lastLoad = $info;
|
||||
$info = $this->_CPULoad();
|
||||
}
|
||||
|
||||
$last = $this->_lastLoad;
|
||||
$this->_lastLoad = $info;
|
||||
|
||||
$d_user = $info[0] - $last[0];
|
||||
$d_nice = $info[1] - $last[1];
|
||||
$d_system = $info[2] - $last[2];
|
||||
$d_idle = $info[3] - $last[3];
|
||||
|
||||
//printf("Delta - User: %f Nice: %f System: %f Idle: %f<br>",$d_user,$d_nice,$d_system,$d_idle);
|
||||
|
||||
if (strncmp(PHP_OS,'WIN',3)==0) {
|
||||
if ($d_idle < 1) $d_idle = 1;
|
||||
return 100*(1-$d_user/$d_idle);
|
||||
return (integer) $info[0];
|
||||
}else {
|
||||
if (empty($this->_lastLoad)) {
|
||||
sleep(1);
|
||||
$this->_lastLoad = $info;
|
||||
$info = $this->_CPULoad();
|
||||
}
|
||||
|
||||
$last = $this->_lastLoad;
|
||||
$this->_lastLoad = $info;
|
||||
|
||||
$d_user = $info[0] - $last[0];
|
||||
$d_nice = $info[1] - $last[1];
|
||||
$d_system = $info[2] - $last[2];
|
||||
$d_idle = $info[3] - $last[3];
|
||||
|
||||
//printf("Delta - User: %f Nice: %f System: %f Idle: %f<br>",$d_user,$d_nice,$d_system,$d_idle);
|
||||
|
||||
$total=$d_user+$d_nice+$d_system+$d_idle;
|
||||
if ($total<1) $total=1;
|
||||
return 100*($d_user+$d_nice+$d_system)/$total;
|
||||
@@ -408,7 +430,7 @@ Committed_AS: 348732 kB
|
||||
$saveE = $this->conn->fnExecute;
|
||||
$this->conn->fnExecute = false;
|
||||
$perf_table = adodb_perf::table();
|
||||
$rs =& $this->conn->SelectLimit("select distinct count(*),sql1,tracer as error_msg from $perf_table where tracer like 'ERROR:%' group by sql1,tracer order by 1 desc",$numsql);//,$numsql);
|
||||
$rs = $this->conn->SelectLimit("select distinct count(*),sql1,tracer as error_msg from $perf_table where tracer like 'ERROR:%' group by sql1,tracer order by 1 desc",$numsql);//,$numsql);
|
||||
$this->conn->fnExecute = $saveE;
|
||||
if ($rs) {
|
||||
$s .= rs2html($rs,false,false,false,false);
|
||||
@@ -442,7 +464,7 @@ Committed_AS: 348732 kB
|
||||
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
|
||||
if ($this->conn->fetchMode !== false) $savem = $this->conn->SetFetchMode(false);
|
||||
//$this->conn->debug=1;
|
||||
$rs =& $this->conn->SelectLimit(
|
||||
$rs = $this->conn->SelectLimit(
|
||||
"select avg(timer) as avg_timer,$sql1,count(*),max(timer) as max_timer,min(timer) as min_timer
|
||||
from $perf_table
|
||||
where {$this->conn->upperCase}({$this->conn->substr}(sql0,1,5)) not in ('DROP ','INSER','COMMI','CREAT')
|
||||
@@ -521,7 +543,7 @@ Committed_AS: 348732 kB
|
||||
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
|
||||
if ($this->conn->fetchMode !== false) $savem = $this->conn->SetFetchMode(false);
|
||||
|
||||
$rs =& $this->conn->SelectLimit(
|
||||
$rs = $this->conn->SelectLimit(
|
||||
"select sum(timer) as total,$sql1,count(*),max(timer) as max_timer,min(timer) as min_timer
|
||||
from $perf_table
|
||||
where {$this->conn->upperCase}({$this->conn->substr}(sql0,1,5)) not in ('DROP ','INSER','COMMI','CREAT')
|
||||
@@ -570,7 +592,7 @@ Committed_AS: 348732 kB
|
||||
/*
|
||||
Raw function returning array of poll paramters
|
||||
*/
|
||||
function &PollParameters()
|
||||
function PollParameters()
|
||||
{
|
||||
$arr[0] = (float)$this->DBParameter('data cache hit ratio');
|
||||
$arr[1] = (float)$this->DBParameter('data reads');
|
||||
@@ -640,6 +662,11 @@ Committed_AS: 348732 kB
|
||||
else return '';
|
||||
}
|
||||
|
||||
function clearsql()
|
||||
{
|
||||
$perf_table = adodb_perf::table();
|
||||
$this->conn->Execute("delete from $perf_table where created<".$this->conn->sysTimeStamp);
|
||||
}
|
||||
/***********************************************************************************************/
|
||||
// HIGH LEVEL UI FUNCTIONS
|
||||
/***********************************************************************************************/
|
||||
@@ -647,6 +674,7 @@ Committed_AS: 348732 kB
|
||||
|
||||
function UI($pollsecs=5)
|
||||
{
|
||||
global $ADODB_LOG_CONN;
|
||||
|
||||
$perf_table = adodb_perf::table();
|
||||
$conn = $this->conn;
|
||||
@@ -659,7 +687,7 @@ Committed_AS: 348732 kB
|
||||
$savelog = $this->conn->LogSQL(false);
|
||||
$info = $conn->ServerInfo();
|
||||
if (isset($_GET['clearsql'])) {
|
||||
$this->conn->Execute("delete from $perf_table");
|
||||
$this->clearsql();
|
||||
}
|
||||
$this->conn->LogSQL($savelog);
|
||||
|
||||
@@ -688,6 +716,8 @@ Committed_AS: 348732 kB
|
||||
else $form = "<td> </td>";
|
||||
|
||||
$allowsql = !defined('ADODB_PERF_NO_RUN_SQL');
|
||||
global $ADODB_PERF_MIN;
|
||||
$app .= " (Min sql timing \$ADODB_PERF_MIN=$ADODB_PERF_MIN secs)";
|
||||
|
||||
if (empty($_GET['hidem']))
|
||||
echo "<table border=1 width=100% bgcolor=lightyellow><tr><td colspan=2>
|
||||
@@ -702,13 +732,16 @@ Committed_AS: 348732 kB
|
||||
switch ($do) {
|
||||
default:
|
||||
case 'stats':
|
||||
if (empty($ADODB_LOG_CONN))
|
||||
echo "<p> <a href=\"?do=viewsql&clearsql=1\">Clear SQL Log</a><br>";
|
||||
echo $this->HealthCheck();
|
||||
//$this->conn->debug=1;
|
||||
echo $this->CheckMemory();
|
||||
echo $this->CheckMemory();
|
||||
break;
|
||||
case 'poll':
|
||||
$self = htmlspecialchars($_SERVER['PHP_SELF']);
|
||||
echo "<iframe width=720 height=80%
|
||||
src=\"{$_SERVER['PHP_SELF']}?do=poll2&hidem=1\"></iframe>";
|
||||
src=\"{$self}?do=poll2&hidem=1\"></iframe>";
|
||||
break;
|
||||
case 'poll2':
|
||||
echo "<pre>";
|
||||
@@ -743,13 +776,13 @@ Committed_AS: 348732 kB
|
||||
//$this->conn->debug=1;
|
||||
if ($secs <= 1) $secs = 1;
|
||||
echo "Accumulating statistics, every $secs seconds...\n";flush();
|
||||
$arro =& $this->PollParameters();
|
||||
$arro = $this->PollParameters();
|
||||
$cnt = 0;
|
||||
set_time_limit(0);
|
||||
sleep($secs);
|
||||
while (1) {
|
||||
|
||||
$arr =& $this->PollParameters();
|
||||
$arr = $this->PollParameters();
|
||||
|
||||
$hits = sprintf('%2.2f',$arr[0]);
|
||||
$reads = sprintf('%12.4f',($arr[1]-$arro[1])/$secs);
|
||||
@@ -885,7 +918,7 @@ Committed_AS: 348732 kB
|
||||
{
|
||||
|
||||
|
||||
$PHP_SELF = $_SERVER['PHP_SELF'];
|
||||
$PHP_SELF = htmlspecialchars($_SERVER['PHP_SELF']);
|
||||
$sql = isset($_REQUEST['sql']) ? $_REQUEST['sql'] : '';
|
||||
|
||||
if (isset($_SESSION['phplens_sqlrows'])) $rows = $_SESSION['phplens_sqlrows'];
|
||||
|
||||
Reference in New Issue
Block a user