MediaWiki  master
ProfilerSectionOnly.php
Go to the documentation of this file.
1 <?php
30  protected $sprofiler;
31 
32  public function __construct( array $params = [] ) {
33  parent::__construct( $params );
34  $this->sprofiler = new SectionProfiler();
35  }
36 
37  public function scopedProfileIn( $section ) {
38  return $this->sprofiler->scopedProfileIn( $section );
39  }
40 
41  public function close() {
42  }
43 
44  public function getFunctionStats() {
45  return $this->sprofiler->getFunctionStats();
46  }
47 
48  public function getOutput() {
49  return $this->getFunctionReport();
50  }
51 
68  protected function getFunctionReport() {
69  $data = $this->getFunctionStats();
70  usort( $data, static function ( $a, $b ) {
71  return $b['real'] <=> $a['real']; // descending
72  } );
73 
74  $width = 140;
75  $nameWidth = $width - 65;
76  $format = "%-{$nameWidth}s %6d %9d %9d %9d %9d %7.3f%% %9d";
77  $out = [];
78  $out[] = sprintf( "%-{$nameWidth}s %6s %9s %9s %9s %9s %7s %9s",
79  'Name', 'Calls', 'Total', 'Min', 'Each', 'Max', '%', 'Mem'
80  );
81  foreach ( $data as $stats ) {
82  $out[] = sprintf( $format,
83  $stats['name'],
84  $stats['calls'],
85  $stats['real'] * 1000,
86  $stats['min_real'] * 1000,
87  $stats['real'] / $stats['calls'] * 1000,
88  $stats['max_real'] * 1000,
89  $stats['%real'],
90  $stats['memory']
91  );
92  }
93  return implode( "\n", $out );
94  }
95 }
ProfilerSectionOnly
Profiler that only tracks explicit profiling sections.
Definition: ProfilerSectionOnly.php:28
ProfilerSectionOnly\getFunctionReport
getFunctionReport()
Get a report of profiled functions sorted by inclusive wall clock time in descending order.
Definition: ProfilerSectionOnly.php:68
Profiler
Profiler base class that defines the interface and some shared functionality.
Definition: Profiler.php:36
SectionProfiler
Arbitrary section name based PHP profiling.
Definition: SectionProfiler.php:35
ProfilerSectionOnly\getFunctionStats
getFunctionStats()
Get the aggregated inclusive profiling data for each method.
Definition: ProfilerSectionOnly.php:44
ProfilerSectionOnly\scopedProfileIn
scopedProfileIn( $section)
Mark the start of a custom profiling frame (e.g.
Definition: ProfilerSectionOnly.php:37
ProfilerSectionOnly\close
close()
Close opened profiling sections.
Definition: ProfilerSectionOnly.php:41
ProfilerSectionOnly\getOutput
getOutput()
Returns a profiling output to be stored in debug file.
Definition: ProfilerSectionOnly.php:48
ProfilerSectionOnly\__construct
__construct(array $params=[])
Definition: ProfilerSectionOnly.php:32
Profiler\$params
array $params
All of the params passed from $wgProfiler.
Definition: Profiler.php:40
ProfilerSectionOnly\$sprofiler
SectionProfiler $sprofiler
Definition: ProfilerSectionOnly.php:30