예제 #1
0
 /**
  * List of files in $dir whose filename has the format $format
  *
  * @return array Files
  */
 private static function getFiles($format, $dir, $preprocessed = false)
 {
     $list = preg_grep($format, scandir($dir));
     $files = array();
     // If current script under profiler, get it's output file name for exclusion
     if (function_exists('xdebug_get_profiler_filename') && ($profiler_filename = xdebug_get_profiler_filename()) !== false) {
         $selfFile = realpath($profiler_filename);
     }
     foreach ($list as $file) {
         $absoluteFilename = realpath($dir . '/' . $file);
         // Make sure that script never parses the profile currently being generated. (infinite loop)
         if (!empty($selfFile) && $selfFile === $absoluteFilename) {
             continue;
         }
         if (!$preprocessed) {
             // Exclude preprocessed files
             if (endsWith($absoluteFilename, Webgrind::$config->preprocessedSuffix)) {
                 continue;
             }
             // If set in config, exclude Webgrind files profiles
             $invokeUrl = self::getInvokeUrl($absoluteFilename);
             if (Webgrind::$config->hideWebgrindProfiles && startsWith($invokeUrl, WEBGRIND_ROOT)) {
                 continue;
             }
         }
         $files[$file] = array('absoluteFilename' => $absoluteFilename, 'mtime' => filemtime($absoluteFilename), 'preprocessed' => $preprocessed, 'filesize' => self::bytestostring(filesize($absoluteFilename)));
         if (!$preprocessed) {
             $files[$file]['invokeUrl'] = $invokeUrl;
         }
     }
     return $files;
 }
예제 #2
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     $this->_xlog['time'] = microtime(true);
     $this->_xlog['memory'] = memory_get_usage();
     $this->_xlog['maxmem'] = $this->_xlog['memory'];
     $this->_xlog['minmem'] = $this->_xlog['memory'];
     $this->_xdebug_on = !empty(xdebug_get_profiler_filename());
 }
예제 #3
0
 public function html()
 {
     $h = '<div class="kanon-profiler">';
     if (function_exists('xdebug_get_profiler_filename')) {
         $h .= '<div>XDebug: ' . xdebug_get_profiler_filename() . '</div>';
     }
     $h .= '<div>Total queries: ' . count($this->_sql) . '</div>';
     $totalSqlTime = 0;
     foreach ($this->_sql as $sqlInfo) {
         $totalSqlTime += $sqlInfo['time'];
     }
     $h .= '<div>Total runtime: ' . number_format(microtime(true) - self::$_enableTime, 6, '.', '') . '</div>';
     $h .= '<div>Total time: ' . number_format($totalSqlTime, 6, '.', '') . '</div>';
     $h .= '<table width="100%" class="sql">';
     foreach ($this->_sql as $sqlInfo) {
         $h .= '<tr><td>';
         $h .= '<strong style="font-weight: normal;color: #ddd;">' . htmlspecialchars($sqlInfo['sql']) . '</strong>';
         $h .= '<div>';
         if ($sqlInfo['time'] > 0.01) {
             $h .= '<span style="color: #f00">';
         }
         $h .= 'Time: ' . number_format($sqlInfo['time'], 6, '.', '');
         if ($sqlInfo['time'] > 0.01) {
             $h .= '</span>';
         }
         $h .= ' Start: ' . number_format($sqlInfo['start'] - self::$_enableTime, 6, '.', '');
         if ($traceInfo = $this->_getTraceController($sqlInfo['trace'])) {
             $h .= ' ' . $traceInfo['class'] . $traceInfo['type'] . $traceInfo['function'] . '() at line ' . $traceInfo['line'];
         }
         $i = 0;
         $skip = array('profiler', 'mysqlDriver', 'storageDriver', 'modelStorage', 'modelExpression', 'modelQueryBuilder', 'modelResultSet');
         foreach ($sqlInfo['trace'] as $traceInfo) {
             if (in_array($traceInfo['class'], $skip)) {
                 array_shift($sqlInfo['trace']);
             } else {
                 break;
             }
         }
         foreach ($sqlInfo['trace'] as $traceInfo) {
             $i++;
             $h .= '<div style="line-height: 1em;font-size:10px;">';
             $h .= '#' . $i . ' ' . $traceInfo['class'] . $traceInfo['type'] . $traceInfo['function'] . '() at line ' . $traceInfo['line'];
             $h .= '</div>';
         }
         $h .= '</div>';
         $h .= '</td></tr>';
     }
     $h .= '</table>';
     $h .= yProfiler::html();
     return $h . '</div>';
 }
 /**
  * destructor, outputs Total Render time if DEBUG>0
  */
 function __destruct()
 {
     if (DEBUG > 0) {
         kataDebugOutput('Total Render Time (including Models) ' . (microtime(true) - $this->starttime) . ' secs');
         kataDebugOutput('Memory used ' . number_format(memory_get_usage(true)) . ' bytes');
         kataDebugOutput('Parameters ' . print_R($this->params, true));
         if (function_exists('xdebug_get_profiler_filename')) {
             $fn = xdebug_get_profiler_filename();
             if (false !== $fn) {
                 kataDebugOutput('profilefile:' . $fn);
             }
         }
         kataDebugOutput('Loaded classes: ' . implode(' ', array_keys(classRegistry::getLoadedClasses())));
     }
 }
