ProfilerSimpleUDP.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * @file
  4. * @ingroup Profiler
  5. */
  6. require_once(dirname(__FILE__).'/ProfilerSimple.php');
  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. function getFunctionReport() {
  14. global $wgUDPProfilerHost, $wgUDPProfilerPort;
  15. if ( $this->mCollated['-total']['real'] < $this->mMinimumTime ) {
  16. # Less than minimum, ignore
  17. return;
  18. }
  19. $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
  20. $plength=0;
  21. $packet="";
  22. foreach ($this->mCollated as $entry=>$pfdata) {
  23. $pfline=sprintf ("%s %s %d %f %f %f %f %s\n", $this->getProfileID(),"-",$pfdata['count'],
  24. $pfdata['cpu'],$pfdata['cpu_sq'],$pfdata['real'],$pfdata['real_sq'],$entry);
  25. $length=strlen($pfline);
  26. /* printf("<!-- $pfline -->"); */
  27. if ($length+$plength>1400) {
  28. socket_sendto($sock,$packet,$plength,0,$wgUDPProfilerHost,$wgUDPProfilerPort);
  29. $packet="";
  30. $plength=0;
  31. }
  32. $packet.=$pfline;
  33. $plength+=$length;
  34. }
  35. socket_sendto($sock,$packet,$plength,0x100,$wgUDPProfilerHost,$wgUDPProfilerPort);
  36. }
  37. }