Go to the documentation of this file.
22 use Psr\Log\LoggerInterface;
24 use Wikimedia\ScopedCallback;
57 if ( isset(
$params[
'profileID'] ) ) {
58 $this->profileID =
$params[
'profileID'];
62 $this->logger = LoggerFactory::getInstance(
'profiler' );
70 if ( self::$instance ===
null ) {
74 'class' => ProfilerStub::class,
80 $inSample = mt_rand( 0,
$params[
'sampling'] - 1 ) === 0;
82 if ( PHP_SAPI ===
'cli' || PHP_SAPI ===
'phpdbg' || !$inSample ) {
83 $params[
'class'] = ProfilerStub::class;
86 if ( !is_array(
$params[
'output'] ) ) {
103 if ( self::$instance && !( self::$instance instanceof
ProfilerStub ) ) {
104 throw new MWException(
'Could not replace non-stub profiler instance.' );
106 self::$instance = $profiler;
114 $this->profileID = $id;
121 if ( $this->profileID ===
false ) {
145 if ( $this->context ) {
148 $this->logger->warning( __METHOD__ .
" called before setContext, " .
149 "fallback to RequestContext::getMain()." );
201 foreach ( $this->params[
'output'] as $outputType ) {
205 $outputClass = strpos( $outputType,
'ProfilerOutput' ) ===
false
206 ?
'ProfilerOutput' . ucfirst( $outputType )
208 if ( !class_exists( $outputClass ) ) {
209 throw new MWException(
"'$outputType' is an invalid output type" );
211 $outputInstance =
new $outputClass( $this, $this->params );
212 if ( $outputInstance->canUse() ) {
213 $outputs[] = $outputInstance;
227 $timeElapsed = $request->getElapsedTime();
228 $timeElapsedThreshold = $this->params[
'threshold'];
229 if ( $timeElapsed <= $timeElapsedThreshold ) {
235 if ( !$output->logsToOutput() ) {
236 $outputs[] = $output;
242 foreach ( $outputs as $output ) {
243 $output->log( $stats );
255 if ( !$this->allowOutput ) {
261 if ( $output->logsToOutput() ) {
262 $outputs[] = $output;
268 foreach ( $outputs as $output ) {
269 $output->log( $stats );
284 if ( $this->allowOutput ) {
285 foreach ( headers_list() as
$header ) {
286 if ( preg_match(
'#^content-type: (\w+/\w+);?#i',
$header, $m ) ) {
300 $this->allowOutput =
true;
static getCurrentWikiDbDomain()
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)
Logs 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 shared functionality.
__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)