MediaWiki  1.28.1
XhprofDataTest.php
Go to the documentation of this file.
1 <?php
28 class XhprofDataTest extends PHPUnit_Framework_TestCase {
29 
34  public function testSplitKey( $key, $expect ) {
35  $this->assertSame( $expect, XhprofData::splitKey( $key ) );
36  }
37 
38  public function provideSplitKey() {
39  return [
40  [ 'main()', [ null, 'main()' ] ],
41  [ 'foo==>bar', [ 'foo', 'bar' ] ],
42  [ 'bar@1==>bar@2', [ 'bar@1', 'bar@2' ] ],
43  [ 'foo==>bar==>baz', [ 'foo', 'bar==>baz' ] ],
44  [ '==>bar', [ '', 'bar' ] ],
45  [ '', [ null, '' ] ],
46  ];
47  }
48 
52  public function testInclude() {
53  $xhprofData = $this->getXhprofDataFixture( [
54  'include' => [ 'main()' ],
55  ] );
56  $raw = $xhprofData->getRawData();
57  $this->assertArrayHasKey( 'main()', $raw );
58  $this->assertArrayHasKey( 'main()==>foo', $raw );
59  $this->assertArrayHasKey( 'main()==>xhprof_disable', $raw );
60  $this->assertSame( 3, count( $raw ) );
61  }
62 
71  public function testInclusiveMetricsStructure() {
72  $metricStruct = [
73  'ct' => 'int',
74  'wt' => 'array',
75  'cpu' => 'array',
76  'mu' => 'array',
77  'pmu' => 'array',
78  ];
79  $statStruct = [
80  'total' => 'numeric',
81  'min' => 'numeric',
82  'mean' => 'numeric',
83  'max' => 'numeric',
84  'variance' => 'numeric',
85  'percent' => 'numeric',
86  ];
87 
88  $xhprofData = $this->getXhprofDataFixture();
89  $metrics = $xhprofData->getInclusiveMetrics();
90 
91  foreach ( $metrics as $name => $metric ) {
92  $this->assertArrayStructure( $metricStruct, $metric );
93 
94  foreach ( $metricStruct as $key => $type ) {
95  if ( $type === 'array' ) {
96  $this->assertArrayStructure( $statStruct, $metric[$key] );
97  if ( $name === 'main()' ) {
98  $this->assertEquals( 100, $metric[$key]['percent'] );
99  }
100  }
101  }
102  }
103  }
104 
113  public function testCompleteMetricsStructure() {
114  $metricStruct = [
115  'ct' => 'int',
116  'wt' => 'array',
117  'cpu' => 'array',
118  'mu' => 'array',
119  'pmu' => 'array',
120  'calls' => 'array',
121  'subcalls' => 'array',
122  ];
123  $statsMetrics = [ 'wt', 'cpu', 'mu', 'pmu' ];
124  $statStruct = [
125  'total' => 'numeric',
126  'min' => 'numeric',
127  'mean' => 'numeric',
128  'max' => 'numeric',
129  'variance' => 'numeric',
130  'percent' => 'numeric',
131  'exclusive' => 'numeric',
132  ];
133 
134  $xhprofData = $this->getXhprofDataFixture();
135  $metrics = $xhprofData->getCompleteMetrics();
136 
137  foreach ( $metrics as $name => $metric ) {
138  $this->assertArrayStructure( $metricStruct, $metric, $name );
139 
140  foreach ( $metricStruct as $key => $type ) {
141  if ( in_array( $key, $statsMetrics ) ) {
142  $this->assertArrayStructure(
143  $statStruct, $metric[$key], $key
144  );
145  $this->assertLessThanOrEqual(
146  $metric[$key]['total'], $metric[$key]['exclusive']
147  );
148  }
149  }
150  }
151  }
152 
158  public function testEdges() {
159  $xhprofData = $this->getXhprofDataFixture();
160  $this->assertSame( [], $xhprofData->getCallers( 'main()' ) );
161  $this->assertSame( [ 'foo', 'xhprof_disable' ],
162  $xhprofData->getCallees( 'main()' )
163  );
164  $this->assertSame( [ 'main()' ],
165  $xhprofData->getCallers( 'foo' )
166  );
167  $this->assertSame( [], $xhprofData->getCallees( 'strlen' ) );
168  }
169 
174  public function testCriticalPath() {
175  $xhprofData = $this->getXhprofDataFixture();
176  $path = $xhprofData->getCriticalPath();
177 
178  $last = null;
179  foreach ( $path as $key => $value ) {
180  list( $func, $call ) = XhprofData::splitKey( $key );
181  $this->assertSame( $last, $func );
182  $last = $call;
183  }
184  $this->assertSame( $last, 'bar@1' );
185  }
186 
215  protected function getXhprofDataFixture( array $opts = [] ) {
216  return new XhprofData( [
217  'foo==>bar' => [
218  'ct' => 2,
219  'wt' => 57,
220  'cpu' => 92,
221  'mu' => 1896,
222  'pmu' => 0,
223  ],
224  'foo==>strlen' => [
225  'ct' => 2,
226  'wt' => 21,
227  'cpu' => 141,
228  'mu' => 752,
229  'pmu' => 0,
230  ],
231  'bar==>bar@1' => [
232  'ct' => 1,
233  'wt' => 18,
234  'cpu' => 19,
235  'mu' => 752,
236  'pmu' => 0,
237  ],
238  'main()==>foo' => [
239  'ct' => 1,
240  'wt' => 304,
241  'cpu' => 307,
242  'mu' => 4008,
243  'pmu' => 0,
244  ],
245  'main()==>xhprof_disable' => [
246  'ct' => 1,
247  'wt' => 8,
248  'cpu' => 10,
249  'mu' => 768,
250  'pmu' => 392,
251  ],
252  'main()' => [
253  'ct' => 1,
254  'wt' => 353,
255  'cpu' => 351,
256  'mu' => 6112,
257  'pmu' => 1424,
258  ],
259  ], $opts );
260  }
261 
269  protected function assertArrayStructure( $struct, $actual, $label = null ) {
270  $this->assertInternalType( 'array', $actual, $label );
271  $this->assertCount( count( $struct ), $actual, $label );
272  foreach ( $struct as $key => $type ) {
273  $this->assertArrayHasKey( $key, $actual );
274  $this->assertInternalType( $type, $actual[$key] );
275  }
276  }
277 }
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
Definition: deferred.txt:11
the array() calling protocol came about after MediaWiki 1.4rc1.
testCriticalPath()
XhprofData::getCriticalPath XhprofData.
$value
assertArrayStructure($struct, $actual, $label=null)
Assert that the given array has the described structure.
testInclusiveMetricsStructure()
Validate the structure of data returned by Xhprof::getInclusiveMetrics().
$last
getXhprofDataFixture(array $opts=[])
Get an Xhprof instance that has been primed with a set of known testing data.
testSplitKey($key, $expect)
XhprofData::splitKey provideSplitKey.
XhprofData AutoLoader
testCompleteMetricsStructure()
Validate the structure of data returned by Xhprof::getCompleteMetrics().
Convenience class for working with XHProf profiling data https://github.com/phacility/xhprof.
Definition: XhprofData.php:32
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
Definition: distributors.txt:9
testInclude()
XhprofData::pruneData.
testEdges()
XhprofData::getCallers XhprofData::getCallees XhprofData.
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
Definition: injection.txt:35
static splitKey($key)
Convert an xhprof data key into an array of ['parent', 'child'] function names.
Definition: XhprofData.php:113
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
Definition: hooks.txt:2491
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:300