Beispiel #1
0
 public function bench(RestServer $rest)
 {
     $rest->getResponse()->appendResponse("It took " . round(xdebug_time_index(), 5) . " seconds\n");
     $rest->getResponse()->appendResponse("Used " . round(xdebug_memory_usage() / 1024, 5) . "Kb of Memory\n");
     $rest->getResponse()->appendResponse("Used at peak " . round(xdebug_peak_memory_usage() / 1024, 5) . "Kb of Memory\n");
     return $rest;
 }
Beispiel #2
0
 /**
  * @param \Civi\API\Event\RespondEvent $event
  *   API response event.
  */
 public function onApiRespond(\Civi\API\Event\RespondEvent $event)
 {
     $apiRequest = $event->getApiRequest();
     $result = $event->getResponse();
     if (function_exists('xdebug_time_index') && \CRM_Utils_Array::value('debug', $apiRequest['params']) && is_array($result)) {
         $result['xdebug']['peakMemory'] = xdebug_peak_memory_usage();
         $result['xdebug']['memory'] = xdebug_memory_usage();
         $result['xdebug']['timeIndex'] = xdebug_time_index();
         $event->setResponse($result);
     }
 }
Beispiel #3
0
		/**
 * Weird little script to trigger an xdebug info box.
		 * I use this to test for bottlenecks before I discovered cache grind. I'll leave it in incase I need it for something.
		 *
		 * @param string $msg A message, useful for identifying a break point.
		 */
function xdebugInfo ($msg = false)
{
	if ($init['debug'])
	{
		trigger_error(
				'[xdbInfo] ' . ($msg ? '<span style="color:white;background-color:#D60;">' . $msg . '</span> | ' : null) .
						 '
    Mem: <span style="color:white;background-color:#D60;">' . Round(
								(xdebug_memory_usage() / 1000), 2) . '
    Kb</span>, Time: <span style="color:white;background-color:#D60;">' . str_pad(
								Round(xdebug_time_index(), 4), 6, '0') . 'secs</span>', E_USER_WARNING);
	}
}
Beispiel #4
0
 /**
  * Returns memory usage
  *
  * @return string
  */
 public static function getMemoryUsage()
 {
     $memory = false;
     if (function_exists('xdebug_memory_usage')) {
         $memory = xdebug_memory_usage();
     } elseif (function_exists('memory_get_usage')) {
         $memory = memory_get_usage();
     }
     if ($memory === false) {
         return "Memory usage function not found.";
     }
     $usage = number_format(round($memory / 1024 / 1024, 2), 2);
     return "{$usage} Mb";
 }
Beispiel #5
0
/**
 * @param string $entity
 *   type of entities to deal with
 * @param string $action
 *   create, get, delete or some special action name.
 * @param array $params
 *   array to be passed to function
 * @param null $extra
 *
 * @return array|int
 */
function civicrm_api($entity, $action, $params, $extra = NULL)
{
    $apiRequest = array();
    $apiRequest['entity'] = CRM_Utils_String::munge($entity);
    $apiRequest['action'] = CRM_Utils_String::munge($action);
    $apiRequest['version'] = civicrm_get_api_version($params);
    $apiRequest['params'] = $params;
    $apiRequest['extra'] = $extra;
    $apiWrappers = array(CRM_Utils_API_HTMLInputCoder::singleton(), CRM_Utils_API_NullOutputCoder::singleton(), CRM_Utils_API_ReloadOption::singleton(), CRM_Utils_API_MatchOption::singleton());
    CRM_Utils_Hook::apiWrappers($apiWrappers, $apiRequest);
    try {
        require_once 'api/v3/utils.php';
        require_once 'api/Exception.php';
        if (!is_array($params)) {
            throw new API_Exception('Input variable `params` is not an array', 2000);
        }
        _civicrm_api3_initialize();
        $errorScope = CRM_Core_TemporaryErrorScope::useException();
        // look up function, file, is_generic
        $apiRequest += _civicrm_api_resolve($apiRequest);
        if (strtolower($action) == 'create' || strtolower($action) == 'delete' || strtolower($action) == 'submit') {
            $apiRequest['is_transactional'] = 1;
            $transaction = new CRM_Core_Transaction();
        }
        // support multi-lingual requests
        if ($language = CRM_Utils_Array::value('option.language', $params)) {
            _civicrm_api_set_locale($language);
        }
        _civicrm_api3_api_check_permission($apiRequest['entity'], $apiRequest['action'], $apiRequest['params']);
        $fields = _civicrm_api3_api_getfields($apiRequest);
        // we do this before we
        _civicrm_api3_swap_out_aliases($apiRequest, $fields);
        if (strtolower($action) != 'getfields') {
            if (empty($apiRequest['params']['id'])) {
                $apiRequest['params'] = array_merge(_civicrm_api3_getdefaults($apiRequest, $fields), $apiRequest['params']);
            }
            //if 'id' is set then only 'version' will be checked but should still be checked for consistency
            civicrm_api3_verify_mandatory($apiRequest['params'], NULL, _civicrm_api3_getrequired($apiRequest, $fields));
        }
        // For input filtering, process $apiWrappers in forward order
        foreach ($apiWrappers as $apiWrapper) {
            $apiRequest = $apiWrapper->fromApiInput($apiRequest);
        }
        $function = $apiRequest['function'];
        if ($apiRequest['function'] && $apiRequest['is_generic']) {
            // Unlike normal API implementations, generic implementations require explicit
            // knowledge of the entity and action (as well as $params). Bundle up these bits
            // into a convenient data structure.
            $result = $function($apiRequest);
        } elseif ($apiRequest['function'] && !$apiRequest['is_generic']) {
            _civicrm_api3_validate_fields($apiRequest['entity'], $apiRequest['action'], $apiRequest['params'], $fields);
            $result = isset($extra) ? $function($apiRequest['params'], $extra) : $function($apiRequest['params']);
        } else {
            return civicrm_api3_create_error("API (" . $apiRequest['entity'] . ", " . $apiRequest['action'] . ") does not exist (join the API team and implement it!)");
        }
        // For output filtering, process $apiWrappers in reverse order
        foreach (array_reverse($apiWrappers) as $apiWrapper) {
            $result = $apiWrapper->toApiOutput($apiRequest, $result);
        }
        if (CRM_Utils_Array::value('format.is_success', $apiRequest['params']) == 1) {
            if ($result['is_error'] === 0) {
                return 1;
            } else {
                return 0;
            }
        }
        if (!empty($apiRequest['params']['format.only_id']) && isset($result['id'])) {
            return $result['id'];
        }
        if (CRM_Utils_Array::value('is_error', $result, 0) == 0) {
            _civicrm_api_call_nested_api($apiRequest['params'], $result, $apiRequest['action'], $apiRequest['entity'], $apiRequest['version']);
        }
        if (function_exists('xdebug_time_index') && CRM_Utils_Array::value('debug', $apiRequest['params']) && is_array($result)) {
            $result['xdebug']['peakMemory'] = xdebug_peak_memory_usage();
            $result['xdebug']['memory'] = xdebug_memory_usage();
            $result['xdebug']['timeIndex'] = xdebug_time_index();
        }
        return $result;
    } catch (PEAR_Exception $e) {
        if (CRM_Utils_Array::value('format.is_success', $apiRequest['params']) == 1) {
            return 0;
        }
        $error = $e->getCause();
        if ($error instanceof DB_Error) {
            $data["error_code"] = DB::errorMessage($error->getCode());
            $data["sql"] = $error->getDebugInfo();
        }
        if (!empty($apiRequest['params']['debug'])) {
            if (method_exists($e, 'getUserInfo')) {
                $data['debug_info'] = $error->getUserInfo();
            }
            if (method_exists($e, 'getExtraData')) {
                $data['debug_info'] = $data + $error->getExtraData();
            }
            $data['trace'] = $e->getTraceAsString();
        } else {
            $data['tip'] = "add debug=1 to your API call to have more info about the error";
        }
        $err = civicrm_api3_create_error($e->getMessage(), $data, $apiRequest);
        if (!empty($apiRequest['is_transactional'])) {
            $transaction->rollback();
        }
        return $err;
    } catch (API_Exception $e) {
        if (!isset($apiRequest)) {
            $apiRequest = array();
        }
        if (CRM_Utils_Array::value('format.is_success', CRM_Utils_Array::value('params', $apiRequest)) == 1) {
            return 0;
        }
        $data = $e->getExtraParams();
        $data['entity'] = CRM_Utils_Array::value('entity', $apiRequest);
        $data['action'] = CRM_Utils_Array::value('action', $apiRequest);
        $err = civicrm_api3_create_error($e->getMessage(), $data, $apiRequest, $e->getCode());
        if (CRM_Utils_Array::value('debug', CRM_Utils_Array::value('params', $apiRequest)) && empty($data['trace'])) {
            $err['trace'] = $e->getTraceAsString();
        }
        if (!empty($apiRequest['is_transactional'])) {
            $transaction->rollback();
        }
        return $err;
    } catch (Exception $e) {
        if (CRM_Utils_Array::value('format.is_success', $apiRequest['params']) == 1) {
            return 0;
        }
        $data = array();
        $err = civicrm_api3_create_error($e->getMessage(), $data, $apiRequest, $e->getCode());
        if (!empty($apiRequest['params']['debug'])) {
            $err['trace'] = $e->getTraceAsString();
        }
        if (!empty($apiRequest['is_transactional'])) {
            $transaction->rollback();
        }
        return $err;
    }
}
 public function getRecord()
 {
     // record_files = array();
     $lineNum = 0;
     if (file_exists($this->_coverageLog)) {
         if ($handle = fopen($this->_coverageLog, 'r')) {
             $lineNumTotal = trim(shell_exec('cat ' . $this->_coverageLog . ' |wc -l'));
             while (!feof($handle)) {
                 if ($line = fgets($handle)) {
                     $lineNum++;
                     echo "INFO____: Calculate line " . $lineNum . " (" . $lineNum . "/" . $lineNumTotal . ").\n";
                     echo "INFO____: Memory used: " . (int) (xdebug_memory_usage() / (1024 * 1024)) . "M.\n";
                     $record = json_decode($line, true);
                     $this->appendRecord($record);
                     // record_files_tmp = array_keys($record);
                     // record_files =
                     // array_unique(array_merge($record_files,
                     // $record_files_tmp));
                 }
             }
             unset($record);
             fclose($handle);
             return true;
         } else {
             throw new Exception("ERROR____: Read Record failed!");
         }
     }
     throw new Exception("ERROR____: Record not exist!");
 }
