Skip to content

Commit

Permalink
MDL-71705 libraries: xhprof upgraded to 2.3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyatregubov committed Dec 9, 2021
1 parent 5ee0b62 commit 6f069f5
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 77 deletions.
6 changes: 3 additions & 3 deletions lib/xhprof/README.md
Expand Up @@ -11,7 +11,7 @@ This version supports PHP7
- 7.2
- 7.3
- 7.4
- 8.0 beta4
- 8.0

# Installation
```
Expand Down Expand Up @@ -63,8 +63,8 @@ array(
)
```

- `wt` The number of times the function was called
- `ct` The execution time of a function method is time consuming
- `wt` The execution time of the function method is time consuming
- `ct` The number of times the function was called
- `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
Expand Down
18 changes: 3 additions & 15 deletions lib/xhprof/xhprof_html/callgraph.php
Expand Up @@ -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';
Expand All @@ -56,8 +47,8 @@
// parents/children functions of it will be shown.
'func' => array(XHPROF_STRING_PARAM, ''),

// image type, can be 'jpg', 'gif', 'ps', 'png'
'type' => array(XHPROF_STRING_PARAM, 'png'),
// image type, can be 'jpg', 'gif', 'ps', 'png', 'svg'
'type' => array(XHPROF_STRING_PARAM, 'svg'),

// only functions whose exclusive time over the total time
// is larger than this threshold will be shown.
Expand Down Expand Up @@ -87,10 +78,7 @@
$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
Expand Down
6 changes: 0 additions & 6 deletions lib/xhprof/xhprof_html/css/xhprof.css
Expand Up @@ -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;
}
Expand Down
14 changes: 1 addition & 13 deletions lib/xhprof/xhprof_html/index.php
Expand Up @@ -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';
Expand Down Expand Up @@ -89,10 +80,7 @@
$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);
Expand Down
13 changes: 1 addition & 12 deletions lib/xhprof/xhprof_html/typeahead.php
Expand Up @@ -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 moodle_xhprofrun();
// End moodle modification.
$xhprof_runs_impl = new XHProfRuns_Default();

require_once $GLOBALS['XHPROF_LIB_ROOT'].'/display/typeahead_common.php';
41 changes: 22 additions & 19 deletions lib/xhprof/xhprof_lib/display/xhprof.php
Expand Up @@ -43,7 +43,7 @@
* Get the base URL path from the SCRIPT_NAME.
*/
$base_path = rtrim(dirname($_SERVER['SCRIPT_NAME']), '/\\');

$base_url = htmlentities($_SERVER['SCRIPT_NAME']);

/**
* Generate references to required stylesheets & javascript.
Expand All @@ -56,9 +56,10 @@
*
*/
function xhprof_include_js_css($ui_dir_url_path = null) {
global $base_path;

if (empty($ui_dir_url_path)) {
$ui_dir_url_path = rtrim(dirname($_SERVER['SCRIPT_NAME']), '/\\');
$ui_dir_url_path = $base_path;
}

// style sheets
Expand Down Expand Up @@ -453,7 +454,7 @@ function profiler_report ($url_params,
global $stats;
global $pc_stats;
global $diff_mode;
global $base_path;
global $base_url;

// if we are reporting on a specific function, we can trim down
// the report(s) to just stuff that is relevant to this function.
Expand Down Expand Up @@ -482,22 +483,22 @@ function profiler_report ($url_params,
'symbol'),
'all');

$top_link_query_string = "$base_path/?" . http_build_query($base_url_params);
$top_link_query_string = "$base_url?" . http_build_query($base_url_params);

if ($diff_mode) {
$diff_text = "Diff";
$base_url_params = xhprof_array_unset($base_url_params, 'run1');
$base_url_params = xhprof_array_unset($base_url_params, 'run2');
$run1_link = xhprof_render_link('View Run #' . $run1,
"$base_path/?" .
"$base_url?" .
http_build_query(xhprof_array_set($base_url_params,
'run',
$run1)));
$run2_txt = sprintf("<b>Run #%s:</b> %s",
$run2, $run2_desc);

$run2_link = xhprof_render_link('View Run #' . $run2,
"$base_path/?" .
"$base_url?" .
http_build_query(xhprof_array_set($base_url_params,
'run',
$run2)));
Expand All @@ -519,7 +520,7 @@ function profiler_report ($url_params,
$links [] = $run1_link;
$links [] = $run2_link;
$links [] = xhprof_render_link('Invert ' . $diff_text . ' Report',
"$base_path/?".
"$base_url?".
http_build_query($inverted_params));
}

Expand Down Expand Up @@ -660,7 +661,7 @@ function print_function_info($url_params, $info, $sort, $run1, $run2) {
global $metrics;
global $format_cbk;
global $display_calls;
global $base_path;
global $base_url;

// Toggle $odd_or_even
$odd_even = 1 - $odd_even;
Expand All @@ -672,7 +673,7 @@ function print_function_info($url_params, $info, $sort, $run1, $run2) {
print('<tr bgcolor="#e5e5e5">');
}

$href = "$base_path/?" .
$href = "$base_url?" .
http_build_query(xhprof_array_set($url_params,
'symbol', $info["fn"]));

Expand Down Expand Up @@ -717,15 +718,15 @@ function print_flat_data($url_params, $title, $flat_data, $sort, $run1, $run2, $
global $stats;
global $sortable_columns;
global $vwbar;
global $base_path;
global $base_url;

$size = count($flat_data);
if (!$limit) { // no limit
$limit = $size;
$display_link = "";
} else {
$display_link = xhprof_render_link(" [ <b class=bubble>display all </b>]",
"$base_path/?" .
"$base_url?" .
http_build_query(xhprof_array_set($url_params,
'all', 1)));
}
Expand All @@ -739,7 +740,7 @@ function print_flat_data($url_params, $title, $flat_data, $sort, $run1, $run2, $
foreach ($stats as $stat) {
$desc = stat_description($stat);
if (array_key_exists($stat, $sortable_columns)) {
$href = "$base_path/?"
$href = "$base_url?"
. http_build_query(xhprof_array_set($url_params, 'sort', $stat));
$header = xhprof_render_link($desc, $href);
} else {
Expand Down Expand Up @@ -791,6 +792,7 @@ function full_report($url_params, $symbol_tab, $sort, $run1, $run2) {
global $format_cbk;
global $display_calls;
global $base_path;
global $base_url;

$possible_metrics = xhprof_get_possible_metrics();

Expand All @@ -799,10 +801,10 @@ function full_report($url_params, $symbol_tab, $sort, $run1, $run2) {
$base_url_params = xhprof_array_unset(xhprof_array_unset($url_params,
'run1'),
'run2');
$href1 = "$base_path/?" .
$href1 = "$base_url?" .
http_build_query(xhprof_array_set($base_url_params,
'run', $run1));
$href2 = "$base_path/?" .
$href2 = "$base_url?" .
http_build_query(xhprof_array_set($base_url_params,
'run', $run2));

Expand Down Expand Up @@ -961,7 +963,7 @@ function pc_info($info, $base_ct, $base_info, $parent) {

function print_pc_array($url_params, $results, $base_ct, $base_info, $parent,
$run1, $run2) {
global $base_path;
global $base_url;

// Construct section title
if ($parent) {
Expand All @@ -980,7 +982,7 @@ function print_pc_array($url_params, $results, $base_ct, $base_info, $parent,

$odd_even = 0;
foreach ($results as $info) {
$href = "$base_path/?" .
$href = "$base_url?" .
http_build_query(xhprof_array_set($url_params,
'symbol', $info["fn"]));

Expand Down Expand Up @@ -1051,6 +1053,7 @@ function symbol_report($url_params,
global $sort_col;
global $display_calls;
global $base_path;
global $base_url;

$possible_metrics = xhprof_get_possible_metrics();

Expand All @@ -1067,9 +1070,9 @@ function symbol_report($url_params,
$base_url_params = xhprof_array_unset(xhprof_array_unset($url_params,
'run1'),
'run2');
$href1 = "$base_path?"
$href1 = "$base_url?"
. http_build_query(xhprof_array_set($base_url_params, 'run', $run1));
$href2 = "$base_path?"
$href2 = "$base_url?"
. http_build_query(xhprof_array_set($base_url_params, 'run', $run2));

print("<h3 align=center>$regr_impr summary for $rep_symbol<br><br></h3>");
Expand Down Expand Up @@ -1157,7 +1160,7 @@ function symbol_report($url_params,
$desc = stat_description($stat);
if (array_key_exists($stat, $sortable_columns)) {

$href = "$base_path/?" .
$href = "$base_url?" .
http_build_query(xhprof_array_set($url_params,
'sort', $stat));
$header = xhprof_render_link($desc, $href);
Expand Down
6 changes: 1 addition & 5 deletions lib/xhprof/xhprof_lib/utils/callgraph_utils.php
Expand Up @@ -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)) {
Expand Down
6 changes: 4 additions & 2 deletions lib/xhprof/xhprof_lib/utils/xhprof_lib.php
Expand Up @@ -19,8 +19,10 @@
// Do not add any display specific code here.
//

function xhprof_error($message) {
error_log($message);
if (!function_exists('xhprof_error')) {
function xhprof_error($message) {
error_log($message);
}
}

/*
Expand Down
4 changes: 2 additions & 2 deletions lib/xhprof/xhprof_lib/utils/xhprof_runs.php
Expand Up @@ -91,7 +91,7 @@ public function __construct($dir = null) {
// if specified, else we default to the directory
// in which the error_log file resides.

if (empty($dir)) {
if (empty($dir) && !($dir = getenv('XHPROF_OUTPUT_DIR'))) {
$dir = ini_get("xhprof.output_dir");
if (empty($dir)) {

Expand All @@ -101,7 +101,7 @@ public function __construct($dir = null) {
"Trying {$dir} as default. You can either pass the " .
"directory location as an argument to the constructor ".
"for XHProfRuns_Default() or set xhprof.output_dir ".
"ini param.");
"ini param, or set XHPROF_OUTPUT_DIR environment variable.");
}
}
$this->dir = $dir;
Expand Down

0 comments on commit 6f069f5

Please sign in to comment.