vpietri/magento2-developer-quickdevbar

View on GitHub
view/base/templates/tab/sql.phtml

Summary

Maintainability
Test Coverage
<?php
/** @var ADM\QuickDevBar\Block\Tab\Content\Sql $block */
?>
<?php if ($block->getAllQueries()): ?>
<table class="qdb_table_2col">
  <tr>
    <th><?php echo __('Statistics'); ?></th>
    </td>
    <td>
      <?=  sprintf(
          '%s queries in %s (average time: %s) - %s queries/second',
          $block->getTotalNumQueries(),
          $block->formatSqlTime($block->getTotalElapsedSecs()),
          $block->formatSqlTime($block->getAverage()),
          $block->getNumQueriesPerSecond()
      ); ?>
    </td>
  </tr>
  <tr>
    <th></th>
    <td>
      <?=  sprintf(
          '%s SELECT - %s INSERT - %s UPDATE - %s DELETE - %s TRANSACTION',
          $block->getTotalNumQueriesByType(Zend_Db_Profiler::SELECT),
          $block->getTotalNumQueriesByType(Zend_Db_Profiler::INSERT),
          $block->getTotalNumQueriesByType(Zend_Db_Profiler::UPDATE),
          $block->getTotalNumQueriesByType(Zend_Db_Profiler::DELETE),
          $block->getTotalNumQueriesByType(Zend_Db_Profiler::TRANSACTION)
      ); ?>
    </td>
  </tr>
  <tr>
    <th><?=  __('Longest'); ?></th>
    <td>
      <?=  $block->formatSql($block->getLongestQuery()); ?>
    </td>
  </tr>
  <tr>
    <th></th>
    <td>
      <span>(<?=   $block->formatSqlTime($block->getLongestQueryTime()); ?>)</span>
    </td>
  </tr>
</table>

<div class="qdb-panel">
    <table class="qdb_table striped filterable sortable tablesorter grade">
    <thead>
    <tr>
        <th>#</th>
        <th class="{sorter: false}">SQL</th>
        <th class="{sorter: 'text'}">Args</th>
        <?php if($block->useQdbProfiler()): ?>
            <th class="{sorter: false}">Bt</th>
        <?php endif; ?>
        <th class="{sorter: 'digit'}">Time</th>

    </tr>
    </thead>
    <tbody>
    <?php
      $i = 0;
      foreach ($block->getAllQueries() as $i => $query): ?>
        <tr class="<?php echo  $query['grade']; ?>">
          <td><?php echo $i;?></td>
          <td class="sqlquery"><?php echo $block->formatSql($query['sql']); ?></td>
          <td class="sqlargs"><?php echo $block->formatParams($query['params']); ?></td>

            <?php if($block->useQdbProfiler()): ?>
                <td><?php echo  $block->formatSqlTrace($query['bt'])  ?></td>
            <?php endif; ?>
            <td class="sqltimer"><?php echo  $block->formatSqlTime($query['time']); ?></td>
        </tr>
        <?php $i++; ?>
      <?php endforeach ?>
    </tbody>
    </table>
</div>

<?php else:?>
SQL profiler is not active<br/>
You can use command line
<pre>bin/magento dev:quickdevbar:enable</pre>
and use a specific profiler with backtrace
<pre>bin/magento dev:quickdevbar:enable --sql-profiler</pre>
or set a new key for $config array in file app/etc/env.php<br/>
<pre>$config[db][connection][default][profiler] = 1</pre>
<?php  endif ?>