[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/profiler/ -> ProfilerSimpleDB.php (source)

   1  <?php
   2  /**
   3   * Profiler storing information in the DB.
   4   *
   5   * This program is free software; you can redistribute it and/or modify
   6   * it under the terms of the GNU General Public License as published by
   7   * the Free Software Foundation; either version 2 of the License, or
   8   * (at your option) any later version.
   9   *
  10   * This program is distributed in the hope that it will be useful,
  11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13   * GNU General Public License for more details.
  14   *
  15   * You should have received a copy of the GNU General Public License along
  16   * with this program; if not, write to the Free Software Foundation, Inc.,
  17   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18   * http://www.gnu.org/copyleft/gpl.html
  19   *
  20   * @file
  21   * @ingroup Profiler
  22   */
  23  
  24  /**
  25   * $wgProfiler['class'] = 'ProfilerSimpleDB';
  26   *
  27   * @ingroup Profiler
  28   */
  29  class ProfilerSimpleDB extends ProfilerStandard {
  30  	protected function collateOnly() {
  31          return true;
  32      }
  33  
  34  	public function isPersistent() {
  35          return true;
  36      }
  37  
  38      /**
  39       * Log the whole profiling data into the database.
  40       */
  41  	public function logData() {
  42          global $wgProfilePerHost;
  43  
  44          # Do not log anything if database is readonly (bug 5375)
  45          if ( wfReadOnly() ) {
  46              return;
  47          }
  48  
  49          if ( $wgProfilePerHost ) {
  50              $pfhost = wfHostname();
  51          } else {
  52              $pfhost = '';
  53          }
  54  
  55          try {
  56              $this->collateData();
  57  
  58              $dbw = wfGetDB( DB_MASTER );
  59              $useTrx = ( $dbw->getType() === 'sqlite' ); // much faster
  60              if ( $useTrx ) {
  61                  $dbw->startAtomic( __METHOD__ );
  62              }
  63              foreach ( $this->mCollated as $name => $data ) {
  64                  $eventCount = $data['count'];
  65                  $timeSum = (float)( $data['real'] * 1000 );
  66                  $memorySum = (float)$data['memory'];
  67                  $name = substr( $name, 0, 255 );
  68  
  69                  // Kludge
  70                  $timeSum = $timeSum >= 0 ? $timeSum : 0;
  71                  $memorySum = $memorySum >= 0 ? $memorySum : 0;
  72  
  73                  $dbw->update( 'profiling',
  74                      array(
  75                          "pf_count=pf_count+{$eventCount}",
  76                          "pf_time=pf_time+{$timeSum}",
  77                          "pf_memory=pf_memory+{$memorySum}",
  78                      ),
  79                      array(
  80                          'pf_name' => $name,
  81                          'pf_server' => $pfhost,
  82                      ),
  83                      __METHOD__ );
  84  
  85                  $rc = $dbw->affectedRows();
  86                  if ( $rc == 0 ) {
  87                      $dbw->insert( 'profiling',
  88                          array(
  89                              'pf_name' => $name,
  90                              'pf_count' => $eventCount,
  91                              'pf_time' => $timeSum,
  92                              'pf_memory' => $memorySum,
  93                              'pf_server' => $pfhost
  94                          ),
  95                          __METHOD__,
  96                          array( 'IGNORE' )
  97                      );
  98                  }
  99                  // When we upgrade to mysql 4.1, the insert+update
 100                  // can be merged into just a insert with this construct added:
 101                  //     "ON DUPLICATE KEY UPDATE ".
 102                  //     "pf_count=pf_count + VALUES(pf_count), ".
 103                  //     "pf_time=pf_time + VALUES(pf_time)";
 104              }
 105              if ( $useTrx ) {
 106                  $dbw->endAtomic( __METHOD__ );
 107              }
 108          } catch ( DBError $e ) {
 109          }
 110      }
 111  }


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1