public static function handlePageOutput($hook, $type, $html, $params)
{
$profiler = new self();
$min_percentage = elgg_get_config('profiling_minimum_percentage');
if ($min_percentage !== null) {
$profiler->minimum_percentage = $min_percentage;
}
$tree = $profiler->buildTree(_elgg_services()->timer);
$tree = $profiler->formatTree($tree);
$data['tree'] = $tree;
$data['total'] = $tree['duration'] . " seconds";
$list = [];
$profiler->flattenTree($list, $tree);
$root = elgg_get_config('path');
$list = array_map(function ($period) use($root) {
$period['name'] = str_replace("Closure {$root}", "Closure ", $period['name']);
return "{$period['percentage']}% ({$period['duration']}) {$period['name']}";
}, $list);
$data['list'] = $list;
$html .= "<script>console.log(" . json_encode($data) . ");</script>";
return $html;
}