MediaWiki
REL1_24
|
00001 <?php 00029 class ProfilerSimpleDB extends ProfilerStandard { 00030 protected function collateOnly() { 00031 return true; 00032 } 00033 00034 public function isPersistent() { 00035 return true; 00036 } 00037 00041 public function logData() { 00042 global $wgProfilePerHost; 00043 00044 # Do not log anything if database is readonly (bug 5375) 00045 if ( wfReadOnly() ) { 00046 return; 00047 } 00048 00049 if ( $wgProfilePerHost ) { 00050 $pfhost = wfHostname(); 00051 } else { 00052 $pfhost = ''; 00053 } 00054 00055 try { 00056 $this->collateData(); 00057 00058 $dbw = wfGetDB( DB_MASTER ); 00059 $useTrx = ( $dbw->getType() === 'sqlite' ); // much faster 00060 if ( $useTrx ) { 00061 $dbw->startAtomic( __METHOD__ ); 00062 } 00063 foreach ( $this->mCollated as $name => $data ) { 00064 $eventCount = $data['count']; 00065 $timeSum = (float)( $data['real'] * 1000 ); 00066 $memorySum = (float)$data['memory']; 00067 $name = substr( $name, 0, 255 ); 00068 00069 // Kludge 00070 $timeSum = $timeSum >= 0 ? $timeSum : 0; 00071 $memorySum = $memorySum >= 0 ? $memorySum : 0; 00072 00073 $dbw->update( 'profiling', 00074 array( 00075 "pf_count=pf_count+{$eventCount}", 00076 "pf_time=pf_time+{$timeSum}", 00077 "pf_memory=pf_memory+{$memorySum}", 00078 ), 00079 array( 00080 'pf_name' => $name, 00081 'pf_server' => $pfhost, 00082 ), 00083 __METHOD__ ); 00084 00085 $rc = $dbw->affectedRows(); 00086 if ( $rc == 0 ) { 00087 $dbw->insert( 'profiling', 00088 array( 00089 'pf_name' => $name, 00090 'pf_count' => $eventCount, 00091 'pf_time' => $timeSum, 00092 'pf_memory' => $memorySum, 00093 'pf_server' => $pfhost 00094 ), 00095 __METHOD__, 00096 array( 'IGNORE' ) 00097 ); 00098 } 00099 // When we upgrade to mysql 4.1, the insert+update 00100 // can be merged into just a insert with this construct added: 00101 // "ON DUPLICATE KEY UPDATE ". 00102 // "pf_count=pf_count + VALUES(pf_count), ". 00103 // "pf_time=pf_time + VALUES(pf_time)"; 00104 } 00105 if ( $useTrx ) { 00106 $dbw->endAtomic( __METHOD__ ); 00107 } 00108 } catch ( DBError $e ) { 00109 } 00110 } 00111 }