32ab60eb944a982ec72157c22155bd253927dc84
[lhc/web/wiklou.git] / includes / profiler / ProfilerSimpleUDP.php
1 <?php
2 /**
3 * @file
4 * @ingroup Profiler
5 */
6
7 if ( !class_exists( 'ProfilerSimple' ) ) {
8 require_once( dirname( __FILE__ ) . '/ProfilerSimple.php' );
9 }
10
11 /**
12 * ProfilerSimpleUDP class, that sends out messages for 'udpprofile' daemon
13 * (the one from mediawiki/trunk/udpprofile SVN )
14 * @ingroup Profiler
15 */
16 class ProfilerSimpleUDP extends ProfilerSimple {
17 function getFunctionReport() {
18 global $wgUDPProfilerHost, $wgUDPProfilerPort;
19
20 if ( $this->mCollated['-total']['real'] < $this->mMinimumTime ) {
21 # Less than minimum, ignore
22 return;
23 }
24
25 $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
26 $plength=0;
27 $packet="";
28 foreach ($this->mCollated as $entry=>$pfdata) {
29 $pfline=sprintf ("%s %s %d %f %f %f %f %s\n", $this->getProfileID(),"-",$pfdata['count'],
30 $pfdata['cpu'],$pfdata['cpu_sq'],$pfdata['real'],$pfdata['real_sq'],$entry);
31 $length=strlen($pfline);
32 /* printf("<!-- $pfline -->"); */
33 if ($length+$plength>1400) {
34 socket_sendto($sock,$packet,$plength,0,$wgUDPProfilerHost,$wgUDPProfilerPort);
35 $packet="";
36 $plength=0;
37 }
38 $packet.=$pfline;
39 $plength+=$length;
40 }
41 socket_sendto($sock,$packet,$plength,0x100,$wgUDPProfilerHost,$wgUDPProfilerPort);
42 }
43 }