37 $profiler =
new self();
38 $min_percentage =
_elgg_services()->config->profiling_minimum_percentage;
39 if ($min_percentage !== null) {
40 $profiler->minimum_percentage = $min_percentage;
44 $tree = $profiler->formatTree($tree);
47 'total' => $tree[
'duration'] .
" seconds",
51 $profiler->flattenTree(
$list, $tree);
54 $list = array_map(
function ($period) use ($root) {
55 $period[
'name'] =
str_replace(
"Closure $root",
"Closure ", $period[
'name']);
56 return "{$period['percentage']}% ({$period['duration']}) {$period['name']}";
61 $html = $hook->getValue();
62 $html .=
"<script>console.log(" . json_encode($data) .
");</script>";
96 $is_root = empty(
$list);
98 if (isset($tree[
'periods'])) {
99 foreach ($tree[
'periods'] as $period) {
102 unset($tree[
'periods']);
104 $tree[
'name'] =
trim($prefix);
108 usort(
$list,
function ($a, $b) {
109 if ($a[
'duration'] == $b[
'duration']) {
112 return ($a[
'duration'] > $b[
'duration']) ? -1 : 1;
124 $tree[
'duration'] =
sprintf($this->duration_format, $tree[
'duration']);
125 if (isset($tree[
'percentage'])) {
126 $tree[
'percentage'] =
sprintf($this->percentage_format, $tree[
'percentage']);
128 if (isset($tree[
'periods'])) {
129 $tree[
'periods'] = array_map([$this,
'formatTree'], $tree[
'periods']);
145 if ($begin ===
false ||
$end ===
false) {
148 $has_own_markers = isset($times[
Timer::MARKER_BEGIN]) && isset($times[Timer::MARKER_BEGIN]);
158 foreach ($times as $times_key => $period) {
160 if ($period ===
false) {
163 $period[
'percentage'] = 100 * $period[
'duration'] /
$this->total;
164 if ($period[
'percentage'] < $this->minimum_percentage) {
167 $ret[
'periods'][] = $period;
170 if (isset($ret[
'periods'])) {
171 if (!$has_own_markers) {
173 $ret[
'duration'] = 0;
174 foreach ($ret[
'periods'] as $period) {
175 $ret[
'duration'] += $period[
'duration'];
177 $ret[
'percentage'] = 100 * $ret[
'duration'] /
$this->total;
180 usort($ret[
'periods'],
function ($a, $b) {
181 if ($a[
'duration'] == $b[
'duration']) {
184 return ($a[
'duration'] > $b[
'duration']) ? -1 : 1;
202 $first = reset($times);
203 if (is_array($first)) {
222 if (is_array($last)) {
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
if(elgg_trigger_plugin_hook('usersettings:save', 'user', $hooks_params, true)) foreach($request->validation() ->all() as $item) $data
Capture timing info for profiling.
analyzePeriod($name, array $times)
Analyze a time period.
findBeginTime(array $times)
Get the microtime start time.
Models an event passed to hook handlers.
foreach($notification_settings as $purpose=> $prefered_methods) if((bool) elgg_get_config('enable_delayed_email')) $start
__invoke(\Elgg\Hook $hook)
Append a SCRIPT element to the page output.
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.