home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / perf-db2.inc.php < prev    next >
Encoding:
PHP Script  |  2004-03-20  |  3.0 KB  |  100 lines

  1. <?php
  2. /* 
  3. V4.21 20 Mar 2004  (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights reserved.
  4.   Released under both BSD license and Lesser GPL library license. 
  5.   Whenever there is any discrepancy between the two licenses, 
  6.   the BSD license will take precedence. See License.txt. 
  7.   Set tabs to 4 for best viewing.
  8.   
  9.   Latest version is available at http://php.weblogs.com/
  10.   
  11.   Library for basic performance monitoring and tuning 
  12.   
  13. */
  14.  
  15.  
  16. // Simple guide to configuring db2: so-so http://www.devx.com/gethelpon/10MinuteSolution/16575
  17.  
  18. // SELECT * FROM TABLE(SNAPSHOT_APPL('SAMPLE', -1)) as t
  19. class perf_db2 extends adodb_perf{
  20.     var $createTableSQL = "CREATE TABLE adodb_logsql (
  21.           created TIMESTAMP NOT NULL,
  22.           sql0 varchar(250) NOT NULL,
  23.           sql1 varchar(4000) NOT NULL,
  24.           params varchar(3000) NOT NULL,
  25.           tracer varchar(500) NOT NULL,
  26.           timer decimal(16,6) NOT NULL
  27.         )";
  28.         
  29.     var $settings = array(
  30.     'Ratios',
  31.         'data cache hit ratio' => array('RATIO',
  32.             "SELECT 
  33.                 case when sum(POOL_DATA_L_READS+POOL_INDEX_L_READS)=0 then 0 
  34.                 else 100*(1-sum(POOL_DATA_P_READS+POOL_INDEX_P_READS)/sum(POOL_DATA_L_READS+POOL_INDEX_L_READS)) end 
  35.                 FROM TABLE(SNAPSHOT_APPL('',-2)) as t",
  36.             '=WarnCacheRatio'),
  37.             
  38.     'Data Cache',
  39.         'data cache buffers' => array('DATAC',
  40.         'select sum(npages) from SYSCAT.BUFFERPOOLS',
  41.             'See <a href=http://www7b.boulder.ibm.com/dmdd/library/techarticle/anshum/0107anshum.html#bufferpoolsize>tuning reference</a>.' ),
  42.         'cache blocksize' => array('DATAC',
  43.         'select avg(pagesize) from SYSCAT.BUFFERPOOLS',
  44.             '' ),
  45.         'data cache size' => array('DATAC',
  46.         'select sum(npages*pagesize) from SYSCAT.BUFFERPOOLS',
  47.             '' ),
  48.     'Connections',
  49.         'current connections' => array('SESS',
  50.             "SELECT count(*) FROM TABLE(SNAPSHOT_APPL_INFO('',-2)) as t",
  51.             ''),
  52.  
  53.         false
  54.     );
  55.  
  56.  
  57.     function perf_db2(&$conn)
  58.     {
  59.         $this->conn =& $conn;
  60.     }
  61.     
  62.     function Explain($sql,$partial=false)
  63.     {
  64.         $save = $this->conn->LogSQL(false);
  65.         if ($partial) {
  66.             $sqlq = $this->conn->qstr($sql.'%');
  67.             $arr = $this->conn->GetArray("select distinct sql1 from adodb_logsql where sql1 like $sqlq");
  68.             if ($arr) {
  69.                 foreach($arr as $row) {
  70.                     $sql = reset($row);
  71.                     if (crc32($sql) == $partial) break;
  72.                 }
  73.             }
  74.         }
  75.         $qno = rand();
  76.         $ok = $this->conn->Execute("EXPLAIN PLAN SET QUERYNO=$qno FOR $sql");
  77.         ob_start();
  78.         if (!$ok) echo "<p>Have EXPLAIN tables been created?</p>";
  79.         else {
  80.             $rs = $this->conn->Execute("select * from explain_statement where queryno=$qno");
  81.             if ($rs) rs2html($rs);
  82.         }
  83.         $s = ob_get_contents();
  84.         ob_end_clean();
  85.         $this->conn->LogSQL($save);
  86.         
  87.         $s .= $this->Tracer($sql);
  88.         return $s;
  89.     }
  90.     
  91.     
  92.     function Tables()
  93.     {
  94.         $rs = $this->conn->Execute("select tabschema,tabname,card as rows,
  95.             npages pages_used,fpages pages_allocated, tbspace tablespace  
  96.             from syscat.tables where tabschema not in ('SYSCAT','SYSIBM','SYSSTAT') order by 1,2");
  97.         return rs2html($rs,false,false,false,false);
  98.     }
  99. }
  100. ?>