Support offsets in prefix searching
[mediawiki.git] / includes / profiler / output / ProfilerOutputUdp.php
bloba938861f794a4937e7404654ee04233619324872
1 <?php
2 /**
3 * Profiler sending messages over UDP.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup Profiler
24 /**
25 * ProfilerSimpleUDP class, that sends out messages for 'udpprofile' daemon
26 * (see http://git.wikimedia.org/tree/operations%2Fsoftware.git/master/udpprofile)
28 * @ingroup Profiler
29 * @since 1.25
31 class ProfilerOutputUdp extends ProfilerOutput {
32 public function canUse() {
33 # Sockets are not enabled
34 return function_exists( 'socket_create' );
37 public function log( array $stats ) {
38 global $wgUDPProfilerHost, $wgUDPProfilerPort, $wgUDPProfilerFormatString;
40 $sock = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
41 $plength = 0;
42 $packet = "";
43 foreach ( $stats as $pfdata ) {
44 $pfline = sprintf( $wgUDPProfilerFormatString,
45 $this->collector->getProfileID(),
46 $pfdata['calls'],
47 $pfdata['cpu'] / 1000, // ms => sec
48 0.0, // sum of CPU^2 for each invocation (unused)
49 $pfdata['real'] / 1000, // ms => sec
50 0.0, // sum of real^2 for each invocation (unused)
51 $pfdata['name'],
52 $pfdata['memory']
54 $length = strlen( $pfline );
55 if ( $length + $plength > 1400 ) {
56 socket_sendto( $sock, $packet, $plength, 0, $wgUDPProfilerHost, $wgUDPProfilerPort );
57 $packet = "";
58 $plength = 0;
60 $packet .= $pfline;
61 $plength += $length;
63 socket_sendto( $sock, $packet, $plength, 0x100, $wgUDPProfilerHost, $wgUDPProfilerPort );