Beispiel #7
0
 private function log($level, $message)
 {
     //return;
     //error_log("hello buddy in log()");
     global $cfg;
     if (!$this->enabled) {
         return;
     }
     if (function_exists("xdebug_is_enabled") && xdebug_is_enabled()) {
         //print "$level: $message";
         //print_r(debug_backtrace(), true);
         //using the xdebug version is failing with Canary Mismatch error
         ///$stack = xdebug_get_function_stack();
         $stack = debug_backtrace();
         $time = xdebug_time_index();
         $mem = xdebug_memory_usage();
         $entry = new LogEntry($level, $message, $stack, $time, $mem);
         //error_log("finally here?");
     } else {
         $bt = debug_backtrace();
         //print_r($bt);
         // get class, function called by caller of caller of caller
         $cl_f_msg = "";
         if (isset($bt[2])) {
             $class = isset($bt[2]['class']) ? $bt[2]['class'] : "";
             $function = isset($bt[2]['function']) ? $bt[2]['function'] : "";
             $cl_f_msg = ":{$class}::{$function}";
         }
         // get file, line where call to caller of caller was made
         $file = $bt[1]['file'];
         $file = str_replace($_SERVER['DOCUMENT_ROOT'], '', $file);
         $line = $bt[1]['line'];
         // build & return the message
         $back_trace = "{$file}:{$cl_f_msg}:{$line} ";
         $entry = new LogEntry($level, $message, $back_trace, 0, 0);
     }
     if ($cfg['servertype'] != 'prod') {
         array_push($this->entries, $entry);
     }
 }
Beispiel #8
0
 public static function printMemoryUsage($prefixString = null)
 {
     $memory = false;
     if (function_exists('xdebug_memory_usage')) {
         $memory = xdebug_memory_usage();
     } elseif (function_exists('memory_get_usage')) {
         $memory = memory_get_usage();
     }
     if ($memory !== false) {
         $usage = round($memory / 1024 / 1024, 2);
         if (!is_null($prefixString)) {
             Piwik::log($prefixString);
         }
         Piwik::log("Memory usage = {$usage} Mb");
     } else {
         Piwik::log("Memory usage function not found.");
     }
 }
/**
 * Print common footer :
 * 		conf->global->MAIN_HTML_FOOTER
 * 		conf->global->MAIN_GOOGLE_AN_ID
 * 		conf->global->MAIN_SHOW_TUNING_INFO or $_SERVER["MAIN_SHOW_TUNING_INFO"]
 * 		conf->logbuffer
 *
 * @param	string	$zone	'private' (for private pages) or 'public' (for public pages)
 * @return	void
 */
