ecoco/magento_profiler

View on GitHub
app/design/frontend/base/default/template/ecocode_profiler/collector/cache/panel.phtml

Summary

Maintainability
Test Coverage
<?php
/** @var Ecocode_Profiler_Block_Collector_Base $this */

/** @var Ecocode_Profiler_Model_Collector_CacheDataCollector $collector */
$collector = $this->getCollector();
$iconYes   = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width="28" height="28" viewBox="0 0 12 12" enable-background="new 0 0 12 12" xml:space="preserve">
    <path fill="#5E976E" d="M12,3.1c0,0.4-0.1,0.8-0.4,1.1L5.9,9.8c-0.3,0.3-0.6,0.4-1,0.4c-0.4,0-0.7-0.1-1-0.4L0.4,6.3
    C0.1,6,0,5.6,0,5.2c0-0.4,0.2-0.7,0.4-0.9C0.6,4,1,3.9,1.3,3.9c0.4,0,0.8,0.1,1.1,0.4l2.5,2.5l4.7-4.7c0.3-0.3,0.7-0.4,1-0.4
    c0.4,0,0.7,0.2,0.9,0.4C11.8,2.4,12,2.7,12,3.1z"/>
</svg>';
$iconNo    = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width="28" height="28" viewBox="0 0 12 12" enable-background="new 0 0 12 12" xml:space="preserve">
    <path fill="#B0413E" d="M10.4,8.4L8,6l2.4-2.4c0.8-0.8,0.7-1.6,0.2-2.2C10,0.9,9.2,0.8,8.4,1.6L6,4L3.6,1.6C2.8,0.8,2,0.9,1.4,1.4
    C0.9,2,0.8,2.8,1.6,3.6L4,6L1.6,8.4C0.8,9.2,0.9,10,1.4,10.6c0.6,0.6,1.4,0.6,2.2-0.2L6,8l2.4,2.4c0.8,0.8,1.6,0.7,2.2,0.2
    C11.1,10,11.2,9.2,10.4,8.4z"/>
</svg>';

$cacheTypes = Mage::app()->getCacheInstance()->getTypes();
?>
<h2>Cache metrics</h2>

<div class="metrics">
    <?php foreach ($collector->getStats() as $key => $value): ?>
        <div class="metric">
            <span class="value"><?php echo $value ?></span>
            <span class="label"><?php echo uc_words($key) ?></span>
        </div>

    <?php endforeach; ?>

    <div class="metric">
        <span class="value"><?php echo sprintf('%0.2f', $collector->getTotalTime() * 1000) ?> ms</span>
        <span class="label">Time</span>
    </div>

</div>

<h2>Cache configuration</h2>
<table class="cache-table">
    <thead>
    <tr>
        <th class="key">Id</th>
        <th>Type</th>
        <th>Run Status</th>
        <th>Current Status</th>
        <th class="text-right">
            <a data-url="<?php echo Mage::getUrl('_profiler/cache/clearAll') ?>" class="btn btn-sm ajax-action">Clear
                All</a>
        </th>
    </tr>
    </thead>
    <tbody>
    <?php foreach ($collector->getCacheList() as $cache): ?>
        <?php $currentStatus = $cacheTypes[$cache['id']]->getData('status'); ?>
        <tr>
            <td><?php echo $cache['id'] ?></td>
            <td><?php echo $cache['cache_type'] ?></td>
            <td>
                <?php echo $cache['status'] ? $iconYes : $iconNo ?>
            </td>
            <td>
                <?php echo $currentStatus ? $iconYes : $iconNo ?>
            </td>
            <td class="text-right">
                <?php if ($currentStatus): ?>
                    <a href="#"
                       data-url="<?php echo Mage::getUrl('_profiler/cache/clear', ['types' => $cache['id']]) ?>"
                       class="btn btn-sm ajax-action">Clear</a>
                    <a href="#"
                       data-url="<?php echo Mage::getUrl('_profiler/cache/disable', ['types' => $cache['id']]) ?>"
                       class="btn btn-sm ajax-action">Disable</a>
                <?php else: ?>
                    <a href="#"
                       data-url="<?php echo Mage::getUrl('_profiler/cache/enable', ['types' => $cache['id']]) ?>"
                       class="btn btn-sm ajax-action">Enable</a>
                <?php endif; ?>
            </td>
        </tr>
    <?php endforeach; ?>
    </tbody>
</table>

<h2>
    Cache Backend<br>
    <small><?php echo $collector->getBackendName() ?></small>
</h2>
<table>
    <thead>
    <tr>
        <th>Key</th>
        <th>Value</th>
    </tr>
    </thead>
    <tbody>
    <?php foreach ($collector->getBackendOptions() as $key => $value): ?>
        <tr>
            <td class="nowrap"><?php echo $key ?> </td>
            <td class="nowrap"><?php echo $value ?></td>
        </tr>
    <?php endforeach; ?>
    </tbody>
</table>

<h2>Cache Calls</h2>
<table class="sortable-table">
    <thead>
    <tr>
        <th>#</th>
        <th>Action</th>
        <th style="width: 100%;">Id</th>
        <th>Hit</th>
        <th data-sort="float">Time</th>
    </tr>
    </thead>
    <tbody>
    <?php foreach ($collector->getCacheCalls() as $index => $call): ?>
        <tr>
            <td class="nowrap"><?php echo $index + 1 ?> </td>
            <td><?php echo $call['action'] ?></td>
            <td>
                <?php echo isset($call['id']) ? $call['id'] : '-'; ?>
                <?php if (!empty($call['tags'])): ?>
                    <br>
                    <small><strong>Tags:</strong> <?php echo implode(', ', $call['tags']) ?></small>
                <?php endif; ?>
            </td>
            <td>
                <?php if (isset($call['hit'])): ?>
                    <span class="label status-<?php echo $call['hit'] ? 'success' : 'error' ?>">
                <?php echo $call['hit'] ? 'Hit' : 'Miss' ?>
                </span>
                <?php else: ?>
                    -
                <?php endif ?>
            </td>
            <td class="nowrap"><?php echo sprintf('%0.2f', $call['time'] * 1000) ?> ms</td>
        </tr>
    <?php endforeach; ?>
    </tbody>
</table>
<script>
    (function () {
        var actions = document.querySelectorAll('.cache-table .ajax-action');

        for (var i = 0; i < actions.length; i++) {
            (function () {

                var button = actions[i],
                    url    = button.getAttribute('data-url');

                button.addEventListener('click', function (e) {
                    Sfjs.request(url, function () {
                        window.location.reload();
                    });
                });
            })();
        }
    })();
</script>
<style>
    .cache-table td svg {
        width: 16px;
        height: 16px;
    }
</style>