- Timestamp:
- 09/26/13 15:41:49 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sandbox/2.5.1-evolucao/phpgwapi/inc/adodb/adodb-perf.inc.php
r6057 r8222 1 1 <?php 2 2 /* 3 V 4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.3 V5.18 3 Sep 2012 (c) 2000-2012 John Lim (jlim#natsoft.com). All rights reserved. 4 4 Released under both BSD license and Lesser GPL library license. 5 5 Whenever there is any discrepancy between the two licenses, … … 23 23 define( 'ADODB_OPT_LOW', 1); 24 24 25 global $ADODB_PERF_MIN; 26 $ADODB_PERF_MIN = 0.05; // log only if >= minimum number of secs to run 27 28 25 29 // returns in K the memory of current process, or 0 if not known 26 30 function adodb_getmem() … … 54 58 } 55 59 56 /* return microtime value as a float */60 /* obsolete: return microtime value as a float. Retained for backward compat */ 57 61 function adodb_microtime() 58 62 { 59 $t = microtime(); 60 $t = explode(' ',$t); 61 return (float)$t[1]+ (float)$t[0]; 63 return microtime(true); 62 64 } 63 65 64 66 /* sql code timing */ 65 function &adodb_log_sql(&$connx,$sql,$inputarr)67 function adodb_log_sql(&$connx,$sql,$inputarr) 66 68 { 67 69 $perf_table = adodb_perf::table(); 68 70 $connx->fnExecute = false; 69 $ t0 = microtime();70 $rs = &$connx->Execute($sql,$inputarr);71 $ t1 = microtime();71 $a0 = microtime(true); 72 $rs = $connx->Execute($sql,$inputarr); 73 $a1 = microtime(true); 72 74 73 75 if (!empty($connx->_logsql) && (empty($connx->_logsqlErrors) || !$rs)) { … … 75 77 76 78 if (!empty($ADODB_LOG_CONN)) { 77 $conn = &$ADODB_LOG_CONN;79 $conn = $ADODB_LOG_CONN; 78 80 if ($conn->databaseType != $connx->databaseType) 79 81 $prefix = '/*dbx='.$connx->databaseType .'*/ '; … … 81 83 $prefix = ''; 82 84 } else { 83 $conn = &$connx;85 $conn = $connx; 84 86 $prefix = ''; 85 87 } … … 87 89 $conn->_logsql = false; // disable logsql error simulation 88 90 $dbT = $conn->databaseType; 89 90 $a0 = preg_split('/ /',$t0);91 $a0 = (float)$a0[1]+(float)$a0[0];92 93 $a1 = preg_split('/ /',$t1);94 $a1 = (float)$a1[1]+(float)$a1[0];95 91 96 92 $time = $a1 - $a0; … … 114 110 if (isset($_SERVER['HTTP_HOST'])) { 115 111 $tracer .= '<br>'.$_SERVER['HTTP_HOST']; 116 if (isset($_SERVER['PHP_SELF'])) $tracer .= $_SERVER['PHP_SELF'];112 if (isset($_SERVER['PHP_SELF'])) $tracer .= htmlspecialchars($_SERVER['PHP_SELF']); 117 113 } else 118 if (isset($_SERVER['PHP_SELF'])) $tracer .= '<br>'. $_SERVER['PHP_SELF'];114 if (isset($_SERVER['PHP_SELF'])) $tracer .= '<br>'.htmlspecialchars($_SERVER['PHP_SELF']); 119 115 //$tracer .= (string) adodb_backtrace(false); 120 116 … … 166 162 $isql = "insert into $perf_table (created,sql0,sql1,params,tracer,timer) values( $d,?,?,?,?,?)"; 167 163 } 168 $ok = $conn->Execute($isql,$arr); 164 165 global $ADODB_PERF_MIN; 166 if ($errN != 0 || $time >= $ADODB_PERF_MIN) { 167 $ok = $conn->Execute($isql,$arr); 168 } else 169 $ok = true; 170 169 171 $conn->debug = $saved; 170 172 … … 174 176 $err2 = $conn->ErrorMsg(); 175 177 $conn->_logsql = true; // enable logsql error simulation 176 $perf = &NewPerfMonitor($conn);178 $perf = NewPerfMonitor($conn); 177 179 if ($perf) { 178 180 if ($perf->CreateLogTable()) $ok = $conn->Execute($isql,$arr); … … 228 230 229 231 // Sets the tablename to be used 230 function table($newtable = false)232 static function table($newtable = false) 231 233 { 232 234 static $_table; … … 255 257 */ 256 258 // Algorithm is taken from 257 // http:// msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/example__obtaining_raw_performance_data.asp259 // http://social.technet.microsoft.com/Forums/en-US/winservergen/thread/414b0e1b-499c-411e-8a02-6a12e339c0f1/ 258 260 if (strncmp(PHP_OS,'WIN',3)==0) { 259 261 if (PHP_VERSION == '5.0.0') return false; … … 263 265 if (PHP_VERSION == '4.3.10') return false; # see http://bugs.php.net/bug.php?id=31737 264 266 265 @$c = new COM("WinMgmts:{impersonationLevel=impersonate}!Win32_PerfRawData_PerfOS_Processor.Name='_Total'"); 266 if (!$c) return false; 267 268 $info[0] = $c->PercentProcessorTime; 269 $info[1] = 0; 270 $info[2] = 0; 271 $info[3] = $c->TimeStamp_Sys100NS; 272 //print_r($info); 267 static $FAIL = false; 268 if ($FAIL) return false; 269 270 $objName = "winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\CIMV2"; 271 $myQuery = "SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name = '_Total'"; 272 273 try { 274 @$objWMIService = new COM($objName); 275 if (!$objWMIService) { 276 $FAIL = true; 277 return false; 278 } 279 280 $info[0] = -1; 281 $info[1] = 0; 282 $info[2] = 0; 283 $info[3] = 0; 284 foreach($objWMIService->ExecQuery($myQuery) as $objItem) { 285 $info[0] = $objItem->PercentProcessorTime(); 286 } 287 288 } catch(Exception $e) { 289 $FAIL = true; 290 echo $e->getMessage(); 291 return false; 292 } 293 273 294 return $info; 274 295 } … … 333 354 $info = $this->_CPULoad(); 334 355 if (!$info) return false; 335 336 if (empty($this->_lastLoad)) { 337 sleep(1); 356 357 if (strncmp(PHP_OS,'WIN',3)==0) { 358 return (integer) $info[0]; 359 }else { 360 if (empty($this->_lastLoad)) { 361 sleep(1); 362 $this->_lastLoad = $info; 363 $info = $this->_CPULoad(); 364 } 365 366 $last = $this->_lastLoad; 338 367 $this->_lastLoad = $info; 339 $info = $this->_CPULoad(); 340 } 341 342 $last = $this->_lastLoad; 343 $this->_lastLoad = $info; 344 345 $d_user = $info[0] - $last[0]; 346 $d_nice = $info[1] - $last[1]; 347 $d_system = $info[2] - $last[2]; 348 $d_idle = $info[3] - $last[3]; 349 350 //printf("Delta - User: %f Nice: %f System: %f Idle: %f<br>",$d_user,$d_nice,$d_system,$d_idle); 351 352 if (strncmp(PHP_OS,'WIN',3)==0) { 353 if ($d_idle < 1) $d_idle = 1; 354 return 100*(1-$d_user/$d_idle); 355 }else { 368 369 $d_user = $info[0] - $last[0]; 370 $d_nice = $info[1] - $last[1]; 371 $d_system = $info[2] - $last[2]; 372 $d_idle = $info[3] - $last[3]; 373 374 //printf("Delta - User: %f Nice: %f System: %f Idle: %f<br>",$d_user,$d_nice,$d_system,$d_idle); 375 356 376 $total=$d_user+$d_nice+$d_system+$d_idle; 357 377 if ($total<1) $total=1; … … 409 429 $this->conn->fnExecute = false; 410 430 $perf_table = adodb_perf::table(); 411 $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);431 $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); 412 432 $this->conn->fnExecute = $saveE; 413 433 if ($rs) { … … 443 463 if ($this->conn->fetchMode !== false) $savem = $this->conn->SetFetchMode(false); 444 464 //$this->conn->debug=1; 445 $rs = &$this->conn->SelectLimit(465 $rs = $this->conn->SelectLimit( 446 466 "select avg(timer) as avg_timer,$sql1,count(*),max(timer) as max_timer,min(timer) as min_timer 447 467 from $perf_table … … 522 542 if ($this->conn->fetchMode !== false) $savem = $this->conn->SetFetchMode(false); 523 543 524 $rs = &$this->conn->SelectLimit(544 $rs = $this->conn->SelectLimit( 525 545 "select sum(timer) as total,$sql1,count(*),max(timer) as max_timer,min(timer) as min_timer 526 546 from $perf_table … … 571 591 Raw function returning array of poll paramters 572 592 */ 573 function &PollParameters()593 function PollParameters() 574 594 { 575 595 $arr[0] = (float)$this->DBParameter('data cache hit ratio'); … … 641 661 } 642 662 663 function clearsql() 664 { 665 $perf_table = adodb_perf::table(); 666 $this->conn->Execute("delete from $perf_table where created<".$this->conn->sysTimeStamp); 667 } 643 668 /***********************************************************************************************/ 644 669 // HIGH LEVEL UI FUNCTIONS … … 648 673 function UI($pollsecs=5) 649 674 { 675 global $ADODB_LOG_CONN; 650 676 651 677 $perf_table = adodb_perf::table(); … … 660 686 $info = $conn->ServerInfo(); 661 687 if (isset($_GET['clearsql'])) { 662 $this->c onn->Execute("delete from $perf_table");688 $this->clearsql(); 663 689 } 664 690 $this->conn->LogSQL($savelog); … … 689 715 690 716 $allowsql = !defined('ADODB_PERF_NO_RUN_SQL'); 717 global $ADODB_PERF_MIN; 718 $app .= " (Min sql timing \$ADODB_PERF_MIN=$ADODB_PERF_MIN secs)"; 691 719 692 720 if (empty($_GET['hidem'])) … … 703 731 default: 704 732 case 'stats': 733 if (empty($ADODB_LOG_CONN)) 734 echo "<p> <a href=\"?do=viewsql&clearsql=1\">Clear SQL Log</a><br>"; 705 735 echo $this->HealthCheck(); 706 736 //$this->conn->debug=1; 707 echo $this->CheckMemory(); 737 echo $this->CheckMemory(); 708 738 break; 709 739 case 'poll': 740 $self = htmlspecialchars($_SERVER['PHP_SELF']); 710 741 echo "<iframe width=720 height=80% 711 src=\"{$ _SERVER['PHP_SELF']}?do=poll2&hidem=1\"></iframe>";742 src=\"{$self}?do=poll2&hidem=1\"></iframe>"; 712 743 break; 713 744 case 'poll2': … … 744 775 if ($secs <= 1) $secs = 1; 745 776 echo "Accumulating statistics, every $secs seconds...\n";flush(); 746 $arro = &$this->PollParameters();777 $arro = $this->PollParameters(); 747 778 $cnt = 0; 748 779 set_time_limit(0); … … 750 781 while (1) { 751 782 752 $arr = &$this->PollParameters();783 $arr = $this->PollParameters(); 753 784 754 785 $hits = sprintf('%2.2f',$arr[0]); … … 886 917 887 918 888 $PHP_SELF = $_SERVER['PHP_SELF'];919 $PHP_SELF = htmlspecialchars($_SERVER['PHP_SELF']); 889 920 $sql = isset($_REQUEST['sql']) ? $_REQUEST['sql'] : ''; 890 921
Note: See TracChangeset
for help on using the changeset viewer.