Exemple #1
0
function render_db(EurekaProfiler_Session $session)
{
    $queries = $session->events_of_type('db');
    $colors = get_theme_colors();
    if (empty($queries)) {
        echo '<h2>This panel has no log items.</h2>';
        return;
    }
    ?>
    <table class="summary">
        <tr>
            <td style="background: #953FA1;">
                <h3><?php 
    echo EurekaProfiler_Tools::readable_interval($session->total_query_time());
    ?>
</h3>
                <h4>Total time</h4>
            </td>
        </tr>
        <tr>
            <td style="background: #7B3384;padding-top:0" class="border">
                <?php 
    $chart_rows = array();
    $i = 0;
    foreach ($queries as $query) {
        $i++;
        $chart_rows[] = array($i . ': ' . (empty($query->text) ? $query->query : $query->text), $query->duration);
    }
    echo render_chart($chart_rows, 'Query');
    ?>
                <h4>Time chart</h4>
            </td>
        </tr>
    </table>

    <!-- Query Data-->
    <div class="data-wrapper">
        <table class="data data-db">
            <?php 
    $i = 0;
    foreach ($queries as $query) {
        /* @var $query ProfilerQuery */
        //EXPLAIN info
        if (empty($query->explain)) {
            $explain_html = 'No EXPLAIN info';
        } else {
            $explain_html = array();
            foreach ($query->explain as $key => $value) {
                $name = ucwords(str_replace('_', ' ', $key));
                $explain_html[] = "{$name}: <strong>{$value}</strong>";
            }
            $explain_html = implode(' &middot ', $explain_html);
        }
        //Query Info
        if (empty($query->text)) {
            $query_html = htmlspecialchars($query->query);
        } else {
            $query_html = $query->text;
            $original_query = $query->query;
            if (class_exists('Dump') && method_exists('Dump', 'source')) {
                $original_query = Dump::source($original_query, 'mysql');
            }
            $explain_html = '<a class="show-original-query" title="Show full original query" href="#" onclick="app_show_popup(' . htmlspecialchars(json_encode($original_query)) . ', \'Original query\');return false;">[SHOW]</a>&nbsp;' . $explain_html;
        }
        $html = '<div class="query">' . $query_html . '</div>' . '<div class="query-explain">' . $explain_html . '</div>';
        basic_row($i + 1, $html, EurekaProfiler_Tools::readable_interval($query->duration), $colors[$i % count($colors)]);
        $i++;
    }
    ?>
        </table>
    </div>
<?php 
}