Fixed spacing in db/debug/diff/externalstore/objectcache folder
[mediawiki.git] / includes / profiler / ProfilerSimpleUDP.php
blob83bdf71eb9208a7e94a4b928f4bcbdab85a68fb0
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 * (the one from mediawiki/trunk/udpprofile SVN )
27 * @ingroup Profiler
29 class ProfilerSimpleUDP extends ProfilerSimple {
30 public function isPersistent() {
31 return true;
34 public function logData() {
35 global $wgUDPProfilerHost, $wgUDPProfilerPort;
37 $this->close();
39 if ( isset( $this->mCollated['-total'] ) && $this->mCollated['-total']['real'] < $this->mMinimumTime ) {
40 # Less than minimum, ignore
41 return;
44 if ( !MWInit::functionExists( 'socket_create' ) ) {
45 # Sockets are not enabled
46 return;
49 $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
50 $plength = 0;
51 $packet = "";
52 foreach ( $this->mCollated as $entry => $pfdata ) {
53 if ( !isset( $pfdata['count'] )
54 || !isset( $pfdata['cpu'] )
55 || !isset( $pfdata['cpu_sq'] )
56 || !isset( $pfdata['real'] )
57 || !isset( $pfdata['real_sq'] ) ) {
58 continue;
60 $pfline = sprintf( "%s %s %d %f %f %f %f %s\n", $this->getProfileID(), "-", $pfdata['count'],
61 $pfdata['cpu'], $pfdata['cpu_sq'], $pfdata['real'], $pfdata['real_sq'], $entry );
62 $length = strlen( $pfline );
63 /* printf("<!-- $pfline -->"); */
64 if ( $length + $plength > 1400 ) {
65 socket_sendto( $sock, $packet, $plength, 0, $wgUDPProfilerHost, $wgUDPProfilerPort );
66 $packet = "";
67 $plength = 0;
69 $packet .= $pfline;
70 $plength += $length;
72 socket_sendto( $sock, $packet, $plength, 0x100, $wgUDPProfilerHost, $wgUDPProfilerPort );