Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE)
 {
     // TODO Probably we can move here the database log start and the initial
     //   read of memory usage.
     Timer::start('devel_page');
     return $this->httpKernel->handle($request, $type, $catch);
 }
 public function __invoke(array $record)
 {
     $record['extra']['time_ms'] = Timer::read(self::class);
     if (isset(self::$logger)) {
         $record['extra']['queries'] = count(self::$logger->get(self::class));
     }
     return $record;
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE)
 {
     Timer::start('devel_page');
     if ($this->config->get('memory')) {
         // TODO: Avoid global.
         global $memory_init;
         $memory_init = memory_get_usage();
     }
     if ($this->config->get('query_display')) {
         Database::startLog('devel');
     }
     return $this->httpKernel->handle($request, $type, $catch);
 }
 /**
  * @param string $id
  * @param int $invalidBehavior
  *
  * @return object
  */
 public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
 {
     if (!$this->stopwatch && $this->has('stopwatch')) {
         $this->stopwatch = parent::get('stopwatch');
         $this->stopwatch->openSection();
         $this->hasStopwatch = TRUE;
     }
     if ('stopwatch' === $id) {
         return $this->stopwatch;
     }
     Timer::start($id);
     if ($this->hasStopwatch) {
         $e = $this->stopwatch->start($id, 'service');
     }
     $service = parent::get($id, $invalidBehavior);
     $this->tracedData[$id] = Timer::stop($id);
     if ($this->hasStopwatch && $e->isStarted()) {
         $e->stop();
     }
     return $service;
 }
Exemplo n.º 5
0
 /**
  * Tests Timer::read() time accumulation accuracy across multiple restarts.
  *
  * @covers ::start
  * @covers ::stop
  * @covers ::read
  */
 public function testTimer()
 {
     Timer::start('test');
     usleep(5000);
     $value = Timer::read('test');
     usleep(5000);
     $value2 = Timer::read('test');
     usleep(5000);
     $value3 = Timer::read('test');
     usleep(5000);
     $value4 = Timer::read('test');
     // Although we sleep for 5 milliseconds, we should test that at least 4 ms
     // have past because usleep() is not reliable on Windows. See
     // http://php.net/manual/en/function.usleep.php for more information. The
     // purpose of the test to validate that the Timer class can measure elapsed
     // time not the granularity of usleep() on a particular OS.
     $this->assertGreaterThanOrEqual(4, $value, 'Timer failed to measure at least 4 milliseconds of sleeping while running.');
     $this->assertGreaterThanOrEqual($value + 4, $value2, 'Timer failed to measure at least 8 milliseconds of sleeping while running.');
     $this->assertGreaterThanOrEqual($value2 + 4, $value3, 'Timer failed to measure at least 12 milliseconds of sleeping while running.');
     $this->assertGreaterThanOrEqual($value3 + 4, $value4, 'Timer failed to measure at least 16 milliseconds of sleeping while running.');
     // Stop the timer.
     $value5 = Timer::stop('test');
     $this->assertGreaterThanOrEqual($value4, $value5['time'], 'Timer measured after stopping was not greater than last measurement.');
     // Read again.
     $value6 = Timer::read('test');
     $this->assertEquals($value5['time'], $value6, 'Timer measured after stopping was not equal to the stopped time.');
     // Restart.
     Timer::start('test');
     usleep(5000);
     $value7 = Timer::read('test');
     $this->assertGreaterThanOrEqual($value6 + 4, $value7, 'Timer failed to measure at least 16 milliseconds of sleeping while running.');
     // Stop again.
     $value8 = Timer::stop('test');
     $value9 = Timer::read('test');
     $this->assertEquals($value8['time'], $value9, 'Timer measured after stopping not equal to stop time.');
 }
Exemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     //Registers namespaces for disabled modules.
     $this->getTestDiscovery()->registerTestNamespaces();
     $testClass = $input->getArgument('test-class');
     $url = $input->getOption('url');
     if (!$url) {
         $io->error($this->trans('commands.test.run.messages.url-required'));
         return;
     }
     $this->setEnvironment($url);
     // Create simpletest test id
     $testId = db_insert('simpletest_test_id')->useDefaults(array('test_id'))->execute();
     if (is_subclass_of($testClass, 'PHPUnit_Framework_TestCase')) {
         $io->info($this->trans('commands.test.run.messages.phpunit-pending'));
         return;
     } else {
         $test = new $testClass($testId);
         $io->info($this->trans('commands.test.run.messages.starting-test'));
         Timer::start('run-tests');
         $test->run();
         $end = Timer::stop('run-tests');
         $io->simple($this->trans('commands.test.run.messages.test-duration') . ': ' . \Drupal::service('date.formatter')->formatInterval($end['time'] / 1000));
         $io->simple($this->trans('commands.test.run.messages.test-pass') . ': ' . $test->results['#pass']);
         $io->commentBlock($this->trans('commands.test.run.messages.test-fail') . ': ' . $test->results['#fail']);
         $io->commentBlock($this->trans('commands.test.run.messages.test-exception') . ': ' . $test->results['#exception']);
         $io->simple($this->trans('commands.test.run.messages.test-debug') . ': ' . $test->results['#debug']);
         $this->getModuleHandler()->invokeAll('test_finished', array($test->results));
         $io->newLine();
         $io->info($this->trans('commands.test.run.messages.test-summary'));
         $io->newLine();
         $currentClass = null;
         $currentGroup = null;
         $currentStatus = null;
         $messages = $this->simpletestScriptLoadMessagesByTestIds(array($testId));
         foreach ($messages as $message) {
             if ($currentClass === null || $currentClass != $message->test_class) {
                 $currentClass = $message->test_class;
                 $io->comment($message->test_class);
             }
             if ($currentGroup === null || $currentGroup != $message->message_group) {
                 $currentGroup = $message->message_group;
             }
             if ($currentStatus === null || $currentStatus != $message->status) {
                 $currentStatus = $message->status;
                 if ($message->status == 'fail') {
                     $io->error($this->trans('commands.test.run.messages.group') . ':' . $message->message_group . ' ' . $this->trans('commands.test.run.messages.status') . ':' . $message->status);
                     $io->newLine();
                 } else {
                     $io->info($this->trans('commands.test.run.messages.group') . ':' . $message->message_group . ' ' . $this->trans('commands.test.run.messages.status') . ':' . $message->status);
                     $io->newLine();
                 }
             }
             $io->simple($this->trans('commands.test.run.messages.file') . ': ' . str_replace($this->getDrupalHelper()->getRoot(), '', $message->file));
             $io->simple($this->trans('commands.test.run.messages.method') . ': ' . $message->function);
             $io->simple($this->trans('commands.test.run.messages.line') . ': ' . $message->line);
             $io->simple($this->trans('commands.test.run.messages.message') . ': ' . $message->message);
             $io->newLine();
         }
         return;
     }
 }
Exemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function boot()
 {
     if ($this->booted) {
         return $this;
     }
     // Start a page timer:
     Timer::start('page');
     // Ensure that findSitePath is set.
     if (!$this->sitePath) {
         throw new \Exception('Kernel does not have site path set before calling boot()');
     }
     // Initialize the container.
     $this->initializeContainer();
     // Ensure mt_rand() is reseeded to prevent random values from one page load
     // being exploited to predict random values in subsequent page loads.
     $seed = unpack("L", Crypt::randomBytes(4));
     mt_srand($seed[1]);
     $this->booted = TRUE;
     return $this;
 }
