24use Wikimedia\ScopedCallback;
52 if ( isset( $params[
'profileID'] ) ) {
53 $this->profileID = $params[
'profileID'];
55 $this->params = $params;
64 if ( self::$instance ===
null ) {
68 'class' => ProfilerStub::class,
77 $inSample = mt_rand( 0,
$params[
'sampling'] - 1 ) === 0;
79 if ( PHP_SAPI ===
'cli' || PHP_SAPI ===
'phpdbg' || !$inSample ) {
80 $params[
'class'] = ProfilerStub::class;
83 if ( !is_array(
$params[
'output'] ) ) {
89 return self::$instance;
100 if ( self::$instance && !( self::$instance instanceof
ProfilerStub ) ) {
101 throw new MWException(
'Could not replace non-stub profiler instance.' );
103 self::$instance = $profiler;
111 $this->profileID = $id;
118 if ( $this->profileID ===
false ) {
119 return WikiMap::getCurrentWikiDbDomain()->getId();
121 return $this->profileID;
142 if ( $this->context ) {
145 wfDebug( __METHOD__ .
" called and \$context is null. " .
146 "Return RequestContext::getMain(); for sanity\n" );
147 return RequestContext::getMain();
181 return $this->trxProfiler;
198 foreach ( $this->params[
'output'] as $outputType ) {
202 $outputClass = strpos( $outputType,
'ProfilerOutput' ) ===
false
203 ?
'ProfilerOutput' . ucfirst( $outputType )
205 if ( !class_exists( $outputClass ) ) {
206 throw new MWException(
"'$outputType' is an invalid output type" );
208 $outputInstance =
new $outputClass( $this, $this->params );
209 if ( $outputInstance->canUse() ) {
210 $outputs[] = $outputInstance;
224 $timeElapsed = $request->getElapsedTime();
225 $timeElapsedThreshold = $this->params[
'threshold'];
226 if ( $timeElapsed <= $timeElapsedThreshold ) {
232 if ( !$output->logsToOutput() ) {
233 $outputs[] = $output;
239 foreach ( $outputs as $output ) {
240 $output->log( $stats );
252 if ( !$this->allowOutput ) {
258 if ( $output->logsToOutput() ) {
259 $outputs[] = $output;
265 foreach ( $outputs as $output ) {
266 $output->log( $stats );
281 if ( $this->allowOutput ) {
282 foreach ( headers_list() as
$header ) {
283 if ( preg_match(
'#^content-type: (\w+/\w+);?#i',
$header, $m ) ) {
299 $this->allowOutput = (
$t ===
true );
319 $this->allowOutput =
true;
329 return $this->allowOutput;
$wgProfileLimit
Only record profiling info for pages that took longer than this.
$wgProfiler
Profiler configuration.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Stub profiler that does nothing.
Profiler base class that defines the interface and some trivial functionality.
setAllowOutput()
Enable appending profiles to standard output.
static replaceStubInstance(Profiler $profiler)
Replace the current profiler with $profiler if no non-stub profiler is set.
string bool $profileID
Profiler ID for bucketing data.
static Profiler $instance
setContext( $context)
Sets the context for this Profiler.
setTemplated( $t)
Mark this call as templated or not.
getOutputs()
Get all usable outputs.
close()
Close opened profiling sections.
logData()
Log the data to the backing store for all ProfilerOutput instances that have one.
TransactionProfiler $trxProfiler
__construct(array $params)
profileOut( $functionname)
logDataPageOutputOnly()
Log the data to the script/request output for all ProfilerOutput instances that do so.
getOutput()
Returns a profiling output to be stored in debug file.
static instance()
Singleton.
getContentType()
Get the Content-Type for deciding how to format appended profile output.
getFunctionStats()
Get the aggregated inclusive profiling data for each method.
scopedProfileIn( $section)
Mark the start of a custom profiling frame (e.g.
getTemplated()
Was this call as templated or not.
getAllowOutput()
Whether appending profiles is allowed.
scopedProfileOut(SectionProfileCallback &$section=null)
array $params
All of the params passed from $wgProfiler.
profileIn( $functionname)
getContext()
Gets the context for this Profiler.
Subclass ScopedCallback to avoid call_user_func_array(), which is slow.
Interface for objects which can provide a MediaWiki context on request.