Commit graph

36 commits

Author SHA1 Message Date
Edward Chernenko
9d4a7e4d75 Xhprof: support tideways-xhprof extension
The "tideways" extension was renamed by their developers, see
https://tideways.com/profiler/blog/releasing-new-tideways-xhprof-extension

While doing so, they also renamed enable/disable functions:
tideways_enable -> tideways_xhprof_enable
tideways_disable -> tideways_xhprof_disable

Change-Id: I63bc97dba461dd46241a094dfc59439c0d28a219
2018-06-19 14:43:40 +00:00
Bartosz Dziewoński
485f66f174 Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenient
Find: /isset\(\s*([^()]+?)\s*\)\s*\?\s*\1\s*:\s*/
Replace with: '\1 ?? '

(Everywhere except includes/PHPVersionCheck.php)
(Then, manually fix some line length and indentation issues)

Then manually reviewed the replacements for cases where confusing
operator precedence would result in incorrect results
(fixing those in I478db046a1cc162c6767003ce45c9b56270f3372).

Change-Id: I33b421c8cb11cdd4ce896488c9ff5313f03a38cf
2018-05-30 18:06:13 -07:00
Bartosz Dziewoński
b191e5e860 Use PHP 7 '<=>' operator in 'sort()' callbacks
`$a <=> $b` returns `-1` if `$a` is lesser, `1` if `$b` is lesser,
and `0` if they are equal, which are exactly the values 'sort()'
callbacks are supposed to return.

It also enables the neat idiom `$a[x] <=> $b[x] ?: $a[y] <=> $b[y]`
to sort arrays of objects first by 'x', and by 'y' if they are equal.

* Replace a common pattern like `return $a < $b ? -1 : 1` with the
  new operator (and similar patterns with the variables, the numbers
  or the comparison inverted). Some of the uses were previously not
  correctly handling the variables being equal; this is now
  automatically fixed.
* Also replace `return $a - $b`, which is equivalent to `return
  $a <=> $b` if both variables are integers but less intuitive.