Exemplo n.º 8
0
 public function renderPreview($display_id, $args = array())
 {
     // Save the current path so it can be restored before returning from this function.
     $request_stack = \Drupal::requestStack();
     $current_request = $request_stack->getCurrentRequest();
     $executable = $this->getExecutable();
     // Determine where the query and performance statistics should be output.
     $config = \Drupal::config('views.settings');
     $show_query = $config->get('ui.show.sql_query.enabled');
     $show_info = $config->get('ui.show.preview_information');
     $show_location = $config->get('ui.show.sql_query.where');
     $show_stats = $config->get('ui.show.performance_statistics');
     if ($show_stats) {
         $show_stats = $config->get('ui.show.sql_query.where');
     }
     $combined = $show_query && $show_stats;
     $rows = array('query' => array(), 'statistics' => array());
     $errors = $executable->validate();
     $executable->destroy();
     if (empty($errors)) {
         $this->ajax = TRUE;
         $executable->live_preview = TRUE;
         // AJAX happens via HTTP POST but everything expects exposed data to
         // be in GET. Copy stuff but remove ajax-framework specific keys.
         // If we're clicking on links in a preview, though, we could actually
         // have some input in the query parameters, so we merge request() and
         // query() to ensure we get it all.
         $exposed_input = array_merge(\Drupal::request()->request->all(), \Drupal::request()->query->all());
         foreach (array('view_name', 'view_display_id', 'view_args', 'view_path', 'view_dom_id', 'pager_element', 'view_base_path', AjaxResponseSubscriber::AJAX_REQUEST_PARAMETER, 'ajax_page_state', 'form_id', 'form_build_id', 'form_token') as $key) {
             if (isset($exposed_input[$key])) {
                 unset($exposed_input[$key]);
             }
         }
         $executable->setExposedInput($exposed_input);
         if (!$executable->setDisplay($display_id)) {
             return ['#markup' => t('Invalid display id @display', array('@display' => $display_id))];
         }
         $executable->setArguments($args);
         // Store the current view URL for later use:
         if ($executable->hasUrl() && $executable->display_handler->getOption('path')) {
             $path = $executable->getUrl();
         }
         // Make view links come back to preview.
         // Also override the current path so we get the pager, and make sure the
         // Request object gets all of the proper values from $_SERVER.
         $request = Request::createFromGlobals();
         $request->attributes->set(RouteObjectInterface::ROUTE_NAME, 'entity.view.preview_form');
         $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, \Drupal::service('router.route_provider')->getRouteByName('entity.view.preview_form'));
         $request->attributes->set('view', $this->storage);
         $request->attributes->set('display_id', $display_id);
         $raw_parameters = new ParameterBag();
         $raw_parameters->set('view', $this->id());
         $raw_parameters->set('display_id', $display_id);
         $request->attributes->set('_raw_variables', $raw_parameters);
         foreach ($args as $key => $arg) {
             $request->attributes->set('arg_' . $key, $arg);
         }
         $request_stack->push($request);
         // Suppress contextual links of entities within the result set during a
         // Preview.
         // @todo We'll want to add contextual links specific to editing the View, so
         //   the suppression may need to be moved deeper into the Preview pipeline.
         views_ui_contextual_links_suppress_push();
         $show_additional_queries = $config->get('ui.show.additional_queries');
         Timer::start('entity.view.preview_form');
         if ($show_additional_queries) {
             $this->startQueryCapture();
         }
         // Execute/get the view preview.
         $preview = $executable->preview($display_id, $args);
         if ($show_additional_queries) {
             $this->endQueryCapture();
         }
         $this->render_time = Timer::stop('entity.view.preview_form');
         views_ui_contextual_links_suppress_pop();
         // Prepare the query information and statistics to show either above or
         // below the view preview.
         if ($show_info || $show_query || $show_stats) {
             // Get information from the preview for display.
             if (!empty($executable->build_info['query'])) {
                 if ($show_query) {
                     $query_string = $executable->build_info['query'];
                     // Only the sql default class has a method getArguments.
                     $quoted = array();
                     if ($executable->query instanceof Sql) {
                         $quoted = $query_string->getArguments();
                         $connection = Database::getConnection();
                         foreach ($quoted as $key => $val) {
                             if (is_array($val)) {
                                 $quoted[$key] = implode(', ', array_map(array($connection, 'quote'), $val));
                             } else {
                                 $quoted[$key] = $connection->quote($val);
                             }
                         }
                     }
                     $rows['query'][] = array(array('data' => array('#type' => 'inline_template', '#template' => "<strong>{% trans 'Query' %}</strong>")), array('data' => array('#type' => 'inline_template', '#template' => '<pre>{{ query }}</pre>', '#context' => array('query' => strtr($query_string, $quoted)))));
                     if (!empty($this->additionalQueries)) {
                         $queries[] = array('#prefix' => '<strong>', '#markup' => t('These queries were run during view rendering:'), '#suffix' => '</strong>');
                         foreach ($this->additionalQueries as $query) {
                             $query_string = strtr($query['query'], $query['args']);
                             $queries[] = array('#prefix' => "\n", '#markup' => t('[@time ms] @query', array('@time' => round($query['time'] * 100000, 1) / 100000.0, '@query' => $query_string)));
                         }
                         $rows['query'][] = array(array('data' => array('#type' => 'inline_template', '#template' => "<strong>{% trans 'Other queries' %}</strong>")), array('data' => array('#prefix' => '<pre>', 'queries' => $queries, '#suffix' => '</pre>')));
                     }
                 }
                 if ($show_info) {
                     $rows['query'][] = array(array('data' => array('#type' => 'inline_template', '#template' => "<strong>{% trans 'Title' %}</strong>")), Xss::filterAdmin($executable->getTitle()));
                     if (isset($path)) {
                         // @todo Views should expect and store a leading /. See:
                         //   https://www.drupal.org/node/2423913
                         $path = \Drupal::l($path->toString(), $path);
                     } else {
                         $path = t('This display has no path.');
                     }
                     $rows['query'][] = array(array('data' => array('#prefix' => '<strong>', '#markup' => t('Path'), '#suffix' => '</strong>')), array('data' => array('#markup' => $path)));
                 }
                 if ($show_stats) {
                     $rows['statistics'][] = array(array('data' => array('#type' => 'inline_template', '#template' => "<strong>{% trans 'Query build time' %}</strong>")), t('@time ms', array('@time' => intval($executable->build_time * 100000) / 100)));
                     $rows['statistics'][] = array(array('data' => array('#type' => 'inline_template', '#template' => "<strong>{% trans 'Query execute time' %}</strong>")), t('@time ms', array('@time' => intval($executable->execute_time * 100000) / 100)));
                     $rows['statistics'][] = array(array('data' => array('#type' => 'inline_template', '#template' => "<strong>{% trans 'View render time' %}</strong>")), t('@time ms', array('@time' => intval($executable->render_time * 100000) / 100)));
                 }
                 \Drupal::moduleHandler()->alter('views_preview_info', $rows, $executable);
             } else {
                 // No query was run. Display that information in place of either the
                 // query or the performance statistics, whichever comes first.
                 if ($combined || $show_location === 'above') {
                     $rows['query'][] = array(array('data' => array('#prefix' => '<strong>', '#markup' => t('Query'), '#suffix' => '</strong>')), array('data' => array('#markup' => t('No query was run'))));
                 } else {
                     $rows['statistics'][] = array(array('data' => array('#prefix' => '<strong>', '#markup' => t('Query'), '#suffix' => '</strong>')), array('data' => array('#markup' => t('No query was run'))));
                 }
             }
         }
     } else {
         foreach ($errors as $display_errors) {
             foreach ($display_errors as $error) {
                 drupal_set_message($error, 'error');
             }
         }
         $preview = t('Unable to preview due to validation errors.');
     }
     // Assemble the preview, the query info, and the query statistics in the
     // requested order.
     $table = array('#type' => 'table', '#prefix' => '<div class="views-query-info">', '#suffix' => '</div>');
     if ($show_location === 'above' || $show_location === 'below') {
         if ($combined) {
             $table['#rows'] = array_merge($rows['query'], $rows['statistics']);
         } else {
             $table['#rows'] = $rows['query'];
         }
     } elseif ($show_stats === 'above' || $show_stats === 'below') {
         $table['#rows'] = $rows['statistics'];
     }
     if ($show_location === 'above' || $show_stats === 'above') {
         $output = ['table' => $table, 'preview' => $preview];
     } elseif ($show_location === 'below' || $show_stats === 'below') {
         $output = ['preview' => $preview, 'table' => $table];
     }
     // Ensure that we just remove an additional request we pushed earlier.
     // This could happen if $errors was not empty.
     if ($request_stack->getCurrentRequest() != $current_request) {
         $request_stack->pop();
     }
     return $output;
 }
Exemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     //Registers namespaces for disabled modules.
     $this->getTestDiscovery()->registerTestNamespaces();
     $test_class = $input->getArgument('test-class');
     $url = $input->getOption('url');
     if (!$url) {
         $output->writeln('[+] <error>' . $this->trans('commands.test.run.messages.url-required') . '</error>');
         return;
     }
     $this->setEnvironment($url);
     // Create simpletest test id
     $test_id = db_insert('simpletest_test_id')->useDefaults(array('test_id'))->execute();
     if (is_subclass_of($test_class, 'PHPUnit_Framework_TestCase')) {
         $output->writeln('[+] <info>' . $this->trans('commands.test.run.messages.phpunit-pending') . '</info>');
         return;
     } else {
         $test = new $test_class($test_id);
         $output->writeln('[+] <info>' . $this->trans('commands.test.run.messages.starting-test') . '</info>');
         Timer::start('run-tests');
         $test->run();
         $end = Timer::stop('run-tests');
         $output->writeln('[+] <info>' . $this->trans('commands.test.run.messages.test-duration') . ': ' . \Drupal::service('date.formatter')->formatInterval($end['time'] / 1000) . '</info>');
         $output->writeln('[+] <info>' . $this->trans('commands.test.run.messages.test-pass') . ': ' . $test->results['#pass'] . '</info>');
         $output->writeln('[+] <error>' . $this->trans('commands.test.run.messages.test-fail') . ': ' . $test->results['#fail'] . '</error>');
         $output->writeln('[+] <error>' . $this->trans('commands.test.run.messages.test-exception') . ': ' . $test->results['#exception'] . '</error>');
         $output->writeln('[+] <info>' . $this->trans('commands.test.run.messages.test-debug') . ': ' . $test->results['#debug'] . '</info>');
         $this->getModuleHandler()->invokeAll('test_finished', array($test->results));
         print "\n";
         $output->writeln($this->trans('commands.test.run.messages.test-summary'));
         print "\n";
         $current_class = null;
         $current_group = null;
         $current_status = null;
         $messages = $this->simpletest_script_load_messages_by_test_ids(array($test_id));
         foreach ($messages as $message) {
             if ($current_class === null || $current_class != $message->test_class) {
                 $current_class = $message->test_class;
                 $output->writeln('[+] <info>' . $message->test_class . '</info>');
             }
             if ($current_group === null || $current_group != $message->message_group) {
                 $current_group = $message->message_group;
             }
             if ($current_status === null || $current_status != $message->status) {
                 $current_status = $message->status;
                 if ($message->status == 'fail') {
                     $output->writeln('[+] <error>' . $this->trans('commands.test.run.messages.group') . ':' . $message->message_group . ' ' . $this->trans('commands.test.run.messages.status') . ':' . $message->status . '</error>');
                     print "\n";
                 } else {
                     $output->writeln('[+] <info>' . $this->trans('commands.test.run.messages.group') . ':' . $message->message_group . ' ' . $this->trans('commands.test.run.messages.status') . ':' . $message->status . '</info>');
                     print "\n";
                 }
             }
             $output->writeln('[-] <info>' . $this->trans('commands.test.run.messages.file') . ': ' . str_replace(DRUPAL_ROOT, '', $message->file) . '</info>');
             $output->writeln('[-] <info>' . $this->trans('commands.test.run.messages.method') . ': ' . $message->function . '</info>');
             $output->writeln('[-] <info>' . $this->trans('commands.test.run.messages.line') . ': ' . $message->line . '</info>');
             $output->writeln('[-] <info>' . $this->trans('commands.test.run.messages.message') . ': ' . $message->message . '</info>');
             print "\n";
         }
         return;
     }
 }
