MediaWiki  1.33.0
ProfilerOutputText.php
Go to the documentation of this file.
1 <?php
32  protected $thresholdMs;
33 
35  parent::__construct( $collector, $params );
36  $this->thresholdMs = $params['thresholdMs'] ?? 1.0;
37  }
38 
39  public function logsToOutput() {
40  return true;
41  }
42 
43  public function log( array $stats ) {
44  if ( $this->collector->getTemplated() ) {
45  $out = '';
46 
47  // Filter out really tiny entries
48  $min = $this->thresholdMs;
49  $stats = array_filter( $stats, function ( $a ) use ( $min ) {
50  return $a['real'] > $min;
51  } );
52  // Sort descending by time elapsed
53  usort( $stats, function ( $a, $b ) {
54  return $b['real'] <=> $a['real'];
55  } );
56 
57  array_walk( $stats,
58  function ( $item ) use ( &$out ) {
59  $out .= sprintf( "%6.2f%% %3.3f %6d - %s\n",
60  $item['%real'], $item['real'], $item['calls'], $item['name'] );
61  }
62  );
63 
64  $contentType = $this->collector->getContentType();
65  if ( wfIsCLI() ) {
66  print "<!--\n{$out}\n-->\n";
67  } elseif ( $contentType === 'text/html' ) {
68  $visible = $this->params['visible'] ?? false;
69  if ( $visible ) {
70  print "<pre>{$out}</pre>";
71  } else {
72  print "<!--\n{$out}\n-->\n";
73  }
74  } elseif ( $contentType === 'text/javascript' || $contentType === 'text/css' ) {
75  print "\n/*\n{$out}*/\n";
76  }
77  }
78  }
79 }
ProfilerOutputText\$thresholdMs
float $thresholdMs
Min real time display threshold.
Definition: ProfilerOutputText.php:32
$out
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:780
ProfilerOutputText
The least sophisticated profiler output class possible, view your source! :)
Definition: ProfilerOutputText.php:30
ProfilerOutput\$collector
Profiler $collector
Definition: ProfilerOutput.php:29
ProfilerOutputText\__construct
__construct(Profiler $collector, array $params)
Definition: ProfilerOutputText.php:34
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
ProfilerOutput\$params
array $params
Configuration of $wgProfiler.
Definition: ProfilerOutput.php:31
ProfilerOutputText\log
log(array $stats)
Log MediaWiki-style profiling data.
Definition: ProfilerOutputText.php:43
Profiler
Profiler base class that defines the interface and some trivial functionality.
Definition: Profiler.php:33
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
ProfilerOutputText\logsToOutput
logsToOutput()
Does log() just send the data to the request/script output?
Definition: ProfilerOutputText.php:39
wfIsCLI
wfIsCLI()
Check if we are running from the commandline.
Definition: GlobalFunctions.php:1974
ProfilerOutput
Base class for profiling output.
Definition: ProfilerOutput.php:27