You are here

function xhprof_compute_diff in XHProf 7

Same name and namespace in other branches
  1. 6 xhprof.inc \xhprof_compute_diff()

Hierarchical diff: Compute and return difference of two call graphs: Run2 - Run1.

@author Kannan

1 call to xhprof_compute_diff()
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 1509

Code

function xhprof_compute_diff($xhprof_data1, $xhprof_data2) {
  global $display_calls;

  // use the second run to decide what metrics we will do the diff on
  $metrics = xhprof_get_metrics($xhprof_data2);
  $xhprof_delta = $xhprof_data2;
  foreach ($xhprof_data1 as $parent_child => $info) {
    if (!isset($xhprof_delta[$parent_child])) {

      // this pc combination was not present in run1;
      // initialize all values to zero.
      if ($display_calls) {
        $xhprof_delta[$parent_child] = array(
          "ct" => 0,
        );
      }
      else {
        $xhprof_delta[$parent_child] = array();
      }
      foreach ($metrics as $metric) {
        $xhprof_delta[$parent_child][$metric] = 0;
      }
    }
    if ($display_calls) {
      $xhprof_delta[$parent_child]["ct"] -= $info["ct"];
    }
    foreach ($metrics as $metric) {
      $xhprof_delta[$parent_child][$metric] -= $info[$metric];
    }
  }
  return $xhprof_delta;
}