public function XHProfAggregator::average in XHProf 6
Same name and namespace in other branches
- 7 XHProfLib/XHProfAggregator.php \XHProfAggregator::average()
Return value
array
File
- XHProfLib/
XHProfAggregator.php, line 17
Class
Code
public function average() {
$keys = array();
foreach ($this->runs as $data) {
$keys = $keys + array_keys($data);
}
$agg_run = array();
$run_count = count($runs);
foreach ($keys as $key) {
$agg_key = array();
// Check which runs have this parent_child function key, collect metrics if so.
foreach ($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] = array();
foreach ($agg_key as $metric => $vals) {
$sd = self::sd($vals);
$mean = array_sum($vals) / count($vals);
$good_vals = array();
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;
}