/**
* Profiler wrapper for XHProf extension.
*
- * Mimics the output of ProfilerStandard using data collected via the XHProf
- * PHP extension.
- *
* @code
* $wgProfiler['class'] = 'ProfilerXhprof';
* $wgProfiler['flags'] = XHPROF_FLAGS_NO_BUILTINS;
* $wgProfiler['output'] = 'udp';
* @endcode
*
- * Rather than obeying wfProfileIn() and wfProfileOut() calls placed in the
- * application code, ProfilerXhprof profiles all functions using the XHProf
- * PHP extenstion. For PHP5 users, this extension can be installed via PECL or
- * your operating system's package manager. XHProf support is built into HHVM.
+ * ProfilerXhprof profiles all functions using the XHProf PHP extenstion.
+ * For PHP5 users, this extension can be installed via PECL or your operating
+ * system's package manager. XHProf support is built into HHVM.
*
* To restrict the functions for which profiling data is collected, you can
* use either a whitelist ($wgProfiler['include']) or a blacklist
$this->sprofiler = new SectionProfiler();
}
- /**
- * No-op for xhprof profiling.
- *
- * Use the 'include' configuration key instead if you need to constrain
- * the functions that are profiled.
- *
- * @param string $functionname
- */
- public function profileIn( $functionname ) {
- }
-
- /**
- * No-op for xhprof profiling.
- *
- * Use the 'include' configuration key instead if you need to constrain
- * the functions that are profiled.
- *
- * @param string $functionname
- */
- public function profileOut( $functionname ) {
- }
-
public function scopedProfileIn( $section ) {
return $this->sprofiler->scopedProfileIn( $section );
}
$main = null; // units in ms
foreach ( $metrics as $fname => $stats ) {
- // Convert elapsed times from μs to ms to match ProfilerStandard
+ // Convert elapsed times from μs to ms to match interface
$entry = array(
'name' => $fname,
'calls' => $stats['ct'],
// Merge in all of the custom profile sections
foreach ( $this->sprofiler->getFunctionStats() as $stats ) {
+ if ( $stats['name'] === '-total' ) {
+ // Discard section profiler running totals
+ continue;
+ }
+
// @note: getFunctionStats() values already in ms
- $stats['%real'] = $stats['real'] / $main['real'];
+ $stats['%real'] = $main['real'] ? $stats['real'] / $main['real'] * 100 : 0;
$stats['%cpu'] = $main['cpu'] ? $stats['cpu'] / $main['cpu'] * 100 : 0;
$stats['%memory'] = $main['memory'] ? $stats['memory'] / $main['memory'] * 100 : 0;
$profile[] = $stats; // assume no section names collide with $metrics
}
return implode( "\n", $out );
}
+
+ /**
+ * Retrieve raw data from xhprof
+ * @return array
+ */
+ public function getRawData() {
+ return $this->xhprof->getRawData();
+ }
}