예제 #5
0
 public static function view($removefieldset = false)
 {
     if (!self::$_started) {
         return;
     }
     self::$timeEnd = self::getmicrotime();
     $time = sprintf('%.5f', self::$timeEnd - self::$timeStart);
     $files = sprintf('%.5f', self::$filesTime);
     $rapportSQL = sprintf('%.2f', 100 * self::$totalTime / $time);
     $rapportPHP = 100 - $rapportSQL;
     $memoryPeak = round(memory_get_peak_usage() / 1048576, 3);
     $content = 'File ' . $_SERVER['SCRIPT_NAME'] . "\n" . 'Loaded in ' . $time . ' seconds' . "\n" . 'Loaded PHP files : ' . self::$filesLoaded . "\n" . 'SQL requests : ' . sprintf('%.5f', self::$totalTime) . ' seconds (' . self::$sqlNbRequests . ' requests)' . "\n" . '% SQL/PHP : ' . $rapportSQL . ' / ' . $rapportPHP . ' %' . "\n" . 'Memory Peak : ' . $memoryPeak . 'Mo' . "\n";
     if (function_exists('xdebug_get_profiler_filename') && xdebug_get_profiler_filename()) {
         $content .= 'XDebug Profile : ' . xdebug_get_profiler_filename() . "\n";
     }
     if (function_exists('xdebug_get_profiler_filename') && xdebug_get_tracefile_name()) {
         $content .= 'XDebug Trace : ' . xdebug_get_tracefile_name() . "\n";
     }
     $content .= 'User : '******' (' . CMS_session::getUserId() . ')' : 'none') . "\n";
     $content .= 'Session Id ' . Zend_Session::getId() . "\n";
     //$content .= 'Current page '.CMS_session::getPageID()."\n";
     if (VIEW_SQL && $_SERVER["SCRIPT_NAME"] != PATH_ADMIN_WR . '/stat.php') {
         $stat = array('stat_time_start' => self::$timeStart, 'stat_time_end' => self::$timeEnd, 'stat_total_time' => self::$totalTime, 'stat_sql_nb_requests' => self::$sqlNbRequests, 'stat_sql_table' => self::$sqlTable, 'stat_content_name' => basename($_SERVER["SCRIPT_NAME"]), 'stat_files_table' => self::$filesTable, 'stat_memory_table' => self::$memoryTable, 'stat_memory_peak' => $memoryPeak, 'stat_files_loaded' => self::$filesLoaded);
         $statName = 'stat_' . md5(rand());
         //save stats to cache (for 10 min)
         $cache = new CMS_cache($statName, 'atm-stats', 600, false);
         if ($cache) {
             $cache->save($stat);
         }
     }
     $content = !$removefieldset ? '<fieldset style="width:200px;" class="atm-debug"><legend>Debug Statistics</legend><pre>' . $content . '</pre>' : 'Debug Statistics :' . "\n" . $content;
     if (isset($statName)) {
         $content .= '<a href="' . PATH_ADMIN_WR . '/stat.php?stat=' . $statName . '" target="_blank">View statistics detail</a>';
     }
     //end xhprof profiling
     if (defined('APPLICATION_ENABLE_PROFILING') && APPLICATION_ENABLE_PROFILING && function_exists('xhprof_disable')) {
         $xhprof_data = xhprof_disable();
         include_once APPLICATION_XHPROF_ROOT_FS . "/xhprof_lib/utils/xhprof_lib.php";
         include_once APPLICATION_XHPROF_ROOT_FS . "/xhprof_lib/utils/xhprof_runs.php";
         $xhprof_runs = new XHProfRuns_Default();
         $profileName = md5($_SERVER['REQUEST_URI']);
         $run_id = $xhprof_runs->save_run($xhprof_data, md5($_SERVER['REQUEST_URI']));
         $content .= '<br /><a href="' . APPLICATION_XHPROF_URI . 'xhprof_html/index.php?run=' . $run_id . '&amp;source=' . $profileName . '" target="_blank">View profiling detail</a>';
     }
     $content .= !$removefieldset ? '</fieldset>' : '';
     return $content;
 }
