*/
class ProfilerXhprof extends Profiler {
/**
- * @var Xhprof $xhprof
+ * @var XhprofData|null $xhprofData
*/
- protected $xhprof;
+ protected $xhprofData;
/**
* Profiler for explicit, arbitrary, frame labels
*/
public function __construct( array $params = [] ) {
parent::__construct( $params );
- $this->xhprof = new Xhprof( $params );
+
+ $flags = isset( $params['flags'] ) ? $params['flags'] : 0;
+ $options = isset( $params['exclude'] )
+ ? [ 'ignored_functions' => $params['exclude'] ] : [];
+ Xhprof::enable( $flags, $options );
$this->sprofiler = new SectionProfiler();
}
+ /**
+ * @return XhprofData
+ */
+ public function getXhprofData() {
+ if ( !$this->xhprofData ) {
+ $this->xhprofData = new XhprofData( Xhprof::disable(), $this->params );
+ }
+ return $this->xhprofData;
+ }
+
public function scopedProfileIn( $section ) {
$key = 'section.' . ltrim( $section, '.' );
return $this->sprofiler->scopedProfileIn( $key );
}
public function getFunctionStats() {
- $metrics = $this->xhprof->getCompleteMetrics();
+ $metrics = $this->getXhprofData()->getCompleteMetrics();
$profile = [];
$main = null; // units in ms
* @return array
*/
public function getRawData() {
- return $this->xhprof->getRawData();
+ return $this->getXhprofData()->getRawData();
}
}