Exemplo n.º 1
0
 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>";
 }
 public static function stopProfiler()
 {
     if (self::$profilerStarted) {
         $data = xhprof_disable();
         $data = serialize($data);
         $file_class = 'PhabricatorFile';
         // Since these happen on GET we can't do guarded writes. These also
         // sometimes happen after we've disposed of the write guard; in this
         // case we need to disable the whole mechanism.
         $use_scope = AphrontWriteGuard::isGuardActive();
         if ($use_scope) {
             $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
         } else {
             AphrontWriteGuard::allowDangerousUnguardedWrites(true);
         }
         $caught = null;
         try {
             $file = call_user_func(array($file_class, 'newFromFileData'), $data, array('mime-type' => 'application/xhprof', 'name' => 'profile.xhprof'));
         } catch (Exception $ex) {
             $caught = $ex;
         }
         if ($use_scope) {
             unset($unguarded);
         } else {
             AphrontWriteGuard::allowDangerousUnguardedWrites(false);
         }
         if ($caught) {
             throw $caught;
         } else {
             return $file->getPHID();
         }
     } else {
         return null;
     }
 }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 4
0
 public static function ADisable()
 {
     if (self::_isEnable()) {
         return xhprof_disable();
     }
     return array();
 }
Exemplo n.º 5
0
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);
}
 /**
  * @inheritdoc
  */
 public function save()
 {
     if (function_exists('xhprof_disable')) {
         $data = xhprof_disable();
     }
     return isset($data) && $data !== null ? $data : [];
 }
Exemplo n.º 7
0
 /**
  * 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;
 }
Exemplo n.º 8
0
 /**
  * Stop collecting profiling data.
  *
  * Only the first invocation of this method will effect the internal
  * object state. Subsequent calls will return the data collected by the
  * initial call.
  *
  * @return array Collected profiling data (possibly cached)
  */
 public function stop()
 {
     if ($this->hieraData === null) {
         $this->hieraData = $this->pruneData(xhprof_disable());
     }
     return $this->hieraData;
 }
 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);
 }
Exemplo n.º 10
0
 /**
  * Stop xhprof profiler
  *
  * @return array|null xhprof data from the run, or null if xhprof was not running.
  */
 public static function disable()
 {
     if (self::isEnabled()) {
         self::$enabled = false;
         return xhprof_disable();
     }
 }
Exemplo n.º 11
0
function xhprof_stop()
{
    // 关闭xhprof
    global $gearman_enabled;
    $error = error_get_last();
    $resp_time = sprintf("%.4f", $GLOBALS['AX_PAGE_END_TIME'] - $GLOBALS['AX_PAGE_START_TIME']);
    if (!empty($error) || $GLOBALS['AX_XHPROF_IS_RUN'] || $resp_time >= $GLOBALS['AX_XHPROF_TIMEOUT']) {
        $data = array();
        $data['host'] = $_SERVER['HTTP_HOST'];
        $data['uri'] = $_SERVER['REQUEST_URI'];
        $data['client_time'] = date('Y-m-d H:i:s');
        $data['resp_time'] = $resp_time;
        $data['xhprof'] = null;
        if ($GLOBALS['AX_XHPROF_IS_RUN']) {
            $data['xhprof'] = xhprof_disable();
            $GLOBALS['AX_XHPROF_IS_RUN'] = false;
        }
        $data['error'] = $error;
        // 检查是否安装gearman扩展,并已设置gearman server
        if ($gearman_enabled) {
            $ret = do_background_job('xhprof.write', serialize($data));
            echo "\n<!-- gearman save: {$ret} -->\n";
        } else {
            $xhprof_run = new XHProfRuns_DB();
            $run_id = $xhprof_run->save_run($data);
            echo "\n<!-- xhprof save, id: {$run_id} -->\n";
        }
    }
}
Exemplo n.º 12
0
 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>';
 }
Exemplo n.º 13
0
 /**
  * Collects data.
  *
  * @param MvcEvent $mvcEvent
  */
 public function collect(MvcEvent $mvcEvent)
 {
     $rawData = xhprof_disable();
     $rawData = empty($rawData) ? [] : $rawData;
     $data = $this->getFunctions($rawData);
     $heaps = [];
     foreach ($this->options->getMetrics() as $name => $options) {
         $this->data[$name] = [];
         $heaps[$name] = new MaxHeap();
     }
     if (!empty($data)) {
         foreach ($data as $entry) {
             /** @var Entry $entry */
             foreach ($this->options->getMetrics() as $name => $options) {
                 if ($options['skipInternal'] && $entry->isInternal()) {
                     continue;
                 }
                 if (!empty($options['skipPattern']) && preg_match($options['skipPattern'], $entry->getName())) {
                     continue;
                 }
                 $heaps[$name]->insert(['name' => $entry->getName(), 'value' => $entry->{$options['getter']}()]);
             }
         }
         foreach ($this->options->getMetrics() as $name => $options) {
             for ($i = $options['limit']; $i--;) {
                 $value = $heaps[$name]->extract();
                 $this->data[$name][$value['name']] = $value['value'];
             }
         }
     }
 }
Exemplo n.º 14
0
 public function index()
 {
     function bar($x)
     {
         if ($x > 0) {
             bar($x - 1);
         }
     }
     function foo()
     {
         for ($idx = 0; $idx < 5; $idx++) {
             bar($idx);
             $x = strlen("abc");
         }
     }
     //开启调试
     xhprof_enable();
     // cpu:XHPROF_FLAGS_CPU 内存:XHPROF_FLAGS_MEMORY
     // 如果两个一起:XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY
     xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
     //要测试的php代码
     foo();
     //停止监测
     $xhprof_data = xhprof_disable();
     // display raw xhprof data for the profiler run
     print_r($xhprof_data);
     //包含工具类,在下载的 tgz 包中可以找到
     //$XHPROF_ROOT = realpath(dirname(__FILE__) .'/..');
     Vendor('Xhprof.autoload');
     //Vendor('Xhprof.xhprof_runs');
     //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.
 }
