Commit graph

133 commits

Author SHA1 Message Date
Daimona Eaytoy
1d6776fdbc Replace deprecated MWException
Also remove some unchecked exception from doc comments.

Bug: T328220
Bug: T240672
Change-Id: I88b1e948ce5da77d9c4862a2b98793d6ba00cf8b
2024-01-19 21:58:42 +00:00
Derick Alangi
b7a34fcb23 profiler: Cleanup base class and remove dead code
* Deprecate ::setProfileID(). This was added in r17776 to allow callers
  (e.g. LocalSettings.php and StartProfiler.php, outside Git) to change
  the ID at runtime. Site admins don't seem to do this in practice.
  We have since then introduced request IDs, and the ability to
  declaratively describe the Profiler singleton via $wgProfiler,
  where 'profileID' is already supported nowadays.

  The propertly can stil be set for other purposes by sub-classes.

* Remove ::setContext() and ::getContext() which was already hard
  deprecated a while ago (1.38).

* Deprecate ::getAllowOutput() which is unused.

* Profiler::$context has been removed too since the methods consuming
  this member has been removed.

Change-Id: Id2ff252e506d4445e68e1e944d44f3b4b0bdbdb4
2023-09-28 00:34:14 +00:00
Tim Starling
580ec48e5b Fix more PHPStorm inspections (#2)
* Illegal string offset and invalid argument supplied to foreach, due to incorrect type information
* Array internal pointer reset is unnecessary
* $hookData unused since MW 1.35 due to incomplete revert
* array_push() with single element
* Unnecessary sprintf()
* for loop can be replaced with str_repeat()
* preg_replace() can be replaced with rtrim()
* array_values() call is redundant
* Unnecessary cast to string
* Unnecessary ternary. Often the result relies on short-circuit evaluation, but I find it more readable nonetheless.

Change-Id: I4c45bdb59b51b243fa96286bec8b58deb097d707
2023-03-25 00:19:58 +00:00
Amir Sarabadani
4bb2886562 Reorg: Migrate WikiMap to WikiMap/ out of includes
And WikiReference

Bug: T321882
Change-Id: I60cf4b9ef02b9d58118caa39172677ddfe03d787
2023-02-27 05:19:46 +01:00
Timo Tijhof
24ef8e93e9 profiler: Restore lost --profiler feature for Maintenance scripts
== Status quo

In web requests we have:
* Setup.php: Load LocalSettings.php (CommonSettings.php in prod),
  which may assign $wgProfiler, e.g. if X-Wikimedia-Debug is used.
* Setup.php: Pass global to Profiler::init().

No Profiler::instance() singleton calls exist until after this point,
which is good as otherwise it'd initialise the singleton incorrectly.

In maintenance scripts, today we have the following broken sequence:
* doMaintenance: Load MaintenanceRunner.
* MaintenanceRunner: Register the '--profiler' option.
* doMaintenance: Define MW_FINAL_SETUP_CALLBACK.
* doMaintenance: Load Setup.php.
* Setup.php: Load LocalSettings.php
* Setup.php: Call MW_FINAL_SETUP_CALLBACK
** calls MaintenanceRunner::setup
** calls MaintenanceRunner::activateProfiler
** this constructs the Profiler object directly (duplicating Profiler::init)
   and saves the singleton via Profiler::replaceStubInstance.
   The activateProfiler() method also uses the singleton to enable
   outputting of results at shutdown, and set Rdbms warning limits.
* Setup.php: Call $wgSettings->apply().
* Setup.php: Pass global to Profiler::init().
** It wipes the singleton we just made.
** It re-creates it based on $wgProfiler, which MaintenanceRunner
   failed to overwrite (it used to, but this was lost when
   SettingsBuilder and MaintenanceRunner were introduced).
** It explicitly forces ProfilerStub in CLI mode, thus even if
   $wgProfiler was assigned, it would still not work.

== Change

The above made sense prior to the MaintenanceRunner and
SettingsBuilder refactoring when more of Setup.php ran before
Maintenance began doing its thing, and thus it made sense that
Setup's Profiler::init call would force stub for CLI mode, and then
let Maintenance use replaceStubInstance to replace it afterward, but
the order has changed.

I'm using this oppertunity to get rid of the "replace afterwards"
approach and instead use SettingsBuilder to set wgProfiler correctly
in the first place, and further more recognise the concept of
CLI-enablement as an explicit (internal) option to avoid a conflict
between these two requirements.

Note that this isn't the first time it broke. It also broke some time
before 2014 when change I35faedff818af2ad45 restored its behaviour.

== Test plan

* Using MediaWiki-Docker which includes tideways_xhprof, and set the
  snippet in LocalSettings to set $wgProfiler:
  <https://www.mediawiki.org/wiki/MediaWiki-Docker/Configuration_recipes/Profiling>
* Confirm that view-source:/wiki/Main_Page contains no profiler output.
* Confirm that view-source:/wiki/Main_Page?forceprofile=1 does.
* Confirm that `php maintenance/showJobs.php` and
  `php maintenance/showJobs.php --profile text` both don't print
  a profile today.
* Apply this change.
* `php maintenance/showJobs.php --profile text` now prints a profile.

Change-Id: Ia1a86f0443bf7ae746811e9de5dda89f20ad446f
2023-01-05 18:28:52 +00:00
Aaron Schulz
bca5955434 rdbms: add statsd metrics to TransactionProfiler
This makes it easy to create alerts based on graphite metrics.
Each (event name, HTTP method) pair will have a counter metric,
with *.rate measuring the rate of requests violating the rule.

Bug: T258125
Change-Id: I7de56fbdfde25fa8f695416ddf27e2fe357b71dc
2022-11-30 20:18:43 -08:00
Umherirrender
ea5ea60b31 Various doc fixes about false on method arguments/return types
Doc-only changes

Change-Id: I5177f582ae7ee70c357e9389fed14819faf79463
2022-11-10 19:23:46 +00:00
Timo Tijhof
41333fa512 profiler: Inject $wgProfiler from Setup.php to Profiler
Follows-up I58ff3c193190d78a. Small step toward not run-time reading
the global (and using Config here is non-trivial/unsafe).

Change-Id: Ic527e493baabe700c50f75fadaa5b51615a5e597
2022-11-09 02:58:19 +00:00
Aryeh Gregor
aca8de4d75 Don't assume $wgProfiler is set in Profiler
This was breaking HttpRequestFactoryTest for me, because it adds
$wgProfiler to an array and $wgProfiler is null in unit tests. The
suppressed PHAN warning was actually quite correct -- there was no
guarantee that $wgProfiler was set!

What I'm not clear on is how this test worked for anyone else.

Change-Id: I58ff3c193190d78a2591d9450cb7f2dae5d4a997
2022-04-06 16:06:56 +03:00
Umherirrender
6caf78c2c8 phan: Remove PhanPossiblyUndeclaredVariable suppression
Make phan stricter about conditional variable declaration
Remaining false positive issues are suppressed.
The suppression and the setting change can only be done together

Bug: T259172
Change-Id: I1f200ac37df7448453688bf464a8250c97313e5d
2022-03-30 19:47:15 +00:00
Umherirrender
70e2514db8 profiler: Remove deprecated profileIn/profileOut
Bug: T241956
Change-Id: I1e0f732f22f4499c032dd4c189c2e1d2891f6192
2022-01-02 22:25:38 +01:00
Timo Tijhof
df32228920 profiler: Remove dependency on WebRequest from Profiler
I intent to remove Profiler::getContext/setContext after a week
without deprecation. I consider these methods as internal (they
predate the stable interface policy, and we forgot to triage this
class, it has neither `@stable` nor `@internal`).

The hard-deprecation in this commit is to detect any use that may
have gone unnoticed in WMF production from Codesearch analysis alone,
where no usage was found.

Bug: T292269
Change-Id: Id40679f21cc7a3f77a1b96a4bbd55daeaea16892
2021-10-09 03:00:45 +00:00
DannyS712
1fbdc8f19d Remove deprecated Profiler::(get|set)Templated
Deprecated and unused

Change-Id: I7b46543e0e32b6f13fcf8f8fb9273946ffbbdee9
2020-10-22 02:55:31 +00:00
Umherirrender
d790580fda Fix typos related to repeated words
Change-Id: Ibc187d95b003017255bc87adf56afae7a59bd3db
2020-09-27 10:25:36 +00:00
Timo Tijhof
063a528bc8 profiler: Use PSR-3 logging in Profiler and ProfilerOutput classes
* Use the "profiler" channel consistently within this component,
  and set it in the constructor of the base classes.

* Fold legacy "profilererror" channel into "profiler".
  Previously, the wfDebugLog wrapper was using the INFO severity,
  which is the default given wfDebugLog does not support severity.

Change-Id: I1e7dcbc221b395a4ea792e18f4d4da36b5ee40df
2020-08-12 03:51:29 +00:00
Tim Starling
47a1619027 Remove terminating line breaks from debug messages
A terminating line break has not been required in wfDebug() since 2014,
however no migration was done. Some of these line breaks found their way
into LoggerInterface::debug() calls, where they mess up the formatting
of the debug log.

So, remove terminating line breaks from wfDebug() and
LoggerInterface::debug() calls.

Also:
* Fix the stripping of leading line breaks from the log header emitted
  by Setup.php. This feature, accidentally broken in 2014, allows
  requests to be distinguished in the log file.
* Avoid using the global variable $self.
* Move the logging of the client IP back to Setup.php. It was moved to
  WebRequest in the hopes that it would not always be needed, however
  $wgRequest->getIP() is now called unconditionally a few lines up in
  Setup.php. This means that it is put in its proper place after the
  "start request" message.
* Wrap the log header code in a closure so that variables like $name do
  not leak into global scope.
* In Linker.php, remove a few instances of an unnecessary second
  parameter to wfDebug().

Change-Id: I96651d3044a95b9d210b51cb8368edc76bebbb9e
2020-06-03 12:01:16 +10:00
jenkins-bot
63d850f225 Merge "Remove $wgProfileLimit setting" 2020-03-19 23:17:37 +00:00
Timo Tijhof
c75a4ac16f Remove $wgProfileLimit setting
Deprecated since MediaWiki 1.25.

Bug: T247777
Bug: T228895
Change-Id: I638d9a219df7b5c661548354fd3d219ada340a86
2020-03-19 23:03:20 +00:00
Timo Tijhof
ac26a3575d profiler: Improve $wgProfiler docs in DefaultSettings.php
In particular, document the 'threshold' option.

Bug: T247777
Change-Id: I36eeb13ac3beb4a67c841e0a6fc262f89cda7242
2020-03-19 23:00:01 +00:00
Timo Tijhof
d83fcce5cb profiler: Clean up file headers and @ingroup
* Remove redundant file description for files that only define
  a class where the class description suffices.
* Ensure the file has a license header and @file.

* Remove any @ingroup from the file comment block.
  These clutter the Doxygen pages with duplicate entries.
* Ensure the class block has an @ingroup set.

* Remove @since when @internal is set.
* Add any missing @since to public classes that were created
  recently enough to easily find out when:
  - ProfilerExcimer was introduced in 1.33 (6373e3d1d4).

Change-Id: I6b18289a15a3085857acd7c9004ec819f7914b29
2020-02-05 23:28:12 +00:00
James D. Forrester
4f2d1efdda Coding style: Auto-fix MediaWiki.Classes.UnsortedUseStatements.UnsortedUse
Change-Id: I94a0ae83c65e8ee419bbd1ae1e86ab21ed4d8210
2020-01-10 09:32:25 -08:00
Daimona Eaytoy
b1a5367ec8 Fix new phan errors, part 7
Bug: T231636
Change-Id: Ia5e0abee7163c5a1abd0bb53b89603cc2e7a9b5c
2019-10-21 22:10:20 +00:00
Timo Tijhof
8a87ec2778 profiler: Centralise output responsibility from ProfilerOutputText to Profiler
Make it Profiler.php's responsibility to enforce this, based on the
existing signal from ProfilerOutput::logsToOutput().

The ProfilerOutputText class should not have to double-check this
a second time.

Long-term, I'd like even this check in Profiler::logDataPageOutputOnly
to be removed, because really the external caller of that should
know whether it is safe to output stuff or not rather than stashing
its own state inside Profiler::$allowOutput and then implicitly
reading it back out again later on. But, that's for another time.

Also:
* Remove use of deprecated Profiler::setTemplated while at it.
* Make 'visible' parameter explicit, as for other parameters.

Change-Id: Iaa3fc4ea25a059b90235d769db60c04b8f152f05
2019-08-28 16:07:18 +00:00
Timo Tijhof
bc7c85d609 profiler: Rename Profile::setTemplated to Profile::setAllowOutput
This is set from three places:
1) SkinTemplate.php, 2) Maintenance.php, and 3) load.php.