function printCommonFooter($zone = 'private')
{
    global $conf, $hookmanager;
    global $micro_start_time;
    if ($zone == 'private') {
        print "\n" . '<!-- Common footer for private page -->' . "\n";
    } else {
        print "\n" . '<!-- Common footer for public page -->' . "\n";
    }
    if (!empty($conf->global->MAIN_HTML_FOOTER)) {
        print $conf->global->MAIN_HTML_FOOTER . "\n";
    }
    print "\n";
    if (!empty($conf->use_javascript_ajax)) {
        print '<script type="text/javascript" language="javascript">jQuery(document).ready(function() {' . "\n";
        print '<!-- If page_y set, we set scollbar with it -->' . "\n";
        print "page_y=getParameterByName('page_y', 0);";
        print "if (page_y > 0) \$('html, body').scrollTop(page_y);";
        print '<!-- Set handler to add page_y param on some a href links -->' . "\n";
        print 'jQuery(".reposition").click(function() {
    	           var page_y = $(document).scrollTop();
    	           /* alert(page_y); */
    	           this.href=this.href+\'&page_y=\'+page_y;
    	           });' . "\n";
        print '});' . "\n";
        print '</script>' . "\n";
    }
    // Google Analytics (need Google module)
    if (!empty($conf->google->enabled) && !empty($conf->global->MAIN_GOOGLE_AN_ID)) {
        if (empty($conf->dol_use_jmobile)) {
            print "\n";
            print '<script type="text/javascript">' . "\n";
            print '  var _gaq = _gaq || [];' . "\n";
            print '  _gaq.push([\'_setAccount\', \'' . $conf->global->MAIN_GOOGLE_AN_ID . '\']);' . "\n";
            print '  _gaq.push([\'_trackPageview\']);' . "\n";
            print '' . "\n";
            print '  (function() {' . "\n";
            print '    var ga = document.createElement(\'script\'); ga.type = \'text/javascript\'; ga.async = true;' . "\n";
            print '    ga.src = (\'https:\' == document.location.protocol ? \'https://ssl\' : \'http://www\') + \'.google-analytics.com/ga.js\';' . "\n";
            print '    var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(ga, s);' . "\n";
            print '  })();' . "\n";
            print '</script>' . "\n";
        }
    }
    // End of tuning
    if (!empty($_SERVER['MAIN_SHOW_TUNING_INFO']) || !empty($conf->global->MAIN_SHOW_TUNING_INFO)) {
        print "\n" . '<script type="text/javascript">' . "\n";
        print 'window.console && console.log("';
        if (!empty($conf->global->MEMCACHED_SERVER)) {
            print 'MEMCACHED_SERVER=' . $conf->global->MEMCACHED_SERVER . ' - ';
        }
        print 'MAIN_OPTIMIZE_SPEED=' . (isset($conf->global->MAIN_OPTIMIZE_SPEED) ? $conf->global->MAIN_OPTIMIZE_SPEED : 'off');
        if ($micro_start_time) {
            $micro_end_time = microtime(true);
            print ' - Build time: ' . ceil(1000 * ($micro_end_time - $micro_start_time)) . ' ms';
        }
        if (function_exists("memory_get_usage")) {
            print ' - Mem: ' . memory_get_usage();
        }
        if (function_exists("xdebug_memory_usage")) {
            print ' - XDebug time: ' . ceil(1000 * xdebug_time_index()) . ' ms';
            print ' - XDebug mem: ' . xdebug_memory_usage();
            print ' - XDebug mem peak: ' . xdebug_peak_memory_usage();
        }
        if (function_exists("zend_loader_file_encoded")) {
            print ' - Zend encoded file: ' . (zend_loader_file_encoded() ? 'yes' : 'no');
        }
        print '");' . "\n";
        print '</script>' . "\n";
        // Add Xdebug coverage of code
        if (defined('XDEBUGCOVERAGE')) {
            print_r(xdebug_get_code_coverage());
        }
    }
    // If there is some logs in buffer to show
    if (count($conf->logbuffer)) {
        print "\n";
        print "<!-- Start of log output\n";
        //print '<div class="hidden">'."\n";
        foreach ($conf->logbuffer as $logline) {
            print $logline . "<br>\n";
        }
        //print '</div>'."\n";
        print "End of log output -->\n";
    }
    $parameters = array();
    $reshook = $hookmanager->executeHooks('printCommonFooter', $parameters);
    // Note that $action and $object may have been modified by some hooks
}
Beispiel #10
0
/**
 * Print common footer :
 * 		conf->global->MAIN_HTML_FOOTER
 * 		conf->global->MAIN_GOOGLE_AN_ID
 * 		DOL_TUNING
 * 		conf->logbuffer
 *
 * @param	string	$zone	'private' (for private pages) or 'public' (for public pages)
 * @return	void
 */
function printCommonFooter($zone = 'private')
{
    global $conf;
    global $micro_start_time;
    if ($zone == 'private') {
        print "\n" . '<!-- Common footer for private page -->' . "\n";
    } else {
        print "\n" . '<!-- Common footer for public page -->' . "\n";
    }
    if (!empty($conf->global->MAIN_HTML_FOOTER)) {
        print $conf->global->MAIN_HTML_FOOTER . "\n";
    }
    // Google Analytics (need Google module)
    if (!empty($conf->google->enabled) && !empty($conf->global->MAIN_GOOGLE_AN_ID)) {
        if (empty($conf->dol_use_jmobile)) {
            print "\n";
            print '<script type="text/javascript">' . "\n";
            print '  var _gaq = _gaq || [];' . "\n";
            print '  _gaq.push([\'_setAccount\', \'' . $conf->global->MAIN_GOOGLE_AN_ID . '\']);' . "\n";
            print '  _gaq.push([\'_trackPageview\']);' . "\n";
            print '' . "\n";
            print '  (function() {' . "\n";
            print '    var ga = document.createElement(\'script\'); ga.type = \'text/javascript\'; ga.async = true;' . "\n";
            print '    ga.src = (\'https:\' == document.location.protocol ? \'https://ssl\' : \'http://www\') + \'.google-analytics.com/ga.js\';' . "\n";
            print '    var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(ga, s);' . "\n";
            print '  })();' . "\n";
            print '</script>' . "\n";
        }
    }
    // End of tuning
    if (!empty($_SERVER['DOL_TUNING']) || !empty($conf->global->MAIN_SHOW_TUNING_INFO)) {
        print "\n" . '<script type="text/javascript">' . "\n";
        print 'window.console && console.log("';
        if (!empty($conf->global->MEMCACHED_SERVER)) {
            print 'MEMCACHED_SERVER=' . $conf->global->MEMCACHED_SERVER . ' - ';
        }
        print 'MAIN_OPTIMIZE_SPEED=' . (isset($conf->global->MAIN_OPTIMIZE_SPEED) ? $conf->global->MAIN_OPTIMIZE_SPEED : 'off');
        if ($micro_start_time) {
            $micro_end_time = dol_microtime_float(true);
            print ' - Build time: ' . ceil(1000 * ($micro_end_time - $micro_start_time)) . ' ms';
        }
        if (function_exists("memory_get_usage")) {
            print ' - Mem: ' . memory_get_usage();
        }
        if (function_exists("xdebug_memory_usage")) {
            print ' - XDebug time: ' . ceil(1000 * xdebug_time_index()) . ' ms';
            print ' - XDebug mem: ' . xdebug_memory_usage();
            print ' - XDebug mem peak: ' . xdebug_peak_memory_usage();
        }
        if (function_exists("zend_loader_file_encoded")) {
            print ' - Zend encoded file: ' . (zend_loader_file_encoded() ? 'yes' : 'no');
        }
        print '");' . "\n";
        print '</script>' . "\n";
        // Add Xdebug coverage of code
        if (defined('XDEBUGCOVERAGE')) {
            var_dump(xdebug_get_code_coverage());
        }
    }
    // If there is some logs in buffer to show
    if (count($conf->logbuffer)) {
        print "\n";
        print "<!-- Start of log output\n";
        //print '<div class="hidden">'."\n";
        foreach ($conf->logbuffer as $logline) {
            print $logline . "<br>\n";
        }
        //print '</div>'."\n";
        print "End of log output -->\n";
    }
}
Beispiel #11
0
 /**
  * Détermine les données de la debug bar.
  *
  * @return void
  */
 public function setData()
 {
     $this->aDebugBarData = array();
     $this->aDebugBarData['num_data'] = array();
     if ($this->aConfig['tabs']['super_globales']) {
         $this->aDebugBarData['num_data']['get'] = count($_GET);
         $this->aDebugBarData['num_data']['post'] = count($_POST);
         $this->aDebugBarData['num_data']['cookie'] = count($_COOKIE);
         $this->aDebugBarData['num_data']['files'] = count($_FILES);
         $this->aDebugBarData['num_data']['session'] = count($_SESSION);
         $this->aDebugBarData['num_data']['server'] = count($_SERVER);
         $this->aDebugBarData['num_data']['env'] = count($_ENV);
         $this->aDebugBarData['num_data']['request'] = count($_REQUEST);
     }
     if ($this->aConfig['tabs']['app']) {
         $this->aDebugBarData['definedVars'] = self::getDefinedVars();
         $this->aDebugBarData['definedConstants'] = self::getDefinedConstants();
         $this->aDebugBarData['configVars'] = $this->okt->config->get();
         $this->aDebugBarData['userVars'] = $this->okt->user->getData(0);
         $this->aDebugBarData['l10nVars'] = !empty($__l10n) ? $__l10n : array();
         $this->aDebugBarData['num_data']['definedVars'] = count($this->aDebugBarData['definedVars']);
         $this->aDebugBarData['num_data']['definedConstants'] = count($this->aDebugBarData['definedConstants']);
         $this->aDebugBarData['num_data']['configVars'] = count($this->aDebugBarData['configVars']);
         $this->aDebugBarData['num_data']['userVars'] = count($this->aDebugBarData['userVars']);
         $this->aDebugBarData['num_data']['l10nVars'] = count($this->aDebugBarData['l10nVars']);
     }
     if ($this->aConfig['tabs']['logs']) {
         $this->aDebugBarData['num_data']['logs'] = $this->okt->debug->getNum();
     }
     if ($this->aConfig['tabs']['db']) {
         $this->aDebugBarData['num_data']['queries'] = $this->okt->db->nbQueries();
     }
     if ($this->aConfig['tabs']['tools']) {
         $this->aDebugBarData['execTime'] = util::getExecutionTime();
         if (OKT_XDEBUG) {
             $this->aDebugBarData['memUsage'] = util::l10nFileSize(xdebug_memory_usage());
             $this->aDebugBarData['peakUsage'] = util::l10nFileSize(xdebug_peak_memory_usage());
         } else {
             $this->aDebugBarData['memUsage'] = util::l10nFileSize(memory_get_usage());
             $this->aDebugBarData['peakUsage'] = util::l10nFileSize(memory_get_peak_usage());
         }
     }
 }
