You are here

public function Aggregator::sum in XHProf 8

Parameters

bool $skip_bad_runs: Set to TRUE to prevent this method from failing in the case of a bad run (i.e. a corrupt, unserializable file).

Return value

array

File

src/XHProfLib/Aggregator.php, line 87

Class

Aggregator

Namespace

Drupal\xhprof\XHProfLib

Code

public function sum($skip_bad_runs = FALSE) {
  $keys = [];
  $agg_run = [];
  foreach ($this->runs as $run) {
    try {
      $run = $this->xhprof_runs
        ->getRun($run['run_id'], $run['namespace']);
    } catch (\UnexpectedValueException $e) {
      if ($skip_bad_runs) {
        continue;
      }
      else {
        throw $e;
      }
    }
    $keys = $run
      ->getKeys();
    foreach ($keys as $key) {
      foreach ($run
        ->getMetrics($key) as $metric => $val) {
        if (isset($agg_run[$key][$metric])) {
          $agg_run[$key][$metric] += $val;
        }
        else {
          $agg_run[$key][$metric] = $val;
        }
      }
    }
  }
  return $agg_run;
}