These last two are very much *not* HTML-templated output.
Rename these this method pair to getAllowOutput/setAllowOutput instead,
which is less confusing going forward. No known callers outside of
core (updated in the next commit), but I'll keep compat for one
release cycle just in case.

Change-Id: I828f95332dca3c6766b2b485ffb71762542b42d7
2019-08-28 01:10:56 +00:00
Aaron Schulz
93f29a1286 Deprecate Profiler::profileIn and Profiler::profileOut stubs
Change-Id: I2a8764d2464883e9fe66048e97b688c5a76d595a
2019-03-14 23:03:44 +00:00
Aaron Schulz
58ee03b13d Avoid sending duplicate ProfilerOutputText comments/html
Change-Id: I4130845cdb7208b8456740e5dbaf8bf96e175f49
2019-03-13 10:27:38 -07:00
Aaron Schulz
5196ac32c6 Rename WikiMap DB domain ID methods to reduce confusion with web domains
Those added in this same release do not need alias methods.

Change-Id: I05feeb9b0b13afe43aea1f95551965489cdbe094
2019-02-06 12:28:45 -08:00
Aaron Schulz
42a6f991e0 Use new WikiMap::getCurrentWikiDomain() for objectcache and profiler keyspace
Change-Id: I0e77c58a55b7ce908ec1d6399ec6629d00a48953
2018-10-30 06:41:07 +00:00
Umherirrender
130ec2523d Fix PhanTypeMismatchDeclaredParam
Auto fix MediaWiki.Commenting.FunctionComment.DefaultNullTypeParam sniff

