Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402]

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