Ejemplo n.º 1
0
 /**
  * Stop all profiling actions and submit collected data.
  */
 public static function stop()
 {
     if (self::$mode === self::MODE_NONE) {
         return;
     }
     $mode = self::$mode;
     if (self::$trace['tx'] === 'default' && self::$extension === self::EXTENSION_TIDEWAYS) {
         self::$trace['tx'] = tideways_transaction_name() ?: 'default';
     }
     if (function_exists('tideways_last_detected_exception') && ($exception = tideways_last_detected_exception())) {
         self::logException($exception);
     } elseif (function_exists("http_response_code") && http_response_code() >= 500) {
         self::logFatal("PHP request set error HTTP response code to '" . http_response_code() . "'.", "", 0, E_USER_ERROR);
     }
     $profilingData = array();
     if (($mode & self::MODE_FULL) > 0) {
         if (self::$extension === self::EXTENSION_TIDEWAYS) {
             $profilingData = tideways_disable();
         } elseif (self::$extension === self::EXTENSION_XHPROF) {
             $profilingData = xhprof_disable();
             self::$currentRootSpan->stopTimer();
         }
         $annotations = array('mem' => ceil(memory_get_peak_usage() / 1024));
         if (self::$extension === self::EXTENSION_TIDEWAYS) {
             $annotations['xhpv'] = phpversion('tideways');
         } elseif (self::$extension === self::EXTENSION_XHPROF) {
             $annotations['xhpv'] = phpversion('xhprof');
         }
         if (extension_loaded('xdebug')) {
             $annotations['xdebug'] = '1';
         }
         $annotations['php'] = PHP_VERSION;
         if (isset($_SERVER['REQUEST_URI'])) {
             $annotations['title'] = '';
             if (isset($_SERVER['REQUEST_METHOD'])) {
                 $annotations['title'] = $_SERVER["REQUEST_METHOD"] . ' ';
             }
             if (isset($_SERVER['HTTP_HOST'])) {
                 $annotations['title'] .= (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . self::getRequestUri();
             } elseif (isset($_SERVER['SERVER_ADDR'])) {
                 $annotations['title'] .= (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['SERVER_ADDR'] . self::getRequestUri();
             }
             if (isset($_SERVER['QUERY_STRING'])) {
                 $annotations['query'] = $_SERVER['QUERY_STRING'];
             }
         } elseif (php_sapi_name() === "cli") {
             $annotations['title'] = basename($_SERVER['argv'][0]);
         }
     } else {
         self::$currentRootSpan->stopTimer();
         $annotations = array('mem' => ceil(memory_get_peak_usage() / 1024));
     }
     self::$currentRootSpan->annotate($annotations);
     if (($mode & self::MODE_PROFILING) > 0) {
         self::$trace['profdata'] = $profilingData ?: array();
     }
     self::$mode = self::MODE_NONE;
     $spans = self::$currentRootSpan->getSpans();
     if (self::$error === true || ($mode & self::MODE_FULL) > 0) {
         self::$trace['spans'] = $spans;
         self::$backend->socketStore(self::$trace);
     } else {
         self::$trace['spans'] = isset($spans[0]) ? array($spans[0]) : array();
         // prevent flooding udp by accident
         self::$backend->udpStore(self::$trace);
     }
     self::$trace = null;
     // free memory
     self::$logLevel = 0;
 }