Change-Id: I865323fd0295aabd06f3e3c75e0e5043fb31069e
2018-07-07 00:34:30 +00:00
Aaron Schulz
07c38641b2 Fix Profiler::getOutputs() type documentation
Change-Id: I4ff2ccc16363bfc3093b75263da2b09c3af40627
2018-02-22 10:58:36 -08: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
Kunal Mehta
251a0b97e5 Treat phpdbg as run from the command line when checking PHP_SAPI
phpdbg is a gdb-style debugger for PHP that is run from the command
line. However, it has a different PHP_SAPI value, so it was impossible
to run maintenance scripts with it (until now).

To avoid having to check both PHP_SAPI values in a bunch of places,
introduce wfIsCLI() to easily check whether running from the
command-line or not.

We're (CI team) interested in generating code coverage with phpdbg
instead of xdebug, hence this patch.

Bug: T184043
Change-Id: Id1f994ca146d7858cd8bb6ab6cdbb7718ff524fb
2018-01-03 23:00:37 -08:00
Umherirrender
a9007e8baf Add missing & to @param documentation to match functon call
Change-Id: I81e68310abcbc59964b22e0e74842d509f6b1fb9
2017-08-11 18:47:46 +02:00
Aaron Schulz
59053a0716 Move ChronologyProtector/TransactionProfiler to Rdbms namespace
Change-Id: I37a655bd8bd267c9bc32028b55925b2dce527d33
2017-01-26 10:30:57 -08:00
Kunal Mehta
61adc1e146 Use namespaced ScopedCallback
The un-namespaced \ScopedCallback is deprecated.