Exemplo n.º 15
0
 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>';
         }
     });
 }
Exemplo n.º 16
0
 function stop_xhprof_profiling()
 {
     $xhprofData = xhprof_disable();
     $xhprofNameSpace = 'predict';
     $xhprofRuns = new XHProfRuns_Default();
     $xhprofRunID = $xhprofRuns->save_run($xhprofData, $xhprofNameSpace);
 }
Exemplo n.º 17
0
 public function benchmark_end()
 {
     $controller = MPF::get_instance()->get_current_controller();
     $this->namespace = get_class($controller);
     $run = xhprof_disable();
     $this->xhprof_data = serialize($run);
 }
Exemplo n.º 18
0
 /**
  * collect data
  */
 public function collect()
 {
     if (!extension_loaded('xhprof')) {
         throw new \RuntimeException('xhprof extension is not loaded');
     }
     $this->addData(\xhprof_disable());
 }
Exemplo n.º 19
0
 public function tearDown()
 {
     if (!extension_loaded('xhprof')) {
         return parent::tearDown();
     }
     $xhprofData = xhprof_disable();
     $this->endTime = microtime(true);
     if (defined('ARRAY_FILTER_USE_KEY')) {
         // ignore all phpunit related keys
         // var_dump($xhprofData);
         $xhprofData = array_filter($xhprofData, function ($key) {
             return !preg_match('/PHPUnit/', $key);
         }, ARRAY_FILTER_USE_KEY);
     }
     include_once $_ENV['XHPROF_ROOT'] . "/xhprof_lib/utils/xhprof_lib.php";
     include_once $_ENV['XHPROF_ROOT'] . "/xhprof_lib/utils/xhprof_runs.php";
     $namespace = 'LazyRecord:' . $this->getName();
     $runs = new XHProfRuns_Default();
     $runId = $runs->save_run($xhprofData, $namespace);
     $host = 'localhost';
     if (isset($_ENV['XHPROF_HOST'])) {
         $host = $_ENV['XHPROF_HOST'];
     }
     echo "\n---------------------------------\n";
     printf("Profile test %d times spent %.2f seconds\n", $this->N, $this->endTime - $this->startTime);
     printf("See profiling result at http://%s/index.php?run=%s&source=%s\n", $host, $runId, $namespace);
     parent::tearDown();
 }
Exemplo n.º 20
0
function xhprof_shutdown()
{
    global $xhprofMainConfig;
    $xhprof_data = xhprof_disable();
    if (function_exists('fastcgi_finish_request')) {
        fastcgi_finish_request();
    }
    try {
        require_once __DIR__ . '/../xhprof/classes/data.php';
        $xhprof_data_obj = new \ay\xhprof\Data($xhprofMainConfig['pdo']);
        $xhprof_data_obj->save($xhprof_data);
    } catch (Exception $e) {
        // old php versions don't like Exceptions in shutdown functions
        // -> log them to have some usefull info in the php-log
        if (PHP_VERSION_ID < 504000) {
            if (function_exists('log_exception')) {
                log_exception($e);
            } else {
                error_log($e->__toString());
            }
        }
        // re-throw to show the caller something went wrong
        throw $e;
    }
}
Exemplo n.º 21
0
 /**
  * @inheritdoc
  */
 public function save()
 {
     $headers = \Yii::$app->request->getHeaders();
     if (function_exists('xhprof_disable') && $headers['xhprof-enabled']) {
         $data = xhprof_disable();
     }
     return isset($data) && $data !== null ? $data : [];
 }
Exemplo n.º 22
0
 /**
  * Stop profiling session
  *
  * @return void
  */
 public function stop()
 {
     if (!$this->started) {
         return;
     }
     $xhprof_data = xhprof_disable();
     require_once self::$xhprof_path . "/xhprof/classes/data.php";
     $xhprof_data_obj = new \ay\xhprof\Data(self::$config['pdo']);
     $xhprof_data_obj->save($xhprof_data);
 }
Exemplo n.º 23
0
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);
}
Exemplo n.º 24
0
 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);
     }
 }
Exemplo n.º 25
0
 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}";
 }
Exemplo n.º 26
0
 /**
  * 后置拦截器,在所有操作进行完毕之后进行拦截
  */
 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");
     }
 }
Exemplo n.º 27
0
 /**
  * Stop profiling and save and/or return results.
  *
  * @return array Profiling results
  */
 public function profileStop()
 {
     $data = array();
     if ($this->xhprof_on) {
         $this->xhprof_on = false;
         $data = xhprof_disable();
         if ($this->storage) {
             $this->storage->saveProfile($data);
         }
     }
     return $data;
 }
Exemplo n.º 28
0
 /**
  * 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>';
     }
 }
Exemplo n.º 29
0
 /**
  * {@inheritdoc}
  */
 public function collect(Request $request, Response $response, \Exception $exception = null)
 {
     require_once $this->container->getParameter('jns_xhprof.location.lib');
     require_once $this->container->getParameter('jns_xhprof.location.runs');
     $xhprof_data = xhprof_disable();
     if ($this->logger) {
         $this->logger->debug('Disabled XHProf');
     }
     $xhprof_runs = new XHProfRuns_Default();
     $run_id = $xhprof_runs->save_run($xhprof_data, "Symfony");
     $this->data = array('xhprof' => $run_id, 'xhprof_url' => $this->container->getParameter('jns_xhprof.location.web'));
 }
Exemplo n.º 30
0
 /**
  * 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);
     }
 }