Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix display bugs in profiling #26731

Merged
merged 3 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions tools/profiling/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ public function query($sql)
}

if (!$explain) {
$uniqSql = preg_replace('/[\'"][a-f0-9]{32}[\'"]/', '<span style="color:blue">XX</span>', $sql);
$uniqSql = preg_replace('/[0-9]+/', '<span style="color:blue">XX</span>', $uniqSql);
$uniqSql = preg_replace('/[\'"][a-f0-9]{32}[\'"]/', 'XX', $sql);
$uniqSql = preg_replace('/[0-9]+/', 'XX', $uniqSql);
if (!isset($this->uniqQueries[$uniqSql])) {
$this->uniqQueries[$uniqSql] = 0;
}

++$this->uniqQueries[$uniqSql];

// No cache for query
Expand Down
8 changes: 8 additions & 0 deletions tools/profiling/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ public static function coreRenderWidget($module, $registeredHookName, $params)

$result = parent::coreRenderWidget($module, $registeredHookName, $params);

/*
* It's not a hook which has been triggered but
* it's a widget
*/
if (empty($registeredHookName)) {
$registeredHookName = 'renderWidget';
}

Profiler::getInstance()->interceptHook(
$registeredHookName,
[
Expand Down
8 changes: 6 additions & 2 deletions tools/profiling/Profiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,12 @@ public function processData()
$queryRow['filesort'] = true;
}

foreach ($explain as $row) {
$queryRow['rows'] *= (int) $row['rows'];
if (is_array($explain)) {
foreach ($explain as $row) {
$queryRow['rows'] *= (int) $row['rows'];
}
} else {
$queryRow['rows'] = 'N/A';
}

if (stristr($data['query'], 'group by') && !preg_match('/(avg|count|min|max|group_concat|sum)\s*\(/i', $data['query'])) {
Expand Down
2 changes: 1 addition & 1 deletion tools/profiling/templates/functions/load-time.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
{elseif $data > 0.8}
<span class="warning">{round($data * 1000)}</span>
{else}
<span class="success">{round($data * 1000)}</span>
<span class="success">{sprintf('%01.3f', $data * 1000)}</span>
{/if}
ms
{/function}
8 changes: 6 additions & 2 deletions tools/profiling/templates/stopwatch.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<tr>
<td class="pre"><pre>{preg_replace("/(^[\s]*)/m", "", htmlspecialchars($data['query'], ENT_NOQUOTES, 'utf-8', false))}</pre></td>
<td data-value="{$data['time']}">
{load_time data=($data['time'] * 1000)}
{load_time data=($data['time'])}
</td>

<td>{$data['rows']}</td>
Expand All @@ -63,7 +63,11 @@
</td>
<td data-value="{$data['location']}">
<a href="javascript:void(0);" onclick="$('#callstack_{$callstack_md5}').toggle();">{$data['location']}</a>
<div id="callstack_{$callstack_md5}" style="display:none">{implode('<br>', $data['stack'])}</div>
<div id="callstack_{$callstack_md5}" style="display:none">
{foreach $data['stack'] as $stack}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to implode with nofilter when you can use foreach :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You get a trailing <br> like this

{$stack}<br/>
{/foreach}
</div>
</td>
</tr>
{/foreach}
Expand Down