[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/lib/adodb/perf/ -> perf-db2.inc.php (source)

   1  <?php
   2  /*
   3  V5.19  23-Apr-2014  (c) 2000-2014 John Lim (jlim#natsoft.com). 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://adodb.sourceforge.net
  10  
  11    Library for basic performance monitoring and tuning
  12  
  13  */
  14  
  15  // security - hide paths
  16  if (!defined('ADODB_DIR')) die();
  17  
  18  // Simple guide to configuring db2: so-so http://www.devx.com/gethelpon/10MinuteSolution/16575
  19  
  20  // SELECT * FROM TABLE(SNAPSHOT_APPL('SAMPLE', -1)) as t
  21  class perf_db2 extends adodb_perf{
  22      var $createTableSQL = "CREATE TABLE adodb_logsql (
  23            created TIMESTAMP NOT NULL,
  24            sql0 varchar(250) NOT NULL,
  25            sql1 varchar(4000) NOT NULL,
  26            params varchar(3000) NOT NULL,
  27            tracer varchar(500) NOT NULL,
  28            timer decimal(16,6) NOT NULL
  29          )";
  30  
  31      var $settings = array(
  32      'Ratios',
  33          'data cache hit ratio' => array('RATIO',
  34              "SELECT
  35                  case when sum(POOL_DATA_L_READS+POOL_INDEX_L_READS)=0 then 0
  36                  else 100*(1-sum(POOL_DATA_P_READS+POOL_INDEX_P_READS)/sum(POOL_DATA_L_READS+POOL_INDEX_L_READS)) end
  37                  FROM TABLE(SNAPSHOT_APPL('',-2)) as t",
  38              '=WarnCacheRatio'),
  39  
  40      'Data Cache',
  41          'data cache buffers' => array('DATAC',
  42          'select sum(npages) from SYSCAT.BUFFERPOOLS',
  43              'See <a href=http://www7b.boulder.ibm.com/dmdd/library/techarticle/anshum/0107anshum.html#bufferpoolsize>tuning reference</a>.' ),
  44          'cache blocksize' => array('DATAC',
  45          'select avg(pagesize) from SYSCAT.BUFFERPOOLS',
  46              '' ),
  47          'data cache size' => array('DATAC',
  48          'select sum(npages*pagesize) from SYSCAT.BUFFERPOOLS',
  49              '' ),
  50      'Connections',
  51          'current connections' => array('SESS',
  52              "SELECT count(*) FROM TABLE(SNAPSHOT_APPL_INFO('',-2)) as t",
  53              ''),
  54  
  55          false
  56      );
  57  
  58  
  59  	function perf_db2(&$conn)
  60      {
  61          $this->conn = $conn;
  62      }
  63  
  64  	function Explain($sql,$partial=false)
  65      {
  66          $save = $this->conn->LogSQL(false);
  67          if ($partial) {
  68              $sqlq = $this->conn->qstr($sql.'%');
  69              $arr = $this->conn->GetArray("select distinct sql1 from adodb_logsql where sql1 like $sqlq");
  70              if ($arr) {
  71                  foreach($arr as $row) {
  72                      $sql = reset($row);
  73                      if (crc32($sql) == $partial) break;
  74                  }
  75              }
  76          }
  77          $qno = rand();
  78          $ok = $this->conn->Execute("EXPLAIN PLAN SET QUERYNO=$qno FOR $sql");
  79          ob_start();
  80          if (!$ok) echo "<p>Have EXPLAIN tables been created?</p>";
  81          else {
  82              $rs = $this->conn->Execute("select * from explain_statement where queryno=$qno");
  83              if ($rs) rs2html($rs);
  84          }
  85          $s = ob_get_contents();
  86          ob_end_clean();
  87          $this->conn->LogSQL($save);
  88  
  89          $s .= $this->Tracer($sql);
  90          return $s;
  91      }
  92  
  93      /**
  94       *  Gets a list of tables
  95       *
  96       * @param int $throwaway discarded variable to match the parent method
  97       * @return string The formatted table list
  98       */
  99  	function Tables($throwaway=0)
 100      {
 101          $rs = $this->conn->Execute("select tabschema,tabname,card as rows,
 102              npages pages_used,fpages pages_allocated, tbspace tablespace
 103              from syscat.tables where tabschema not in ('SYSCAT','SYSIBM','SYSSTAT') order by 1,2");
 104          return rs2html($rs,false,false,false,false);
 105      }
 106  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1