PageRenderTime 39ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/adodb/perf/perf-db2.inc.php

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