Use xhprof to test php performance in the development environment

Source: Internet
Author: User
XHProf is a hierarchical PHP performance analysis tool. It reports the number of requests and various metrics at the function level, including the blocking time, CPU time, and memory usage. Now let's talk about how XHProf tests php performance in the development environment. Produced with a probability of 1%... XHProf is a hierarchical PHP performance analysis tool. It reports the number of requests and various metrics at the function level, including the blocking time, CPU time, and memory usage. Now let's talk about how XHProf tests php performance in the development environment.

Generate test data with a probability of 1%, and try not to affect the efficiency of the formal environment.

class XHProf {    // private $XHProfPath = 'xhprof/';    private $XHProfPath = '/usr/local/apache/htdocs/xhprof/';    private $applicationName = 'sias_application';    private $sampleSize = 100;    private static $enabled = false;    public function XHProf_Start() {        if (mt_rand(1, $this->sampleSize) == 1) {            include_once $this->XHProfPath . 'xhprof_lib/utils/xhprof_lib.php';            include_once $this->XHProfPath . 'xhprof_lib/utils/xhprof_runs.php';            xhprof_enable(XHPROF_FLAGS_NO_BUILTINS + XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);            self::$enabled = true;        }    }    public function XHProf_End() {        if (self::$enabled) {            $XHProfData = xhprof_disable();            $XHProfRuns = new XHProfRuns_Default();            $XHProfRuns->save_run($XHProfData, $this->applicationName);        }    }}

Test results:

Overall Summary     Total Incl. Wall Time (microsec):     48,162 microsecsTotal Incl. CPU (microsecs):     32,994 microsecsTotal Incl. MemUse (bytes):     2,773,464 bytesTotal Incl. PeakMemUse (bytes):     2,867,664 bytesNumber of Function Calls:     749

The following test results show that the most time-consuming connection is to connect to the database, so we try to optimize the database as much as possible.

Address:

Reprinted at will, but please attach the article address :-)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.