MediaWiki  REL1_31
ProfilerOutputDb.php
Go to the documentation of this file.
1 <?php
25 
34  private $perHost = false;
35 
37  parent::__construct( $collector, $params );
38 
39  // Initialize per-host profiling from config, back-compat if available
40  if ( isset( $this->params['perHost'] ) ) {
41  $this->perHost = $this->params['perHost'];
42  }
43  }
44 
45  public function canUse() {
46  # Do not log anything if database is readonly (T7375)
47  return !wfReadOnly();
48  }
49 
50  public function log( array $stats ) {
51  try {
52  $dbw = wfGetDB( DB_MASTER );
53  } catch ( DBError $e ) {
54  return; // ignore
55  }
56 
57  $fname = __METHOD__;
58  $dbw->onTransactionIdle( function () use ( $stats, $dbw, $fname ) {
59  $pfhost = $this->perHost ? wfHostname() : '';
60  // Sqlite: avoid excess b-tree rebuilds (mostly for non-WAL mode)
61  // non-Sqlite: lower contention with small transactions
62  $useTrx = ( $dbw->getType() === 'sqlite' );
63 
64  try {
65  $useTrx ? $dbw->startAtomic( $fname ) : null;
66 
67  foreach ( $stats as $data ) {
68  $name = $data['name'];
69  $eventCount = $data['calls'];
70  $timeSum = (float)$data['real'];
71  $memorySum = (float)$data['memory'];
72  $name = substr( $name, 0, 255 );
73 
74  // Kludge
75  $timeSum = $timeSum >= 0 ? $timeSum : 0;
76  $memorySum = $memorySum >= 0 ? $memorySum : 0;
77 
78  $dbw->upsert( 'profiling',
79  [
80  'pf_name' => $name,
81  'pf_count' => $eventCount,
82  'pf_time' => $timeSum,
83  'pf_memory' => $memorySum,
84  'pf_server' => $pfhost
85  ],
86  [ [ 'pf_name', 'pf_server' ] ],
87  [
88  "pf_count=pf_count+{$eventCount}",
89  "pf_time=pf_time+{$timeSum}",
90  "pf_memory=pf_memory+{$memorySum}",
91  ],
92  $fname
93  );
94  }
95  } catch ( DBError $e ) {
96  // ignore
97  }
98 
99  try {
100  $useTrx ? $dbw->endAtomic( $fname ) : null;
101  } catch ( DBError $e ) {
102  // ignore
103  }
104  } );
105  }
106 }
use
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Definition: APACHE-LICENSE-2.0.txt:10
array
the array() calling protocol came about after MediaWiki 1.4rc1.
wfHostname
wfHostname()
Fetch server name for use in error reporting etc.
Definition: GlobalFunctions.php:1420
wfReadOnly
wfReadOnly()
Check whether the wiki is in read-only mode.
Definition: GlobalFunctions.php:1262
ProfilerOutput\$collector
Profiler $collector
Definition: ProfilerOutput.php:29
Wikimedia\Rdbms\DBError
Database error base class.
Definition: DBError.php:30
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:37
ProfilerOutputDb\$perHost
bool $perHost
Whether to store host data with profiling calls.
Definition: ProfilerOutputDb.php:34
ProfilerOutput\$params
array $params
Configuration of $wgProfiler.
Definition: ProfilerOutput.php:31
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2812
Profiler
Profiler base class that defines the interface and some trivial functionality.
Definition: Profiler.php:33
DB_MASTER
const DB_MASTER
Definition: defines.php:29
$fname
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
Definition: Setup.php:112
ProfilerOutputDb\__construct
__construct(Profiler $collector, array $params)
Definition: ProfilerOutputDb.php:36
ProfilerOutputDb\log
log(array $stats)
Log MediaWiki-style profiling data.
Definition: ProfilerOutputDb.php:50
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:22
ProfilerOutput
Base class for profiling output.
Definition: ProfilerOutput.php:27
ProfilerOutputDb\canUse
canUse()
Can this output type be used?
Definition: ProfilerOutputDb.php:45
ProfilerOutputDb
Logs profiling data into the local DB.
Definition: ProfilerOutputDb.php:32
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2171