time(), 'name' => $name ); } public static function startTimer() { if (empty(static::$_startTime)) { /** @var Orange35_ProductImport_Helper_Data $helper */ $helper = Mage::helper('orange35_productImport'); $helper->log("timer start at", true); static::$_startTime = time(); } } public function stopTimer() { if (empty(static::$_endTime)) { static::$_endTime = time(); static::$_timers[count(static::$_timers) - 1]['duration'] = static::$_endTime - static::$_timers[count(static::$_timers) - 1]['start']; } } public function layoutTimers() { $this->stopTimer(); $totalTime = static::$_endTime - static::$_startTime; $totalTime = max(0.1, $totalTime); $totalSaved = 0; foreach (static::$_timers as &$timer) { $timer['percent'] = $timer['duration'] / $totalTime * 100; $totalSaved += $timer['duration']; } unset($timer); $this->log("\nTimers list:"); foreach (static::$_timers as $timer) { $this->log($timer['name'], $timer['duration'] . " sec", number_format($timer['percent'], 1) . "%"); } $this->log(""); $minSaved = number_format($totalSaved / 60, 2); $this->log("Total time (from timers): ", $totalSaved . " sec (" . $minSaved . " min)\n"); return $this; } /** * @param $message * @param string $message2 * @param string $message3 * @return $this */ protected function log($message, $message2 = '', $message3 = '') { $col1Padding = str_repeat(' ', self::PADDING_COL - strlen($message)); if (!empty($message2)) { $message .= $col1Padding . $message2; if (!empty($message3)) { $col2Padding = str_repeat(' ', self::PADDING_COL_SECOND - strlen($message2)); $message .= $col2Padding . $message3; } } /** @var Orange35_ProductImport_Helper_Data $helper */ $helper = Mage::app()->getHelper('orange35_productImport'); $helper->log($message); return $this; } }