Beispiel #12
0
 /**
  * Prepare template for render from View
  *
  * @throws \Exception if template path is incorrect
  */
 public function output()
 {
     $template = $this->template;
     $data = $this->data;
     $css = $this->css;
     $js = $this->js;
     $title = $this->title;
     ob_start();
     try {
         if (!file_exists(APP . "Templates/_pages/{$template}.html")) {
             throw new \Exception("The required Template ({$template}) not exist.");
         }
         require APP . 'Templates/_shared/header.html';
         require APP . "Templates/_pages/{$template}.html";
         require APP . 'Templates/_shared/footer.html';
     } catch (\Exception $e) {
         echo 'Template exception: ', $e->getMessage(), "\n";
     }
     //only for debug, return time execution and memory usage
     echo '<!-- Memory: ';
     echo round(xdebug_memory_usage() / 1024, 2), ' (';
     echo round(xdebug_peak_memory_usage() / 1024, 2), ') KByte - Time: ';
     echo xdebug_time_index();
     echo ' Seconds -->';
     ob_end_flush();
 }
Beispiel #13
0
/**
 * メモリの使用量を表示する
 *
 * @return  void
 */
function p2_print_memory_usage()
{
    if (function_exists('memory_get_usage')) {
        $usage = memory_get_usage();
    } elseif (function_exists('xdebug_memory_usage')) {
        $usage = xdebug_memory_usage();
    } else {
        $usage = -1;
    }
    $kb = $usage / 1024;
    $kb = number_format($kb, 2, '.', '');
    echo 'Memory Usage: ' . $kb . 'KiB';
}
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;
    }
}
Beispiel #15
0
<pre>
<?php 
require 'ezc_mail_setup.php';
error_reporting(E_ALL);
$parser = new ezcMailParser();
$set = new ezcMailFileSet(array(dirname(__FILE__) . '/ezcmailtest.mail'));
echo "Memory: ", xdebug_memory_usage(), " bytes\n\n";
$mail = $parser->parseMail($set);
foreach ($mail as $mailPart) {
    echo "From: {$mailPart->from->email}\n";
    echo "Subject: {$mailPart->subject}\n";
}
unset($mail);
echo "\nMaximum Memory: ", xdebug_peak_memory_usage(), " bytes\n";
Beispiel #16
0
 function llxFooter($foot = '')
 {
     global $conf, $langs, $dolibarr_auto_user, $micro_start_time;
     // Core error message
     if (defined("MAIN_CORE_ERROR") && constant("MAIN_CORE_ERROR") == 1) {
         // Ajax version
         if ($conf->use_javascript_ajax) {
             $title = img_warning() . ' ' . $langs->trans('CoreErrorTitle');
             print ajax_dialog($title, $langs->trans('CoreErrorMessage'));
         } else {
             $msg = img_warning() . ' ' . $langs->trans('CoreErrorMessage');
             print '<div class="error">' . $msg . '</div>';
         }
         define("MAIN_CORE_ERROR", 0);
     }
     print "\n\n";
     if (preg_match('/^smartphone/', $conf->smart_menu) && isset($conf->browser->phone)) {
         print '</div> <!-- end div data-role="content" -->' . "\n";
         print '</div> <!-- end div data-role="page" -->' . "\n";
     }
     print '</div> <!-- end div class="fiche" -->' . "\n";
     print "\n" . '</td></tr></table> <!-- end right area -->' . "\n";
     if ($conf->use_javascript_ajax && !empty($conf->global->MAIN_MENU_USE_JQUERY_LAYOUT)) {
         print '</div></div> <!-- end main layout -->' . "\n";
     }
     print "\n";
     if ($foot) {
         print '<!-- ' . $foot . ' -->' . "\n";
     }
     if (!empty($conf->global->MAIN_HTML_FOOTER)) {
         print $conf->global->MAIN_HTML_FOOTER . "\n";
     }
     // If there is some logs in buffer to show
     if (sizeof($conf->logbuffer)) {
         print "\n";
         print "<!-- Start of log output\n";
         //print '<div class="hidden">'."\n";
         foreach ($conf->logbuffer as $logline) {
             print $logline . "<br>\n";
         }
         //print '</div>'."\n";
         print "End of log output -->\n";
     }
     // End of tuning
     if (!empty($_SERVER['DOL_TUNING'])) {
         $micro_end_time = dol_microtime_float(true);
         print "\n" . '<script type="text/javascript">console.log("';
         if (!empty($conf->global->MEMCACHED_SERVER)) {
             print 'MEMCACHED_SERVER=' . $conf->global->MEMCACHED_SERVER . ' - ';
         }
         print 'MAIN_OPTIMIZE_SPEED=' . (isset($conf->global->MAIN_OPTIMIZE_SPEED) ? $conf->global->MAIN_OPTIMIZE_SPEED : 'off');
         print ' - Build time: ' . ceil(1000 * ($micro_end_time - $micro_start_time)) . ' ms';
         if (function_exists("memory_get_usage")) {
             print ' - Mem: ' . memory_get_usage();
         }
         if (function_exists("xdebug_memory_usage")) {
             print ' - XDebug time: ' . ceil(1000 * xdebug_time_index()) . ' ms';
             print ' - XDebug mem: ' . xdebug_memory_usage();
             print ' - XDebug mem peak: ' . xdebug_peak_memory_usage();
         }
         if (function_exists("zend_loader_file_encoded")) {
             print ' - Zend encoded file: ' . (zend_loader_file_encoded() ? 'yes' : 'no');
         }
         print '")</script>' . "\n";
         // Add Xdebug coverage of code
         if (defined('XDEBUGCOVERAGE')) {
             var_dump(xdebug_get_code_coverage());
         }
     }
     print "</body>\n";
     print "</html>\n";
 }
