/** * Calculate metric value from set of timer names * * @param array $timerNames * @param string $fetchKey * @return int */ protected function _aggregateTimerValues(array $timerNames, $fetchKey = Magento_Profiler::FETCH_AVG) { /* Prepare pattern that matches timers with deepest nesting level only */ $nestingSep = preg_quote(Magento_Profiler::NESTING_SEPARATOR, '/'); array_map('preg_quote', $timerNames, array('/')); $pattern = '/(?<=' . $nestingSep . '|^)(?:' . implode('|', $timerNames) . ')$/'; /* Sum profiler values for matched timers */ $result = 0; foreach ($this->_getTimers() as $timerId) { if (preg_match($pattern, $timerId)) { $result += Magento_Profiler::fetch($timerId, $fetchKey); } } /* Convert seconds -> milliseconds */ $result = round($result * 1000); return $result; }
/** * Retrieve the list of timer Ids * * @return array */ protected function _getTimers() { $pattern = $this->_filter; $timerIds = $this->_getSortedTimers(); $result = array(); foreach ($timerIds as $timerId) { /* Filter by timer id pattern */ if ($pattern && !preg_match($pattern, $timerId)) { continue; } /* Filter by column value thresholds */ $skip = false; foreach ($this->_thresholds as $fetchKey => $minAllowedValue) { $skip = Magento_Profiler::fetch($timerId, $fetchKey) < $minAllowedValue; /* First value not less than the allowed one forces to include timer to the result */ if (!$skip) { break; } } if (!$skip) { $result[] = $timerId; } } return $result; }
/** * @dataProvider fetchExceptionDataProvider * @expectedException Varien_Exception */ public function testFetchException($timerId, $fetchKey) { Magento_Profiler::fetch($timerId, $fetchKey); }