You are here

function xhprof_compute_flat_info in XHProf 6

Same name and namespace in other branches
  1. 7 xhprof.inc \xhprof_compute_flat_info()

Analyze hierarchical raw data, and compute per-function (flat) inclusive and exclusive metrics.

Also, store overall totals in the 2nd argument.

@author Kannan Muthukkaruppan

Parameters

array $raw_data XHProf format raw profiler data.:

array &$overall_totals OUT argument for returning: overall totals for various metrics.

Return value

array Returns a map from function name to its call count and inclusive & exclusive metrics (such as wall time, etc.).

1 call to xhprof_compute_flat_info()
xhprof_profiler_report in ./xhprof.inc
Analyze raw data & generate the profiler report (common for both single run mode and diff mode).

File

./xhprof.inc, line 1602

Code

function xhprof_compute_flat_info($raw_data, &$overall_totals) {
  $metrics = xhprof_get_metrics($raw_data);
  $overall_totals = array(
    "ct" => 0,
    "wt" => 0,
    "ut" => 0,
    "st" => 0,
    "cpu" => 0,
    "mu" => 0,
    "pmu" => 0,
    "samples" => 0,
  );

  // Compute inclusive times for each function.
  $symbol_tab = xhprof_compute_inclusive_times($raw_data);

  // Total metric value is the metric value for "main()".
  foreach ($metrics as $metric) {
    $overall_totals[$metric] = $symbol_tab["main()"][$metric];
  }

  // Initialize exclusive (self) metric value to inclusive metric value to start with.
  // In the same pass, also add up the total number of function calls.
  foreach ($symbol_tab as $symbol => $info) {
    foreach ($metrics as $metric) {
      $symbol_tab[$symbol]["excl_" . $metric] = $symbol_tab[$symbol][$metric];
    }

    // Keep track of total number of calls.
    $overall_totals["ct"] += $info["ct"];
  }

  // Adjust exclusive times by deducting inclusive time of children.
  foreach ($raw_data as $parent_child => $info) {
    list($parent, $child) = xhprof_parse_parent_child($parent_child);
    if ($parent) {
      foreach ($metrics as $metric) {

        // make sure the parent exists hasn't been pruned.
        if (isset($symbol_tab[$parent])) {
          $symbol_tab[$parent]["excl_" . $metric] -= $info[$metric];
        }
      }
    }
  }
  return $symbol_tab;
}