Navigation Menu

Skip to content

Commit

Permalink
Merge branch 'MDL-70297-311' of git://github.com/ilyatregubov/moodle …
Browse files Browse the repository at this point in the history
…into MOODLE_311_STABLE
  • Loading branch information
junpataleta committed Jan 21, 2021
2 parents 23baaf8 + f12a16b commit a10a3f9
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/thirdpartylibs.xml
Expand Up @@ -172,7 +172,7 @@
<location>xhprof</location>
<name>XHProf</name>
<license>Apache</license>
<version>0.9.4</version>
<version>2.2.3</version>
<licenseversion>2.0</licenseversion>
</library>
<library>
Expand Down
5 changes: 0 additions & 5 deletions lib/xhprof/README

This file was deleted.

114 changes: 114 additions & 0 deletions 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
<?php
array(
"main()" => 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)
7 changes: 2 additions & 5 deletions lib/xhprof/readme_moodle.txt
@@ -1,11 +1,8 @@
Description of XHProf 0.9.4 library/viewer import into Moodle
Description of XHProf 2.2.3 library/viewer import into Moodle

Removed (commit #1):
* .arcconfig - Definitions for arcanist/phabricator removed completely
* composer.json - Composer's definition removed completely
* examples - examples dir removed completely
* extension - extension dir removed completely
* package.xml - PECL package definition removed completely
* xhprof_html/docs - documentation dir removed completely

Added (commit #2 - always taken from current moodle.git master):
Expand All @@ -19,7 +16,6 @@ Our changes: Look for "moodle" in code (commit #3 - always mimic from current m
* xhprof_html/typeahead.php -|
* xhprof_html/css/xhprof.css: Minor tweaks to report styles
* xhprof_lib/utils/callgraph_utils.php: Modified to use $CFG->pathtodot
* xhprof_lib/utils/xhprof_runs.php: applied patch from https://github.com/phacility/xhprof/pull/99

TODO:
* improvements to the listing mode: various commodity details like:
Expand All @@ -42,4 +38,5 @@ TODO:
20190314 - MDL-64543 - Brendan Heywood (brendanheywood): Add support for conditional slow profiling
20191016 - MDL-65349 - Brendan Heywood (brendanheywood): Improved url matching behaviour
20201012 - MDL-67081 - Brendan Heywood (brendanheywood): Support selective profiles from CLI
20201210 - MDL-70297 - Ilya Tregubov (ilyatregubov): Upgrade to 2.2.3 release;

2 changes: 1 addition & 1 deletion lib/xhprof/xhprof_html/typeahead.php
Expand Up @@ -29,14 +29,14 @@
\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.

Expand Down
4 changes: 4 additions & 0 deletions lib/xhprof/xhprof_lib/utils/xhprof_lib.php
Expand Up @@ -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;
}
Expand Down
4 changes: 1 addition & 3 deletions lib/xhprof/xhprof_lib/utils/xhprof_runs.php
Expand Up @@ -149,9 +149,7 @@ function list_runs() {
if (is_dir($this->dir)) {
echo "<hr/>Existing runs:\n<ul>\n";
$files = glob("{$this->dir}/*.{$this->suffix}");
usort($files, function($a, $b) {
return filemtime($b) - filemtime($a);
});
usort($files, function($a, $b) {return filemtime($b) - filemtime($a);});
foreach ($files as $file) {
list($run,$source) = explode('.', basename($file));
echo '<li><a href="' . htmlentities($_SERVER['SCRIPT_NAME'])
Expand Down

0 comments on commit a10a3f9

Please sign in to comment.