* (Do not replace `return strcmp( $a, $b )`. It is also equivalent
  when both variables are strings, but if any of the variables is not,
  'strcmp()' converts it to a string before comparison, which could
  give different results than '<=>', so changing this would require
  careful review and isn't worth it.)
* Also replace `return $a > $b`, which presumably sort of works most
  of the time (returns `1` if `$b` is lesser, and `0` if they are
  equal or `$a` is lesser) but is erroneous.

Change-Id: I19a3d2fc8fcdb208c10330bd7a42c4e05d7f5cf3
2018-05-30 18:05:20 -07:00
Umherirrender
3124a990a2 Use ::class to resolve class names in includes files
This helps to find renamed or misspelled classes earlier.
Phan will check the class names

Change-Id: I07a925c2a9404b0865e8a8703864ded9d14aa769
2018-01-27 20:34:29 +01:00
jenkins-bot
bc213a9d46 Merge "build: Prepare for mediawiki/mediawiki-codesniffer to 0.9.0" 2017-06-27 08:57:28 +00:00
Bryan Davis
aaf1e17088 Remove "@author Bryan Davis" and "Brad Jorsch" annotations
Undo traces of a practice we carried over from past projects and
existing examples that is neither universal nor actively encouraged in
the MediaWiki codebase.

Bug: T139301
Change-Id: I5c9c89b72a45a44aa4264a5e57b003c1a86cdf6e
Co-Authored-By: Brad Jorsch <bjorsch@wikimedia.org>
2017-06-26 15:25:46 -06:00
Umherirrender
be42e09aa8 build: Prepare for mediawiki/mediawiki-codesniffer to 0.9.0
The used phpcs has a bug, so the version 0.9.0 could not be enforced at the moment.
Will be fixed in next version, see T167168

Changed:
- Remove duplicate newline at end of file
- Add space between function and ( for closures
- and -> &&, or -> ||

Change-Id: I4172fb08861729bccd55aecbd07e029e2638d311
2017-06-26 17:14:31 +00:00
Kunal Mehta
de53d90568 profiler: Support tideways for PHP7 profiling
xhprof does not support PHP7, and it doesn't seem like upstream will be
working on that any time soon.

Tideways is a profiler that is basically a drop-in replacement for
xhprof with functions renamed. So Xhprof::enable() and Xhprof::disable()
will now try to use tideways if that is installed and xhprof is not.

Bug: T152186
Change-Id: I0d7d2de56ac638ca2851c662f527049bd620c0e9
2016-12-06 23:38:19 +00:00
Ori Livneh
20abb707ba Decouple Xhprof profiling from profiling data processing
The motivation for this patch came from trying to use xhprof to profile the
unit tests. I was able to profile specific test suites, but if I tried to
profile a complete PHPUnit run, I ended up with empty profiling data. My
initial suspicion was that this was due to some Xhprof buffer getting
exhausted. The actual reason ended up being much simpler: the XhprofTest suite
indirectly called xhprof_enable() / xhprof_disable(), which stopped xhprof and
cleared out the data, so that when I was calling xhprof_disable() at the end of
the run, there was no profiling data to return, because xhprof was not running.

For the most part the XhprofTest was already doing the right thing by trying to
avoid having side-effects or relying on xhprof. Wherever possible, test fixture
profiling data was used in lieu of actually running xhprof. But this was not
totally successful because the Xhprof class coupled the collection of data to
the processing of data. Xhprof::__construct() called xhprof_enable(), so there
was no real way around that.

I think that the right way to fix that is to decouple profiling from profiling
data analysis. Thus I renamed 'Xhprof' to 'XhprofData', and modified the class
so that it expects to be fed profiling data rather than going out and
collecting it on its own. As a result, it is now possible to profile a full
phpunit run with xhprof, and the work that went into writing fixtures for the
Xhprof unit tests pays off: the class and the tests no longer have a hard
dependency on the xhprof extension, and the tests do not have to be skipped
when it is not installed. And the tests are really testing the system under
test, rather than the xhprof extension.

Finally, I added a new Xhprof class, which really is just an extremely thin
wrapper around xhprof_enable() / xhprof_disable(). The only extra functionality
it provides is the ability to check whether xhprof is running, via
Xhprof::isEnabled(). Calling Xhprof::enable() when it is already enabled will
cause an exception to be thrown. This should help us avoid running into
situations where two components contend for control of the profiler without
realizing it. A unit test tests this behavior.

The only part of this change that is not covered by tests is the change to
ProfilerXhprof. I tested it manually and it works.

Change-Id: Ica96beded68f04083abaf48ef1ae8c726eb60fa6
2016-05-12 22:23:05 +00:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Ori Livneh
6618307102 Improve ProfilerXhprof's blacklist/whitelist capabilities
* Apply the blacklist / whitelist to profiled sections, not just function names.
* Allow shell-style wildcard patterns in blacklist / whitelist.
* Prefix all profiled section names with 'section.', to distinguish them from
  functions.

Note that shell-style wildcard patterns are not supported by xhprof natively,
but it won't barf on them either, nor will they match against actual function
names (since shell wildcard characters are not valid for PHP function names),
and the filtering will still be enforced in ProfilerXhprof.

This has the side-effect of working around https://github.com/facebook/hhvm/issues/4385

Bug: T99829
Change-Id: I8354ed922fa7b42857eda03be8f62b89ac78d0d6
2015-05-21 12:09:12 -07:00
Stanislav Malyshev
750e4eb9d9 Allow dumping raw xhprof data for consumption by xhprof GUI
Change-Id: Iab90cef1c61b92ffc6d46a6bc93a03cf7bc2adb9
2015-03-04 01:29:02 +00:00
jenkins-bot
812fb5f5bd Merge "Made profileIn/profileOut methods a no-op" 2015-01-08 19:45:30 +00:00
Aaron Schulz
9dfea19e7b Added ProfilerSectionOnly class
Change-Id: I45d1036433a7cca13293de22adf1b63b916393fe
2015-01-08 02:10:02 -08:00
Aaron Schulz
4236b9beb6 Made profileIn/profileOut methods a no-op
Change-Id: I781f62be9747bb41af6faad6fbe265414fb77669
2015-01-08 01:54:51 -08:00
Aaron Schulz
4a56f3ba58 Removed ProfilerStandard and ProfilerSimpleTrace
Change-Id: I2b0e0ac1a277e66b15095e766ed5df834b1ae5f9
2015-01-07 11:36:57 -08:00
Bryan Davis
57ce0b309d xhprof: Guard against division by 0
Warning: Division by zero in
/srv/mediawiki/php-1.25wmf12/includes/profiler/ProfilerXhprof.php on
line 143

Change-Id: Ibb3d0ce836d30663c511809b6e1dece4baa4da92
2014-12-18 09:29:36 -07:00
Bryan Davis
9904a823b0 xhprof: discard section profiler running totals
The '-total' record from the section profiler used for measuring
sub-function timing is not useful in the cumulative xhprof report data.

Change-Id: Ieb79b0e82e0bed54653fab016c133cc74ec4f637
2014-12-17 17:52:06 -07:00
Bryan Davis
4449c9bcfa xhprof: Fix magnitude of %real measurements from scoped profiler
Change-Id: I06e5b3d82cfddd1a407c56819c9bdd91f160e928
2014-12-17 16:36:04 -07:00
Chad Horohoe
9d2c050683 Remove $logType and $visible, leftover from before output refactoring
Change-Id: I4d320b27471608d38b65c14c132d45c6ce3e94a8
2014-12-09 19:10:42 +00:00
Aaron Schulz
1b32de48d5 Made xhprof scopedProfileIn() work via merging SectionProfiler results
* This works around various pecl/hhvm xhprof extension issues.

Change-Id: I04555db1d0781bafc758ab9965c4af2fab9569f4
2014-12-08 23:39:37 +00:00
Aaron Schulz
e145b81e5d Refactored xhprof getFunctionReport() to use getFunctionStats()
* Also added more doc comments to getFunctionStats()

Change-Id: I3741713d3c80b0bbc622eb17ce4c3a047bf5a06c
2014-12-08 23:39:18 +00:00
Aaron Schulz
9ed769df16 Removed unused getSummaryReport method
Change-Id: Id65c6702cc2eb75047fbfa88a6b79163c7dc2528
2014-12-08 12:52:01 -08:00
umherirrender
489d793882 Fixed spacing
- Added/removed spaces around parenthesis
- Added newline in empty blocks
- Added space after switch/foreach/function
- Use tabs at begin of line
- Add newline at end of file

Change-Id: I244cdb2c333489e1020931bf4ac5266a87439f0d
2014-12-05 22:28:07 +01:00
Aaron Schulz
dcd639f9f9 Switched hook profiling to use scopedProfileIn
* Also made scopedProfileOut handle the case where the callback
  was null (e.g. when there are no frame methods for xhprof).

Change-Id: Ife242bda8e046990d0d8ac27d628975b7b4a14d7
2014-12-04 19:32:38 +00:00
jenkins-bot
0add9d5ba7 Merge "Remove Profiler::isStub()" 2014-12-04 07:42:27 +00:00
Chad Horohoe
52f3b13312 Remove Profiler::isStub()
Just check for ProfilerStub directly.

Change-Id: I503916599f182df4206da5282193ae6ec9324ee6
2014-12-03 20:19:56 -08:00
Aaron Schulz
cd9931fd65 Removed useless "use" clause from closure
Change-Id: Ie2e0328548b185e77b919c0b8bd18a5005d94037
2014-12-03 23:34:00 +00:00
Aaron Schulz
9d0f0119c6 Removed bogus argument in frame profiling method
* Caused "Warning: xhprof_frame_end() expects exactly 0 parameters, 1 given in includes/libs/ScopedCallback.php on line 70"

Change-Id: I1ab5a973a185738cae97de4cfdc3cca78598d35e
2014-12-01 10:36:48 -08:00
Timo Tijhof
ff6513f28b Remove '@section LICENSE'
This was used in 2 special classes, the logger classes and spread
to a few other random classes.

Afaik this has no meaning. Is for something we don't use, and
goes against the meaning of '@section' in Doxygen, which we do
use.

In Doxygen output, all LICENSE references became links to
ProfilerXhprof (the one Doxygen encoutered first).

Bug: T72328
Change-Id: Icc7c443245c70bc0f549bee7d105eef5691c864d
2014-11-26 02:20:55 +00:00
Aaron Schulz
240152117c Added custom frame support to Profiler
* Made use of it in the DatabaseBase classes
* For the xhprof class, this only works in HHVM for now

Change-Id: I95d7cc128d4a770328fbdd2b546972d3fc2e2e8a
2014-11-25 14:52:21 -07:00
Bryan Davis
ddb57b78c0 Remove calls to legacy Profiler::debug()
Profiler::debug() was moved to ProfilerStandard. Since we have
a proposed patch set already that will remove
wfProfileIn()/wfProfileout() calls that wrap whole methods this seem
like an easy problem to solve by removing this logging functionality.

Change-Id: I429ec29fe4393ce886361b896b650fd39480eda5
2014-11-19 11:55:28 -07:00
Chad Horohoe
b8d93fb4fd Refactor profiling output from profiling
* Added a standard getFunctionStats() method for Profilers to return
  per function data as maps. This is not toolbar specific like getRawData().
* Cleaned up the interface of SectionProfiler::getFunctionStats() a bit.
* Removed unused cpu_sq, real_sq fields from profiler UDP output.
* Moved getTime/getInitialTime to ProfilerStandard.

Co-Authored-By: Aaron Schulz <aschulz@wikimedia.org>
Change-Id: I266ed82031a434465f64896eb327f3872fdf1db1
2014-11-17 19:26:04 -07:00
Aaron Schulz
7d3fca19ef Avoid sending spammy @X xhprof entries over UDP
Change-Id: I8509932f7368cab2a5426f437845e2849a82d9b4
2014-11-14 19:15:07 +00:00
Chad Horohoe
4fa6c46c94 Remove per-template profiling
Creates absurd dependency on the profiler from the parser. This profiling
is also not compatible with function-level profiling that we're trying to
aim for with xhprof.

Change-Id: I3c780fcb06e3470a0cbf50311ba916a0b67ea49e
2014-11-12 18:18:30 -08:00
Bryan Davis
46c47e11bc Enable profiling via xhprof
Add a helper class to assist in collecting profiling information using
XHProf <https://github.com/phacility/xhprof> and a Profiler
implementation to hook it into the existing MediaWiki profiling system.

The Profiler includes support for generating tabular reports similar to
the traditional output of ProfilerSimpleText and ProfilerSimpleTrace or
sending data to a udpprofile daemon as supported by ProfilerSimpleUDP.
It also produces data compatible with the debugging toolbar.

Bug: T759
Change-Id: I16a75cb7636cb5dcef3830d738b2dcd2047d0aaa
2014-11-08 11:47:25 -07:00