private function analyzePeriod($name, array $times)
{
$begin = $this->findBeginTime($times);
$end = $this->findEndTime($times);
if ($begin === false || $end === false) {
return false;
}
unset($times[':begin'], $times[':end']);
$total = $this->diffMicrotime($begin, $end);
$ret = ['name' => $name, 'percentage' => 100, 'duration' => $total];
foreach ($times as $times_key => $period) {
$period = $this->analyzePeriod($times_key, $period);
if ($period === false) {
continue;
}
$period['percentage'] = 100 * $period['duration'] / $this->total;
if ($period['percentage'] < $this->minimum_percentage) {
continue;
}
$ret['periods'][] = $period;
}
if (isset($ret['periods'])) {
usort($ret['periods'], function ($a, $b) {
if ($a['duration'] == $b['duration']) {
return 0;
}
return $a['duration'] > $b['duration'] ? -1 : 1;
});
}
return $ret;
}