Change-Id: Ie014d5a775ead66335a24acac9d339915884d1a4
2016-10-17 15:46:05 -07:00
Aaron Schulz
058707ef38 Fix SectionProfileCallback type error
Avoids "Argument 1 passed to Profiler::scopedProfileOut() must
be an instance of ScopedCallback, SectionProfileCallback given"

Change-Id: I92713de71df9722d8a5d7e5cd04460aff71cf096
2016-09-30 15:57:44 -07: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
Aaron Schulz
660a775931 Remove old ProfilerOutputUdp class
This uses a non-standard output and requires a custom
collector that wmf does not maintain nor use anymore.

Change-Id: I41a68f7061465417fbdc5ca41f8eb6e1f99f1111
2015-10-21 20:59:47 -07:00
Ori Livneh
c099155a17 ellapsed => elapsed
Also fix some files that don't end with a newline.

Change-Id: Id0672d685b929a5832b42f733dad49683536180a
2015-06-23 03:32:33 +00:00
Vivek Ghaisas
fd9178e4c3 Fix braces code style
Bug: T102805
Change-Id: I7ce4c71dd605f9be79a630602391271bb269b962
2015-06-17 16:28:51 +03:00
Aaron Schulz
016fd0b776 Refactored entry points to have uniform shutdown handling
* Added doPreOutputCommit() and doPostOutputShutdown(),
  which most entry points just using the later
