From e0601790984347c541f683655aef66631eae3e57 Mon Sep 17 00:00:00 2001 From: Ilya Tregubov Date: Tue, 19 Jan 2021 09:31:19 +0200 Subject: [PATCH] MDL-70297 libraries: xhprof upgraded to 2.2.3 --- lib/xhprof/README | 5 - lib/xhprof/README.md | 114 ++++++++++++++++++ lib/xhprof/xhprof_html/callgraph.php | 14 +-- lib/xhprof/xhprof_html/css/xhprof.css | 6 - lib/xhprof/xhprof_html/index.php | 14 +-- lib/xhprof/xhprof_html/typeahead.php | 13 +- .../xhprof_lib/utils/callgraph_utils.php | 6 +- lib/xhprof/xhprof_lib/utils/xhprof_lib.php | 4 + lib/xhprof/xhprof_lib/utils/xhprof_runs.php | 4 +- 9 files changed, 123 insertions(+), 57 deletions(-) delete mode 100644 lib/xhprof/README create mode 100644 lib/xhprof/README.md diff --git a/lib/xhprof/README b/lib/xhprof/README deleted file mode 100644 index a8c15fa9283..00000000000 --- a/lib/xhprof/README +++ /dev/null @@ -1,5 +0,0 @@ -For installation and usage notes refer to: - xhprof_html/docs/index.html - -To view the latest version of the doc, go to: - http://pecl.php.net/package/xhprof ---> [View Documentation] diff --git a/lib/xhprof/README.md b/lib/xhprof/README.md new file mode 100644 index 00000000000..08d768df6e9 --- /dev/null +++ b/lib/xhprof/README.md @@ -0,0 +1,114 @@ +# xhprof for PHP7 +[![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) + +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. + +This version supports PHP7 + +# PHP Version +- 7.0 +- 7.1 +- 7.2 +- 7.3 +- 7.4 +- 8.0 beta4 + +# Installation +``` +git clone https://github.com/longxinH/xhprof.git ./xhprof +cd xhprof/extension/ +/path/to/php7/bin/phpize +./configure --with-php-config=/path/to/php7/bin/php-config +make && sudo make install +``` + +#### configuration add to your php.ini +``` +[xhprof] +extension = xhprof.so +xhprof.output_dir = /tmp/xhprof +``` + +### php.ini configuration +|     Options       | Defaults | Version | Explain | +| --------------- |:-------------:|:-------------:|:---------| +|xhprof.output_dir  | "" | All |Output directory| +|xhprof.sampling_interval  | 100000 | >= v2.* | Sampling interval to be used by the sampling profiler, in microseconds| +|xhprof.sampling_depth  | INT_MAX | >= v2.* | Depth to trace call-chain by the sampling profiler| +|xhprof.collect_additional_info  | 0 | >= v2.1 | Collect mysql_query, curl_exec internal info. The default is 0. Open value is 1| + +# Turn on extra collection +#### php.ini adds xhprof.collect_additional_info +```sh +xhprof.collect_additional_info = 1 +```` +# Options +```php +xhprof_enable(XHPROF_FLAGS_NO_BUILTINS | XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY); +``` +- `XHPROF_FLAGS_NO_BUILTINS` do not profile builtins +- `XHPROF_FLAGS_CPU` gather CPU times for funcs +- `XHPROF_FLAGS_MEMORY` gather memory usage for funcs + +Example +```php + array( + "wt" => 237, + "ct" => 1, + "cpu" => 100, + ) +) +``` + +- `wt` The number of times the function was called +- `ct` The execution time of a function method is time consuming +- `cpu` The CPU time consumed by the function method execution +- `mu` Memory used by function methods. The call is zend_memory_usage to get the memory usage +- `pmu` Peak memory used by the function method. The call is zend_memory_peak_usage to get the memory + +### PDO::exec +### PDO::query +### mysqli_query +```php +$mysqli = new mysqli("localhost", "my_user", "my_password", "user"); +$result = $mysqli->query("SELECT * FROM user LIMIT 10"); +``` +##### Output data +``` +mysqli::query#SELECT * FROM user LIMIT 10 +``` + +### PDO::prepare +Convert preprocessing placeholders for actual parameters, more intuitive analytic performance (does not change the zend execution process) +```php +$_sth = $db->prepare("SELECT * FROM user where userid = :id and username = :name"); +$_sth->execute([':id' => '1', ':name' => 'admin']); +$data1 = $_sth->fetch(); + +$_sth = $db->prepare("SELECT * FROM user where userid = ?"); +$_sth->execute([1]); +$data2 = $_sth->fetch(); +``` +##### Output data +``` +PDOStatement::execute#SELECT * FROM user where userid = 1 and username = admin +PDOStatement::execute#SELECT * FROM user where userid = 1 +``` + +### Curl +```php +$ch = curl_init(); +curl_setopt($ch, CURLOPT_URL, "http://www.baidu.com"); +$output = curl_exec($ch); +curl_close($ch); +``` +##### Output data +``` +curl_exec#http://www.baidu.com +``` + +## PECL Repository +[![pecl](resource/pecl.png)](https://pecl.php.net/package/xhprof) diff --git a/lib/xhprof/xhprof_html/callgraph.php b/lib/xhprof/xhprof_html/callgraph.php index 49cd8efc4a7..46fc6a5245f 100644 --- a/lib/xhprof/xhprof_html/callgraph.php +++ b/lib/xhprof/xhprof_html/callgraph.php @@ -29,15 +29,6 @@ * @author Changhao Jiang (cjiang@facebook.com) */ -// Start moodle modification: moodleize this script. -require_once(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php'); -require_once($CFG->libdir . '/xhprof/xhprof_moodle.php'); -require_login(); -require_capability('moodle/site:config', context_system::instance()); -raise_memory_limit(MEMORY_HUGE); -\core\session\manager::write_close(); -// End moodle modification. - // by default assume that xhprof_html & xhprof_lib directories // are at the same level. $GLOBALS['XHPROF_LIB_ROOT'] = dirname(__FILE__) . '/../xhprof_lib'; @@ -87,10 +78,7 @@ if (!array_key_exists($type, $xhprof_legal_image_types)) { $type = $params['type'][1]; // default image type. } -// Start moodle modification: use own XHProfRuns implementation. -// $xhprof_runs_impl = new XHProfRuns_Default(); -$xhprof_runs_impl = new moodle_xhprofrun(); -// End moodle modification. +$xhprof_runs_impl = new XHProfRuns_Default(); if (!empty($run)) { // single run call graph image generation diff --git a/lib/xhprof/xhprof_html/css/xhprof.css b/lib/xhprof/xhprof_html/css/xhprof.css index 250b9903fc3..c3abf8622b7 100644 --- a/lib/xhprof/xhprof_html/css/xhprof.css +++ b/lib/xhprof/xhprof_html/css/xhprof.css @@ -13,12 +13,6 @@ * limitations under the License. */ -/* Start moodle modification: add basic, smaller, font specs */ -body, p, table, li { - font: normal normal normal 13px/1.231 arial, helvetica, clean, sans-serif; -} -/* End moodle modification */ - td.sorted { color:#0000FF; } diff --git a/lib/xhprof/xhprof_html/index.php b/lib/xhprof/xhprof_html/index.php index 80e7821fe92..f21d32fd5d0 100644 --- a/lib/xhprof/xhprof_html/index.php +++ b/lib/xhprof/xhprof_html/index.php @@ -31,15 +31,6 @@ // Changhao Jiang // -// Start moodle modification: moodleize this script. -require_once(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php'); -require_once($CFG->libdir . '/xhprof/xhprof_moodle.php'); -require_login(); -require_capability('moodle/site:config', context_system::instance()); -raise_memory_limit(MEMORY_HUGE); -\core\session\manager::write_close(); -// End moodle modification. - // by default assume that xhprof_html & xhprof_lib directories // are at the same level. $GLOBALS['XHPROF_LIB_ROOT'] = dirname(__FILE__) . '/../xhprof_lib'; @@ -89,10 +80,7 @@ $vbbar = ' class="vbbar"'; $vrbar = ' class="vrbar"'; $vgbar = ' class="vgbar"'; -// Start moodle modification: use own XHProfRuns implementation. -// $xhprof_runs_impl = new XHProfRuns_Default(); -$xhprof_runs_impl = new moodle_xhprofrun(); -// End moodle modification. +$xhprof_runs_impl = new XHProfRuns_Default(); displayXHProfReport($xhprof_runs_impl, $params, $source, $run, $wts, $symbol, $sort, $run1, $run2); diff --git a/lib/xhprof/xhprof_html/typeahead.php b/lib/xhprof/xhprof_html/typeahead.php index 4b5a0273a1d..ba98e0c383d 100644 --- a/lib/xhprof/xhprof_html/typeahead.php +++ b/lib/xhprof/xhprof_html/typeahead.php @@ -21,23 +21,12 @@ * Changhao Jiang */ -// Start moodle modification: moodleize this script. -require_once(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php'); -require_once($CFG->libdir . '/xhprof/xhprof_moodle.php'); -require_login(); -require_capability('moodle/site:config', context_system::instance()); -\core\session\manager::write_close(); -// End moodle modification. - // by default assume that xhprof_html & xhprof_lib directories // are at the same level. $GLOBALS['XHPROF_LIB_ROOT'] = dirname(__FILE__) . '/../xhprof_lib'; require_once $GLOBALS['XHPROF_LIB_ROOT'].'/display/xhprof.php'; -// Start moodle modification: use own XHProfRuns implementation. -// $xhprof_runs_impl = new XHProfRuns_Default(); -$xhprof_runs_impl = new moodle_xhprofrun(); -// End moodle modification. +$xhprof_runs_impl = new XHProfRuns_Default(); require_once $GLOBALS['XHPROF_LIB_ROOT'].'/display/typeahead_common.php'; diff --git a/lib/xhprof/xhprof_lib/utils/callgraph_utils.php b/lib/xhprof/xhprof_lib/utils/callgraph_utils.php index 3a70aa0b06e..90f4c31a202 100644 --- a/lib/xhprof/xhprof_lib/utils/callgraph_utils.php +++ b/lib/xhprof/xhprof_lib/utils/callgraph_utils.php @@ -107,11 +107,7 @@ function xhprof_generate_image_by_dot($dot_script, $type) { 2 => array("pipe", "w") ); - // Start moodle modification: use $CFG->pathtodot for executing this. - // $cmd = " dot -T".$type; - global $CFG; - $cmd = (!empty($CFG->pathtodot) ? $CFG->pathtodot : 'dot') . ' -T' . $type; - // End moodle modification. + $cmd = " dot -T".$type; $process = proc_open( $cmd, $descriptorspec, $pipes, sys_get_temp_dir(), array( 'PATH' => getenv( 'PATH' ) ) ); if (is_resource($process)) { diff --git a/lib/xhprof/xhprof_lib/utils/xhprof_lib.php b/lib/xhprof/xhprof_lib/utils/xhprof_lib.php index 4a07e900f1c..c63bf1eb69a 100644 --- a/lib/xhprof/xhprof_lib/utils/xhprof_lib.php +++ b/lib/xhprof/xhprof_lib/utils/xhprof_lib.php @@ -909,6 +909,10 @@ function xhprof_param_init($params) { $p = implode(',', array_filter(explode(',', $p), 'ctype_xdigit')); } + if ($k == 'symbol') { + $p = strip_tags($p); + } + // create a global variable using the parameter name. $GLOBALS[$k] = $p; } diff --git a/lib/xhprof/xhprof_lib/utils/xhprof_runs.php b/lib/xhprof/xhprof_lib/utils/xhprof_runs.php index 115645bd587..01e9d069f38 100644 --- a/lib/xhprof/xhprof_lib/utils/xhprof_runs.php +++ b/lib/xhprof/xhprof_lib/utils/xhprof_runs.php @@ -149,9 +149,7 @@ class XHProfRuns_Default implements iXHProfRuns { if (is_dir($this->dir)) { echo "
Existing runs:\n