Example #1
0
 /**
  * @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));
 }
 /**
  * Logs all rendered templates into the internal log object.
  * Each logged template contains the template name, the required compile time,
  * the required render time and the required cache time.
  */
 public function logResults(Logger $log)
 {
     $rows = array(array('name', 'compile_time', 'render_time', 'cache_time'));
     $total_time = 0;
     foreach (\Smarty_Internal_Debug::$template_data as $template_file) {
         $total_time += $template_file['render_time'];
         $total_time += $template_file['cache_time'];
         $template_file['name'] = str_replace($this->rootDir, '', $template_file['name']);
         $template_file['compile_time'] = $this->utils->formatTime($template_file['compile_time']);
         $template_file['render_time'] = $this->utils->formatTime($template_file['render_time']);
         $template_file['cache_time'] = $this->utils->formatTime($template_file['cache_time']);
         unset($template_file['start_time']);
         $rows[] = array_values($template_file);
     }
     $total_time = round($total_time, 5);
     $total_count = count($rows) - 1;
     $label = "Benchmark Template ({$total_count} @ {$total_time} sec)";
     $table = array($label, $rows);
     $log->table($table);
 }