MediaWiki  1.23.8
ProfilerMwprof.php
Go to the documentation of this file.
1 <?php
35 class ProfilerMwprof extends Profiler {
36 
37  // Message types
38 
39  const TYPE_SINGLE = 1;
40  const TYPE_RUNNING = 2;
41 
51  public function isPersistent() {
52  return true;
53  }
54 
63  public function profileIn( $inName ) {
64  $this->mWorkStack[] = array( $inName, count( $this->mWorkStack ),
65  $this->getTime(), $this->getTime( 'cpu' ) );
66  }
67 
75  public function getFunctionReport() {
76  return '';
77  }
78 
87  public function profileOut( $outName ) {
88  list( $inName, $inCount, $inWall, $inCpu ) = array_pop( $this->mWorkStack );
89 
90  // Check for unbalanced profileIn / profileOut calls.
91  // Bad entries are logged but not sent.
92  if ( $inName !== $outName ) {
93  $this->debugGroup( 'ProfilerUnbalanced', json_encode( array( $inName, $outName ) ) );
94  return;
95  }
96 
97  $elapsedCpu = $this->getTime( 'cpu' ) - $inCpu;
98  $elapsedWall = $this->getTime() - $inWall;
99  $this->updateEntry( $outName, $elapsedCpu, $elapsedWall );
100  $this->updateTrxProfiling( $outName, $elapsedWall );
101  }
102 
110  public function updateEntry( $name, $elapsedCpu, $elapsedWall ) {
111  // If this is the first measurement for this entry, store plain values.
112  // Many profiled functions will only be called once per request.
113  if ( !isset( $this->mCollated[$name] ) ) {
114  $this->mCollated[$name] = array(
115  'cpu' => $elapsedCpu,
116  'wall' => $elapsedWall,
117  'count' => 1,
118  );
119  return;
120  }
121 
122  $entry = &$this->mCollated[$name];
123 
124  // If it's the second measurement, convert the plain values to
125  // RunningStat instances, so we can push the incoming values on top.
126  if ( $entry['count'] === 1 ) {
127  $cpu = new RunningStat();
128  $cpu->push( $entry['cpu'] );
129  $entry['cpu'] = $cpu;
130 
131  $wall = new RunningStat();
132  $wall->push( $entry['wall'] );
133  $entry['wall'] = $wall;
134  }
135 
136  $entry['count']++;
137  $entry['cpu']->push( $elapsedCpu );
138  $entry['wall']->push( $elapsedWall );
139  }
140 
149  public function logData() {
150  global $wgUDPProfilerHost, $wgUDPProfilerPort;
151 
152  $this->close();
153 
154  $sock = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
155  socket_connect( $sock, $wgUDPProfilerHost, $wgUDPProfilerPort );
156  $bufferLength = 0;
157  $buffer = '';
158  foreach ( $this->mCollated as $name => $entry ) {
159  $count = $entry['count'];
160  $cpu = $entry['cpu'];
161  $wall = $entry['wall'];
162 
163  if ( $count === 1 ) {
164  $data = array( self::TYPE_SINGLE, $name, $cpu, $wall );
165  } else {
166  $data = array( self::TYPE_RUNNING, $name, $count,
167  $cpu->m1, $cpu->m2, $cpu->min, $cpu->max,
168  $wall->m1, $wall->m2, $wall->min, $wall->max );
169  }
170 
171  $encoded = MWMessagePack::pack( $data );
172  $length = strlen( $encoded );
173 
174  // If adding this entry would cause the size of the buffer to
175  // exceed the standard ethernet MTU size less the UDP header,
176  // send all pending data and reset the buffer. Otherwise, continue
177  // accumulating entries into the current buffer.
178  if ( $length + $bufferLength > 1450 ) {
179  socket_send( $sock, $buffer, $bufferLength, 0 );
180  $buffer = '';
181  $bufferLength = 0;
182  }
183  $buffer .= $encoded;
184  $bufferLength += $length;
185  }
186  if ( $bufferLength !== 0 ) {
187  socket_send( $sock, $buffer, $bufferLength, 0 );
188  }
189  }
190 }
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
ProfilerMwprof\profileOut
profileOut( $outName)
Close a profiling section.
Definition: ProfilerMwprof.php:87
ProfilerMwprof\isPersistent
isPersistent()
Indicate that this Profiler subclass is persistent.
Definition: ProfilerMwprof.php:51
ProfilerMwprof\updateEntry
updateEntry( $name, $elapsedCpu, $elapsedWall)
Update an entry with timing data.
Definition: ProfilerMwprof.php:110
ProfilerMwprof\TYPE_RUNNING
const TYPE_RUNNING
Definition: ProfilerMwprof.php:40
RunningStat
Represents a running summary of a stream of numbers.
Definition: RunningStat.php:52
Profiler\close
close()
Close opened profiling sections.
Definition: Profiler.php:253
Profiler
Definition: Profiler.php:97
Profiler\getTime
getTime( $metric=false)
Get the initial time of the request, based either on $wgRequestTime or $wgRUstart.
Definition: Profiler.php:438
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
ProfilerMwprof\getFunctionReport
getFunctionReport()
Produce an empty function report.
Definition: ProfilerMwprof.php:75
list
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
ProfilerMwprof
Profiler class for Mwprof.
Definition: ProfilerMwprof.php:35
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
$count
$count
Definition: UtfNormalTest2.php:96
MWMessagePack\pack
static pack( $value)
Encode a value using MessagePack.
Definition: MWMessagePack.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
Profiler\updateTrxProfiling
updateTrxProfiling( $method, $realtime)
Register the name and time of a method for slow DB trx detection.
Definition: Profiler.php:283
ProfilerMwprof\profileIn
profileIn( $inName)
Start a profiling section.
Definition: ProfilerMwprof.php:63
Profiler\debugGroup
debugGroup( $group, $s)
Add an entry in the debug log group.
Definition: Profiler.php:764
ProfilerMwprof\TYPE_SINGLE
const TYPE_SINGLE
Definition: ProfilerMwprof.php:39
ProfilerMwprof\logData
logData()
Serialize profiling data and send to a profiling data aggregator.
Definition: ProfilerMwprof.php:149