38 $profiler =
new self();
39 $min_percentage =
_elgg_services()->config->profiling_minimum_percentage;
40 if ($min_percentage !== null) {
41 $profiler->minimum_percentage = $min_percentage;
45 $tree = $profiler->formatTree($tree);
48 'total' => $tree[
'duration'] .
' seconds',
52 $profiler->flattenTree(
$list, $tree);
55 $list = array_map(
function ($period) use ($root) {
56 $period[
'name'] =
str_replace(
"Closure {$root}",
'Closure ', $period[
'name']);
57 return "{$period['percentage']}% ({$period['duration']}) {$period['name']}";
62 $html = $event->getValue();
63 $html .=
'<script>console.log(' . json_encode($data) .
');</script>';
99 $is_root = empty(
$list);
101 if (isset($tree[
'periods'])) {
102 foreach ($tree[
'periods'] as $period) {
106 unset($tree[
'periods']);
109 $tree[
'name'] =
trim($prefix);
113 usort(
$list,
function ($a, $b) {
114 if ($a[
'duration'] == $b[
'duration']) {
118 return ($a[
'duration'] > $b[
'duration']) ? -1 : 1;
131 $tree[
'duration'] =
sprintf($this->duration_format, $tree[
'duration']);
132 if (isset($tree[
'percentage'])) {
133 $tree[
'percentage'] =
sprintf($this->percentage_format, $tree[
'percentage']);
136 if (isset($tree[
'periods'])) {
137 $tree[
'periods'] = array_map([$this,
'formatTree'], $tree[
'periods']);
154 if ($begin ===
false ||
$end ===
false) {
168 foreach ($times as $times_key => $period) {
170 if ($period ===
false) {
174 $period[
'percentage'] = 100 * $period[
'duration'] /
$this->total;
175 if ($period[
'percentage'] < $this->minimum_percentage) {
179 $ret[
'periods'][] = $period;
182 if (isset($ret[
'periods'])) {
183 if (!$has_own_markers) {
185 $ret[
'duration'] = 0;
186 foreach ($ret[
'periods'] as $period) {
187 $ret[
'duration'] += $period[
'duration'];
190 $ret[
'percentage'] = 100 * $ret[
'duration'] /
$this->total;
193 usort($ret[
'periods'],
function ($a, $b) {
194 if ($a[
'duration'] == $b[
'duration']) {
198 return ($a[
'duration'] > $b[
'duration']) ? -1 : 1;
218 $first = reset($times);
219 if (is_array($first)) {
240 if (is_array($last)) {
__invoke(\Elgg\Event $event)
Append a SCRIPT element to the page output.
static project()
Get the project root (where composer is installed) path with "/".
getTimes()
Get the tree of recorded start/end times.
if(!$user||!$user->canDelete()) $name
Capture timing info for profiling.
analyzePeriod($name, array $times)
Analyze a time period.
$html
A wrapper to render a section of the page shell.
findBeginTime(array $times)
Get the microtime start time.
foreach($notification_settings as $purpose=> $prefered_methods) if((bool) elgg_get_config('enable_delayed_email')) $start
if(!$entity instanceof\ElggUser) $data
formatTree(array $tree)
Nicely format the elapsed time values.
findEndTime(array $times)
Get the microtime end time.
Analyzes duration of functions, queries, and processes.
flattenTree(array &$list=[], array $tree=[], $prefix= '')
Turn the tree of times into a sorted list.
diffMicrotime($start, $end)
Calculate a precise time difference.
_elgg_services()
Get the global service provider.
buildTree(Timer $timer)
Return a tree of time periods from a Timer.
Models an event passed to event handlers.