Exemplo n.º 10
0
 public function renderPreview($display_id, $args = array())
 {
     // Save the current path so it can be restored before returning from this function.
     $old_q = current_path();
     // Determine where the query and performance statistics should be output.
     $config = \Drupal::config('views.settings');
     $show_query = $config->get('ui.show.sql_query.enabled');
     $show_info = $config->get('ui.show.preview_information');
     $show_location = $config->get('ui.show.sql_query.where');
     $show_stats = $config->get('ui.show.performance_statistics');
     if ($show_stats) {
         $show_stats = $config->get('ui.show.sql_query.where');
     }
     $combined = $show_query && $show_stats;
     $rows = array('query' => array(), 'statistics' => array());
     $output = '';
     $errors = $this->executable->validate();
     $this->executable->destroy();
     if (empty($errors)) {
         $this->ajax = TRUE;
         $this->executable->live_preview = TRUE;
         // AJAX happens via HTTP POST but everything expects exposed data to
         // be in GET. Copy stuff but remove ajax-framework specific keys.
         // If we're clicking on links in a preview, though, we could actually
         // have some input in the query parameters, so we merge request() and
         // query() to ensure we get it all.
         $exposed_input = array_merge(\Drupal::request()->request->all(), \Drupal::request()->query->all());
         foreach (array('view_name', 'view_display_id', 'view_args', 'view_path', 'view_dom_id', 'pager_element', 'view_base_path', 'ajax_html_ids', 'ajax_page_state', 'form_id', 'form_build_id', 'form_token') as $key) {
             if (isset($exposed_input[$key])) {
                 unset($exposed_input[$key]);
             }
         }
         $this->executable->setExposedInput($exposed_input);
         if (!$this->executable->setDisplay($display_id)) {
             return t('Invalid display id @display', array('@display' => $display_id));
         }
         $this->executable->setArguments($args);
         // Store the current view URL for later use:
         if ($this->executable->display_handler->getOption('path')) {
             $path = $this->executable->getUrl();
         }
         // Make view links come back to preview.
         $this->override_path = 'admin/structure/views/view/' . $this->id() . '/preview/' . $display_id;
         // Also override the current path so we get the pager.
         $original_path = current_path();
         $q = _current_path($this->override_path);
         if ($args) {
             $q .= '/' . implode('/', $args);
             _current_path($q);
         }
         // Suppress contextual links of entities within the result set during a
         // Preview.
         // @todo We'll want to add contextual links specific to editing the View, so
         //   the suppression may need to be moved deeper into the Preview pipeline.
         views_ui_contextual_links_suppress_push();
         $show_additional_queries = $config->get('ui.show.additional_queries');
         Timer::start('entity.view.preview_form');
         if ($show_additional_queries) {
             $this->startQueryCapture();
         }
         // Execute/get the view preview.
         $preview = $this->executable->preview($display_id, $args);
         $preview = drupal_render($preview);
         if ($show_additional_queries) {
             $this->endQueryCapture();
         }
         $this->render_time = Timer::stop('entity.view.preview_form');
         views_ui_contextual_links_suppress_pop();
         // Reset variables.
         unset($this->override_path);
         _current_path($original_path);
         // Prepare the query information and statistics to show either above or
         // below the view preview.
         if ($show_info || $show_query || $show_stats) {
             // Get information from the preview for display.
             if (!empty($this->executable->build_info['query'])) {
                 if ($show_query) {
                     $query_string = $this->executable->build_info['query'];
                     // Only the sql default class has a method getArguments.
                     $quoted = array();
                     if ($this->executable->query instanceof Sql) {
                         $quoted = $query_string->getArguments();
                         $connection = Database::getConnection();
                         foreach ($quoted as $key => $val) {
                             if (is_array($val)) {
                                 $quoted[$key] = implode(', ', array_map(array($connection, 'quote'), $val));
                             } else {
                                 $quoted[$key] = $connection->quote($val);
                             }
                         }
                     }
                     $rows['query'][] = array(array('data' => array('#type' => 'inline_template', '#template' => "<strong>{% trans 'Query' %}</strong>")), array('data' => array('#type' => 'inline_template', '#template' => '<pre>{{ query }}</pre>', '#context' => array('query' => strtr($query_string, $quoted)))));
                     if (!empty($this->additionalQueries)) {
                         $queries = '<strong>' . t('These queries were run during view rendering:') . '</strong>';
                         foreach ($this->additionalQueries as $query) {
                             if ($queries) {
                                 $queries .= "\n";
                             }
                             $query_string = strtr($query['query'], $query['args']);
                             $queries .= t('[@time ms] @query', array('@time' => round($query['time'] * 100000, 1) / 100000.0, '@query' => $query_string));
                         }
                         $rows['query'][] = array(array('data' => array('#type' => 'inline_template', '#template' => "<strong>{% trans 'Other queries' %}</strong>")), SafeMarkup::set('<pre>' . $queries . '</pre>'));
                     }
                 }
                 if ($show_info) {
                     $rows['query'][] = array(array('data' => array('#type' => 'inline_template', '#template' => "<strong>{% trans 'Title' %}</strong>")), Xss::filterAdmin($this->executable->getTitle()));
                     if (isset($path)) {
                         $path = _l($path, $path);
                     } else {
                         $path = t('This display has no path.');
                     }
                     $rows['query'][] = array(SafeMarkup::set('<strong>' . t('Path') . '</strong>'), $path);
                 }
                 if ($show_stats) {
                     $rows['statistics'][] = array('<strong>' . t('Query build time') . '</strong>', t('@time ms', array('@time' => intval($this->executable->build_time * 100000) / 100)));
                     $rows['statistics'][] = array('<strong>' . t('Query execute time') . '</strong>', t('@time ms', array('@time' => intval($this->executable->execute_time * 100000) / 100)));
                     $rows['statistics'][] = array('<strong>' . t('View render time') . '</strong>', t('@time ms', array('@time' => intval($this->executable->render_time * 100000) / 100)));
                 }
                 \Drupal::moduleHandler()->alter('views_preview_info', $rows, $this->executable);
             } else {
                 // No query was run. Display that information in place of either the
                 // query or the performance statistics, whichever comes first.
                 if ($combined || $show_location === 'above') {
                     $rows['query'] = array(array(SafeMarkup::set('<strong>' . t('Query') . '</strong>'), t('No query was run')));
                 } else {
                     $rows['statistics'] = array(array(SafeMarkup::set('<strong>' . t('Query') . '</strong>'), t('No query was run')));
                 }
             }
         }
     } else {
         foreach ($errors as $display_errors) {
             foreach ($display_errors as $error) {
                 drupal_set_message($error, 'error');
             }
         }
         $preview = t('Unable to preview due to validation errors.');
     }
     // Assemble the preview, the query info, and the query statistics in the
     // requested order.
     $table = array('#type' => 'table', '#prefix' => '<div class="views-query-info">', '#suffix' => '</div>');
     if ($show_location === 'above' || $show_location === 'below') {
         if ($combined) {
             $table['#rows'] = array_merge($rows['query'], $rows['statistics']);
         } else {
             $table['#rows'] = $rows['query'];
         }
     } elseif ($show_stats === 'above' || $show_stats === 'below') {
         $table['#rows'] = $rows['statistics'];
     }
     if ($show_location === 'above' || $show_stats === 'above') {
         $output .= drupal_render($table) . $preview;
     } elseif ($show_location === 'below' || $show_stats === 'below') {
         $output .= $preview . drupal_render($table);
     }
     _current_path($old_q);
     return $output;
 }
