MediaWiki  1.33.0
XhprofDataTest.php
Go to the documentation of this file.
1 <?php
25 class XhprofDataTest extends PHPUnit\Framework\TestCase {
26 
27  use MediaWikiCoversValidator;
28 
33  public function testSplitKey( $key, $expect ) {
34  $this->assertSame( $expect, XhprofData::splitKey( $key ) );
35  }
36 
37  public function provideSplitKey() {
38  return [
39  [ 'main()', [ null, 'main()' ] ],
40  [ 'foo==>bar', [ 'foo', 'bar' ] ],
41  [ 'bar@1==>bar@2', [ 'bar@1', 'bar@2' ] ],
42  [ 'foo==>bar==>baz', [ 'foo', 'bar==>baz' ] ],
43  [ '==>bar', [ '', 'bar' ] ],
44  [ '', [ null, '' ] ],
45  ];
46  }
47 
51  public function testInclude() {
52  $xhprofData = $this->getXhprofDataFixture( [
53  'include' => [ 'main()' ],
54  ] );
55  $raw = $xhprofData->getRawData();
56  $this->assertArrayHasKey( 'main()', $raw );
57  $this->assertArrayHasKey( 'main()==>foo', $raw );
58  $this->assertArrayHasKey( 'main()==>xhprof_disable', $raw );
59  $this->assertSame( 3, count( $raw ) );
60  }
61 
70  public function testInclusiveMetricsStructure() {
71  $metricStruct = [
72  'ct' => 'int',
73  'wt' => 'array',
74  'cpu' => 'array',
75  'mu' => 'array',
76  'pmu' => 'array',
77  ];
78  $statStruct = [
79  'total' => 'numeric',
80  'min' => 'numeric',
81  'mean' => 'numeric',
82  'max' => 'numeric',
83  'variance' => 'numeric',
84  'percent' => 'numeric',
85  ];
86 
87  $xhprofData = $this->getXhprofDataFixture();
88  $metrics = $xhprofData->getInclusiveMetrics();
89 
90  foreach ( $metrics as $name => $metric ) {
91  $this->assertArrayStructure( $metricStruct, $metric );
92 
93  foreach ( $metricStruct as $key => $type ) {
94  if ( $type === 'array' ) {
95  $this->assertArrayStructure( $statStruct, $metric[$key] );
96  if ( $name === 'main()' ) {
97  $this->assertEquals( 100, $metric[$key]['percent'] );
98  }
99  }
100  }
101  }
102  }
103 
112  public function testCompleteMetricsStructure() {
113  $metricStruct = [
114  'ct' => 'int',
115  'wt' => 'array',
116  'cpu' => 'array',
117  'mu' => 'array',
118  'pmu' => 'array',
119  'calls' => 'array',
120  'subcalls' => 'array',
121  ];
122  $statsMetrics = [ 'wt', 'cpu', 'mu', 'pmu' ];
123  $statStruct = [
124  'total' => 'numeric',
125  'min' => 'numeric',
126  'mean' => 'numeric',
127  'max' => 'numeric',
128  'variance' => 'numeric',
129  'percent' => 'numeric',
130  'exclusive' => 'numeric',
131  ];
132 
133  $xhprofData = $this->getXhprofDataFixture();
134  $metrics = $xhprofData->getCompleteMetrics();
135 
136  foreach ( $metrics as $name => $metric ) {
137  $this->assertArrayStructure( $metricStruct, $metric, $name );
138 
139  foreach ( $metricStruct as $key => $type ) {
140  if ( in_array( $key, $statsMetrics ) ) {
141  $this->assertArrayStructure(
142  $statStruct, $metric[$key], $key
143  );
144  $this->assertLessThanOrEqual(
145  $metric[$key]['total'], $metric[$key]['exclusive']
146  );
147  }
148  }
149  }
150  }
151 
156  public function testEdges() {
157  $xhprofData = $this->getXhprofDataFixture();
158  $this->assertSame( [], $xhprofData->getCallers( 'main()' ) );
159  $this->assertSame( [ 'foo', 'xhprof_disable' ],
160  $xhprofData->getCallees( 'main()' )
161  );
162  $this->assertSame( [ 'main()' ],
163  $xhprofData->getCallers( 'foo' )
164  );
165  $this->assertSame( [], $xhprofData->getCallees( 'strlen' ) );
166  }
167 
171  public function testCriticalPath() {
172  $xhprofData = $this->getXhprofDataFixture();
173  $path = $xhprofData->getCriticalPath();
174 
175  $last = null;
176  foreach ( $path as $key => $value ) {
177  list( $func, $call ) = XhprofData::splitKey( $key );
178  $this->assertSame( $last, $func );
179  $last = $call;
180  }
181  $this->assertSame( $last, 'bar@1' );
182  }
183 
212  protected function getXhprofDataFixture( array $opts = [] ) {
213  return new XhprofData( [
214  'foo==>bar' => [
215  'ct' => 2,
216  'wt' => 57,
217  'cpu' => 92,
218  'mu' => 1896,
219  'pmu' => 0,
220  ],
221  'foo==>strlen' => [
222  'ct' => 2,
223  'wt' => 21,
224  'cpu' => 141,
225  'mu' => 752,
226  'pmu' => 0,
227  ],
228  'bar==>bar@1' => [
229  'ct' => 1,
230  'wt' => 18,
231  'cpu' => 19,
232  'mu' => 752,
233  'pmu' => 0,
234  ],
235  'main()==>foo' => [
236  'ct' => 1,
237  'wt' => 304,
238  'cpu' => 307,
239  'mu' => 4008,
240  'pmu' => 0,
241  ],
242  'main()==>xhprof_disable' => [
243  'ct' => 1,
244  'wt' => 8,
245  'cpu' => 10,
246  'mu' => 768,
247  'pmu' => 392,
248  ],
249  'main()' => [
250  'ct' => 1,
251  'wt' => 353,
252  'cpu' => 351,
253  'mu' => 6112,
254  'pmu' => 1424,
255  ],
256  ], $opts );
257  }
258 
266  protected function assertArrayStructure( $struct, $actual, $label = null ) {
267  $this->assertInternalType( 'array', $actual, $label );
268  $this->assertCount( count( $struct ), $actual, $label );
269  foreach ( $struct as $key => $type ) {
270  $this->assertArrayHasKey( $key, $actual );
271  $this->assertInternalType( $type, $actual[$key] );
272  }
273  }
274 }
XhprofData\splitKey
static splitKey( $key)
Convert an xhprof data key into an array of ['parent', 'child'] function names.
Definition: XhprofData.php:113
XhprofDataTest
Definition: XhprofDataTest.php:25
XhprofDataTest\testCriticalPath
testCriticalPath()
XhprofData::getCriticalPath.
Definition: XhprofDataTest.php:171
captcha-old.count
count
Definition: captcha-old.py:249
XhprofDataTest\testInclusiveMetricsStructure
testInclusiveMetricsStructure()
Validate the structure of data returned by Xhprof::getInclusiveMetrics().
Definition: XhprofDataTest.php:70
XhprofDataTest\provideSplitKey
provideSplitKey()
Definition: XhprofDataTest.php:37
$last
$last
Definition: profileinfo.php:416
php
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
XhprofDataTest\getXhprofDataFixture
getXhprofDataFixture(array $opts=[])
Get an Xhprof instance that has been primed with a set of known testing data.
Definition: XhprofDataTest.php:212
XhprofDataTest\testInclude
testInclude()
XhprofData::pruneData.
Definition: XhprofDataTest.php:51
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
list
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
XhprofDataTest\assertArrayStructure
assertArrayStructure( $struct, $actual, $label=null)
Assert that the given array has the described structure.
Definition: XhprofDataTest.php:266
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
$value
$value
Definition: styleTest.css.php:49
XhprofDataTest\testCompleteMetricsStructure
testCompleteMetricsStructure()
Validate the structure of data returned by Xhprof::getCompleteMetrics().
Definition: XhprofDataTest.php:112
XhprofDataTest\testEdges
testEdges()
XhprofData::getCallers XhprofData::getCallees.
Definition: XhprofDataTest.php:156
XhprofData
Convenience class for working with XHProf profiling data https://github.com/phacility/xhprof.
Definition: XhprofData.php:31
$path
$path
Definition: NoLocalSettings.php:25
as
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
XhprofDataTest\testSplitKey
testSplitKey( $key, $expect)
XhprofData::splitKey provideSplitKey.
Definition: XhprofDataTest.php:33
$type
$type
Definition: testCompression.php:48