X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fprofiler%2FProfilerXhprof.php;h=5f7fc0028a0bd4e9bb51b87015c9b7b4f073a995;hb=f63e30ae50fe9ea91cc609d6352d0069f375bb78;hp=64d2de71be301643fefdfe344b662bab0acdde2f;hpb=152cd9e470b104284394ecf35eb085425ef57654;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/profiler/ProfilerXhprof.php b/includes/profiler/ProfilerXhprof.php index 64d2de71be..5f7fc0028a 100644 --- a/includes/profiler/ProfilerXhprof.php +++ b/includes/profiler/ProfilerXhprof.php @@ -34,19 +34,14 @@ * $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 - * ($wgProfiler['exclude']) containing an array of function names. The - * blacklist functionality is built into HHVM and will completely exclude the - * named functions from profiling collection. The whitelist is implemented by - * Xhprof class which will filter the data collected by XHProf before reporting. - * See documentation for the Xhprof class and the XHProf extension for - * additional information. + * ($wgProfiler['exclude']) containing an array of function names. + * Shell-style patterns are also accepted. * * @author Bryan Davis * @copyright © 2014 Bryan Davis and Wikimedia Foundation. @@ -77,36 +72,43 @@ class ProfilerXhprof extends Profiler { $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 ) { + public function scopedProfileIn( $section ) { + $key = 'section.' . ltrim( $section, '.' ); + return $this->sprofiler->scopedProfileIn( $key ); } /** * 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 ); + public function close() { } /** - * No-op for xhprof profiling. + * Check if a function or section should be excluded from the output. + * + * @param string $name Function or section name. + * @return bool */ - public function close() { + private function shouldExclude( $name ) { + if ( $name === '-total' ) { + return true; + } + if ( !empty( $this->params['include'] ) ) { + foreach ( $this->params['include'] as $pattern ) { + if ( fnmatch( $pattern, $name, FNM_NOESCAPE ) ) { + return false; + } + } + return true; + } + if ( !empty( $this->params['exclude'] ) ) { + foreach ( $this->params['exclude'] as $pattern ) { + if ( fnmatch( $pattern, $name, FNM_NOESCAPE ) ) { + return true; + } + } + } + return false; } public function getFunctionStats() { @@ -115,6 +117,9 @@ class ProfilerXhprof extends Profiler { $main = null; // units in ms foreach ( $metrics as $fname => $stats ) { + if ( $this->shouldExclude( $fname ) ) { + continue; + } // Convert elapsed times from μs to ms to match interface $entry = array( 'name' => $fname, @@ -136,8 +141,7 @@ class ProfilerXhprof extends Profiler { // Merge in all of the custom profile sections foreach ( $this->sprofiler->getFunctionStats() as $stats ) { - if ( $stats['name'] === '-total' ) { - // Discard section profiler running totals + if ( $this->shouldExclude( $stats['name'] ) ) { continue; } @@ -206,4 +210,12 @@ class ProfilerXhprof extends Profiler { } return implode( "\n", $out ); } + + /** + * Retrieve raw data from xhprof + * @return array + */ + public function getRawData() { + return $this->xhprof->getRawData(); + } }