MediaWiki REL1_33
Timing.php
Go to the documentation of this file.
1<?php
21use Psr\Log\LoggerAwareInterface;
22use Psr\Log\LoggerInterface;
23use Psr\Log\NullLogger;
24
45class Timing implements LoggerAwareInterface {
46
48 private $entries = [];
49
51 protected $logger;
52
53 public function __construct( array $params = [] ) {
54 $this->clearMarks();
55 $this->setLogger( $params['logger'] ?? new NullLogger() );
56 }
57
64 public function setLogger( LoggerInterface $logger ) {
65 $this->logger = $logger;
66 }
67
75 public function mark( $markName ) {
76 $this->entries[$markName] = [
77 'name' => $markName,
78 'entryType' => 'mark',
79 'startTime' => microtime( true ),
80 'duration' => 0,
81 ];
82 return $this->entries[$markName];
83 }
84
89 public function clearMarks( $markName = null ) {
90 if ( $markName !== null ) {
91 unset( $this->entries[$markName] );
92 } else {
93 $this->entries = [
94 'requestStart' => [
95 'name' => 'requestStart',
96 'entryType' => 'mark',
97 'startTime' => $_SERVER['REQUEST_TIME_FLOAT'],
98 'duration' => 0,
99 ],
100 ];
101 }
102 }
103
124 public function measure( $measureName, $startMark = 'requestStart', $endMark = null ) {
125 $start = $this->getEntryByName( $startMark );
126 if ( $start === null ) {
127 $this->logger->error( __METHOD__ . ": The mark '$startMark' does not exist" );
128 return false;
129 }
130 $startTime = $start['startTime'];
131
132 if ( $endMark ) {
133 $end = $this->getEntryByName( $endMark );
134 if ( $end === null ) {
135 $this->logger->error( __METHOD__ . ": The mark '$endMark' does not exist" );
136 return false;
137 }
138 $endTime = $end['startTime'];
139 } else {
140 $endTime = microtime( true );
141 }
142
143 $this->entries[$measureName] = [
144 'name' => $measureName,
145 'entryType' => 'measure',
146 'startTime' => $startTime,
147 'duration' => $endTime - $startTime,
148 ];
149
150 return $this->entries[$measureName];
151 }
152
156 private function sortEntries() {
157 uasort( $this->entries, function ( $a, $b ) {
158 return $a['startTime'] <=> $b['startTime'];
159 } );
160 }
161
165 public function getEntries() {
166 $this->sortEntries();
167 return $this->entries;
168 }
169
175 public function getEntriesByType( $entryType ) {
176 $this->sortEntries();
177 $entries = [];
178 foreach ( $this->entries as $entry ) {
179 if ( $entry['entryType'] === $entryType ) {
180 $entries[] = $entry;
181 }
182 }
183 return $entries;
184 }
185
190 public function getEntryByName( $name ) {
191 return $this->entries[$name] ?? null;
192 }
193}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
An interface to help developers measure the performance of their applications.
Definition Timing.php:45
array[] $entries
Definition Timing.php:48
sortEntries()
Sort entries in chronological order with respect to startTime.
Definition Timing.php:156
clearMarks( $markName=null)
Definition Timing.php:89
mark( $markName)
Store a timestamp with the associated name (a "mark")
Definition Timing.php:75
LoggerInterface $logger
Definition Timing.php:51
getEntriesByType( $entryType)
Definition Timing.php:175
getEntryByName( $name)
Definition Timing.php:190
measure( $measureName, $startMark='requestStart', $endMark=null)
This method stores the duration between two marks along with the associated name (a "measure").
Definition Timing.php:124
setLogger(LoggerInterface $logger)
Sets a logger instance on the object.
Definition Timing.php:64
getEntries()
Definition Timing.php:165
__construct(array $params=[])
Definition Timing.php:53
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
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:271
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
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))
$params