@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Update external xhprof copy to latest upstream version

Summary:
* Update Phorge's ~2009 copy of `xhprof_lib.php` to latest upstream version cf21149 from 2021-06-14 (first included in release v2.3.3, unchanged in latest release v2.3.10) located at https://github.com/longxinH/xhprof/commits/master/xhprof_lib/utils/xhprof_lib.php
* Function signatures have not changed
* Continue to include Phorge's custom change to comment the call to `init_metrics()`

Closes T15950

Test Plan:
* Ensure the XHProf extension is installed and enabled
* Enable DarkConsole
* Open DarkConsole and select "XHProf"
* Click on Profile Page
* Compare results between a run with and without this patch.

Reviewers: O1 Blessed Committers, mainframe98

Reviewed By: O1 Blessed Committers, mainframe98

Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Maniphest Tasks: T15950

Differential Revision: https://we.phorge.it/D25836

+96 -11
+96 -11
externals/xhprof/xhprof_lib.php
··· 19 19 // Do not add any display specific code here. 20 20 // 21 21 22 - function xhprof_error($message) { 23 - error_log($message); 22 + if (!function_exists('xhprof_error')) { 23 + function xhprof_error($message) { 24 + error_log($message); 25 + } 24 26 } 25 27 26 28 /* ··· 31 33 */ 32 34 function xhprof_get_possible_metrics() { 33 35 static $possible_metrics = 34 - array("wt" => array("Wall", "microsecs", "walltime" ), 35 - "ut" => array("User", "microsecs", "user cpu time" ), 36 + array("wt" => array("Wall", "microsecs", "walltime"), 37 + "ut" => array("User", "microsecs", "user cpu time"), 36 38 "st" => array("Sys", "microsecs", "system cpu time"), 37 39 "cpu" => array("Cpu", "microsecs", "cpu time"), 38 40 "mu" => array("MUse", "bytes", "memory usage"), ··· 41 43 return $possible_metrics; 42 44 } 43 45 46 + /** 47 + * Initialize the metrics we'll display based on the information 48 + * in the raw data. 49 + * 50 + * @author Kannan 51 + */ 52 + function init_metrics($xhprof_data, $rep_symbol, $sort, $diff_report = false) { 53 + global $stats; 54 + global $pc_stats; 55 + global $metrics; 56 + global $diff_mode; 57 + global $sortable_columns; 58 + global $sort_col; 59 + global $display_calls; 60 + 61 + $diff_mode = $diff_report; 62 + 63 + if (!empty($sort)) { 64 + if (array_key_exists($sort, $sortable_columns)) { 65 + $sort_col = $sort; 66 + } else { 67 + print("Invalid Sort Key $sort specified in URL"); 68 + } 69 + } 70 + 71 + // For C++ profiler runs, walltime attribute isn't present. 72 + // In that case, use "samples" as the default sort column. 73 + if (!isset($xhprof_data["main()"]["wt"])) { 74 + 75 + if ($sort_col == "wt") { 76 + $sort_col = "samples"; 77 + } 78 + 79 + // C++ profiler data doesn't have call counts. 80 + // ideally we should check to see if "ct" metric 81 + // is present for "main()". But currently "ct" 82 + // metric is artificially set to 1. So, relying 83 + // on absence of "wt" metric instead. 84 + $display_calls = false; 85 + } else { 86 + $display_calls = true; 87 + } 88 + 89 + // parent/child report doesn't support exclusive times yet. 90 + // So, change sort hyperlinks to closest fit. 91 + if (!empty($rep_symbol)) { 92 + $sort_col = str_replace("excl_", "", $sort_col); 93 + } 94 + 95 + if ($display_calls) { 96 + $stats = array("fn", "ct", "Calls%"); 97 + } else { 98 + $stats = array("fn"); 99 + } 100 + 101 + $pc_stats = $stats; 102 + 103 + $possible_metrics = xhprof_get_possible_metrics(); 104 + foreach ($possible_metrics as $metric => $desc) { 105 + if (isset($xhprof_data["main()"][$metric])) { 106 + $metrics[] = $metric; 107 + // flat (top-level reports): we can compute 108 + // exclusive metrics reports as well. 109 + $stats[] = $metric; 110 + $stats[] = "I" . $desc[0] . "%"; 111 + $stats[] = "excl_" . $metric; 112 + $stats[] = "E" . $desc[0] . "%"; 113 + 114 + // parent/child report for a function: we can 115 + // only breakdown inclusive times correctly. 116 + $pc_stats[] = $metric; 117 + $pc_stats[] = "I" . $desc[0] . "%"; 118 + } 119 + } 120 + } 121 + 44 122 /* 45 123 * Get the list of metrics present in $xhprof_data as an array. 46 124 * ··· 259 337 } 260 338 261 339 $bad_runs = array(); 262 - foreach($runs as $idx => $run_id) { 340 + foreach ($runs as $idx => $run_id) { 263 341 264 - $raw_data = $xhprof_runs_impl->get_run($run_id, $source, '?'); 342 + $raw_data = $xhprof_runs_impl->get_run($run_id, $source, $description); 265 343 266 344 // use the first run to derive what metrics to aggregate on. 267 345 if ($idx == 0) { ··· 283 361 } 284 362 285 363 if ($use_script_name) { 286 - $page = '?'; 364 + $page = $description; 287 365 288 366 // create a fake function '__script::$page', and have and edge from 289 367 // main() to '__script::$page'. We will also need edges to transfer ··· 294 372 // it shows up above the new entry in reports sorted by 295 373 // inclusive metrics or call counts. 296 374 if ($page) { 297 - foreach($raw_data["main()"] as $metric => $val) { 375 + foreach ($raw_data["main()"] as $metric => $val) { 298 376 $fake_edge[$metric] = $val; 299 377 $new_main[$metric] = $val + 0.00001; 300 378 } ··· 316 394 // if this is an old edge originating from main(), it now 317 395 // needs to be from '__script::$page' 318 396 if (substr($parent_child, 0, 9) == "main()==>") { 319 - $child =substr($parent_child, 9); 397 + $child = substr($parent_child, 9); 320 398 // ignore the newly added edge from main() 321 399 if (substr($child, 0, 10) != "__script::") { 322 400 $parent_child = xhprof_build_parent_child_key("__script::$page", ··· 381 459 382 460 $metrics = xhprof_get_metrics($raw_data); 383 461 384 - $overall_totals = array( "ct" => 0, 462 + $overall_totals = array("ct" => 0, 385 463 "wt" => 0, 386 464 "ut" => 0, 387 465 "st" => 0, ··· 829 907 exit(); 830 908 } 831 909 910 + if ($k === 'run') { 911 + $p = implode(',', array_filter(explode(',', $p), 'ctype_xdigit')); 912 + } 913 + 914 + if ($k == 'symbol') { 915 + $p = strip_tags($p); 916 + } 917 + 832 918 // create a global variable using the parameter name. 833 919 $GLOBALS[$k] = $p; 834 920 } ··· 863 949 864 950 return ($res); 865 951 } 866 -