Exemplo n.º 11
0
 /**
  * Invokes any cron handlers implementing hook_cron.
  */
 protected function invokeCronHandlers()
 {
     $module_previous = '';
     // Iterate through the modules calling their cron handlers (if any):
     foreach ($this->moduleHandler->getImplementations('cron') as $module) {
         if (!$module_previous) {
             $this->logger->notice('Starting execution of @module_cron().', ['@module' => $module]);
         } else {
             $this->logger->notice('Starting execution of @module_cron(), execution of @module_previous_cron() took @time.', ['@module' => $module, '@module_previous' => $module_previous, '@time' => Timer::read('cron_' . $module_previous) . 'ms']);
         }
         Timer::start('cron_' . $module);
         // Do not let an exception thrown by one module disturb another.
         try {
             $this->moduleHandler->invoke($module, 'cron');
         } catch (\Exception $e) {
             watchdog_exception('cron', $e);
         }
         Timer::stop('cron_' . $module);
         $module_previous = $module;
     }
     if ($module_previous) {
         $this->logger->notice('Execution of @module_previous_cron() took @time.', ['@module_previous' => $module_previous, '@time' => Timer::read('cron_' . $module_previous) . 'ms']);
     }
 }
Exemplo n.º 12
0
 /**
  * @param $operation
  *   Memcached operation. For example, 'get' or 'set'.
  *
  * @param $results
  *   Result of request to memcached.
  *
  * @param $memcached_keys
  *   Array which contains memcached key as an array keys and related
  *   Drupal cache id as an array values.
  *
  * @param $cache_bin
  *   Name of Drupal cache bin.
  *
  * @param $cluster_name
  *   Name of the memcached cluster defined in settings.
  */
 public static function process($operation, $results, $memcached_keys, $cache_bin, $cluster_name)
 {
     $key = 'memcache_storage_' . self::$counter;
     $used_time = Timer::read($key);
     if (sizeof($memcached_keys) > 1) {
         $operation .= 'Multi';
     }
     foreach ($memcached_keys as $memcached_key => $cache_key) {
         $result = $results;
         if (in_array($operation, ['get', 'getMulti'])) {
             $result = isset($results[$memcached_key]) ? TRUE : FALSE;
         }
         self::$log[] = ['operation' => $operation, 'used_time' => $used_time, 'result' => $result, 'cache_bin' => $cache_bin, 'cache_key' => $cache_key, 'memcached_key' => $memcached_key, 'cluster_name' => $cluster_name];
     }
 }
