Last active
November 28, 2017 09:43
-
-
Save kandy/7ae16d74e2bdc35ffd7b524f089259c2 to your computer and use it in GitHub Desktop.
simple profiler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // include in bootsrap or add to auto_prepend_file | |
| // tideways extension required (see: https://tideways.io/profiler/docs/setup/installation) | |
| (function () { | |
| if (!function_exists('tideways_enable') | |
| ||!isset($_SERVER['HTTP_ACCEPT']) | |
| || strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false | |
| ) { | |
| return; | |
| } | |
| ini_set('tideways.max_spans', 10000); | |
| tideways_enable(TIDEWAYS_FLAGS_NO_HIERACHICAL ); | |
| tideways_span_watch('Magento\Framework\App\Bootstrap::createApplication'); | |
| tideways_span_watch('Magento\Framework\View\Element\Template::fetchView', 'view'); | |
| tideways_span_watch('Magento\Framework\View\Page\Config::build', 'view'); | |
| tideways_span_callback('Magento\Framework\ObjectManager\Factory\AbstractFactory::createObject', function($context) { | |
| $id = tideways_span_create('om'); | |
| tideways_span_annotate($id, ["class" => $context["args"][0]]); | |
| return $id; | |
| }); | |
| tideways_span_watch('Zend_Cache_Core::load'); | |
| //tideways_span_watch('Composer\Autoload\ClassLoader::loadClass'); | |
| tideways_span_watch('Magento\Eav\Model\Config::getAttribute'); | |
| tideways_span_watch('Magento\Eav\Model\Entity\Collection\AbstractCollection::load'); | |
| tideways_span_watch('Magento\Framework\Data\Collection\AbstractDb::load'); | |
| tideways_span_watch('Magento\Framework\App\FrontController::dispatch'); | |
| tideways_span_callback('file_get_contents', function($context) { | |
| $id = tideways_span_create('io'); | |
| tideways_span_annotate($id, ["file" => $context["args"][0]]); | |
| return $id; | |
| }); | |
| tideways_span_callback('fopen', function($context) { | |
| $id = tideways_span_create('io'); | |
| tideways_span_annotate($id, ["file" => $context["args"][0]]); | |
| return $id; | |
| }); | |
| register_shutdown_function(function () { | |
| tideways_disable(); | |
| $spans = tideways_get_spans(); | |
| $app = $spans[0]; | |
| $end = $app['e'][0]; | |
| echo " | |
| <div style='height: 31vh '></div> | |
| <div class='profiller'> | |
| <style> | |
| .profiller { padding:5px; border: 2px solid #88a; background: #FFF; width: 100%; height: 30vh; overflow: scroll; position: fixed; z-index: 5000; bottom: 0px;} | |
| .profiller > .row { height: 15px; font-size: 12px; position: relative; border-bottom: 1px dotted rgba(64,64,64,0.1); } | |
| .profiller > .row:hover { background-color: rgba(180,180,220, 0.2); color: #000;} | |
| .profiller > .row > .annotation { display: inline-block; width: 25%; height: 15px; overflow: hidden; z-index: 5; top: 0; vertical-align: text-top; } | |
| .row-head span{display: inline-block; width: 3%; text-align: right} | |
| </style> | |
| "; | |
| $i = 0; | |
| echo "<div class='row row-head'>"; | |
| echo "<div class='annotation'> </div>"; | |
| echo "<span>t(ms)</span>"; | |
| echo "<span>n(#)</span>"; | |
| echo '</div>'; | |
| foreach ($spans as $s => $span) { | |
| $total = 0; | |
| foreach ($span['b'] as $p => $b) { | |
| $total += ($span['e'][$p] - $b); | |
| } | |
| if ($total < 1100) { | |
| continue; | |
| } | |
| if (!isset($span['a'])) { | |
| $span['a'] = array(); | |
| } | |
| $annotations = htmlspecialchars(str_replace(['{', '}', '"', ',', '\\\\', '\\/'], ['', '', '', "\n", '\\', '/'], json_encode($span['a']))); | |
| echo "<div class='row row-{$span['n']}' style='' title='$annotations' >"; | |
| echo "<div class='annotation'>", | |
| substr($annotations, 0, 60), "</div>"; | |
| echo "<span style='display: inline-block; width: 3%; text-align: right'>", | |
| sprintf(" %.0F", $total / 1000), "</span>"; | |
| echo "<span style='display: inline-block; width: 3%; text-align: right'>", count($span['b']), "</span>"; | |
| echo "<span style='display: inline-block; width: 3%; text-align: right'>", htmlspecialchars($span['n']), " </span>"; | |
| foreach ($span['b'] as $p => $b) { | |
| echo "<b style=' text-align: center; display:block; position: absolute; height: 15px; top:0;" . | |
| "left: " . sprintf("%.3F", 40 + $b * 60 / $end) . "%;" . | |
| "width: " . sprintf("%.3F", ($span['e'][$p] - $b) * 60 / $end) . "%;" . | |
| "background: hsl(" . ($i * 345 % 255) . ", 50%, 55%)' | |
| title='" . sprintf("%.0F", ($span['e'][$p] - $b) / 1000) . "ms' | |
| > </b>"; | |
| } | |
| $i++; | |
| echo "</div>"; | |
| } | |
| echo "</div>"; | |
| }); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment