/** * @param Logger $log * @return mixed */ public function logResults(Logger $log) { foreach (array_keys($this->results) as $event) { if (empty($this->results[$event][0])) { unset($this->results[$event]); continue; } $listeners = array(); foreach (Enlight()->Events()->getListeners($event) as $listener) { $listener = $listener->getListener(); if ($listener[0] === $this) { continue; } if (is_array($listener) && is_object($listener[0])) { $listener[0] = get_class($listener[0]); } if (is_array($listener)) { $listener = implode('::', $listener); } $listeners[] = $listener; } $this->results[$event] = array(0 => $event, 1 => $this->utils->formatMemory(0 - $this->results[$event][1]), 2 => $this->utils->formatTime(0 - $this->results[$event][2]), 3 => $listeners); } $this->results = array_values($this->results); foreach ($this->results as $result) { $order[] = $result[2]; } array_multisort($order, SORT_NUMERIC, SORT_DESC, $this->results); array_unshift($this->results, array('name', 'memory', 'time', 'listeners')); $label = 'Benchmark Events'; $table = array($label, $this->results); $log->table($table); }
/** * Logs all controller events into the internal log object. * Each logged events contains the event name, the execution time and the allocated peak of memory. * * @param \Enlight_Event_EventArgs $args * @return void */ public function onBenchmarkEvent(\Enlight_Event_EventArgs $args) { if (empty($this->results)) { $this->results[] = array('name', 'memory', 'time'); $this->startTime = microtime(true); $this->startMemory = memory_get_peak_usage(true); } $this->results[] = array(0 => str_replace('Enlight_Controller_', '', $args->getName()), 1 => $this->utils->formatMemory(memory_get_peak_usage(true) - $this->startMemory), 2 => $this->utils->formatTime(microtime(true) - $this->startTime)); }