MediaWiki  1.32.5
ProfilerOutputDb.php
Go to the documentation of this file.
1 <?php
26 
35  private $perHost = false;
36 
38  parent::__construct( $collector, $params );
39 
40  // Initialize per-host profiling from config, back-compat if available
41  if ( isset( $this->params['perHost'] ) ) {
42  $this->perHost = $this->params['perHost'];
43  }
44  }
45 
46  public function canUse() {
47  # Do not log anything if database is readonly (T7375)
48  return !wfReadOnly();
49  }
50 
51  public function log( array $stats ) {
52  try {
53  $dbw = wfGetDB( DB_MASTER );
54  } catch ( DBError $e ) {
55  return; // ignore
56  }
57 
58  $fname = __METHOD__;
59  $dbw->onTransactionCommitOrIdle( function ( Database $dbw ) use ( $stats, $fname ) {
60  $pfhost = $this->perHost ? wfHostname() : '';
61  // Sqlite: avoid excess b-tree rebuilds (mostly for non-WAL mode)
62  // non-Sqlite: lower contention with small transactions
63  $useTrx = ( $dbw->getType() === 'sqlite' );
64 
65  try {
66  $useTrx ? $dbw->startAtomic( $fname ) : null;
67 
68  foreach ( $stats as $data ) {
69  $name = $data['name'];
70  $eventCount = $data['calls'];
71  $timeSum = (float)$data['real'];
72  $memorySum = (float)$data['memory'];
73  $name = substr( $name, 0, 255 );
74 
75  // Kludge
76  $timeSum = $timeSum >= 0 ? $timeSum : 0;
77  $memorySum = $memorySum >= 0 ? $memorySum : 0;
78 
79  $dbw->upsert( 'profiling',
80  [
81  'pf_name' => $name,
82  'pf_count' => $eventCount,
83  'pf_time' => $timeSum,
84  'pf_memory' => $memorySum,
85  'pf_server' => $pfhost
86  ],
87  [ [ 'pf_name', 'pf_server' ] ],
88  [
89  "pf_count=pf_count+{$eventCount}",
90  "pf_time=pf_time+{$timeSum}",
91  "pf_memory=pf_memory+{$memorySum}",
92  ],
93  $fname
94  );
95  }
96  } catch ( DBError $e ) {
97  // ignore
98  }
99 
100  try {
101  $useTrx ? $dbw->endAtomic( $fname ) : null;
102  } catch ( DBError $e ) {
103  // ignore
104  }
105  } );
106  }
107 }
Wikimedia\Rdbms\Database
Relational database abstraction object.
Definition: Database.php:48
Wikimedia\Rdbms\Database\endAtomic
endAtomic( $fname=__METHOD__)
Ends an atomic section of SQL statements.
Definition: Database.php:3703
wfHostname
wfHostname()
Fetch server name for use in error reporting etc.
Definition: GlobalFunctions.php:1392
wfReadOnly
wfReadOnly()
Check whether the wiki is in read-only mode.
Definition: GlobalFunctions.php:1237
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:35
ProfilerOutputDb\$perHost
bool $perHost
Whether to store host data with profiling calls.
Definition: ProfilerOutputDb.php:35
ProfilerOutput\$params
array $params
Configuration of $wgProfiler.
Definition: ProfilerOutput.php:31
Wikimedia\Rdbms\Database\startAtomic
startAtomic( $fname=__METHOD__, $cancelable=self::ATOMIC_NOT_CANCELABLE)
Begin an atomic section of SQL statements.
Definition: Database.php:3673
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2693
Wikimedia\Rdbms\Database\upsert
upsert( $table, array $rows, array $uniqueIndexes, array $set, $fname=__METHOD__)
INSERT ON DUPLICATE KEY UPDATE wrapper, upserts an array into a table.
Definition: Database.php:2863
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
DB_MASTER
const DB_MASTER
Definition: defines.php:26
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))
$fname
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
Definition: Setup.php:121
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2221
ProfilerOutputDb\__construct
__construct(Profiler $collector, array $params)
Definition: ProfilerOutputDb.php:37
ProfilerOutputDb\log
log(array $stats)
Log MediaWiki-style profiling data.
Definition: ProfilerOutputDb.php:51
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:9
ProfilerOutput
Base class for profiling output.
Definition: ProfilerOutput.php:27
Wikimedia\Rdbms\IDatabase\getType
getType()
Get the type of the DBMS, as it appears in $wgDBtype.
ProfilerOutputDb\canUse
canUse()
Can this output type be used?
Definition: ProfilerOutputDb.php:46
ProfilerOutputDb
Logs profiling data into the local DB.
Definition: ProfilerOutputDb.php:33