Go to the documentation of this file.
24 use Wikimedia\ScopedCallback;
52 if ( isset(
$params[
'profileID'] ) ) {
53 $this->profileID =
$params[
'profileID'];
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'] ) ) {
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 ) {
142 if ( $this->context ) {
145 wfDebug( __METHOD__ .
" called and \$context is null. " .
146 "Return RequestContext::getMain(); for sanity\n" );
187 abstract public function close();
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() ) {
239 foreach ( $outputs as
$output ) {
252 if ( !$this->allowOutput ) {
258 if (
$output->logsToOutput() ) {
265 foreach ( $outputs as
$output ) {
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;
$wgProfileLimit
Only record profiling info for pages that took longer than this.
getTemplated()
Was this call as templated or not.
static getCurrentWikiDbDomain()
setTemplated( $t)
Mark this call as templated or not.
static replaceStubInstance(Profiler $profiler)
Replace the current profiler with $profiler if no non-stub profiler is set.
static instance()
Singleton.
getOutput()
Returns a profiling output to be stored in debug file.
getContentType()
Get the Content-Type for deciding how to format appended profile output.
static Profiler $instance
Stub profiler that does nothing.
string bool $profileID
Profiler ID for bucketing data.
IContextSource $context
Current request context.
scopedProfileIn( $section)
Mark the start of a custom profiling frame (e.g.
getOutputs()
Get all usable outputs.
TransactionProfiler $trxProfiler
Subclass ScopedCallback to avoid call_user_func_array(), which is slow.
profileOut( $functionname)
$wgProfiler
Profiler configuration.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
profileIn( $functionname)
close()
Close opened profiling sections.
setAllowOutput()
Enable appending profiles to standard output.
Profiler base class that defines the interface and some trivial functionality.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
__construct(array $params)
setContext( $context)
Sets the context for this Profiler.
logData()
Log the data to the backing store for all ProfilerOutput instances that have one.
static getMain()
Get the RequestContext object associated with the main request.
getContext()
Gets the context for this Profiler.
Interface for objects which can provide a MediaWiki context on request.
getFunctionStats()
Get the aggregated inclusive profiling data for each method.
logDataPageOutputOnly()
Log the data to the script/request output for all ProfilerOutput instances that do so.
getAllowOutput()
Whether appending profiles is allowed.
array $params
All of the params passed from $wgProfiler.
scopedProfileOut(SectionProfileCallback &$section=null)