From: Tim Starling Date: Fri, 7 Dec 2018 04:13:43 +0000 (+1100) Subject: ProfilerExcimer: allow early start X-Git-Tag: 1.34.0-rc.0~3234^2 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmembres/cotisations/gestion/rappel_supprimer.php?a=commitdiff_plain;h=0f1156a3fb180249040b3faf8b4952532eadc697;p=lhc%2Fweb%2Fwiklou.git ProfilerExcimer: allow early start Allow the profiler to be started elsewhere and passed into ProfilerExcimer via the configuration array. This allows the profiler to be started in the auto_prepend_file. XHProf doesn't need this because it has a single global profiler. Change-Id: I348499a15d9cc42de0ba1a20afc2283b794931a3 --- diff --git a/includes/profiler/ProfilerExcimer.php b/includes/profiler/ProfilerExcimer.php index 776136fe4d..20f9a78508 100644 --- a/includes/profiler/ProfilerExcimer.php +++ b/includes/profiler/ProfilerExcimer.php @@ -5,24 +5,40 @@ class ProfilerExcimer extends Profiler { private $realProf; private $period; + /** + * @param array $params Associative array of parameters: + * - period: The sampling period + * - maxDepth: The maximum stack depth collected + * - cpuProfiler: A pre-started ExcimerProfiler instance for CPU + * profiling of the entire request including configuration. + * - realProfiler: A pre-started ExcimerProfiler instance for wall + * clock profiling of the entire request. + */ public function __construct( array $params = [] ) { parent::__construct( $params ); $this->period = $params['period'] ?? 0.01; $maxDepth = $params['maxDepth'] ?? 100; - $this->cpuProf = new ExcimerProfiler; - $this->cpuProf->setEventType( EXCIMER_CPU ); - $this->cpuProf->setPeriod( $this->period ); - $this->cpuProf->setMaxDepth( $maxDepth ); - - $this->realProf = new ExcimerProfiler; - $this->realProf->setEventType( EXCIMER_REAL ); - $this->realProf->setPeriod( $this->period ); - $this->realProf->setMaxDepth( $maxDepth ); + if ( isset( $params['cpuProfiler'] ) ) { + $this->cpuProf = $params['cpuProfiler']; + } else { + $this->cpuProf = new ExcimerProfiler; + $this->cpuProf->setEventType( EXCIMER_CPU ); + $this->cpuProf->setPeriod( $this->period ); + $this->cpuProf->setMaxDepth( $maxDepth ); + $this->cpuProf->start(); + } - $this->cpuProf->start(); - $this->realProf->start(); + if ( isset( $params['realProfiler'] ) ) { + $this->realProf = $params['realProfiler']; + } else { + $this->realProf = new ExcimerProfiler; + $this->realProf->setEventType( EXCIMER_REAL ); + $this->realProf->setPeriod( $this->period ); + $this->realProf->setMaxDepth( $maxDepth ); + $this->realProf->start(); + } } public function scopedProfileIn( $section ) {