Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 30 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| ProfilerSectionOnly | |
0.00% |
0 / 30 |
|
0.00% |
0 / 6 |
56 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| scopedProfileIn | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| close | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getFunctionStats | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getOutput | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getFunctionReport | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | /** |
| 8 | * Profiler that only tracks explicit profiling sections |
| 9 | * |
| 10 | * @ingroup Profiler |
| 11 | * @since 1.25 |
| 12 | * @see $wgProfiler |
| 13 | */ |
| 14 | class ProfilerSectionOnly extends Profiler { |
| 15 | /** @var SectionProfiler */ |
| 16 | protected $sprofiler; |
| 17 | |
| 18 | public function __construct( array $params = [] ) { |
| 19 | parent::__construct( $params ); |
| 20 | $this->sprofiler = new SectionProfiler(); |
| 21 | } |
| 22 | |
| 23 | /** @inheritDoc */ |
| 24 | public function scopedProfileIn( $section ): ?SectionProfileCallback { |
| 25 | return $this->sprofiler->scopedProfileIn( $section ); |
| 26 | } |
| 27 | |
| 28 | public function close() { |
| 29 | } |
| 30 | |
| 31 | /** @inheritDoc */ |
| 32 | public function getFunctionStats() { |
| 33 | return $this->sprofiler->getFunctionStats(); |
| 34 | } |
| 35 | |
| 36 | /** @inheritDoc */ |
| 37 | public function getOutput() { |
| 38 | return $this->getFunctionReport(); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Get a report of profiled functions sorted by inclusive wall clock time |
| 43 | * in descending order. |
| 44 | * |
| 45 | * Each line of the report includes this data: |
| 46 | * - Function name |
| 47 | * - Number of times function was called |
| 48 | * - Total wall clock time spent in function in microseconds |
| 49 | * - Minimum wall clock time spent in function in microseconds |
| 50 | * - Average wall clock time spent in function in microseconds |
| 51 | * - Maximum wall clock time spent in function in microseconds |
| 52 | * - Percentage of total wall clock time spent in function |
| 53 | * - Total delta of memory usage from start to end of function in bytes |
| 54 | * |
| 55 | * @return string |
| 56 | */ |
| 57 | protected function getFunctionReport() { |
| 58 | $data = $this->getFunctionStats(); |
| 59 | usort( $data, static function ( $a, $b ) { |
| 60 | return $b['real'] <=> $a['real']; // descending |
| 61 | } ); |
| 62 | |
| 63 | $width = 140; |
| 64 | $nameWidth = $width - 65; |
| 65 | $format = "%-{$nameWidth}s %6d %9d %9d %9d %9d %7.3f%% %9d"; |
| 66 | $out = []; |
| 67 | $out[] = sprintf( "%-{$nameWidth}s %6s %9s %9s %9s %9s %7s %9s", |
| 68 | 'Name', 'Calls', 'Total', 'Min', 'Each', 'Max', '%', 'Mem' |
| 69 | ); |
| 70 | foreach ( $data as $stats ) { |
| 71 | $out[] = sprintf( $format, |
| 72 | $stats['name'], |
| 73 | $stats['calls'], |
| 74 | $stats['real'] * 1000, |
| 75 | $stats['min_real'] * 1000, |
| 76 | $stats['real'] / $stats['calls'] * 1000, |
| 77 | $stats['max_real'] * 1000, |
| 78 | $stats['%real'], |
| 79 | $stats['memory'] |
| 80 | ); |
| 81 | } |
| 82 | return implode( "\n", $out ); |
| 83 | } |
| 84 | } |