Beispiel #17
0
 /**
  * Log a message
  *
  * @param string $message    The message to be logged
  * @param int $loglevel        The log level
  */
 function log($message, $loglevel = MIDCOM_LOG_DEBUG)
 {
     if (!$this->_enabled || $this->_loglevel < $loglevel) {
         return;
     }
     $file = fopen($this->_filename, 'a+');
     if (function_exists('xdebug_memory_usage')) {
         static $lastmem = 0;
         $curmem = xdebug_memory_usage();
         $delta = $curmem - $lastmem;
         $lastmem = $curmem;
         $prefix = sprintf("%s (%012.9f, %9s, %7s):\t", date('M d Y H:i:s'), xdebug_time_index(), number_format($curmem, 0, ',', '.'), number_format($delta, 0, ',', '.'));
     } else {
         $prefix = date('M d Y H:i:s') . "\t";
     }
     if (array_key_exists($loglevel, $this->_loglevels)) {
         $prefix .= '[' . $this->_loglevels[$loglevel] . '] ';
     }
     //find the proper caller
     $bt = debug_backtrace(false);
     $prefix .= $this->_get_caller($bt);
     fputs($file, $prefix . trim($message) . "\n");
     fclose($file);
     if ($this->firephp && !_midcom_headers_sent()) {
         try {
             $log_method = $this->_loglevels[$loglevel];
             if ($loglevel == MIDCOM_LOG_DEBUG) {
                 $log_method = 'log';
             }
             if ($loglevel == MIDCOM_LOG_CRIT) {
                 $log_method = 'error';
             }
             $this->firephp->{$log_method}($message);
         } catch (Exception $e) {
             // Ignore FirePHP errors for now
         }
     }
 }
Beispiel #18
0
if (file_exists($settings_file)) {
    include $settings_file;
}
$BaseTemplate->template_path = SKINS_PATH;
Template::Set('MODULE_NAV_INC', $NAVBAR);
Template::Set('MODULE_HEAD_INC', $HTMLHead);
ob_start();
MainController::RunAllActions();
$page_content = ob_get_clean();
$BaseTemplate->Set('title', MainController::$page_title . ' - ' . SITE_NAME);
$BaseTemplate->Set('page_title', MainController::$page_title . ' - ' . SITE_NAME);
if (file_exists(SKINS_PATH . '/layout.tpl')) {
    $BaseTemplate->Set('page_htmlhead', Template::Get('core_htmlhead.tpl', true));
    $BaseTemplate->Set('page_htmlreq', Template::Get('core_htmlreq.tpl', true));
    $BaseTemplate->Set('page_content', $page_content);
    $BaseTemplate->ShowTemplate('layout.tpl');
} else {
    # It's a template sammich!
    $BaseTemplate->ShowTemplate('header.tpl');
    echo $page_content;
    $BaseTemplate->ShowTemplate('footer.tpl');
}
# Force connection close
DB::close();
if (Config::Get('XDEBUG_BENCHMARK')) {
    $run_time = xdebug_time_index();
    $memory_end = xdebug_memory_usage();
    echo 'TOTAL MEMORY: ' . ($memory_end - $memory_start) . '<br />';
    echo 'PEAK: ' . xdebug_peak_memory_usage() . '<br />';
    echo 'RUN TIME: ' . $run_time . '<br />';
}
Beispiel #19
0
 static function xMemory($title = null)
 {
     $mem = (double) xdebug_memory_usage() / (double) (1024 * 1024);
     $mem = number_format($mem, 5) . ", " . time();
     echo "{$title}: {$mem}<p>";
     flush();
 }
