You are here

public function XHProfAggregator::sum in XHProf 6

Same name and namespace in other branches
  1. 7 XHProfLib/XHProfAggregator.php \XHProfAggregator::sum()

Return value

array

File

XHProfLib/XHProfAggregator.php, line 64

Class

XHProfAggregator

Code

public function sum() {
  $keys = array();
  foreach ($this->runs as $data) {
    $keys = $keys + array_keys($data);
  }
  $agg_run = array();
  foreach ($keys as $key) {
    $agg_key = array();

    // Check which runs have this parent_child function key, collect metrics if so.
    foreach ($this->runs as $data) {
      if (isset($data[$key])) {
        foreach ($data[$key] as $metric => $val) {
          $agg_key[$metric][] = $val;
        }
      }
    }

    // Sum each metric for the key into the aggregated run.
    $agg_run[$key] = array();
    foreach ($agg_key as $metric => $vals) {
      $agg_run[$key][$metric] = array_sum($vals);
    }
  }
  return $agg_run;
}