Exemplo n.º 13
0
 /**
  * {@inheritdoc}
  */
 public function boot()
 {
     if ($this->booted) {
         return $this;
     }
     // Start a page timer:
     Timer::start('page');
     // Load legacy and other functional code.
     require_once DRUPAL_ROOT . '/core/includes/common.inc';
     require_once DRUPAL_ROOT . '/core/includes/database.inc';
     require_once DRUPAL_ROOT . '/core/includes/path.inc';
     require_once DRUPAL_ROOT . '/core/includes/module.inc';
     require_once DRUPAL_ROOT . '/core/includes/theme.inc';
     require_once DRUPAL_ROOT . '/core/includes/pager.inc';
     require_once DRUPAL_ROOT . '/core/includes/menu.inc';
     require_once DRUPAL_ROOT . '/core/includes/tablesort.inc';
     require_once DRUPAL_ROOT . '/core/includes/file.inc';
     require_once DRUPAL_ROOT . '/core/includes/unicode.inc';
     require_once DRUPAL_ROOT . '/core/includes/form.inc';
     require_once DRUPAL_ROOT . '/core/includes/mail.inc';
     require_once DRUPAL_ROOT . '/core/includes/errors.inc';
     require_once DRUPAL_ROOT . '/core/includes/schema.inc';
     require_once DRUPAL_ROOT . '/core/includes/entity.inc';
     // Ensure that findSitePath is set.
     if (!$this->sitePath) {
         throw new \Exception('Kernel does not have site path set before calling boot()');
     }
     // Initialize the container.
     $this->initializeContainer();
     // Ensure mt_rand() is reseeded to prevent random values from one page load
     // being exploited to predict random values in subsequent page loads.
     $seed = unpack("L", Crypt::randomBytes(4));
     mt_srand($seed[1]);
     $this->container->get('stream_wrapper_manager')->register();
     $this->booted = TRUE;
     return $this;
 }