/** * 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()); } } }
/** * @test */ public function checkMemoryThresholdEnoughMemory() { $mockConfig = new stdClass(); $mockConfig->trigger = 'always'; $mockConfig->enableFilters = true; $mockConfig->filters = new stdClass(); $mockConfig->filters->sampling = 100; $mockConfig->filters->timeThreshold = 0; $mockConfig->filters->memoryThreshold = 5 * 1024 * 1024; // 5MB $mockConfig->filters->requestUriWhiteList = ''; $mockConfig->filters->requestUriBlackList = ''; $mockConfig->captureModelInfo = false; $mockConfig->captureBacktraces = false; Varien_Profiler::reInit(); Varien_Profiler::setConfiguration($mockConfig); Varien_Profiler::start('TEST'); $memory = array(); for ($i = 0; $i < 6 * 1024; $i++) { $memory[] = str_repeat('M', 1024); } Varien_Profiler::stop('TEST'); $this->assertTrue(Varien_Profiler::checkThresholds()); }