예제 #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));
 }
예제 #3
0
 /**
  * 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);
 }
예제 #4
0
 /**
  * @param Logger $log
  * @return mixed
  */
 public function logResults(Logger $log)
 {
     $errors = $this->errorHandler->getErrorLog();
     if (empty($errors)) {
         return;
     }
     $counts = array();
     foreach ($errors as $errorKey => $error) {
         $counts[$errorKey] = $error['count'];
     }
     array_multisort($counts, SORT_NUMERIC, SORT_DESC, $errors);
     $rows = array();
     foreach ($errors as $error) {
         if (!$rows) {
             $rows[] = array_keys($error);
         }
         $rows[] = $this->utils->encode(array_values($error));
     }
     $table = array('Error Log (' . count($errors) . ')', $rows);
     $log->table($table);
 }
예제 #5
0
 /**
  * @param Logger $log
  * @return mixed
  */
 public function logResults(Logger $log)
 {
     if (empty($this->exceptions)) {
         return;
     }
     $rows = array(array('code', 'name', 'message', 'line', 'file', 'trace'));
     foreach ($this->exceptions as $exception) {
         $rows[] = $this->utils->encode(array($exception->getCode(), get_class($exception), $exception->getMessage(), $exception->getLine(), $exception->getFile(), explode("\n", $exception->getTraceAsString())));
     }
     $table = array('Exception Log (' . count($this->exceptions) . ')', $rows);
     $log->table($table);
     foreach ($this->exceptions as $exception) {
         $log->error((string) $exception);
     }
 }