|
1
|
|
|
<? |
|
|
|
|
|
|
2
|
|
|
use Arrilot\BitrixModels\Debug\IlluminateQueryDebugger; |
|
3
|
|
|
use Illuminate\Database\Capsule\Manager; |
|
4
|
|
|
|
|
5
|
|
|
if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die(); |
|
6
|
|
|
|
|
7
|
|
|
if (!$bShowStat) { |
|
8
|
|
|
return; |
|
9
|
|
|
} |
|
10
|
|
|
|
|
11
|
|
|
$totalQueryCount = 0; |
|
12
|
|
|
$totalQueryTime = 0.0; |
|
13
|
|
|
|
|
14
|
|
|
$queryLog = Manager::getQueryLog(); |
|
15
|
|
|
foreach($queryLog as $loggedQuery) { |
|
16
|
|
|
$totalQueryCount++; |
|
17
|
|
|
$totalQueryTime += $loggedQuery['time'] / 1000; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
echo '<div class="bx-component-debug bx-debug-summary" style="bottom: 80px;">'; |
|
21
|
|
|
echo 'Статистика SQL запросов illuminate/database<br>'; |
|
22
|
|
|
echo '<a title="Посмотреть подробную статистику по запросам" href="javascript:BX_DEBUG_INFO_ILLUMINATE.Show(); BX_DEBUG_INFO_ILLUMINATE.ShowDetails(\'BX_DEBUG_INFO_ILLUMINATE_1\');">'.'Всего SQL запросов: '."</a> ".intval($totalQueryCount)."<br>"; |
|
23
|
|
|
echo "Время исполнения запросов: ".round($totalQueryTime, 4)." сек.<br>"; |
|
24
|
|
|
echo '</div><div class="empty"></div>'; |
|
25
|
|
|
|
|
26
|
|
|
//CJSPopup |
|
27
|
|
|
require_once($_SERVER["DOCUMENT_ROOT"].BX_ROOT."/modules/main/interface/admin_lib.php"); |
|
28
|
|
|
?> |
|
29
|
|
|
<script type="text/javascript"> |
|
30
|
|
|
BX_DEBUG_INFO_ILLUMINATE = new BX.CDebugDialog(); |
|
31
|
|
|
</script> |
|
32
|
|
|
<? |
|
33
|
|
|
$obJSPopup = new CJSPopupOnPage('', array()); |
|
34
|
|
|
$obJSPopup->jsPopup = 'BX_DEBUG_INFO_ILLUMINATE'; |
|
35
|
|
|
$obJSPopup->StartDescription('bx-core-debug-info'); |
|
36
|
|
|
?> |
|
37
|
|
|
<p>Всего запросов: <?= $totalQueryCount ?>, время: <?= round($totalQueryTime, 4) ?> сек.</p> |
|
38
|
|
|
<p>Поиск: <input type="text" style="height:16px" onkeydown="filterTable(this, 'queryDebugIlluminate', 1)" onpaste="filterTable(this, 'queryDebugIlluminate', 1)" oninput="filterTable(this, 'queryDebugIlluminate', 1)"></p> |
|
39
|
|
|
<? |
|
40
|
|
|
$obJSPopup->StartContent(['buffer' => true]); |
|
41
|
|
|
if(count($queryLog) > 0) { |
|
42
|
|
|
?><div class="bx-debug-content bx-debug-content-table"><? |
|
43
|
|
|
$arQueries = []; |
|
44
|
|
|
foreach ($queryLog as $j => $arQueryDebug) { |
|
45
|
|
|
$strSql = $arQueryDebug["query"]; |
|
46
|
|
|
$arQueries[$strSql]["COUNT"]++; |
|
47
|
|
|
$arQueries[$strSql]["CALLS"][] = [ |
|
48
|
|
|
"QUERY" => $strSql, |
|
49
|
|
|
"BINDINGS" => $arQueryDebug['bindings'], |
|
50
|
|
|
"TIME"=> $arQueryDebug["time"] / 1000, |
|
51
|
|
|
]; |
|
52
|
|
|
} |
|
53
|
|
|
?><table id="queryDebugIlluminate" cellpadding="0" cellspacing="0" border="0"><? |
|
54
|
|
|
$j = 1; |
|
55
|
|
|
foreach($arQueries as $strSql => $query) { |
|
56
|
|
|
?><tr> |
|
57
|
|
|
<td class="number" valign="top"><?= $j ?></td> |
|
58
|
|
|
<td><a href="javascript:BX_DEBUG_INFO_ILLUMINATE.ShowDetails('BX_DEBUG_INFO_ILLUMINATE_<?= $j ?>')"><?= htmlspecialcharsbx(substr($strSql, 0, 100))."..."?></a> (<?= $query["COUNT"] ?>) </td> |
|
59
|
|
|
<td class="number" valign="top"><? |
|
60
|
|
|
$t = 0.0; |
|
61
|
|
|
foreach($query["CALLS"] as $call) { |
|
62
|
|
|
$t += $call["TIME"]; |
|
63
|
|
|
} |
|
64
|
|
|
echo number_format($t / $query["COUNT"], 5); |
|
65
|
|
|
?></td> |
|
66
|
|
|
</tr><? |
|
67
|
|
|
$j++; |
|
68
|
|
|
} |
|
69
|
|
|
?></table> |
|
70
|
|
|
</div>#DIVIDER#<div class="bx-debug-content bx-debug-content-details"> |
|
71
|
|
|
<? |
|
72
|
|
|
$j = 1; |
|
73
|
|
|
foreach($arQueries as $strSql => $query) { |
|
74
|
|
|
?><div id="BX_DEBUG_INFO_ILLUMINATE_<?= $j ?>" style="display:none"> |
|
75
|
|
|
<b>Запрос № <?= $j ?>:</b> |
|
76
|
|
|
<br /><br /> |
|
77
|
|
|
<? |
|
78
|
|
|
$strSql = preg_replace("/[\\n\\r\\t\\s ]+/", " ", $strSql); |
|
79
|
|
|
$strSql = preg_replace("/^ +/", "", $strSql); |
|
80
|
|
|
$strSql = preg_replace("/ (INNER JOIN|OUTER JOIN|LEFT JOIN|SET|LIMIT) /i", "\n\\1 ", $strSql); |
|
81
|
|
|
$strSql = preg_replace("/(INSERT INTO [A-Z_0-1]+?)\\s/i", "\\1\n", $strSql); |
|
82
|
|
|
$strSql = preg_replace("/(INSERT INTO [A-Z_0-1]+?)([(])/i", "\\1\n\\2", $strSql); |
|
83
|
|
|
$strSql = preg_replace("/([\\s)])(VALUES)([\\s(])/i", "\\1\n\\2\n\\3", $strSql); |
|
84
|
|
|
$strSql = preg_replace("/ (FROM|WHERE|ORDER BY|GROUP BY|HAVING) /i", "\n\\1\n", $strSql); |
|
85
|
|
|
echo str_replace(["\n"], ["<br />"], htmlspecialcharsbx($strSql)); |
|
86
|
|
|
?> |
|
87
|
|
|
<br /><br /> |
|
88
|
|
|
<? |
|
89
|
|
|
$k = 1; |
|
90
|
|
|
foreach($query["CALLS"] as $call) { |
|
91
|
|
|
?> |
|
92
|
|
|
<br /> |
|
93
|
|
|
<b>Экземпляр № <?= $k ?>:</b><br> |
|
94
|
|
|
<?= htmlspecialcharsbx(IlluminateQueryDebugger::interpolateQuery($call['QUERY'], $call['BINDINGS'])) ?> |
|
95
|
|
|
<br /><br /> |
|
96
|
|
|
Время выполнения: <?= round($call["TIME"], 5) ?> сек. |
|
97
|
|
|
<? |
|
98
|
|
|
$k++; |
|
99
|
|
|
} |
|
100
|
|
|
?></div> |
|
101
|
|
|
<? |
|
102
|
|
|
$j++; |
|
103
|
|
|
}; |
|
104
|
|
|
?> |
|
105
|
|
|
</div> |
|
106
|
|
|
<? |
|
107
|
|
|
} |
|
108
|
|
|
$obJSPopup->StartButtons(); |
|
109
|
|
|
$obJSPopup->ShowStandardButtons(array('close')); |
|
110
|
|
|
|
Short opening tags are disabled in PHP’s default configuration. In such a case, all content of this file is output verbatim to the browser without being parsed, or executed.
As a precaution to avoid these problems better use the long opening tag
<?php.