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
This commit is contained in:
Timo Tijhof 2021-10-02 22:06:38 +01:00 committed by Krinkle
parent dfd0c73975
commit df32228920
4 changed files with 12 additions and 26 deletions

View file

@ -1062,16 +1062,13 @@ function wfLogWarning( $msg, $callerOffset = 1, $level = E_USER_WARNING ) {
* @todo Move logic to MediaWiki.php
*/
function wfLogProfilingData() {
$context = RequestContext::getMain();
$profiler = Profiler::instance();
$profiler->setContext( $context );
$profiler->logData();
// Send out any buffered statsd metrics as needed
MediaWiki::emitBufferedStatsdData(
MediaWikiServices::getInstance()->getStatsdDataFactory(),
$context->getConfig()
MediaWikiServices::getInstance()->getMainConfig()
);
}

View file

@ -1138,7 +1138,6 @@ class MediaWiki {
// Handle external profiler outputs.
// Any embedded profiler outputs were already processed in outputResponsePayload().
$profiler = Profiler::instance();
$profiler->setContext( $this->context );
$profiler->logData();
self::emitBufferedStatsdData(

View file

@ -126,29 +126,23 @@ abstract class Profiler {
}
/**
* Sets the context for this Profiler
*
* @internal
* @param IContextSource $context
* @since 1.25
*/
public function setContext( $context ) {
wfDeprecated( __METHOD__, '1.38' );
$this->context = $context;
}
/**
* Gets the context for this Profiler
*
* @internal
* @return IContextSource
* @since 1.25
*/
public function getContext() {
if ( $this->context ) {
return $this->context;
} else {
$this->logger->warning( __METHOD__ . " called before setContext, " .
"fallback to RequestContext::getMain()." );
return RequestContext::getMain();
}
wfDeprecated( __METHOD__, '1.38' );
return $this->context ?? RequestContext::getMain();
}
public function profileIn( $functionname ) {
@ -222,12 +216,12 @@ abstract class Profiler {
* @since 1.25
*/
public function logData() {
$request = $this->getContext()->getRequest();
$timeElapsed = $request->getElapsedTime();
$timeElapsedThreshold = $this->params['threshold'];
if ( $timeElapsed <= $timeElapsedThreshold ) {
return;
if ( $this->params['threshold'] > 0.0 ) {
// Note, this is also valid for CLI processes.
$timeElapsed = microtime( true ) - $_SERVER['REQUEST_TIME_FLOAT'];
if ( $timeElapsed <= $this->params['threshold'] ) {
return;
}
}
$outputs = [];

View file

@ -1253,10 +1253,6 @@ abstract class Maintenance {
// Handle external profiler outputs
// FIXME: Handle embedded outputs as well, such as ProfilerOutputText (T253547)
$profiler = Profiler::instance();
// FIXME: Make Profiler not need a WebRequest (T292269)
// This set/get call silences the Profiler::getContext warning.
// This is "safe" so long as Profiler.php only uses this to call WebRequest::getElapsedTime().
$profiler->setContext( RequestContext::getMain() );
$profiler->logData();
MediaWiki::emitBufferedStatsdData(