Added missing GPLv2 headers in some places.
[lhc/web/wiklou.git] / includes / profiler / ProfilerSimpleUDP.php
1 <?php
2 /**
3 * Profiler sending messages over UDP.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup Profiler
22 */
23
24 /**
25 * ProfilerSimpleUDP class, that sends out messages for 'udpprofile' daemon
26 * (the one from mediawiki/trunk/udpprofile SVN )
27 * @ingroup Profiler
28 */
29 class ProfilerSimpleUDP extends ProfilerSimple {
30 public function logData() {
31 global $wgUDPProfilerHost, $wgUDPProfilerPort;
32
33 $this->close();
34
35 if ( isset( $this->mCollated['-total'] ) && $this->mCollated['-total']['real'] < $this->mMinimumTime ) {
36 # Less than minimum, ignore
37 return;
38 }
39
40 if ( !MWInit::functionExists( 'socket_create' ) ) {
41 # Sockets are not enabled
42 return;
43 }
44
45 $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
46 $plength = 0;
47 $packet = "";
48 foreach ( $this->mCollated as $entry => $pfdata ) {
49 if( !isset($pfdata['count'])
50 || !isset( $pfdata['cpu'] )
51 || !isset( $pfdata['cpu_sq'] )
52 || !isset( $pfdata['real'] )
53 || !isset( $pfdata['real_sq'] ) ) {
54 continue;
55 }
56 $pfline = sprintf( "%s %s %d %f %f %f %f %s\n", $this->getProfileID(), "-", $pfdata['count'],
57 $pfdata['cpu'], $pfdata['cpu_sq'], $pfdata['real'], $pfdata['real_sq'], $entry);
58 $length = strlen( $pfline );
59 /* printf("<!-- $pfline -->"); */
60 if ( $length + $plength > 1400 ) {
61 socket_sendto( $sock, $packet, $plength, 0, $wgUDPProfilerHost, $wgUDPProfilerPort );
62 $packet = "";
63 $plength = 0;
64 }
65 $packet .= $pfline;
66 $plength += $length;
67 }
68 socket_sendto( $sock, $packet, $plength, 0x100, $wgUDPProfilerHost, $wgUDPProfilerPort );
69 }
70 }