/** * @test * @dataProvider samplingRates */ public function triggerAlwaysSampling($rate, $expectedMax, $expectedMin) { $mockConfig = new stdClass(); $mockConfig->trigger = 'always'; $mockConfig->enableFilters = true; $mockConfig->filters = new stdClass(); $mockConfig->filters->sampling = $rate; $mockConfig->filters->timeThreshold = 0; $mockConfig->filters->memoryThreshold = 0; $mockConfig->filters->requestUriWhiteList = ''; $mockConfig->filters->requestUriBlackList = ''; $mockConfig->captureModelInfo = false; $mockConfig->captureBacktraces = false; $count = 0; $maxRequests = 100000; for ($i = 0; $i < $maxRequests; $i++) { Varien_Profiler::reInit(); Varien_Profiler::setConfiguration($mockConfig); if (Varien_Profiler::isEnabled()) { $count++; } } // let's allow a range of +-10% $this->assertLessThanOrEqual($expectedMax, $count); $this->assertGreaterThanOrEqual($expectedMin, $count); }
/** * Persist profile * * This method is called from the controller_front_send_response_after event * * @author Fabrizio Branca * @since 2014-02-01 * * @param Varien_Event_Observer $event */ public function persistProfile(Varien_Event_Observer $event) { if (!method_exists('Varien_Profiler', 'isEnabled')) { Mage::log('Looks like the wrong Profiler class is being loaded at this point.'); return; } if (Varien_Profiler::isEnabled() && Varien_Profiler::checkThresholds()) { $run = Mage::getModel('aoe_profiler/run'); /* @var $run Aoe_Profiler_Model_Run */ $run->loadStackLogFromProfiler(); $run->populateMetadata(); try { $run->save(); } catch (Exception $e) { Mage::log('Error while saving Aoe_Profiler data: ' . $e->getMessage()); } } }
/** * To HTML * * @return string */ protected function _toHtml() { if (!$this->getForceRender() && (!$this->_beforeToHtml() || !Mage::getStoreConfig('dev/debug/profiler') || !Mage::helper('core')->isDevAllowed())) { return ''; } if (!Varien_Profiler::isEnabled() && !$this->getForceRender()) { if (Mage::getStoreConfig('dev/debug/showDisabledMessage')) { // Adding css. Want to be as obtrusive as possible and not add any file to the header (as bundling might be influenced by this) // That's why I'm embedding css here into the html code... $output = '<style type="text/css">' . Mage::helper('aoe_profiler')->getSkinFileContent('aoe_profiler/css/styles.css') . '</style>'; $url = Mage::helper('core/url')->getCurrentUrl(); $url .= strpos($url, '?') === false ? '?' : '&'; $url .= 'profile=1'; $remoteCallUrl = $url . '&links=1'; $output .= '<div id="profiler"> <p class="hint">Add <a href="' . $url . '#profiler">?profile=1</a> to the url to enable <strong>profiling</strong>.</p> <p class="hint">If you\'re using PHPStorm and have the RemoteCall plugin installed append <a href="' . $remoteCallUrl . '#profiler">?profile=1&links=1</a> to the url to enable <strong>profiling including links to PHPStorm</strong> (this might be a slower).</p> <p class="hint-small">(This message can be hidden in System > Configuration > Developer > Profiler.)</p> </div>'; return $output; } return ''; } $stackModel = Mage::getModel('aoe_profiler/stack'); /* @var $stackModel Aoe_Profiler_Model_Stack */ $stackModel->loadStackLogFromProfiler()->processRawData(); $this->stackLog = $stackModel->getStackLog(); $this->treeData = $stackModel->getTreeData(); // Adding css. Want to be as obtrusive as possible and not add any file to the header (as bundling might be influenced by this) // That's why I'm embedding css here into the html code... $output = '<style type="text/css">' . Mage::helper('aoe_profiler')->getSkinFileContent('aoe_profiler/css/styles.css') . '</style>'; // Icons cannot be embedded using relatives path in this situation. $output .= '<style type="text/css">'; $output .= '#profiler .profiler-open { background-image: url(\'' . $this->getSkinUrl('aoe_profiler/img/button-open.png') . '\'); }' . "\n"; $output .= '#profiler .profiler-closed { background-image: url(\'' . $this->getSkinUrl('aoe_profiler/img/button-closed.png') . '\'); }' . "\n"; foreach ($this->typeIcons as $key => $icon) { $output .= '#profiler .type-' . $key . ' { background-image: url(\'' . $this->getSkinUrl($icon) . '\'); }' . "\n"; } $output .= '</style>'; $hideLinesFasterThan = intval(Mage::getStoreConfig('dev/debug/hideLinesFasterThan')); $title = $this->getTitle() ? $this->getTitle() : 'Profiler'; $output .= <<<HTML <div id="profiler"><h1>{$title}</h1> <div id="p-filter"> <form id="filter-form"> <div class="form-block"> <label for="text-filter">Search for:</label> <input type="text" id="text-filter" value="" placeholder="Text or regular expression" title="Text or regular expression" /> (RegExp is allowed) <br /> <input type="checkbox" id="text-filter-case-sensitivity" value="" /> <label for="text-filter-case-sensitivity">Case sensitive</label> <input type="checkbox" id="show-matches-descendants" value="" /> <label for="show-matches-descendants">Do not hide matches' descendants</label> </div> <div class="form-block" style="padding-left: 15px"> <div>Hide entries faster than <input type="text" id="duration-filter" value="{$hideLinesFasterThan}" /> ms: <button>Filter!</button> </div> <div id="p-track"> <div id="p-handle" class="selected" title="Drag me!"> <img src="{$this->getSkinUrl('aoe_profiler/img/slider.png')}" /> </div> </div> </div> </form> </div> HTML; if (Mage::getSingleton('core/resource')->getConnection('core_read')->getProfiler()->getEnabled()) { $output .= '<p>Number of database queries: ' . Mage::getSingleton('core/resource')->getConnection('core_read')->getProfiler()->getTotalNumQueries() . '</p>'; } $output .= $this->renderHeader(); $output .= '<ul id="treeView" class="treeView">'; $output .= $this->renderTree($this->treeData); $output .= '</ul>'; $output .= '</div>'; // adding js $output .= '<script type="text/javascript">' . Mage::helper('aoe_profiler')->getSkinFileContent('aoe_profiler/js/profiler.js') . '</script>'; return $output; }