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