74 $this->config = array_merge(
84 xhprof_enable( $this->config[
'flags'], [
85 'ignored_functions' => $this->config[
'exclude']
99 if ( $this->hieraData === null ) {
100 $this->hieraData = $this->
pruneData( xhprof_disable() );
118 $this->inclusive = null;
120 $this->hieraData = $this->
pruneData( $data );
154 return $this->
stop();
167 return array_pad( explode(
'==>',
$key, 2 ), -2, null );
178 if ( !$this->config[
'include'] ) {
182 $want = array_fill_keys( $this->config[
'include'],
true );
183 $want[
'main()'] =
true;
186 foreach ( $data
as $key => $stats ) {
187 list( $parent, $child ) = self::splitKey(
$key );
188 if ( isset( $want[$parent] ) || isset( $want[$child] ) ) {
189 $keep[
$key] = $stats;
217 if ( $this->inclusive === null ) {
221 $main = $this->hieraData[
'main()'];
222 $hasCpu = isset( $main[
'cpu'] );
223 $hasMu = isset( $main[
'mu'] );
224 $hasAlloc = isset( $main[
'alloc'] );
226 $this->inclusive = [];
227 foreach ( $this->hieraData
as $key => $stats ) {
228 list( $parent, $child ) = self::splitKey(
$key );
229 if ( !isset( $this->inclusive[$child] ) ) {
230 $this->inclusive[$child] = [
232 'wt' =>
new RunningStat(),
235 $this->inclusive[$child][
'cpu'] =
new RunningStat();
238 $this->inclusive[$child][
'mu'] =
new RunningStat();
239 $this->inclusive[$child][
'pmu'] =
new RunningStat();
242 $this->inclusive[$child][
'alloc'] =
new RunningStat();
243 $this->inclusive[$child][
'free'] =
new RunningStat();
247 $this->inclusive[$child][
'ct'] += $stats[
'ct'];
248 foreach ( $stats
as $stat =>
$value ) {
249 if ( $stat ===
'ct' ) {
253 if ( !isset( $this->inclusive[$child][$stat] ) ) {
258 for ( $i = 0; $i < $stats[
'ct']; $i++ ) {
259 $this->inclusive[$child][$stat]->addObservation(
268 foreach ( $this->inclusive
as $func => $stats ) {
270 if (
$value instanceof RunningStat ) {
272 $percent = ( isset( $main[
$name] ) && $main[
$name] )
273 ? 100 * $total / $main[$name]
275 $this->inclusive[$func][
$name] = [
281 'percent' => $percent,
287 uasort( $this->inclusive, self::makeSortFunction(
288 $this->config[
'sort'],
'total'
313 foreach ( $this->
complete as $func => $stats ) {
314 foreach ( $stats
as $stat =>
$value ) {
315 if ( $stat ===
'ct' ) {
322 $this->
complete[$func][
'calls'] = [];
323 $this->
complete[$func][
'subcalls'] = [];
326 foreach ( $this->hieraData
as $key => $stats ) {
327 list( $parent, $child ) = self::splitKey(
$key );
328 if ( $parent !== null ) {
330 $this->
complete[$child][
'calls'][$parent] = $stats;
331 $this->
complete[$parent][
'subcalls'][$child] = $stats;
334 if ( isset( $this->
complete[$parent] ) ) {
336 foreach ( $stats
as $stat =>
$value ) {
337 if ( $stat ===
'ct' ) {
341 if ( !isset( $this->
complete[$parent][$stat] ) ) {
351 uasort( $this->
complete, self::makeSortFunction(
352 $this->config[
'sort'],
'exclusive'
367 if ( isset( $edges[$function][
'calls'] ) ) {
368 return array_keys( $edges[$function][
'calls'] );
383 if ( isset( $edges[$function][
'subcalls'] ) ) {
384 return array_keys( $edges[$function][
'subcalls'] );
400 $func => $this->hieraData[$func],
406 foreach ( $callees
as $callee ) {
407 $call =
"{$func}==>{$callee}";
408 if ( $maxCall === null ||
409 $this->hieraData[$call][$metric] >
410 $this->hieraData[$maxCall][$metric]
412 $maxCallee = $callee;
416 if ( $maxCall !== null ) {
417 $path[$maxCall] = $this->hieraData[$maxCall];
433 return function ( $a, $b )
use (
$key, $sub ) {
434 if ( isset( $a[
$key] ) && isset( $b[$key] ) ) {
438 $valA = is_array( $a[$key] ) ? $a[
$key][$sub] : $a[
$key];
439 $valB = is_array( $b[$key] ) ? $b[
$key][$sub] : $b[
$key];
440 return $valB - $valA;
443 return isset( $a[$key] ) ? -1 : 1;
Convenience class for working with XHProf https://github.com/phacility/xhprof.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
stop()
Stop collecting profiling data.
the array() calling protocol came about after MediaWiki 1.4rc1.
magic word the default is to use $key to get the and $key value or $key value text $key value html to format the value $key
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
getCompleteMetrics()
Get the inclusive and exclusive metrics for each function call.
getRawData()
Get raw data collected by xhprof.
static makeSortFunction($key, $sub)
Make a closure to use as a sort function.
getCallees($function)
Get a list of all callees from a given function.
__construct(array $config=[])
Configuration data can contain:
static splitKey($key)
Convert an xhprof data key into an array of ['parent', 'child'] function names.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
pruneData($data)
Remove data for functions that are not included in the 'include' configuration array.
loadRawData(array $data)
Load raw data from a prior run for analysis.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
$complete
Per-function inclusive and exclusive data.
getInclusiveMetrics()
Get the inclusive metrics for each function call.
$inclusive
Per-function inclusive data.
Returning false makes less sense for events where the action is complete
getCriticalPath($metric= 'wt')
Find the critical path for the given metric.
$hieraData
Hierarchical profiling data returned by xhprof.
getCallers($function)
Get a list of all callers of a given function.
Allows to change the fields on the form that will be generated $name