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