Show Index and PDO query counts separately in the footer.

This commit is contained in:
flash 2023-07-15 17:15:40 +00:00
parent bff42c26ab
commit 472fc0decc
4 changed files with 13 additions and 4 deletions

View file

@ -43,7 +43,7 @@ class MisuzuContext {
public function getDbQueryCount(): int {
$result = $this->dbConn->query('SHOW SESSION STATUS LIKE "Questions"');
return $result->next() ? $result->getInteger(0) : 0;
return $result->next() ? $result->getInteger(1) : 0;
}
public function createMigrationManager(): DbMigrationManager {

View file

@ -38,12 +38,19 @@ final class TwigMisuzu extends AbstractExtension {
new TwigFunction('git_tag', fn() => GitInfo::tag()),
new TwigFunction('git_branch', fn() => GitInfo::branch()),
new TwigFunction('startup_time', fn(float $time = MSZ_STARTUP) => microtime(true) - $time),
new TwigFunction('sql_query_count', fn() => DB::queries() + $this->ctx->getDbQueryCount()),
new TwigFunction('sql_query_count', fn() => $this->sqlQueryCount()),
new TwigFunction('ndx_version', fn() => Environment::getIndexVersion()),
new TwigFunction('byte_symbol', fn($bytes, $decimal = ByteFormat::DECIMAL_DEFAULT) => ByteFormat::format($bytes, $decimal)),
];
}
public function sqlQueryCount(): array {
$ndx = $this->ctx->getDbQueryCount();
$pdo = DB::queries();
$total = $ndx + $pdo;
return compact('ndx', 'pdo', 'total');
}
public static $units = [
'y' => 'year',
'm' => 'month',

View file

@ -14,8 +14,9 @@
{% endif %}
# <a href="https://git.flash.moe/flashii/misuzu/commit/{{ git_commit_hash(true) }}" target="_blank" rel="noreferrer noopener" class="footer__link">{{ git_commit_hash() }}</a>
{% if constant('MSZ_DEBUG') or current_user.super|default(false) %}
{% set sql_query_count = sql_query_count() %}
/ Index {{ ndx_version() }}
/ SQL Queries: {{ sql_query_count()|number_format }}
/ SQL Queries: {{ sql_query_count.total|number_format }} (<span title="{{ sql_query_count.ndx|number_format }} queries processed through Index">{{ sql_query_count.ndx|number_format }}</span> + <span title="{{ sql_query_count.pdo|number_format }} queries processed through PDO">{{ sql_query_count.pdo|number_format }}</span>)
/ Took: {{ startup_time()|number_format(5) }} seconds
/ Load: {{ (startup_time() - startup_time(constant('MSZ_TPL_RENDER')))|number_format(5) }} seconds
/ Render: {{ startup_time(constant('MSZ_TPL_RENDER'))|number_format(5) }} seconds

View file

@ -92,8 +92,9 @@
# <a href="https://github.com/flashwave/misuzu/commit/{{ git_commit_hash(true) }}" target="_blank" rel="noreferrer noopener">{{ git_commit_hash() }}</a>
</div>
{% if constant('MSZ_DEBUG') or current_user.super|default(false) %}
{% set sql_query_count = sql_query_count() %}
<div class="landingv2-footer-copyright-line">
{{ sql_query_count()|number_format }} queries / {{ (startup_time() - startup_time(constant('MSZ_TPL_RENDER')))|number_format(5) }} load / {{ startup_time(constant('MSZ_TPL_RENDER'))|number_format(5) }} render / {{ startup_time()|number_format(5) }} total
{{ sql_query_count.total|number_format }} (<span title="{{ sql_query_count.ndx|number_format }} queries processed through Index">{{ sql_query_count.ndx|number_format }}</span> + <span title="{{ sql_query_count.pdo|number_format }} queries processed through PDO">{{ sql_query_count.pdo|number_format }}</span>) queries / {{ (startup_time() - startup_time(constant('MSZ_TPL_RENDER')))|number_format(5) }} load / {{ startup_time(constant('MSZ_TPL_RENDER'))|number_format(5) }} render / {{ startup_time()|number_format(5) }} total
</div>
{% endif %}
</div>