/** * Compute inclusive metrics for function. This code was factored out * of xhprof_compute_flat_info(). * * The raw data contains inclusive metrics of a function for each * unique parent function it is called from. The total inclusive metrics * for a function is therefore the sum of inclusive metrics for the * function across all parents. * * @return array Returns a map of function name to total (across all parents) * inclusive metrics for the function. * * @author Kannan */ function xhprof_compute_inclusive_times($raw_data) { global $display_calls; $metrics = xhprof_get_metrics($raw_data); $symbol_tab = array(); /* * First compute inclusive time for each function and total * call count for each function across all parents the * function is called from. */ foreach ($raw_data as $parent_child => $info) { list($parent, $child) = xhprof_parse_parent_child($parent_child); if ($parent == $child) { /* * XHProf PHP extension should never trigger this situation any more. * Recursion is handled in the XHProf PHP extension by giving nested * calls a unique recursion-depth appended name (for example, foo@1). */ xhprof_error("Error in Raw Data: parent & child are both: {$parent}"); return; } if (!isset($symbol_tab[$child])) { if ($display_calls) { $symbol_tab[$child] = array("ct" => $info["ct"]); } else { $symbol_tab[$child] = array(); } foreach ($metrics as $metric) { $symbol_tab[$child][$metric] = $info[$metric]; } } else { if ($display_calls) { /* increment call count for this child */ $symbol_tab[$child]["ct"] += $info["ct"]; } /* update inclusive times/metric for this child */ foreach ($metrics as $metric) { $symbol_tab[$child][$metric] += $info[$metric]; } } } return $symbol_tab; }
$run1 = $_SERVER['argv'][1]; $run2 = $_SERVER['argv'][2]; $extra = isset($_SERVER['argv'][3]) ? $_SERVER['argv'][3] : ''; $source = isset($_SERVER['argv'][4]) ? $_SERVER['argv'][4] : 'drupal-perf'; include_once dirname(__FILE__) . '/xhprof/xhprof_lib/utils/xhprof_lib.php'; include_once dirname(__FILE__) . '/xhprof/xhprof_lib/utils/xhprof_runs.php'; include_once dirname(__FILE__) . '/xhprof/xhprof_lib/display/xhprof.php'; $xhprof_runs_impl = new XHProfRuns_Default(); $run1_data = $xhprof_runs_impl->get_run($run1, $source, $description1); $run2_data = $xhprof_runs_impl->get_run($run2, $source, $description2); $run_delta = xhprof_compute_diff($run1_data, $run2_data); $symbol_tab = xhprof_compute_flat_info($run_delta, $totals); $symbol_tab1 = xhprof_compute_flat_info($run1_data, $totals_1); $symbol_tab2 = xhprof_compute_flat_info($run2_data, $totals_2); $metrics = xhprof_get_metrics($run_delta); function print_pct($numer, $denom) { if ($denom == 0) { $pct = "N/A%"; } else { $pct = xhprof_percent_format($numer / abs($denom)); } return $pct; } function print_num($num, $fmt_func = null) { if (!empty($fmt_func)) { $num = call_user_func($fmt_func, $num); } return $num;