[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/joomla/database/src/Monitor/ -> DebugMonitor.php (source)

   1  <?php
   2  /**
   3   * Part of the Joomla Framework Database Package
   4   *
   5   * @copyright  Copyright (C) 2005 - 2021 Open Source Matters, Inc. All rights reserved.
   6   * @license    GNU General Public License version 2 or later; see LICENSE
   7   */
   8  
   9  namespace Joomla\Database\Monitor;
  10  
  11  use Joomla\Database\QueryMonitorInterface;
  12  
  13  /**
  14   * Query monitor handling logging of queries.
  15   *
  16   * @since  2.0.0
  17   */
  18  final class DebugMonitor implements QueryMonitorInterface
  19  {
  20      /**
  21       * The log of executed SQL statements call stacks by the database driver.
  22       *
  23       * @var    array
  24       * @since  2.0.0
  25       */
  26      private $callStacks = [];
  27  
  28      /**
  29       * The log of executed SQL statements by the database driver.
  30       *
  31       * @var    array
  32       * @since  2.0.0
  33       */
  34      private $logs = [];
  35  
  36      /**
  37       * List of bound params, used with the query.
  38       *
  39       * @var    array
  40       * @since  2.0.0
  41       */
  42      private $boundParams = [];
  43  
  44      /**
  45       * The log of executed SQL statements memory usage (start and stop memory_get_usage) by the database driver.
  46       *
  47       * @var    array
  48       * @since  2.0.0
  49       */
  50      private $memoryLogs = [];
  51  
  52      /**
  53       * The log of executed SQL statements timings (start and stop microtimes) by the database driver.
  54       *
  55       * @var    array
  56       * @since  2.0.0
  57       */
  58      private $timings = [];
  59  
  60      /**
  61       * Act on a query being started.
  62       *
  63       * @param   string         $sql           The SQL to be executed.
  64       * @param   object[]|null  $boundParams   List of bound params, used with the query.
  65       *                                        Each item is an object that holds: value, dataType
  66       *
  67       * @return  void
  68       *
  69       * @since   2.0.0
  70       */
  71  	public function startQuery(string $sql, ?array $boundParams = null): void
  72      {
  73          $this->logs[]        = $sql;
  74  
  75          // Dereference bound parameters to prevent reporting wrong value when reusing the same query object.
  76          $this->boundParams[] = unserialize(serialize($boundParams));
  77  
  78          $this->callStacks[]  = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
  79          $this->memoryLogs[]  = memory_get_usage();
  80          $this->timings[]     = microtime(true);
  81      }
  82  
  83      /**
  84       * Act on a query being stopped.
  85       *
  86       * @return  void
  87       *
  88       * @since   2.0.0
  89       */
  90  	public function stopQuery(): void
  91      {
  92          $this->timings[]    = microtime(true);
  93          $this->memoryLogs[] = memory_get_usage();
  94      }
  95  
  96      /**
  97       * Get the logged call stacks.
  98       *
  99       * @return  array
 100       *
 101       * @since   2.0.0
 102       */
 103  	public function getCallStacks(): array
 104      {
 105          return $this->callStacks;
 106      }
 107  
 108      /**
 109       * Get the logged queries.
 110       *
 111       * @return  array
 112       *
 113       * @since   2.0.0
 114       */
 115  	public function getLogs(): array
 116      {
 117          return $this->logs;
 118      }
 119  
 120      /**
 121       * Get the logged bound params.
 122       *
 123       * @return  array
 124       *
 125       * @since   2.0.0
 126       */
 127  	public function getBoundParams(): array
 128      {
 129          return $this->boundParams;
 130      }
 131  
 132      /**
 133       * Get the logged memory logs.
 134       *
 135       * @return  array
 136       *
 137       * @since   2.0.0
 138       */
 139  	public function getMemoryLogs(): array
 140      {
 141          return $this->memoryLogs;
 142      }
 143  
 144      /**
 145       * Get the logged timings.
 146       *
 147       * @return  array
 148       *
 149       * @since   2.0.0
 150       */
 151  	public function getTimings(): array
 152      {
 153          return $this->timings;
 154      }
 155  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer