Merge branch 'MDL-76956-m400' of https://github.com/sammarshallou/moodle into MOODLE_...
[moodle.git] / lib / xhprof / README.md
blob710e0ecbfe32d5e843e4d2b4fd17db4ec6ba5fef
1 # xhprof for PHP7
2 [![Build Status](https://travis-ci.com/longxinH/xhprof.svg?branch=master)](https://travis-ci.com/longxinH/xhprof) [![Build status](https://ci.appveyor.com/api/projects/status/dornfeel5yutaxte/branch/master?svg=true)](https://ci.appveyor.com/project/longxinH/xhprof/branch/master)
4 XHProf is a function-level hierarchical profiler for PHP and has a simple HTML based navigational interface. The raw data collection component is implemented in C (as a PHP extension). The reporting/UI layer is all in PHP. It is capable of reporting function-level inclusive and exclusive wall times, memory usage, CPU times and number of calls for each function. Additionally, it supports ability to compare two runs (hierarchical DIFF reports), or aggregate results from multiple runs.
6 This version supports PHP7
8 # PHP Version
9 - 7.0
10 - 7.1
11 - 7.2
12 - 7.3
13 - 7.4
14 - 8.0
16 # Installation
17 ```
18 git clone https://github.com/longxinH/xhprof.git ./xhprof
19 cd xhprof/extension/
20 /path/to/php7/bin/phpize
21 ./configure --with-php-config=/path/to/php7/bin/php-config
22 make && sudo make install
23 ```
25 #### configuration add to your php.ini
26 ```
27 [xhprof]
28 extension = xhprof.so
29 xhprof.output_dir = /tmp/xhprof
30 ```
32 ### php.ini configuration
33 |      Options        |  Defaults  |  Version  |  Explain  |
34 | --------------- |:-------------:|:-------------:|:---------|
35 |xhprof.output_dir  | "" | All |Output directory|
36 |xhprof.sampling_interval  | 100000 | >= v2.* | Sampling interval to be used by the sampling profiler, in microseconds|
37 |xhprof.sampling_depth  | INT_MAX | >= v2.* | Depth to trace call-chain by the sampling profiler|
38 |xhprof.collect_additional_info  | 0 | >= v2.1 | Collect mysql_query, curl_exec internal info. The default is 0. Open value is 1|
40 # Turn on extra collection
41 #### php.ini adds xhprof.collect_additional_info
42 ```sh
43 xhprof.collect_additional_info = 1
44 ````
45 # Options
46 ```php
47 xhprof_enable(XHPROF_FLAGS_NO_BUILTINS | XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY);
48 ```
49 - `XHPROF_FLAGS_NO_BUILTINS` do not profile builtins
50 - `XHPROF_FLAGS_CPU` gather CPU times for funcs
51 - `XHPROF_FLAGS_MEMORY` gather memory usage for funcs
53 Example
54 ```php
55 <?php
57 array(
58     "main()" => array(
59         "wt" => 237,
60         "ct" => 1,
61         "cpu" => 100,
62     )
64 ```
66 - `wt` The execution time of the function method is time consuming
67 - `ct` The number of times the function was called
68 - `cpu` The CPU time consumed by the function method execution
69 - `mu` Memory used by function methods. The call is zend_memory_usage to get the memory usage
70 - `pmu` Peak memory used by the function method. The call is zend_memory_peak_usage to get the memory
72 ### PDO::exec
73 ### PDO::query
74 ### mysqli_query
75 ```php
76 $mysqli = new mysqli("localhost", "my_user", "my_password", "user");
77 $result = $mysqli->query("SELECT * FROM user LIMIT 10");
78 ```
79 ##### Output data
80 ```
81 mysqli::query#SELECT * FROM user LIMIT 10
82 ```
84 ### PDO::prepare
85 Convert preprocessing placeholders for actual parameters, more intuitive analytic performance (does not change the zend execution process)
86 ```php
87 $_sth = $db->prepare("SELECT * FROM user where userid = :id and username = :name");
88 $_sth->execute([':id' => '1', ':name' => 'admin']);
89 $data1 = $_sth->fetch();
91 $_sth = $db->prepare("SELECT * FROM user where userid = ?");
92 $_sth->execute([1]);
93 $data2 = $_sth->fetch();
94 ```
95 ##### Output data
96 ```
97 PDOStatement::execute#SELECT * FROM user where userid = 1 and username = admin
98 PDOStatement::execute#SELECT * FROM user where userid = 1
99 ```
101 ### Curl
102 ```php
103 $ch = curl_init();
104 curl_setopt($ch, CURLOPT_URL, "http://www.baidu.com");
105 $output = curl_exec($ch);
106 curl_close($ch);
108 ##### Output data
110 curl_exec#http://www.baidu.com
113 ## PECL Repository
114 [![pecl](resource/pecl.png)](https://pecl.php.net/package/xhprof)