Example #1
0
 public function calculate($netPrice, $tax)
 {
     // Bypass the two fingers crossed handler, by setting an `alert` message
     // By default Shopware would not show `debug` or `info` level debug messages in the log
     $this->logger->alert('Calculating price for tax: ' . $tax);
     return $netPrice * $tax;
 }
 /**
  * @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->formatMemory(0 - $this->results[$event][1]), 2 => 0 - $this->results[$event][2], 3 => $listeners, 4 => $this->results[$event][3]);
     }
     $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', 'start'));
     $label = 'Benchmark Events';
     $table = array($label, $this->results);
     $log->table($table);
 }
 /**
  * Get total execution time in controller
  */
 public function logResults(Logger $log)
 {
     $total_time = $this->utils->formatTime(microtime(true) - $this->startTime);
     $label = "Benchmark Controller ({$total_time} sec)";
     $table = array($label, $this->results);
     $log->table($table);
 }
 /**
  * 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', 'start_time'));
     foreach (\Smarty_Internal_Debug::$template_data as $template_file) {
         $template_file['name'] = str_replace($this->rootDir, '', $template_file['name']);
         $rows[] = array_values($template_file);
     }
     $label = "Benchmark Template";
     $table = array($label, $rows);
     $log->table($table);
 }
 /**
  * Logs all database process to the internal log object.
  * Iterates all queries of the query profiler and writes the query,
  * the parameter and the elapsed seconds for the query into a new row of the log.
  */
 public function logResults(Logger $log)
 {
     $rows = array(array('time', 'count', 'sql', 'params'));
     $counts = array(10000);
     $totalTime = 0;
     $queries = $this->modelLogger->queries;
     if (empty($queries)) {
         return;
     }
     /** @var $query Zend_Db_Profiler_Query */
     foreach ($queries as $query) {
         $id = md5($query['sql']);
         $totalTime += $query['executionMS'];
         if (!isset($rows[$id])) {
             $rows[$id] = array(number_format($query['executionMS'], 5, '.', ''), 1, $query['sql'], $query['params']);
             $counts[$id] = $query['executionMS'];
         } else {
             $rows[$id][1]++;
             $counts[$id] += $query['executionMS'];
             $rows[$id][0] = number_format($counts[$id], 5, '.', '');
         }
     }
     //array_multisort($counts, SORT_NUMERIC, SORT_DESC, $rows);
     $rows = array_values($rows);
     $totalTime = round($totalTime, 5);
     $totalCount = count($queries);
     $label = "Model Querys ({$totalCount} @ {$totalTime} sec)";
     $table = array($label, $rows);
     $log->table($table);
 }
 /**
  * Logs all database process to the internal log object.
  * Iterates all queries of the query profiler and writes the query,
  * the parameter and the elapsed seconds for the query into a new row of the log.
  */
 public function logResults(Logger $log)
 {
     /** @var $profiler \Zend_Db_Profiler */
     $profiler = $this->db->getProfiler();
     $rows = array(array('time', 'count', 'sql', 'params'));
     $counts = array(10000);
     $total_time = 0;
     $queryProfiles = $profiler->getQueryProfiles();
     if (!$queryProfiles) {
         return;
     }
     /** @var $query \Zend_Db_Profiler_Query */
     foreach ($queryProfiles as $query) {
         $id = md5($query->getQuery());
         $total_time += $query->getElapsedSecs();
         if (!isset($rows[$id])) {
             $rows[$id] = array(number_format($query->getElapsedSecs(), 5, '.', ''), 1, $query->getQuery(), $query->getQueryParams());
             $counts[$id] = $query->getElapsedSecs();
         } else {
             $rows[$id][1]++;
             $counts[$id] += $query->getElapsedSecs();
             $rows[$id][0] = number_format($counts[$id], 5, '.', '');
         }
     }
     array_multisort($counts, SORT_NUMERIC, SORT_DESC, $rows);
     $rows = array_values($rows);
     $total_time = round($total_time, 5);
     $total_count = $profiler->getTotalNumQueries();
     $label = "Database Querys ({$total_count} @ {$total_time} sec)";
     $table = array($label, $rows);
     $log->table($table);
 }
 /**
  * Writes an exception to the plugin log.
  *
  * @param string $message
  * @param Exception $e
  */
 private function logException($message, Exception $e)
 {
     $context = ['exception' => $e];
     if ($e instanceof RequestException) {
         $context['response'] = $e->getResponse();
     }
     $this->logger->error($message . ': ' . $e->getMessage(), $context);
 }
Example #8
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);
 }
 /**
  * @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);
     }
 }
Example #10
0
 /**
  * calls every given url with the specific shop cookie
  *
  * @param string[] $urls
  * @param integer $shopId
  */
 public function callUrls($urls, $shopId)
 {
     $shop = $this->getShopDataById($shopId);
     $guzzleConfig = [];
     if (!empty($shop["main_id"])) {
         //is not the main shop call url without shop cookie encoded in it
         $guzzleConfig['cookies'] = ['shop' => $shopId];
     }
     foreach ($urls as $url) {
         $request = $this->guzzleClient->createRequest('GET', $url, $guzzleConfig);
         try {
             $this->guzzleClient->send($request);
         } catch (\Exception $e) {
             $this->logger->error("Warm up http-cache error with shopId " . $shopId . " " . $e->getMessage());
         }
     }
 }
Example #11
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);
 }
 /**
  * @param Logger $log
  * @return mixed
  */
 public function logResults(Logger $log)
 {
     foreach ($this->results as $result) {
         $log->table($result);
     }
 }