public function Aggregator::average in XHProf 8
Return value
array
File
- src/
XHProfLib/ Aggregator.php, line 36
Class
Namespace
Drupal\xhprof\XHProfLibCode
public function average() {
$keys = [];
foreach ($this->runs as $data) {
$keys = $keys + array_keys($data);
}
$agg_run = [];
$run_count = count($this->runs);
foreach ($keys as $key) {
$agg_key = [];
// 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;
}
}
}
// Average each metric for the key into the aggregated run.
$agg_run[$key] = [];
foreach ($agg_key as $metric => $vals) {
$sd = self::sd($vals);
$mean = array_sum($vals) / count($vals);
$good_vals = [];
if ($sd == 0) {
$agg_run[$key][$metric] = array_sum($vals) / count($vals);
}
else {
foreach ($vals as $v) {
$diff = abs($mean - $v);
if (abs($mean - $v) < $sd * 2) {
$good_vals[] = $v;
}
}
$agg_run[$key][$metric] = array_sum($good_vals) / count($good_vals);
}
}
}
return $agg_run;
}