예제 #6
0
if ($is_web) {
    echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">\n<head>\n<title>{$title}</title>\n</head>\n<body>\n<h1>{$title}</h1>\n<pre>\n";
} else {
    echo "{$title}\n\n";
}
if ($is_web) {
    echo "<h3>Using lib version: " . PhpXmlRpc::$xmlrpcVersion . " on PHP version: " . phpversion() . "</h3>\n";
    if ($xd) {
        echo "<h4>XDEBUG profiling enabled: skipping remote tests. Trace file is: " . htmlspecialchars(xdebug_get_profiler_filename()) . "</h4>\n";
    }
    flush();
    ob_flush();
} else {
    echo "Using lib version: " . PhpXmlRpc::$xmlrpcVersion . " on PHP version: " . phpversion() . "\n";
    if ($xd) {
        echo "XDEBUG profiling enabled: skipping remote tests\nTrace file is: " . xdebug_get_profiler_filename() . "\n";
    }
}
// test 'manual style' data encoding vs. 'automatic style' encoding
begin_test('Data encoding (large array)', 'manual encoding');
for ($i = 0; $i < $num_tests; $i++) {
    $vals = array();
    for ($j = 0; $j < 10; $j++) {
        $valarray = array();
        foreach ($data[$j] as $key => $val) {
            $values = array();
            $values[] = new Value($val[0], 'int');
            $values[] = new Value($val[1], 'double');
            $values[] = new Value($val[2], 'string');
            $values[] = new Value($val[3], 'boolean');
            $values[] = new Value($val[4], 'dateTime.iso8601');
예제 #7
0
 function xdebug_info()
 {
     echo xdebug_get_profiler_filename();
 }
예제 #8
0
 /**
  * List of files in $dir whose filename has the format $format
  *
  * @return array Files
  */
 private function getPrepFiles($format, $dir)
 {
     $list = preg_grep($format, scandir($dir));
     $files = array();
     $scriptFilename = $_SERVER['SCRIPT_FILENAME'];
     foreach ($list as $file) {
         $absoluteFilename = $dir . $file;
         // Make sure that script does not include the profile currently being generated. (infinite loop)
         if (function_exists('xdebug_get_profiler_filename') && realpath(xdebug_get_profiler_filename()) == realpath($absoluteFilename)) {
             continue;
         }
         $files[$file] = array('absoluteFilename' => $absoluteFilename, 'mtime' => filemtime($absoluteFilename), 'preprocessed' => true, 'filesize' => $this->bytestostring(filesize($absoluteFilename)));
     }
     return $files;
 }
예제 #9
0
 /**
  * Display debug info gathered along the execution
  *
  * @return void
  */
 public static function showDebugInfo()
 {
     global $Language;
     echo '<div id="footer_debug_separator"/>';
     echo '<div id="footer_debug">';
     echo '<div class="alert alert-info">
                <h4> Development useful information! </h4>
                The section above will show you some useful information about Tuleap for development purpose.
           </div>';
     echo '<div id="footer_debug_content">';
     $debug_compute_tile = microtime(true) - $GLOBALS['debug_time_start'];
     if (function_exists('xdebug_time_index')) {
         $xdebug_time_index = xdebug_time_index();
     }
     $query_time = 0;
     foreach ($GLOBALS['DBSTORE'] as $d) {
         foreach ($d['trace'] as $trace) {
             $query_time += $trace[2] - $trace[1];
         }
     }
     $purifier = Codendi_HTMLPurifier::instance();
     echo '<span class="debug">' . $Language->getText('include_layout', 'query_count') . ": ";
     echo $GLOBALS['DEBUG_DAO_QUERY_COUNT'] . "</span>";
     $percent = (int) ($GLOBALS['DEBUG_TIME_IN_PRE'] * 100 / $debug_compute_tile);
     $sql_percent = (int) ($query_time * 100 / $debug_compute_tile);
     echo '<table border=1><thead><tr><th></th><th>Page generated in</th></tr></thead><tbody>';
     echo '<tr><td>pre.php</td><td>' . number_format(1000 * $GLOBALS['DEBUG_TIME_IN_PRE'], 0, '.', "'") . ' ms (' . $percent . '%)</td>';
     echo '<tr><td>remaining</td><td>' . number_format(1000 * ($debug_compute_tile - $GLOBALS['DEBUG_TIME_IN_PRE']), 0, '.', "'") . ' ms</td>';
     echo '<tr><td><b>total</td><td><b>' . number_format(1000 * $debug_compute_tile, 0, '.', "'") . ' ms</td>';
     if (function_exists('xdebug_time_index')) {
         echo '<tr><td>xdebug</td><td>' . number_format(1000 * $xdebug_time_index, 0, '.', "'") . ' ms</tr>';
     }
     echo '<tr><td>sql</td><td>' . number_format(1000 * $query_time, 0, '.', "'") . ' ms (' . $sql_percent . '%)</tr>';
     echo '</tbody></table>';
     if (function_exists('xdebug_get_profiler_filename')) {
         if ($file = xdebug_get_profiler_filename()) {
             echo '<div>Profiler info has been written in: ' . $file . '</div>';
         }
     }
     $hook_params = array();
     EventManager::instance()->processEvent('layout_footer_debug', $hook_params);
     //Display the config
     // Uncomment this only if you know what you are doing. This may lead to sensitive information leakage /!\
     //echo '<fieldset><legend id="footer_debug_config" class="'. Toggler::getClassname('footer_debug_config') .'">Config:</legend>';
     //echo '<pre>';
     //Config::dump();
     //echo '</pre>';
     //echo '</fieldset>';
     // Display all queries used to generate the page
     echo '<fieldset><legend id="footer_debug_allqueries" class="' . Toggler::getClassname('footer_debug_allqueries') . '">All queries:</legend>';
     echo '<pre>';
     $queries = array();
     $queries_by_time_taken = array();
     $i = 0;
     foreach ($GLOBALS['QUERIES'] as $sql) {
         $t = 0;
         foreach ($GLOBALS['DBSTORE'][md5($sql)]['trace'] as $trace) {
             $t += $trace[2] - $trace[1];
         }
         $q = array('sql' => $purifier->purify($sql), 'total time' => number_format(1000 * $t, 0, '.', "'") . ' ms');
         $queries[] = $q;
         $queries_by_time_taken[] = array('n°' => $i++, 't' => $t) + $q;
     }
     print_r($queries);
     echo '</pre>';
     echo '</fieldset>';
     // Display all queries used to generate the page ordered by time taken
     usort($queries_by_time_taken, array(__CLASS__, 'sort_queries_by_time_taken'));
     echo '<fieldset><legend id="footer_debug_allqueries_time_taken" class="' . Toggler::getClassname('footer_debug_allqueries_time_taken') . '">All queries by time taken:</legend>';
     echo '<table border="1" style="border-collapse:collapse" cellpadding="2" cellspacing="0">';
     echo '<thead><tr><th>n°</th><th style="white-space:nowrap;">time taken</th><th>sum</th><th>sql</th></tr></thead>';
     $i = 0;
     $sum = 0;
     foreach ($queries_by_time_taken as $q) {
         echo '<tr valign="top" class="' . html_get_alt_row_color($i++) . '">';
         echo '<td>' . $q['n°'] . '</td>';
         echo '<td style="white-space:nowrap;">' . $q['total time'] . '</td>';
         echo '<td style="white-space:nowrap;">' . number_format(1000 * ($sum += $q['t']), 0, '.', "'") . ' ms' . '</td>';
         echo '<td><pre>' . $q['sql'] . '</pre></td>';
         echo '</tr>';
     }
     echo '</table>';
     echo '</fieldset>';
     echo '<fieldset><legend id="footer_debug_queriespaths" class="' . Toggler::getClassname('footer_dubug_queriespaths') . '">Path of all queries:</legend>';
     $max = 0;
     foreach ($GLOBALS['DBSTORE'] as $d) {
         foreach ($d['trace'] as $trace) {
             $time_taken = 1000 * round($trace[2] - $trace[1], 3);
             if ($max < $time_taken) {
                 $max = $time_taken;
             }
         }
     }
     $paths = array();
     $time = $GLOBALS['debug_time_start'];
     foreach ($GLOBALS['DBSTORE'] as $d) {
         foreach ($d['trace'] as $trace) {
             $time_taken = 1000 * round($trace[2] - $trace[1], 3);
             self::_debug_backtrace_rec($paths, array_reverse($trace[0]), '[' . 1000 * round($trace[1] - $GLOBALS['debug_time_start'], 3) . '/' . $time_taken . '] ' . ($time_taken >= $max ? ' <span style="background:yellow; padding-left:4px; padding-right:4px; color:red;">top!</span> ' : '') . $purifier->purify($d['sql']));
         }
     }
     echo '<table>';
     self::_debug_display_paths($paths, false);
     echo '</table>';
     echo '</fieldset>';
     //Print the backtrace of specific queries
     /*
                 echo '<pre>';
                 $specific_queries = array(48,49);
                 $i = 0;
                 foreach($GLOBALS['DBSTORE'] as $d) {
                     //echo $i ."\t". $d['sql'] ."\n";
                     if (in_array($i++, $specific_queries)) {
                         $traces = $d['trace'][0];
                         foreach($traces as $trace) {
                             echo '<code>'. $trace['file']. ' #'. $trace['line'] .' ('. (isset($trace['class']) ? $trace['class'] .'::' : '') . $trace['function'] ."</code>\n";
                         }
                         echo "\n";
                     }
                 }
                 echo '</pre>';
                 /**/
     // Display queries executed more than once
     $title_displayed = false;
     foreach ($GLOBALS['DBSTORE'] as $key => $value) {
         if ($GLOBALS['DBSTORE'][$key]['nb'] > 1) {
             if (!$title_displayed) {
                 echo '<fieldset><legend>Queries executed more than once :</legend>';
                 $title_displayed = true;
             }
             echo "<fieldset>";
             echo '<legend id="footer_debug_doublequery_' . $key . '" class="' . Toggler::getClassname('footer_debug_doublequery_' . $key) . '">';
             echo '<b>Run ' . $GLOBALS['DBSTORE'][$key]['nb'] . " times: </b>";
             echo $purifier->purify($GLOBALS['DBSTORE'][$key]['sql']) . "\n";
             echo '</legend>';
             self::_debug_backtraces($GLOBALS['DBSTORE'][$key]['trace']);
             echo "</fieldset>";
         }
     }
     if ($title_displayed) {
         echo '</fieldset>';
     }
     echo '<fieldset>';
     echo '<legend id="footer_debug_session" class="' . Toggler::getClassname('footer_debug_session') . '">Session</legend>';
     echo "<div>";
     echo '<a href="#" onclick="new Ajax.Updater(\'footer_debug_session_data\', \'/include/debug_session.php?reload\');return false;">reload</a>';
     echo '  |  ';
     echo '<a href="#" onclick="new Ajax.Updater(\'footer_debug_session_data\', \'/include/debug_session.php?reset\');return false;">reset</a>';
     echo '<pre id="footer_debug_session_data">' . print_r($_SESSION, 1) . '</pre>';
     echo "</div>";
     echo '</fieldset>';
     echo "</pre>\n";
     echo '</div>';
     echo '</div>';
 }
예제 #10
0
    /**
     * Debug output found at the bottom of the site when debug mode is enabled.
     *
     * @static 
     * @return mixed Only returns something if the installer is being used and in that case it returns FALSE
     */
    public static function getDetails()
    {
        if (defined('PHPFOX_INSTALLER')) {
            return false;
        }
        // SQL
        $iSqlCount = 0;
        $fSum = 0.0;
        $fLimit = 0.05 * 128;
        $iSqlMemory = 0;
        $aKeywords = array('SELECT', 'SELECT ', 'FROM', 'FROM ', 'WHERE ', 'UPDATE ', 'OFFSET', ' AS ', 'UNION ALL', 'INNER JOIN ', 'LEFT JOIN ', 'INSERT INTO ', 'SHOW COLUMNS ', 'ON', 'SET', 'USING', 'USE INDEX', 'JOIN ', 'ORDER BY', 'DESC', 'LIMIT', 'DELETE');
        $oRequest = Phpfox_Request::instance();
        $oFile = Phpfox_File::instance();
        $aReplaces = array_map(array('self', '_addKeywordSyntax'), $aKeywords);
        $sDriver = Phpfox::getParam(array('db', 'driver'));
        $sSql = '';
        $bIsCmd = PHP_SAPI == 'cli' || defined('PHPFOX_IS_AJAX') && PHPFOX_IS_AJAX;
        if (!isset(self::$_aDebugHistory['sql'])) {
            self::$_aDebugHistory['sql'] = array();
        }
        // Fresh install, no need to display sql debug
        if ($sDriver == 'DATABASE_DRIVER') {
            self::$_aDebugHistory['sql'] = array();
        }
        foreach (self::$_aDebugHistory['sql'] as $aLine) {
            if (!isset($aLine['sql'])) {
                continue;
            }
            $iSqlCount++;
            $sExtra = Phpfox_Database::instance()->sqlReport($aLine['sql']);
            if ($bIsCmd) {
                $sSql .= "\n ----------------- \n Rows: " . $aLine['rows'] . " Slave: " . ($aLine['slave'] ? 'Yes' : 'No') . " \n " . $aLine['sql'] . " \n\n";
            } else {
                if ($aLine['time'] == '0.0000000') {
                    $aLine['time'] = '0.0000001';
                }
                $sColor = sprintf('%02X', min(255, $fLimit / $aLine['time']));
                $aLine['sql'] = str_replace($aKeywords, $aReplaces, htmlspecialchars($aLine['sql']));
                $sSql .= '<div class="nDebugInfo">
				<span style="background-color: #FF' . $sColor . $sColor . '; color:#000; padding:2px;">' . $aLine['time'] . '</span>
				| <b>Memory Before:</b> ' . $oFile->filesize($aLine['memory_before']) . '
				| <b>Memory After:</b> ' . $oFile->filesize($aLine['memory_after']) . '
				| <b>Memory Used:</b> ' . $oFile->filesize($aLine['memory_after'] - $aLine['memory_before']) . '
				| <b>Rows:</b> ' . $aLine['rows'] . '
				| <b>Slave:</b> ' . ($aLine['slave'] ? 'Yes' : 'No') . '
				</div>';
                $sSql .= '<div class="nDebugItems">' . self::_parseSQL($aLine['sql']) . '' . $sExtra . '</div>';
            }
            $fSum += $aLine['time'];
            $iSqlMemory += $aLine['memory_after'] - $aLine['memory_before'];
        }
        // General Stats
        $iTotalTime = sprintf('%0.7f', array_sum(explode(' ', microtime())) - PHPFOX_TIME_START);
        $iTotalSqlTime = sprintf('%0.7f', $fSum);
        $sDebugReturn = '<div id="js_main_debug_holder">';
        if (!defined('PHPFOX_MEM_END')) {
            define('PHPFOX_MEM_END', memory_get_usage());
        }
        if (PHPFOX_DEBUG_LEVEL === 1) {
            $sDebugReturn .= '<div style="font-size:9pt; text-align:center; padding-bottom:50px;">Page generated in ' . round($iTotalTime, 4) . ' seconds with ' . $iSqlCount . ' queries and GZIP ' . (Phpfox::getParam('core.use_gzip') ? 'enabled' : 'disabled') . ' on ' . $_SERVER['SERVER_ADDR'] . '.</div>';
        } elseif (PHPFOX_DEBUG_LEVEL === 2 || PHPFOX_DEBUG_LEVEL === 3) {
            $bSlaveEnabled = Phpfox::getParam(array('db', 'slave'));
            $aStats = array('Version' => PhpFox::getVersion(), 'Product Code Name' => PhpFox::getCodeName(), '1' => '', 'Total Time' => $iTotalTime, 'PHP General Time' => $iTotalTime - $iTotalSqlTime, 'GZIP' => Phpfox::getParam('core.use_gzip') ? 'enabled' : 'disabled', '2' => '', 'Driver Version' => $sDriver == 'DATABASE_DRIVER' ? 'N/A' : Phpfox_Database::instance()->getServerInfo(), 'SQL Time' => $iTotalSqlTime, 'SQL Queries' => $iSqlCount, 'SQL Memory Usage' => $oFile->filesize($iSqlMemory), 'SQL Slave Enabled' => $bSlaveEnabled ? 'Yes' : 'No', 'SQL Total Slaves' => $bSlaveEnabled ? count(Phpfox::getParam(array('db', 'slave_servers'))) : 'N/A', 'SQL Slave Server' => $bSlaveEnabled ? Phpfox_Database::instance()->sSlaveServer : 'N/A', '3' => '', 'Total Memory Usage' => $oFile->filesize(PHPFOX_MEM_END), 'Total Memory Usage (Including Debug)' => $oFile->filesize(memory_get_usage()), 'Memory Limit' => $oFile->filesize(self::_getUsableMemory()) . ' (' . @ini_get('memory_limit') . ')', '4' => '', 'Load Balancing Enabled' => Phpfox::getParam(array('balancer', 'enabled')) ? 'Yes' : 'No', 'Requests From' => $oRequest->getServer('SERVER_ADDR'), 'Server ID#' => $oRequest->getServer('PHPFOX_SERVER_ID'), '5' => '', 'Server Time Stamp' => date('F j, Y, g:i a', PHPFOX_TIME), 'PHP Version' => PHP_VERSION, 'PHP Sapi' => php_sapi_name(), 'PHP safe_mode' => PHPFOX_SAFE_MODE ? 'true' : 'false', 'PHP open_basedir' => PHPFOX_OPEN_BASE_DIR ? 'true' : 'false', 'Operating System' => PHP_OS, '6' => '', 'Cache' => Phpfox::getParam('core.cache_storage'));
            if (extension_loaded('xdebug')) {
                $aXdebug = array('4' => '', 'xDebug File Name' => xdebug_get_profiler_filename(), 'xDebug Total Time' => xdebug_time_index());
                $aStats = array_merge($aStats, $aXdebug);
            }
            $sDebugStats = '';
            foreach ($aStats as $sStatTitle => $mStatValue) {
                if (!$mStatValue) {
                    $sDebugStats .= $bIsCmd ? "\n" : "<br />";
                } else {
                    $sDebugStats .= $bIsCmd ? "" . $sStatTitle . ": " . $mStatValue . "\n" : "<div class=\"nDebugLeft\">" . $sStatTitle . ":</div><div>" . $mStatValue . "</div>\n<div class=\"nClear\"></div>\n";
                }
            }
            $aCookies = array();
            $sCookiePrefix = Phpfox::getParam('core.session_prefix');
            $iPrefixLength = strlen($sCookiePrefix);
            foreach ($_COOKIE as $sKey => $sValue) {
                if (substr($sKey, 0, $iPrefixLength) != $sCookiePrefix) {
                    continue;
                }
                $aCookies[$sKey] = $sValue;
            }
            if ($bIsCmd) {
                $sDebugReturn .= $sDebugStats;
                $sDebugReturn .= "##############################################";
            } else {
                $sDebugReturn .= '
				<div id="n_debug">
				<div id="n_debug_header">
					phpFox Developers Debug
					<a href="#" onclick="if (getCookie(\'js_console\')) { deleteCookie(\'js_console\'); $(\'#firebug_no_console\').remove(); } else { setCookie(\'js_console\', \'1\', 365); p(\'Enabled JavaScript Console\'); } return false;">Toggle JavaScript Console</a>
				</div>		
				<div class="nDebugItem"><a href="#" onclick="if (getCookie(\'phpfox_debug_detail\')) { deleteCookie(\'phpfox_debug_detail\'); $(\'#phpfox_debug_detail\').slideDown(); } else { $(\'#phpfox_debug_detail\').slideUp(); setCookie(\'phpfox_debug_detail\', \'1\', 365); } return false;">Debug Details</a></div>
				<div class="nDebugContent nDebugContentShell" id="phpfox_debug_detail"' . (Phpfox::getCookie('phpfox_debug_detail') ? ' style="display:none;"' : '') . '>
					<div class="nDebugContentShell">
						' . $sDebugStats . '
					</div>
				</div>
				';
            }
            if (PHPFOX_DEBUG_LEVEL === 3) {
                if ($bIsCmd) {
                    $sDebugReturn .= $sSql;
                    $sDebugReturn .= "##############################################";
                } else {
                    $sDebugReturn .= '
					<div class="nDebugItem">SQL Queries</div>
					<div class="nDebugContent nDebugContentShell" style="height:400px;">
						' . $sSql . '
					</div>	
					';
                }
            }
            /*
            <div class="nDebugItem">Debug History</div>
            <div class="nDebugContent nDebugContentShell" style="height:200px;">
            	<pre>'. self::_loadData(self::$_aDebugHistory) .'</pre>
            </div>
            */
            if (!$bIsCmd) {
                $sDebugReturn .= '
				<div class="nDebugItem"><a href="#" onclick="if (getCookie(\'phpfox_debug_session\')) { deleteCookie(\'phpfox_debug_session\'); $(\'#phpfox_debug_session\').slideDown(); } else { $(\'#phpfox_debug_session\').slideUp(); setCookie(\'phpfox_debug_session\', \'1\', 365); } return false;">Session</a></div>
				<div class="nDebugContent nDebugContentShell" id="phpfox_debug_session"' . (Phpfox::getCookie('phpfox_debug_session') ? ' style="display:none;"' : '') . '>
					<pre>' . self::_loadData($_SESSION[Phpfox::getParam('core.session_prefix')]) . '</pre>
				</div>
		
				<div class="nDebugItem"><a href="#" onclick="if (getCookie(\'phpfox_debug_cookie\')) { deleteCookie(\'phpfox_debug_cookie\'); $(\'#phpfox_debug_cookie\').slideDown(); } else { $(\'#phpfox_debug_cookie\').slideUp(); setCookie(\'phpfox_debug_cookie\', \'1\', 365); } return false;">Cookie</a></div>
				<div class="nDebugContent nDebugContentShell" id="phpfox_debug_cookie"' . (Phpfox::getCookie('phpfox_debug_cookie') ? ' style="display:none;"' : '') . '>
					<pre>' . self::_loadData($aCookies) . '</pre>
				</div>		
				
				</div>
				';
            }
        }
        $sDebugReturn .= '</div>';
        if (defined('PHPFOX_DEBUG_SHOW_FIXED')) {
            $sDebugReturn .= '<div style="position:fixed; bottom:0px; right:5px; background:#fff; border:1px #dfdfdf solid; width:200px; padding:5px; font-size:16px;">
    				Generated in: ' . round($iTotalTime, 4) . ' <br />
    				SQL: ' . $iSqlCount . ' (' . $iTotalSqlTime . ') <br />
    				Server:  ' . $_SERVER['SERVER_ADDR'] . '
    		</div>';
        }
        return $sDebugReturn;
    }
예제 #11
0
if (!function_exists('xdebug_is_enabled')) {
    print 'XDebug seems to be not installed. Function xdebug_is_enabled not found.';
    llxFooter();
    exit;
}
if (function_exists('socket_create')) {
    $address = ini_get('xdebug.remote_host') ? ini_get('xdebug.remote_host') : '127.0.0.1';
    $port = ini_get('xdebug.remote_port') ? ini_get('xdebug.remote_port') : 9000;
    print "<strong>Current xdebug setup:</strong><br>\n";
    print "* Remote debug setup:<br>\n";
    print 'xdebug.remote_enable = ' . ini_get('xdebug.remote_enable') . "<br>\n";
    print 'xdebug.remote_host = ' . $address . "<br>\n";
    print 'xdebug.remote_port = ' . $port . "<br>\n";
    print "* Profiler setup ";
    if (function_exists('xdebug_get_profiler_filename')) {
        print xdebug_get_profiler_filename() ? "(currently on into file " . xdebug_get_profiler_filename() . ")" : "(currently off)";
    } else {
        print "(currenlty not available)";
    }
    print ":<br>\n";
    print 'xdebug.profiler_enable = ' . ini_get('xdebug.profiler_enable') . "<br>\n";
    print 'xdebug.profiler_enable_trigger = ' . ini_get('xdebug.profiler_enable_trigger') . "<br>\n";
    print 'xdebug.profiler_output_dir = ' . ini_get('xdebug.profiler_output_dir') . "<br>\n";
    print 'xdebug.profiler_output_name = ' . ini_get('xdebug.profiler_output_name') . "<br>\n";
    print 'xdebug.profiler_append = ' . ini_get('xdebug.profiler_append') . "<br>\n";
    print "<br>\n";
    echo "To run a debug session, add parameter<br>";
    echo "* XDEBUG_SESSION_START=aname on your URL. To stop, remove cookie XDEBUG_SESSION_START.<br>\n";
    echo "To run a profiler session (when xdebug.profiler_enable_trigger=1), add parameter<br>\n";
    echo "* XDEBUG_PROFILE=aname on each URL.<br>";
    print "<br>";
예제 #12
0
 private static function debugInfo()
 {
     $global_vars = implode(', ', array_keys($GLOBALS));
     $res = '<div id="debug"><div>' . '<p>memory usage: ' . memory_get_usage() . ' (' . files::size(memory_get_usage()) . ')</p>';
     if (function_exists('xdebug_get_profiler_filename')) {
         $res .= '<p>Elapsed time: ' . xdebug_time_index() . ' seconds</p>';
         $prof_file = xdebug_get_profiler_filename();
         if ($prof_file) {
             $res .= '<p>Profiler file : ' . xdebug_get_profiler_filename() . '</p>';
         } else {
             $prof_url = http::getSelfURI();
             $prof_url .= strpos($prof_url, '?') === false ? '?' : '&';
             $prof_url .= 'XDEBUG_PROFILE';
             $res .= '<p><a href="' . html::escapeURL($prof_url) . '">Trigger profiler</a></p>';
         }
         /* xdebug configuration:
         			zend_extension = /.../xdebug.so
         			xdebug.auto_trace = On
         			xdebug.trace_format = 0
         			xdebug.trace_options = 1
         			xdebug.show_mem_delta = On
         			xdebug.profiler_enable = 0
         			xdebug.profiler_enable_trigger = 1
         			xdebug.profiler_output_dir = /tmp
         			xdebug.profiler_append = 0
         			xdebug.profiler_output_name = timestamp
         			*/
     }
     $res .= '<p>Global vars: ' . $global_vars . '</p>' . '</div></div>';
     return $res;
 }
예제 #13
0
function xdebug_profiler_shutdown_cb()
{
    $is_xmlhttprequest = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
    if (isset($_REQUEST['XDEBUG_PROFILE'])) {
        $used_memory = xdebug_memory_usage();
        $sizename = array(" Bytes", " KB", " MB", " GB");
        $used_memory = round($used_memory / pow(1024, $i = floor(log($used_memory, 1024))), 2) . $sizename[$i];
        $elapsed_time = round(xdebug_time_index() * 1000, 3);
        $profile = xdebug_get_profiler_filename();
        $profile_id = md5($profile);
        /* Show result box */
        if (!$is_xmlhttprequest) {
            if ($profile === false) {
                $path = ini_get('xdebug.profiler_output_dir');
                if ($path != '') {
                    $reason = is_dir($path) ? 'Directory is not writeable' : (file_exists($path) ? "'{$path}' is not directory" : "'{$path}' does not exist");
                    $output = sprintf('Error: Could not create profile dump in %s<br />(Reason: %s)', $path, $reason);
                } else {
                    $output = 'Error: xdebug.profiler_output_dir is not set';
                }
            } else {
                $output = "\n<b>Page generated in</b> {$elapsed_time} ms <b>Used memory:</b> {$used_memory}\n<b>Profiler dump:</b> <a href='/download.php?file={$profile}'>{$profile}</a>\n";
                if ($_REQUEST['XDEBUG_PROFILE'] == 'long') {
                    $output .= shell_exec("/usr/bin/callgrind_annotate --inclusive=yes --tree=both {$profile}");
                }
            }
            echo <<<DATA
<div style="position: absolute; top: 0; z-index: 5000; border: dashed black 1px; background-color: #fff;" id="xdebug_profile_{$profile_id}">
 <a href="#" style="font-size: 11px;" onclick="javascript: document.getElementById('xdebug_profile_{$profile_id}').style.display = 'none'; return false;">[close]</a>
 <pre style="padding: 5px;">{$output}</pre>
 <a href="#" style="font-size: 11px;" onclick="javascript: document.getElementById('xdebug_profile_{$profile_id}').style.display = 'none'; return false;">[close]</a>
</div>
DATA;
        }
    }
    /* Output box with toggles to enable/disable profiler and annotation */
    if (!$is_xmlhttprequest) {
        $profiler = isset($_REQUEST['XDEBUG_PROFILE']) ? array('enabled' => 1, 'checked' => 'checked="checked"', 'display' => 'inline') : array('enabled' => 0, 'checked' => '', 'display' => 'none');
        $profiler['checked_annotate'] = isset($_REQUEST['XDEBUG_PROFILE']) && $_REQUEST['XDEBUG_PROFILE'] == 'long' ? 'checked="checked"' : '';
        echo <<<DATA
<!-- XDEBUG Dynamic Profiler -->
<script type="text/javascript">
<!--
var xdebug_Profiler = {$profiler['enabled']};
function xdebug_setCookie(value)
{
  if (value == '')
    document.cookie = "XDEBUG_PROFILE=; path=/; expires=Thu, 01-Jan-1970 00:00:01 GMT";
  else
    document.cookie = "XDEBUG_PROFILE=" + value + "; path=/; expires=Fri, 01-Jan-2038 00:00:01 GMT";
}
function xdebug_toggleProfiler(output)
{
  var annotate = document.getElementById('xdebug_profiler_annotate');

  if (xdebug_Profiler) {
    xdebug_setCookie('');
    xdebug_Profiler = 0;
    annotate.style.display = 'none';
  } else {
    xdebug_setCookie(output);
    xdebug_Profiler = 1;
    annotate.style.display = 'inline';
  }
  return xdebug_Profiler;
}
// -->
</script>
<div style="padding: 5px; border: dashed black 1px; background-color: #fff; z-index: 1000; position: absolute; top: 0px; right: 5px; " id="xdebug_profile_enable_cookie">
 <label for="xdebug_toggler" style="vertical-align: top">Toggle Profiler</label>
 <input id="xdebug_toggler" type="checkbox" onclick="this.checked = xdebug_toggleProfiler(this.value);" value="short" {$profiler['checked']} />
 <div id="xdebug_profiler_annotate" style="display: {$profiler['display']}">
  <label for="xdebug_annotate" style="vertical-align: top">Annotate</label>
  <input id="xdebug_annotate" type="checkbox" onclick="xdebug_setCookie((this.checked)?this.value:'short');" value="long" {$profiler['checked_annotate']} />
 </div>
</div>
DATA;
    }
}
예제 #14
0
<?php

var_dump(xdebug_get_profiler_filename());
예제 #15
0
 /**
  * Returns the name of the file which is used to save profile information to.
  *
  * @return string
  */
 public function getProfilerFilename()
 {
     return xdebug_get_profiler_filename();
 }