Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

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