$totalProf = '';
$isMaster = !is_null( $this->getLBInfo( 'master' ) );
- if ( !Profiler::instance()->isStub() ) {
+ $profiler = Profiler::instance();
+ if ( !$profiler->isStub() ) {
# generalizeSQL will probably cut down the query to reasonable
# logging size most of the time. The substr is really just a sanity check.
if ( $isMaster ) {
# Include query transaction state
$queryProf .= $this->mTrxShortId ? " [TRX#{$this->mTrxShortId}]" : "";
- wfProfileIn( $totalProf );
- wfProfileIn( $queryProf );
+ $totalProfSection = $profiler->scopedProfileIn( $totalProf );
+ $queryProfSection = $profiler->scopedProfileIn( $queryProf );
}
if ( $this->debug() ) {
$this->reportQueryError( $this->lastError(), $this->lastErrno(), $sql, $fname, $tempIgnore );
}
- if ( !Profiler::instance()->isStub() ) {
- wfProfileOut( $queryProf );
- wfProfileOut( $totalProf );
- }
-
return $this->resultObject( $ret );
}
*/
abstract public function profileOut( $functionname );
+ /**
+ * Mark the start of a custom profiling frame (e.g. DB queries).
+ * The frame ends when the result of this method falls out of scope.
+ *
+ * @param string $section
+ * @return ScopedCallback|null
+ * @since 1.25
+ */
+ abstract public function scopedProfileIn( $section );
+
+ /**
+ * @param ScopedCallback $section
+ */
+ public function scopedProfileOut( ScopedCallback &$section ) {
+ $section = null;
+ }
+
/**
* @return TransactionProfiler
* @since 1.25
}
}
+ public function scopedProfileIn( $section ) {
+ $this->profileIn( $section );
+
+ $that = $this;
+ return new ScopedCallback( function() use ( $that, $section ) {
+ $that->profileOut( $section );
+ } );
+ }
+
/**
* Close opened profiling sections
*/
public function profileOut( $fn ) {
}
+ public function scopedProfileIn( $section ) {
+ return null;
+ }
+
public function getFunctionStats() {
}
public function profileOut( $functionname ) {
}
+ public function scopedProfileIn( $section ) {
+ static $exists = null;
+ // Only HHVM supports this, not the standard PECL extension
+ if ( $exists === null ) {
+ $exists = function_exists( 'xhprof_frame_begin' );
+ }
+
+ if ( $exists ) {
+ xhprof_frame_begin( $section );
+ return new ScopedCallback( function() use ( $section ) {
+ xhprof_frame_end( $section );
+ } );
+ }
+
+ return null;
+ }
+
/**
* No-op for xhprof profiling.
*/