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