Beispiel #20
0
 /**
  * Rendering function on Shutdown of XDEBUG.
  */
 public static function render()
 {
     // Start XDEBUG Tracing and Coverage
     if (self::isXdebugActive()) {
         /*
          * This is the CSS for XDebug Fatal Error
          */
         echo '<!-- Disable XDebug Mode to remove this!-->
             <style type="text/css">
             /*<![CDATA[*/
             table.xdebug-error {
                  font-size: 12px;
                  width: 95%;
                  margin: 0 auto 10px auto;
                  border-color: #666;
                  border-collapse: collapse;
                  border-style: outset;
                  color: #222222;
             }
            .xdebug-error th {
                 background: none repeat scroll 0 0 #E03937;
                 border: 1px inset #BF0000;
                 font-weight: bold;
                 padding: 3px;
                 font-size: 16px;
             }
             .xdebug-error td {
                 background: none repeat scroll 0 0 #FFFFCC;
                 border: 1px solid grey;
                 padding: 2px 2px 2px 5px;
                 vertical-align: top;
             }
             .xdebug-error tr:hover td {
                 background: #ffff88;
             }
             .xdebug-error span {
                 display: none;
             }
             /** Custom Styles not related to XDEBUG **/
             .toggle {
                 font-size: 12px;
                 color: white;
                 float: left;
             }
             /*]]>*/
             </style>';
         /*
          * Reset for hardcoded bgcolor attributes in the "xdebug-error" table.
          * This will select all <td> elements and reset the bgcolor attribute on each element.
          */
         echo "<script type=\"text/javascript\">\n                  var xdebugErrorTable = document.getElementsByClassName('xdebug-error');\n                  if (xdebugErrorTable.length > 0) {\n                    var xdebugErrorTableTds =\n                    document.getElementsByClassName('xdebug-error')[0].getElementsByTagName('td');\n                    for (var i = 0; i < xdebugErrorTableTds.length; i++) {\n                        xdebugErrorTableTds[i].setAttribute('bgcolor', '');\n                    }\n                  }";
         /*
          * Visibility Toggle + Toggle Text Change
          */
         echo 'function toggleXDebugTable(a) {document.getElementById(a).style.display=="none"
               ?(document.getElementById(a).style.display="table",
                 document.getElementById("toggle-icon-"+a).innerHTML="&#9660;")
               :(document.getElementById(a).style.display="none",
                 document.getElementById("toggle-icon-"+a).innerHTML="&#9658;")};';
         echo '</script>';
         /*
          * This is the CSS for XDebug Console via xdebug_dump_superglobals()
          */
         echo '<!-- Disable XDebug Mode to remove this!-->
           <style type="text/css">
           /*<![CDATA[*/
             /* center outer div */
             #x-debug {
                 width: 95%;
                 padding:20px 0px 10px 0px;
                 background: #EFEFEF;
                 border: 1px solid #333;
                 margin: 0 auto; /* centering */
                 margin-top: 15px;
                 margin-bottom: 15px;
             }
             table.xdebug-console, table.xdebug-superglobals {
                 width: 100%;
                 background: none repeat scroll 0 0 #FFFFCC;
                 border-width: 1px;
                 border-style: outset;
                 border-color: #BF0000;
                 border-collapse: collapse;
                 color: #222;
                 font: 12px tahoma,verdana,arial,sans-serif;
                 margin-top: 5px;
                 margin-bottom: 8px;
             }
             table.xdebug-console th, table.xdebug-superglobals th {
                 border: 1px inset #BF0000;
                 padding: 3px;
                 padding-bottom: 3px;
                 font-weight: bold;
                 background: #E03937;
                 text-align: left;
             }
             .xdebug-superglobals td {
                 border: 1px solid grey;
                 padding: 2px;
                 padding-left: 5px;
                 vertical-align:top;
             }
             table.xdebug-console td {
                 border: 1px inset grey;
                 padding: 2px;
                 padding-left: 5px;
             }
             table.xdebug-console td.td1 {width: 30%; padding-left:20px; color:#FF0000; }
             table.xdebug-console td.td2 {width: 70%;}
             table.xdebug-console tr:hover td, table.xdebug-superglobals tr:hover td {
                 background: #ffff88;
             }
             fieldset.xdebug-console {
                 background: none repeat scroll 0 0 #ccc;
                 border: 1px solid #666666;
                 font: 12px tahoma,verdana,arial,sans-serif;
                 margin: 35px;
                 padding: 10px;
                 width: 95%;
             }
             fieldset.xdebug-console legend {
                 background: #fff;
                 border: 1px solid #333;
                 font-weight: bold;
                 padding: 5px 15px;
                 color: #222;
                 float: left;
                 margin-top: -23px;
                 margin-bottom: 10px;
             }
             fieldset.xdebug-console pre {
                 margin: 2px;
                 text-align: left;
                 width: 100%;
             }
             /*]]>*/
             </style>
              <!--[if IE]>
              <style type="text/css">
                 fieldset.xdebug-console legend {
                     position:relative;
                     top: -0.2em;
                 }
              </style>
              <![endif]-->';
         echo '<fieldset class="xdebug-console"><legend>XDebug Console</legend>';
         echo xdebug_dump_superglobals();
         echo '<table class="xdebug-console">';
         echo '<tr><th>Name</th><th>Value</th></tr>';
         echo '<tr>';
         echo '<td class="td1">Time to execute</td>';
         echo '<td class="td2">' . round(xdebug_time_index(), 4) . ' seconds</td>';
         echo '</tr><tr>';
         echo '<td class="td1">Memory Usage (before)</td>';
         echo '<td class="td2">' . self::$xdebug_memory_before . ' MB</td>';
         echo '</tr><tr>';
         echo '<td class="td1">Memory Usage by ' . APPLICATION_NAME . ' </td>';
         echo '<td class="td2">' . self::roundMB(xdebug_memory_usage()) . ' MB</td>';
         echo '</tr><tr>';
         echo '<td class="td1">Memory Peak</td>';
         echo '<td class="td2">' . self::roundMB(xdebug_peak_memory_usage()) . ' MB</td>';
         echo '</tr>';
         // stop tracings and var_dump
         #var_dump(xdebug_get_code_coverage());
         echo '</table>';
         self::showConstants();
         #self::showBrowserInfo();
         self::showHttpHeaders();
         echo '</table>';
         echo '</fieldset>';
         /*
          * Reset for hardcoded bgcolor attributes in the "xdebug-superglobals" table.
          * This will select all <td> elements and reset the bgcolor attribute on each element.
          */
         echo "<script type=\"text/javascript\">\n                  var xdebugTds = document.getElementsByClassName('xdebug-superglobals')[0].getElementsByTagName('td');\n                  for (var i = 0; i < xdebugTds.length; i++) {xdebugTds[i].setAttribute('bgcolor', '');}\n                  xdebugTds[0].setAttribute('width', '30%');\n                  </script>";
     }
 }
