Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $config = $this->config('xhprof.config');
     $extension_loaded = $this->profiler->isLoaded();
     if ($extension_loaded) {
         $help = $this->t('Profile requests with the XHProf or uprofiler php extension.');
     } else {
         $help = $this->t('You must enable the !xhprof or !uprofiler php extension.', ['!xhprof' => $this->l('XHProf', Url::fromUri('https://www.drupal.org/node/946182')), '!uprofiler' => $this->l('uprofiler', Url::fromUri('https://github.com/FriendsOfPHP/uprofiler'))]);
     }
     $form['help'] = array('#type' => 'inline_template', '#template' => '<span class="warning">{{ help }}</span>', '#context' => array('help' => $help));
     $form['enabled'] = array('#type' => 'checkbox', '#title' => $this->t('Enable profiling of page views.'), '#default_value' => $extension_loaded & $config->get('enabled'), '#disabled' => !$extension_loaded);
     $form['settings'] = array('#title' => $this->t('Profiling settings'), '#type' => 'details', '#open' => TRUE, '#states' => array('invisible' => array('input[name="enabled"]' => array('checked' => FALSE))));
     $form['settings']['extension'] = array('#type' => 'select', '#title' => $this->t('Extension'), '#options' => $this->profiler->getExtensions(), '#default_value' => $config->get('extension'), '#description' => $this->t('Choose the extension to use for profiling. The recommended extension is !uprofiler because it is actively maintained.', ['!uprofiler' => $this->l('uprofiler', Url::fromUri('https://github.com/FriendsOfPHP/uprofiler'))]));
     $form['settings']['exclude'] = array('#type' => 'textarea', '#title' => $this->t('Exclude'), '#default_value' => $config->get('exclude'), '#description' => $this->t('Path to exclude for profiling. One path per line.'));
     $form['settings']['interval'] = array('#type' => 'number', '#title' => 'Profiling interval', '#min' => 0, '#default_value' => $config->get('interval'), '#description' => $this->t('The approximate number of requests between XHProf samples. Leave zero to profile all requests.'));
     $flags = array('FLAGS_CPU' => $this->t('Cpu'), 'FLAGS_MEMORY' => $this->t('Memory'), 'FLAGS_NO_BUILTINS' => $this->t('Exclude PHP builtin functions'));
     $form['settings']['flags'] = array('#type' => 'checkboxes', '#title' => 'Profile', '#options' => $flags, '#default_value' => $config->get('flags'), '#description' => $this->t('Flags to choose what profile.'));
     $form['settings']['exclude_indirect_functions'] = array('#type' => 'checkbox', '#title' => 'Exclude indirect functions', '#default_value' => $config->get('exclude_indirect_functions'), '#description' => $this->t('Exclude functions like %call_user_func and %call_user_func_array.', array('%call_user_func' => 'call_user_func', '%call_user_func_array' => 'call_user_func_array')));
     $options = $this->storageManager->getStorages();
     $form['settings']['storage'] = array('#type' => 'radios', '#title' => $this->t('Profile storage'), '#default_value' => $config->get('storage'), '#options' => $options, '#description' => $this->t('Choose the storage class.'));
     if ($this->moduleHandler->moduleExists('webprofiler')) {
         $form['webprofiler'] = array('#title' => $this->t('Webprofiler integration'), '#type' => 'details', '#open' => TRUE, '#states' => array('invisible' => array('input[name="enabled"]' => array('checked' => FALSE))));
         $form['webprofiler']['show_summary_toolbar'] = array('#type' => 'checkbox', '#title' => $this->t('Show summary data in toolbar.'), '#default_value' => $config->get('show_summary_toolbar'), '#description' => $this->t('Show data from the overall summary directly into the Webprofiler toolbar. May slow down the toolbar rendering.'));
     }
     return parent::buildForm($form, $form_state);
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function convert($value, $definition, $name, array $defaults)
 {
     try {
         return $this->profiler->getRun($value);
     } catch (\Exception $e) {
         return NULL;
     }
 }
 /**
  * @param \Symfony\Component\HttpFoundation\Response $response
  * @param string $xhprofRunId
  */
 protected function injectLink(Response $response, $xhprofRunId)
 {
     $content = $response->getContent();
     $pos = mb_strripos($content, '</body>');
     if (FALSE !== $pos) {
         $output = '<div class="xhprof-ui">' . $this->profiler->link($xhprofRunId) . '</div>';
         $content = mb_substr($content, 0, $pos) . $output . mb_substr($content, $pos);
         $response->setContent($content);
     }
 }
Ejemplo n.º 4
0
 /**
  *
  */
 public function runsAction()
 {
     $runs = $run = $this->profiler->getStorage()->getRuns();
     // Table attributes
     $attributes = array('id' => 'xhprof-runs-table');
     // Table header
     $header = array();
     $header[] = array('data' => t('View'));
     $header[] = array('data' => t('Path'), 'field' => 'path');
     $header[] = array('data' => t('Date'), 'field' => 'date', 'sort' => 'desc');
     // Table rows
     $rows = array();
     foreach ($runs as $run) {
         $row = array();
         $row[] = $this->l($run['run_id'], new Url('xhprof.run', array('run' => $run['run_id'])));
         $row[] = isset($run['path']) ? $run['path'] : '';
         $row[] = format_date($run['date'], 'small');
         $rows[] = $row;
     }
     $build['table'] = array('#type' => 'table', '#header' => $header, '#rows' => $rows, '#attributes' => $attributes);
     return $build;
 }
Ejemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function collect(Request $request, Response $response, \Exception $exception = NULL)
 {
     $this->data['run_id'] = $this->profiler->getRunId();
 }