protected function closeTrace()
    {
        if ($this->trace !== null) {
            foreach ($this->trace as $id => $record) {
                if (!$record->exited) {    // last chance to filter non-exited records by FILTER_EXIT callback
                    $remove = false;
                    foreach ($this->filterExitCallbacks as $callback) {
                        $result = (int) $callback($record, false, $this);
                        if ($result & self::SKIP) {
                            $remove = true;
                        }

                        if ($result & self::STOP) {
                            break;
                        }
                    }

                    if ($remove) {
                        unset($this->trace[$id]);
                        continue;
                    }
                }

                $this->indent[$record->level] = 1;
            }

            if (null !== $this->indent) {
                \ksort($this->indent);
                $keys = \array_keys($this->indent);
                $this->indent = \array_combine($keys, \array_keys($keys));
            }

            $null = null;
            $this->trace =& $null;
            $this->indent =& $null;

            if ($this->performStatistics) {
                foreach ($this->statistic as $statistic) {
                    $statistic->averageTime = $statistic->deltaTime / $statistic->count;
                }

                $sortBy = $this->sortBy;
                \uasort($this->statistic, function ($a, $b) use ($sortBy) {
                    return $a->{$sortBy} < $b->{$sortBy};
                });

                $this->statistic =& $null;
            }
        }
    }