Beispiel #21
0
     JError::raiseError(500, 'Controller ' . $viewController . ' not found!');
 }
 $controller = new $viewController($config);
 // Perform the Request task
 // if (CTemplate::mobileTemplate())
 // {
 // 	$controller->executeMobile(JRequest::getCmd('task', ''));
 // } else {
 // 	$controller->execute(JRequest::getCmd('task', ''));
 // }
 $controller->execute(JRequest::getCmd('task', ''));
 $jConfig =& JFactory::getConfig();
 // Some hosting providers has xdebug installed for debugging purposes. We really shouldn't show this
 // on live site unless they turn on debugging mode.
 if (function_exists('xdebug_memory_usage') && $jConfig->getValue('debug')) {
     $memNow = xdebug_memory_usage();
     $db = JFactory::getDBO();
     $db->debug(1);
     echo '<div style="clear:both">&nbsp;</div><pre>';
     echo 'Start usage : ' . cConvertMem($mem) . '<br/>';
     echo 'End usage   : ' . cConvertMem($memNow) . '<br/>';
     echo 'Mem usage   : ' . cConvertMem($memNow - $mem) . '<br/>';
     echo 'Peak mem    : ' . cConvertMem(xdebug_peak_memory_usage()) . '<br/>';
     echo 'Time        : ' . (xdebug_time_index() - $tm) . '<br/>';
     echo 'Query       : ' . $db->getTicker();
     echo '</pre>';
     // Log average page load
     jimport('joomla.filesystem.file');
     $content = JFile::read(COMMUNITY_COM_PATH . DS . 'access.log');
     $params = new JParameter($content);
     $today = strftime('%Y-%m-%d');
Beispiel #22
0
 /**
  * Send HTTP response body and create performance.log
  *
  */
 public function reply($data)
 {
     $this->response->sendHeader();
     echo $data;
     if (function_exists("xdebug_time_index")) {
         $filename = 'app/log/performance.log';
         $time = $this->getRequestURI() . " took " . round(xdebug_time_index(), 5) . " seconds\n";
         $time .= "Used " . round(xdebug_memory_usage() / 1024, 5) . "Kb of Memory\n";
         $time .= "Used at peak " . round(xdebug_peak_memory_usage() / 1024, 5) . "Kb of Memory\n";
         if (is_writeable($filename)) {
             file_put_contents($filename, $time);
         }
     }
 }
Beispiel #23
0
 /**
  * Get memory usage
  *
  * @param bool $peak
  * @return string
  */
 private function _debugMemoryUsage($peak = false)
 {
     $memAvail = ini_get('memory_limit');
     if ($this->_xdebug) {
         $memUsed = $peak ? xdebug_peak_memory_usage() : xdebug_memory_usage();
     } else {
         $memUsed = $peak ? memory_get_peak_usage() : memory_get_usage();
     }
     $memPercent = round($memUsed / $this->_debugGetBytes($memAvail) * 100, 2);
     $memUsedHR = implode('', formatBytes($memUsed));
     return $memUsedHR . ' / ' . $memAvail . ' (' . $memPercent . '%)';
 }
<?php

if (function_exists('xdebug_is_enabled')) {
    if (xdebug_is_enabled()) {
        echo "it seems xdebug is installed and enabled showing memory usage is \n";
        echo number_format(xdebug_memory_usage());
    } else {
        echo "xdebug is installed but not enabled \n";
    }
} else {
    echo 'it seems like xdebug is not installed <a href="http://xdebug.org/wizard.php">http://xdebug.org/wizard.php</a> \\n';
}
Beispiel #25
0
<?php

chdir(dirname(__FILE__));
//require_once '../library/HTMLPurifier.path.php';
shell_exec('php ../maintenance/generate-schema-cache.php');
require_once '../library/HTMLPurifier.path.php';
require_once 'HTMLPurifier.includes.php';
$begin = xdebug_memory_usage();
$schema = HTMLPurifier_ConfigSchema::makeFromSerial();
echo xdebug_memory_usage() - $begin;
// vim: et sw=4 sts=4
Beispiel #26
0
function gjShowErrors()
{
    //call this first after session start
    error_reporting(E_ALL);
    //for test if sessionstart put it after error_reporting
    ini_set('display_errors', 1);
    // 1 to display errors
    ini_set('log_errors', 1);
    global $gjDebug;
    global $gjLocal;
    //usually have to set this in php.ini
    //xdebug_disable();
    //xdebug.collect_assignments
    ini_set('xdebug.collect_includes', '1');
    ini_set('xdebug.collect_params', '1');
    //terse is 1
    ini_set('xdebug.collect_return', '1');
    ini_set('xdebug.collect_vars', '1');
    //for xdebug_get_declared_vars().
    //xdebug.coverage_enable
    ini_set('xdebug.default_enable', '1');
    ini_set('xdebug.dump.SERVER', 'REQUEST_URI,REQUEST_METHOD');
    ini_set('xdebug.dump.GET', '*');
    ini_set('xdebug.dump.SESSION', '*');
    ini_set('xdebug.dump.REQUEST', '*');
    ini_set('xdebug.dump.FILES', '*');
    ini_set('xdebug.dump.COOKIE', '*');
    ini_set('xdebug.dump_globals', '1');
    //xdebug.dump_undefined
    //xdebug.extended_info  only in php.ini
    //xdebug.file_link_format for IDE
    //xdebug.idekey
    //xdebug.manual_url ,link to php manual  defualt http://www.php.net
    ini_set('xdebug.max_nesting_level', '50');
    //xdebug.overload_var_dump
    //xdebug.profiler_append
    //xdebug.profiler_enable
    // ... more profiler options
    // ... more remote options
    ini_set('xdebug.scream', '1');
    // xdebug.show_exception_trace
    ini_set('xdebug.show_local_vars', '1');
    //xdebug.show_mem_delta
    //xdebug.trace_enable_trigger
    ini_set('xdebug.trace_format', '0');
    //0 is for the editor 1 is for IDEs 2 is html
    // xdebug.trace_options
    //xdebug.trace_output_dir  /tmp
    // bad  see php.ini ini_set('xdebug.trace_output_name', 'F:\tmp');
    ini_set('xdebug.var_display_max_children', '128');
    ini_set('xdebug.var_display_max_data', '-1');
    ini_set('xdebug.var_display_max_depth', '-1');
    //not set up on hosted accounts
    if ($gjLocal) {
        try {
            xdebug_enable();
            if (xdebug_is_enabled()) {
                echo 'stack traces are enabled - debugging<BR>';
                //xdebug_start_error_collection();
                echo 'xdebug_memory_usage() ' . number_format(xdebug_memory_usage()) . '<BR>';
                xdebug_start_trace();
            } else {
                echo 'not debugging<br>';
            }
        } catch (Exception $e) {
            echo 'Caught Exception -> message: ', $e->getMessage(), "\n";
            //   or if extended over ridden exception var_dump e->getMessage()
        }
    }
    /*
    xdebug_start_error_collection();
    Starts recording all notices, warnings and errors and prevents their display
    Xdebug will cause PHP not to display any notices, warnings or errors.
    Instead, they are formatted according to Xdebug's normal error formatting rules
    (ie, the error table with the red exclamation mark) and then stored in a buffer.
    This will continue until you call .
    xdebug_stop_error_collection();
    This buffer's contents can be retrieved by calling
    xdebug_get_collected_errors()
    */
    /*
    $bt = debug_backtrace();
    - Generates a user-level error/warning/notice message
    trigger_error("I want a backtrace", E_USER_ERROR);
    debug_print_backtrace() - Prints a backtrace
    */
}
    public static function displayPublicAdminBar($okt)
    {
        $aBasesUrl = new ArrayObject();
        $aPrimaryAdminBar = new ArrayObject();
        $aSecondaryAdminBar = new ArrayObject();
        $aBasesUrl['admin'] = $okt->config->app_path . OKT_ADMIN_DIR;
        $aBasesUrl['logout'] = $aBasesUrl['admin'] . '/index.php?logout=1';
        $aBasesUrl['profil'] = $aBasesUrl['admin'];
        # -- CORE TRIGGER : publicAdminBarBeforeDefaultsItems
        $okt->triggers->callTrigger('publicAdminBarBeforeDefaultsItems', $okt, $aPrimaryAdminBar, $aSecondaryAdminBar, $aBasesUrl);
        # éléments première barre
        $aPrimaryAdminBar[10] = array('intitle' => '<img src="' . OKT_PUBLIC_URL . '/img/notify/error.png" width="22" height="22" alt="' . __('c_c_warning') . '" />', 'items' => array());
        $aPrimaryAdminBar[100] = array('href' => $aBasesUrl['admin'], 'intitle' => __('c_c_administration'));
        $aPrimaryAdminBar[200] = array('intitle' => __('c_c_action_Add'), 'items' => array());
        # éléments seconde barre
        $aSecondaryAdminBar[100] = array('href' => $aBasesUrl['profil'], 'intitle' => sprintf(__('c_c_user_hello_%s'), html::escapeHTML(oktAuth::getUserCN($okt->user->username, $okt->user->lastname, $okt->user->firstname))));
        if (!$okt->languages->unique) {
            $iStartIdx = 150;
            foreach ($okt->languages->list as $aLanguage) {
                if ($aLanguage['code'] == $okt->user->language) {
                    continue;
                }
                $aSecondaryAdminBar[$iStartIdx++] = array('href' => html::escapeHTML($okt->config->app_path . $aLanguage['code'] . '/'), 'title' => html::escapeHTML($aLanguage['title']), 'intitle' => '<img src="' . OKT_PUBLIC_URL . '/img/flags/' . $aLanguage['img'] . '" alt="' . html::escapeHTML($aLanguage['title']) . '" />');
            }
        }
        $aSecondaryAdminBar[200] = array('href' => $aBasesUrl['logout'], 'intitle' => __('c_c_user_log_off_action'));
        # infos super-admin
        if ($okt->checkPerm('is_superadmin')) {
            # avertissement nouvelle version disponible
            if ($okt->config->update_enabled && is_readable(OKT_DIGESTS)) {
                $updater = new oktUpdate($okt->config->update_url, 'okatea', $okt->config->update_type, OKT_CACHE_PATH . '/versions');
                $new_v = $updater->check(util::getVersion());
                if ($updater->getNotify() && $new_v) {
                    # locales
                    l10n::set(OKT_LOCALES_PATH . '/' . $okt->user->language . '/admin.update');
                    $aPrimaryAdminBar[10]['items'][100] = array('href' => $aBasesUrl['admin'] . '/configuration.php?action=update', 'intitle' => sprintf(__('c_a_update_okatea_%s_available'), $new_v));
                }
            }
            # avertissement mode maintenance est activé sur la partie publique
            if ($okt->config->public_maintenance_mode) {
                $aPrimaryAdminBar[10]['items'][300] = array('href' => $aBasesUrl['admin'] . '/configuration.php?action=advanced#tab_others', 'intitle' => sprintf(__('c_a_public_maintenance_mode_enabled'), $new_v));
            }
            # avertissement mode maintenance est activé sur l'admin
            if ($okt->config->admin_maintenance_mode) {
                $aPrimaryAdminBar[10]['items'][400] = array('href' => $aBasesUrl['admin'] . '/configuration.php?action=advanced#tab_others', 'intitle' => sprintf(__('c_a_admin_maintenance_mode_enabled'), $new_v));
            }
            # info execution
            $aExecInfos = array();
            $aExecInfos['execTime'] = util::getExecutionTime();
            if (OKT_XDEBUG) {
                $aExecInfos['memUsage'] = util::l10nFileSize(xdebug_memory_usage());
                $aExecInfos['peakUsage'] = util::l10nFileSize(xdebug_peak_memory_usage());
            } else {
                $aExecInfos['memUsage'] = util::l10nFileSize(memory_get_usage());
                $aExecInfos['peakUsage'] = util::l10nFileSize(memory_get_peak_usage());
            }
            $aSecondaryAdminBar[1000] = array('title' => $aExecInfos['execTime'] . ' s - ' . $aExecInfos['memUsage'], 'intitle' => '<img src="' . OKT_PUBLIC_URL . '/img/ico/terminal.gif" width="16" height="16" alt="" />', 'items' => array(array('intitle' => 'Temps d\'execution du script&nbsp;: ' . $aExecInfos['execTime'] . ' s'), array('intitle' => 'Mémoire utilisée par PHP&nbsp;: ' . $aExecInfos['memUsage']), array('intitle' => 'Pic mémoire allouée par PHP&nbsp;: ' . $aExecInfos['peakUsage']), array('intitle' => 'Router lang&nbsp;: ' . $okt->router->getLanguage()), array('intitle' => 'Router path&nbsp;: ' . $okt->router->getPath()), array('intitle' => 'Router route ID&nbsp;: ' . $okt->router->getFindedRouteId())));
            if (!empty($okt->page->module)) {
                $aSecondaryAdminBar[1000]['items'][] = array('intitle' => '$okt->page->module&nbsp;: ' . $okt->page->module);
            }
            if (!empty($okt->page->action)) {
                $aSecondaryAdminBar[1000]['items'][] = array('intitle' => '$okt->page->action&nbsp;: ' . $okt->page->action);
            }
        }
        # -- CORE TRIGGER : publicAdminBarItems
        $okt->triggers->callTrigger('publicAdminBarItems', $okt, $aPrimaryAdminBar, $aSecondaryAdminBar, $aBasesUrl);
        # sort items of by keys
        $aPrimaryAdminBar->ksort();
        $aSecondaryAdminBar->ksort();
        # remove empty values of admins bars
        $aPrimaryAdminBar = array_filter((array) $aPrimaryAdminBar);
        $aSecondaryAdminBar = array_filter((array) $aSecondaryAdminBar);
        # reverse sedond bar items
        $aSecondaryAdminBar = array_reverse($aSecondaryAdminBar);
        $class = '';
        ?>
		<div id="oktadminbar" class="<?php 
        echo $class;
        ?>
" role="navigation">
			<a class="screen-reader-shortcut" href="#okt-toolbar" tabindex="1"><?php 
        _e('Skip to toolbar');
        ?>
			</a>
			<div class="quicklinks" id="okt-toolbar" role="navigation"
				aria-label="<?php 
        echo util::escapeAttrHTML(__('Top navigation toolbar.'));
        ?>
"
				tabindex="0">
				<ul class="ab-top-menu">
					<?php 
        foreach ($aPrimaryAdminBar as $aPrimaryItem) {
            echo self::getItems($aPrimaryItem);
        }
        ?>
				</ul>
				<ul class="ab-top-secondary ab-top-menu">
					<?php 
        foreach ($aSecondaryAdminBar as $aSecondaryItem) {
            echo self::getItems($aSecondaryItem);
        }
        ?>
				</ul>
			</div>
			<a class="screen-reader-shortcut"
				href="<?php 
        echo $aBasesUrl['logout'];
        ?>
"><?php 
        _e('c_c_user_log_off_action');
        ?>
			</a>
		</div>
		<?php 
    }
Beispiel #28
0
 public static function easybug()
 {
     self::$var['bug']['runsql'] = 0;
     if (!self::$var['ajax'] && function_exists('xdebug_time_index')) {
         self::$var['bug']['runsec'] = function_exists('xdebug_time_index') ? number_format(xdebug_time_index(), 6) : number_format(dmicrotime() - RUNFIRSTTIME, 6);
         $html = '<p>' . self::$var['bug']['runsec'] . 's, runsize: ' . xdebug_memory_usage() . 'Kb, runavgsize: ' . xdebug_peak_memory_usage() . 'Kb, runsql:' . var_export(self::$var['bug']['runsql'], true) . '</p>';
         echo $html;
     } else {
         self::$var['bug']['runsec'] = number_format(dmicrotime() - self::$var['starttime'], 6);
         self::$var['bug']['runmemory'] = intval(return_bytes(memory_get_usage() / (1024 * 1024) . 'k'));
         self::$var['bug']['runsql'] = Factory_Db::countSqlNum();
     }
 }
Beispiel #29
0
 /**
  * Gather and print (and possibly log) amount of used memory.
  *
  * @param string $title
  * @param bool $log
  *   (optional) Whether to log the memory usage information.
  */
 public static function xMemory($title = NULL, $log = FALSE)
 {
     $mem = (double) xdebug_memory_usage() / (double) 1024;
     $mem = number_format($mem, 5) . ", " . time();
     if ($log) {
         echo "<p>{$title}: {$mem}<p>";
         flush();
         CRM_Core_Error::debug_var($title, $mem);
     } else {
         echo "<p>{$title}: {$mem}<p>";
         flush();
     }
 }
Beispiel #30
0
<p><?php 
echo ActiveSupport\DateHelper::to_string('db', time());
?>
</p>
<p><?php 
echo ActiveSupport\DateHelper::to_string('rfc822', time());
?>
</p>
<p><?php 
echo ActiveSupport\TimeHelper::to_string('db', time());
?>
</p>
<p><?php 
echo ActiveSupport\TimeHelper::to_string('rfc822', time());
?>
</p>

<p>Memory usage: <?php 
echo xdebug_memory_usage() / 1024 / 1024;
?>
</p>
<p>Peak Memory usage: <?php 
echo xdebug_peak_memory_usage() / 1024 / 1024;
?>
</p>
<p>Execution Time: <?php 
echo xdebug_time_index();
?>
</p>