MediaWiki REL1_28
ProfilerOutputDb.php
Go to the documentation of this file.
1<?php
32 private $perHost = false;
33
35 parent::__construct( $collector, $params );
36
37 // Initialize per-host profiling from config, back-compat if available
38 if ( isset( $this->params['perHost'] ) ) {
39 $this->perHost = $this->params['perHost'];
40 }
41 }
42
43 public function canUse() {
44 # Do not log anything if database is readonly (bug 5375)
45 return !wfReadOnly();
46 }
47
48 public function log( array $stats ) {
49 $pfhost = $this->perHost ? wfHostname() : '';
50
51 try {
52 $dbw = wfGetDB( DB_MASTER );
53 $useTrx = ( $dbw->getType() === 'sqlite' ); // much faster
54 if ( $useTrx ) {
55 $dbw->startAtomic( __METHOD__ );
56 }
57 foreach ( $stats as $data ) {
58 $name = $data['name'];
59 $eventCount = $data['calls'];
60 $timeSum = (float)$data['real'];
61 $memorySum = (float)$data['memory'];
62 $name = substr( $name, 0, 255 );
63
64 // Kludge
65 $timeSum = $timeSum >= 0 ? $timeSum : 0;
66 $memorySum = $memorySum >= 0 ? $memorySum : 0;
67
68 $dbw->upsert( 'profiling',
69 [
70 'pf_name' => $name,
71 'pf_count' => $eventCount,
72 'pf_time' => $timeSum,
73 'pf_memory' => $memorySum,
74 'pf_server' => $pfhost
75 ],
76 [ [ 'pf_name', 'pf_server' ] ],
77 [
78 "pf_count=pf_count+{$eventCount}",
79 "pf_time=pf_time+{$timeSum}",
80 "pf_memory=pf_memory+{$memorySum}",
81 ],
82 __METHOD__
83 );
84 }
85 if ( $useTrx ) {
86 $dbw->endAtomic( __METHOD__ );
87 }
88 } catch ( DBError $e ) {
89 }
90 }
91}
wfReadOnly()
Check whether the wiki is in read-only mode.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfHostname()
Fetch server name for use in error reporting etc.
Database error base class.
Definition DBError.php:26
Logs profiling data into the local DB.
log(array $stats)
Log MediaWiki-style profiling data.
canUse()
Can this output type be used?
bool $perHost
Whether to store host data with profiling calls.
__construct(Profiler $collector, array $params)
Constructor.
Base class for profiling output.
array $params
Configuration of $wgProfiler.
Profiler base class that defines the interface and some trivial functionality.
Definition Profiler.php:32
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
the array() calling protocol came about after MediaWiki 1.4rc1.
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:304
returning false will NOT prevent logging $e
Definition hooks.txt:2110
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
const DB_MASTER
Definition defines.php:23