function profilingFinalize($pre) { include_once "/usr/share/php5-xhprof/xhprof_lib/utils/xhprof_lib.php"; include_once "/usr/share/php5-xhprof/xhprof_lib/utils/xhprof_runs.php"; $xhprof_runs = new XHProfRuns_Default(); $xhprof_runs->save_run(xhprof_disable(), 'nagvis-' . $pre); }
/** * Stops XHProf profiling and saves profile data in var/log/xhprof * * @return mixed false|string (the run_id)|true (when nosave==true) */ public static function stop($dosave = true) { if (!extension_loaded('xhprof')) { eZPerfLoggerDebug::writeWarning('Extension xhprof not loaded, can not stop profiling', __METHOD__); return false; } if (!self::$profilingRunning) { return false; } $xhprofData = xhprof_disable(); self::$profilingRunning = false; if (!$dosave) { return true; } if (!is_dir(self::$logdir)) { mkdir(self::$logdir); } $logger = new XHProfRuns_Default(self::$logdir); $runId = $logger->save_run($xhprofData, "xhprof"); if ($runId) { // beside profiling data, save extra info in another file to make it more useful later file_put_contents(self::$logdir . "/{$runId}.info", eZPerfLoggerApacheLogger::apacheLogLine('combined')); self::$runs[] = $runId; } return $runId; }
public function testSearchEvents() { $allUsers = Tinebase_User::getInstance()->getFullUsers(''); xhprof_enable(); $numSearches = 0; foreach ($allUsers as $user) { if ($numSearches > 5) { break; } echo "getting month view for {$user->accountDisplayName}\n"; $filterData = array(array('field' => 'container_id', 'operator' => 'in', 'value' => array('/personal/' . $user->getId(), '/shared')), array('field' => 'period', 'operator' => 'within', 'value' => array('from' => '2010-03-01 00:00:00', 'until' => '2010-04-01 00:00:00'))); // $filter = new Calendar_Model_EventFilter($filterData); // $events = Calendar_Controller_Event::getInstance()->search($filter, NULL, FALSE); $this->_json->searchEvents($filterData, NULL); $numSearches += 1; } $xhprof_data = xhprof_disable(); //Tinebase_Core::getDbProfiling(); $XHPROF_ROOT = '/opt/local/www/php5-xhprof'; include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php"; include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php"; $xhprof_runs = new XHProfRuns_Default(); $run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_tine20"); echo "http://localhost/xhprof_html/index.php?run={$run_id}&source=xhprof_tine20 \n"; print_r(Tinebase_Record_Abstract::$cns); }
public function indexAction() { $m_article = $this->load('Article'); $userID = $this->getSession('userID'); if ($userID) { $buffer['username'] = $this->getSession('username'); // User Aritcles $where = array('userID' => USER_ID); $total = $m_article->Where($where)->Total(); $page = $this->get('page'); $page = $page ? $page : 1; $size = 10; $pages = ceil($total / $size); $order = array('addTime' => 'DESC'); $start = ($page - 1) * $size; $limit = $start . ',' . $size; $url = '/user/profile'; $buffer['pageNav'] = generatePageLink($page, $pages, $url, $total); $buffer['articles'] = $m_article->Where($where)->Order($order)->Limit($limit)->Select(); } else { $this->redirect('/'); } // 如果有 xhprof 则开启跟踪功能 if (function_exists('xhprof_disable')) { $data = xhprof_disable(); include_once LIB_PATH . '/xhprof_lib/utils/xhprof_lib.php'; include_once LIB_PATH . '/xhprof_lib/utils/xhprof_runs.php'; $objXhprofRun = new XHProfRuns_Default(); $run_id = $objXhprofRun->save_run($data, 'xhprof'); } $buffer['run_id'] = $run_id; $this->getView()->assign($buffer); }
public function end() { $xhprof_data = xhprof_disable(); $xhprof_runs = new XHProfRuns_Default(); $run_id = $xhprof_runs->save_run($xhprof_data, $this->name); return "<a href='http://localhost:8080/xhprof/xhprof_html/index.php?run={$run_id}&source=" . $this->name . "'>See result</a>"; }
function stop_xhprof_profiling() { $xhprofData = xhprof_disable(); $xhprofNameSpace = 'predict'; $xhprofRuns = new XHProfRuns_Default(); $xhprofRunID = $xhprofRuns->save_run($xhprofData, $xhprofNameSpace); }
private function register() { register_shutdown_function(function () { $execTime = microtime(true) - START_TIME; $memoryUsage = round((memory_get_usage() - START_MEMORY_USAGE) / 1024, 2); $info = '执行时间: ' . round($execTime, 2) . 's, 内存使用: ' . $memoryUsage . 'KB'; $info .= ", 查询次数: " . Db::$queryCount . ", 慢查询数量: " . Db::$slowCount; if ($this->xhporfEnabled) { $route = str_replace('/', '_', CUR_ROUTE); $xhprofData = xhprof_disable(); $dir = DATA_PATH . 'xhprof/'; if (is_dir($dir) || @mkdir($dir)) { $xhprofRuns = new \XHProfRuns_Default($dir); $runId = $xhprofRuns->save_run($xhprofData, $route); $info .= ', 性能分析: <a href="' . $this->xhprofUrl . '?run=' . $runId . '&source=' . $route . '" target="_blank">' . $runId . '</a>'; } } $isAjax = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest'; $isGet = !empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) === 'get'; if ($this->showStatusBar && $isGet && !$isAjax) { echo '<div style="padding:5px 0;background:#faebcc;text-align:center;">'; echo $info; echo '</div>'; } }); }
public static function endProf() { $xhprof_data = xhprof_disable(); $xhprof_runs = new XHProfRuns_Default(); $run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_foo"); echo '<a href="/xhprof_html/index.php?run=' . $run_id . '&source=xhprof_foo" target="_blank">count</a>'; }
static function xhprof($xhprof_data, $res_name = "xhprof_res") { include_once dc_root . 'xhprof_lib/xhprof_lib.php'; include_once dc_root . 'xhprof_lib/xhprof_runs.php'; $xhprof_runs = new XHProfRuns_Default(); $run_id = $xhprof_runs->save_run($xhprof_data, $res_name); $show_url = dc_url . 'xhprof_html/index.php?run=' . $run_id . '&source=' . $res_name; return '<a href="' . $show_url . '" target="_blank">XHPROF_RESULT</a>'; }
/** * Stop and save the xhprof profiler run * * @return string Saved run id */ public static function finish() { // Stop profiling $data = self::stop(); // Save the run $xhprof = new XHProfRuns_Default(); $runId = $xhprof->save_run($data, Configure::read('XHProf.namespace')); return $runId; }
/** * save run data * * @param array $run run data * @param string $namespace save namespace * @return string id */ static function Save($run, $namespace, $root = '') { if ($root) { $root = rtrim($root, '/') . '/'; } include_once $root . "xhprof_lib/utils/xhprof_lib.php"; include_once $root . "xhprof_lib/utils/xhprof_runs.php"; $xhprof = new XHProfRuns_Default(); return $xhprof->save_run($run, $namespace); }
public function save() { if (!$this->aResult) { $this->launchException('Cannot save profile, no result found'); } require_once self::ROOT . '/utils/xhprof_lib.php'; require_once self::ROOT . '/utils/xhprof_runs.php'; $xhprof_runs = new \XHProfRuns_Default(); $run_id = $xhprof_runs->save_run($this->aResult, "xhprof_testing"); }
function xhprofclose() { $xhprof_data = xhprof_disable(); $xhprof_location = "/data/htdocs/xhprof"; include_once "{$xhprof_location}/xhprof_lib/utils/xhprof_lib.php"; include_once "{$xhprof_location}/xhprof_lib/utils/xhprof_runs.php"; $xhprof_runs = new XHProfRuns_Default(); $identifer = str_replace(array('/', '?', '.', '=', '&'), '_', $_SERVER['REQUEST_URI']); $xhprof_runs->save_run($xhprof_data, $identifer); }
function xhprof_shutdown_function() { global $_xhprof; if ($_xhprof['doprofile'] === true) { $profiler_namespace = $_xhprof['namespace']; // namespace for your application $xhprof_data = xhprof_disable(); $xhprof_runs = new XHProfRuns_Default(); $run_id = $xhprof_runs->save_run($xhprof_data, $profiler_namespace, null, $_xhprof); } }
/** * Forces the profiling to stop and populates the $this->_runId property * */ public function stop() { if (empty($this->_runId) && function_exists('xhprof_disable')) { // Stop profiling $data = xhprof_disable(); $libPath = isset($this->_options['libPath']) ? $this->_options['libPath'] : 'xhprof_lib/utils'; include_once $libPath . '/xhprof_lib.php'; include_once $libPath . '/xhprof_runs.php'; $xhprof = new XHProfRuns_Default(); $this->_runId = $xhprof->save_run($data, $this->_source); } }
function end_xhprof($domain = "dachuwang") { try { //end profiling $xhprof_data = xhprof_disable(); $xhprof_runs = new XHProfRuns_Default(); $run_id = $xhprof_runs->save_run($xhprof_data, $domain); } catch (Exception $e) { return FALSE; } return C("xhprof.url") . "/xhprof_html/index.php?run={$run_id}&source={$domain}"; }
/** * 后置拦截器,在所有操作进行完毕之后进行拦截 */ public function postHandle() { $config = InitPHP::getConfig(); if ($config['is_xhprof']) { $xhprof_data = xhprof_disable(); // save raw data for this profiler run using default // implementation of iXHProfRuns. $xhprof_runs = new XHProfRuns_Default(); // save the run under a namespace "xhprof_foo" $run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_foo"); } }
/** * Stops profiling, saves recorded data and provides URL to view the report * @param boolean $html if result should be an HTML link or string URL * @return boolean|string URL to report page or FALSE on error */ public function stop($html = true) { if ($this->isInitialized) { $data = xhprof_disable(); $runs = new \XHProfRuns_Default(); $id = $runs->save_run($data, $this->namespace); $url = "{$this->host}/index.php?run={$id}&source={$this->namespace}"; return $html ? "<a href=\"{$url}\" target=\"_blank\">Profiler output</a>" : $url; } else { return $html ? '<a href="#">XHPROF WAS NOT CONFIGURED CORRECTLY</a>' : false; } }
/** * Stops XHProf * * @return string */ public static function stop() { if (extension_loaded('xhprof')) { $profiler_namespace = 'eRepublikClone'; // namespace for your application $xhprof_data = xhprof_disable(); $xhprof_runs = new XHProfRuns_Default(); $run_id = $xhprof_runs->save_run($xhprof_data, $profiler_namespace); $profiler_url = sprintf('http://localhost/xhprof-master/xhprof_html/index.php?run=%s&source=%s', $run_id, $profiler_namespace); return '<a href="' . $profiler_url . '" target="_blank">Profiler output</a>'; } }
public function dispatchLoopShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) { // stop profiler $xhprof_data = xhprof_disable(); include_once BASE_PATH . '/xhprof_lib/utils/xhprof_lib.php'; include_once BASE_PATH . '/xhprof_lib/utils/xhprof_runs.php'; // save raw data for this profiler run using default // implementation of iXHProfRuns. $xhprof_runs = new XHProfRuns_Default(); // save the run under a namespace "xhprof" $run_id = $xhprof_runs->save_run($xhprof_data, 'xhprof'); echo '<p><a href="http://xhprof/index.php?run=' . $run_id . '&source=xhprof" target="_blank">Xhprof</a></p>'; }
public static function disable() { $data = xhprof_disable(); $logpath = self::logpath(); if (!is_dir($logpath)) { mkdir($logpath, 0755, true); } include LIB . "xhprof/xhprof_lib/utils/xhprof_lib.php"; include LIB . "xhprof/xhprof_lib/utils/xhprof_runs.php"; $xhprof_runs = new \XHProfRuns_Default($logpath); $run_id = $xhprof_runs->save_run($data, SITE); self::graph($run_id); exit; }
public static function end($key = 'ALL', $logName = 'debug') { $endTime = self::getMicroTime(); $run_id = 0; if (self::$xhprof) { $xhprof_data = \xhprof_disable(); $xhprof_runs = new \XHProfRuns_Default(); $run_id = $xhprof_runs->save_run($xhprof_data, 'random'); } $times = $endTime - self::$records[$key]['start_time']; $mem_use = memory_get_usage() - self::$records[$key]['memory_use']; unset(self::$records[$key]); Log::info($logName, array($times, self::convert($mem_use), $run_id, $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'], \json_encode($_REQUEST))); }
function profilerStop($type = 'fpm') { if (isset($_SERVER['ENABLE_PROFILER']) && function_exists('xhprof_enable')) { static $profiler; static $profilerDir; $data = xhprof_disable(); $profilerDir || is_dir($profilerDir = storagePath('profiler')) or mkdir($profilerDir, 0777, true); $pathInfo = strtr($_SERVER['REQUEST_URI'], ['/' => '|']); $microTime = explode(' ', microtime()); $reportFile = $microTime[1] . '-' . substr($microTime[0], 2) . '-' . $_SERVER['REQUEST_METHOD'] . $pathInfo; $profiler or $profiler = new XHProfRuns_Default($profilerDir); $profiler->save_run($data, $type, $reportFile); } }
public function dispatchLoopShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) { // stop profiler $xhprof_data = xhprof_disable(); $XHPROF_ROOT = realpath(dirname(__FILE__) . '/../../'); include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php"; include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php"; // save raw data for this profiler run using default // implementation of iXHProfRuns. $xhprof_runs = new XHProfRuns_Default(); // save the run under a namespace "xhprof_foo" $run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_foo"); echo "<p><a href='http://x/index.php?run={$run_id}&source=xhprof_foo' target='_blank'>Xhprof</a></p>"; }
public function dispatchLoopShutdown(Yaf\Request_Abstract $request, Yaf\Response_Abstract $response) { // stop profiler $xhprof_data = xhprof_disable(); require APPLICATION_PATH . '/xhprof/xhprof_lib/utils/xhprof_lib.php'; require APPLICATION_PATH . '/xhprof/xhprof_lib/utils/xhprof_runs.php'; // save raw data for this profiler run using default // implementation of iXHProfRuns. $xhprof_runs = new XHProfRuns_Default(); // save the run under a namespace "xhprof_foo" $run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_analyze"); //需要查看调用图片时,需要安装graphviz //$html = '<a href="' . XHPROF_HOST . '/xhprof_html/index.php" target="_blank">[xhprof result]</a>'; //$response->appendBody($html); }
function saveXhprof() { global $argv; $_SERVER['REQUEST_URI'] = implode(' ', $argv); // stop profiler $xhprof_data = xhprof_disable(); $xhprofConfig = Configure::read('Environment.xhprof'); include_once $xhprofConfig['utils'] . "xhprof_lib.php"; include_once $xhprofConfig['utils'] . "xhprof_runs.php"; // save raw data for this profiler run using default // implementation of iXHProfRuns. $xhprof_runs = new XHProfRuns_Default($xhprofConfig['storage']); // save the run under a namespace "xhprof_foo" $runId = $xhprof_runs->save_run($xhprof_data, $xhprofConfig['tag']); echo "\n{$xhprofConfig['host']}?run={$runId}&source={$xhprofConfig['tag']}\n"; }
/** * Stops the timer. Returns elapsed as ms or pretty string * * @param string $id * @param bool $prettyPrint If true, elapsed time will be returned in a state suitable for display * * @return float|string The elapsed time in ms */ public static function stop($id, $prettyPrint = true) { if (!isset(static::$_profiles[$id]['start'])) { return 'not profiled'; } static::$_profiles[$id]['stop'] = microtime(true); static::$_profiles[$id]['elapsed'] = static::$_profiles[$id]['stop'] - static::$_profiles[$id]['start']; if (static::$_xhprof) { /** @noinspection PhpUndefinedFunctionInspection */ /** @noinspection PhpUndefinedMethodInspection */ /** @noinspection PhpUndefinedClassInspection */ static::$_profiles[$id]['xhprof'] = ['data' => $_data = xhprof_disable(), 'run_name' => $_runName = $id . microtime(true), 'runs' => $_runs = new \XHProfRuns_Default(), 'run_id' => $_runId = $_runs->save_run($_data, $_runName), 'url' => 'http://xhprof.local/index.php?run=' . $_runId . '&source=' . $_runName]; \Log::debug('~!~ profiler link: ' . static::$_profiles[$id]['xhprof']['url']); } return $prettyPrint ? static::elapsedAsString(static::$_profiles[$id]['elapsed']) : static::$_profiles[$id]['elapsed']; }
public function showresult() { // Render the profiling link if ($this->profiling) { // stop profiler $lo_xhprofdata = xhprof_disable(); $lo_xhprofruns = new \XHProfRuns_Default(); // Save the run under a namespace "xhprof_basket". $li_runid = $lo_xhprofruns->save_run($lo_xhprofdata, "mercury"); echo ' <div style="position:absolute; bottom:0; left:0; z-index:1000"> <a class="btn btn-warning" target="_blank" href="/vendor/lox/xhprof/xhprof_html/index.php?run=' . $li_runid . '&source=mercury"> Profile </a> </div>'; } }
public static function end($source = null) { if (!self::isExtension()) { die("没有xhprof扩展!"); } // 可以return掉 则不影响正常程序 $xhprof_data = xhprof_disable(); $oXHProf = app::get("serveradm")->model("xhprof"); //$run_id = $oXHProf->write_data($xhprof_data); include_once dirname(__FILE__) . "/../vendor/xhprof_lib/utils/xhprof_lib.php"; include_once dirname(__FILE__) . "/../vendor/xhprof_lib/utils/xhprof_runs.php"; $xhprof_runs = new XHProfRuns_Default(); $run_id = $xhprof_runs->save_run($xhprof_data, "xhprof"); $aData = array('source' => 'xhprof', 'run_id' => $run_id, 'request_uri' => kernel::request()->get_request_uri(), 'app' => $_GET['app'], 'ctl' => $_GET['ctl'], 'act' => $_GET['act'], 'wt' => $xhprof_data["main()"]["wt"], 'mu' => $xhprof_data["main()"]["mu"], 'pmu' => $xhprof_data["main()"]["pmu"], 'addtime' => time()); $oXHProf->save($aData); }
public function stop() { // stop profiler $xhprof_data = xhprof_disable(); // display raw xhprof data for the profiler run //print_r($xhprof_data); include_once APPPATH . "vendor/xhprof/utils/xhprof_lib.php"; include_once APPPATH . "vendor/xhprof/utils/xhprof_runs.php"; // save raw data for this profiler run using default // implementation of iXHProfRuns. $xhprof_runs = new XHProfRuns_Default(); // save the run under a namespace "xhprof_foo" $run_id = $xhprof_runs->save_run($xhprof_data, "uap_sns"); //if (!isset($_REQUEST['ajax'])) echo "\r\n".'<!-- Profiler URL:'. Kohana::config('config.xhprof_url') .'?run='.$run_id.'&source=uap_sns -->'; return $run_id; }