* Also fixed problem where text profiling did not show up
* Avoid calling triggerJobs() in the file streaming
  entry points

Bug: T100127
Bug: T100085
Change-Id: Ibc7e768fd483389a01847f08cdeba4058c853d3f
2015-05-29 20:40:46 +00:00
Ori Livneh
27b9c0639d Simplify profiler output class selection
Instead of maintaining a mapping of short names to class names ('db' =>
'ProfilerOutputDb', etc.), let us adopt the convention of using the full
class name to indicate the output type. We can maintain backward-compatibility
by using simple string manipulation to transform short names to the full class
names.

Change-Id: I976e0da2873d88b9892fb41823cfe3af0a2d3974
2015-04-02 11:01:52 -07:00
Ori Livneh
4e5d016e72 Follow-up to Icf644ad34: Introduce ProfilerOutputStats
Change-Id: Ib3585303b75899c4cd7c9c88fb3473b441e52c23
2015-04-01 21:09:20 -07:00
Ori Livneh
1b6f70089d Introduce ProfilerOutputStats
* Associate Profiler objects with a request context by adding a $context
  property with a getter and a setter.
* Introduce ProfilerOutputStats, which writes profiling data to the stats
  buffer associated with the current request context.
* Make it the Profiler class's responsibility to enforce $wgProfilerLimit.
* Deprecate $wgProfilerLimit in favor of the (more aptly named, IMO)
  $wgProfiler['threshold'] config setting.
* Tidy up Profiler instance creation code in Profiler::instance().
* Add Profiler::getOutputs, which returns an array of ProfilerOutput instances
  which are configured for the current profiler and whose canUse() method
  returns true.
* Make ProfilerStub not log by creating a stub ProfilerStub::logData() method
  which does not call the parent. Previously the parent class checked if $this
  was an instance of ProfilerStub and returned early if so.

Task: T90623
Task: T85641
Change-Id: Icf644ad3435c1f30d0a49957a97b481808a3153d
2015-04-02 01:32:46 +00:00
Aaron Schulz
5012ac6c6a Made ProfilerStub return null instead of a dummy ScopedCallback
* This can happen well over 10k times per request due to the message
  hooks. Avoiding the object construction seems prudent.

Change-Id: I45ff7b8c10851f15a25cbea9a2df3669ec21dbd3
2015-03-25 20:50:41 -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
Chad Horohoe
ef621e06eb Make Profiler::$instance private and drop double underscores
Nothing calls it anymore outside of the class

Change-Id: Icc9ebcd63e440f9bafca29647856d36fc493ff39
2015-02-12 12:54:11 -08:00
Niklas Laxström
a7f7f8cbcb Unbreak master by restoring Profiler::profile(In|Out)
Keep functions in the abstract class to keep BC with SMW.

To I781f62be9

Change-Id: I81d3912cbffc88ed66c9d6d787db9f1ffe3b2de3
2015-01-09 09:17:13 +00:00
Aaron Schulz
4236b9beb6 Made profileIn/profileOut methods a no-op
Change-Id: I781f62be9747bb41af6faad6fbe265414fb77669
2015-01-08 01:54:51 -08: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