Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / modules / contrib / devel / webprofiler / src / DataCollector / PerformanceTimingDataCollector.php
1 <?php
2
3 namespace Drupal\webprofiler\DataCollector;
4
5 use Drupal\webprofiler\DrupalDataCollectorInterface;
6 use Drupal\Core\StringTranslation\StringTranslationTrait;
7 use Drupal\webprofiler\Frontend\PerformanceTimingData;
8 use Symfony\Component\HttpFoundation\Request;
9 use Symfony\Component\HttpFoundation\Response;
10 use Symfony\Component\HttpKernel\DataCollector\DataCollector;
11
12 /**
13  * Collects data about frontend performance.
14  */
15 class PerformanceTimingDataCollector extends DataCollector implements DrupalDataCollectorInterface {
16
17   use StringTranslationTrait, DrupalDataCollectorTrait;
18
19   /**
20    * {@inheritdoc}
21    */
22   public function collect(Request $request, Response $response, \Exception $exception = NULL) {
23
24   }
25
26   /**
27    * @param $data
28    */
29   public function setData($data) {
30     $this->data['performance'] = $data;
31   }
32
33   /**
34    * {@inheritdoc}
35    */
36   public function getName() {
37     return 'performance_timing';
38   }
39
40   /**
41    * {@inheritdoc}
42    */
43   public function getTitle() {
44     return $this->t('Performance Timing');
45   }
46
47   /**
48    * {@inheritdoc}
49    */
50   public function getPanelSummary() {
51     if (isset($this->data['performance'])) {
52       $performanceData = new PerformanceTimingData($this->data['performance']);
53       return $this->t('TTFB: @ttfb', ['@ttfb' => sprintf('%.0f ms', $performanceData->getTtfbTiming())]);
54     }
55
56     return NULL;
57   }
58
59   /**
60    * {@inheritdoc}
61    */
62   public function getIcon() {
63     return 'iVBORw0KGgoAAAANSUhEUgAAABUAAAAcCAYAAACOGPReAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQJJREFUeNpi/P//PwO1ARMDDcCooUPEUEYi1AgAcQIQ+0P5H4B4IxAvwKaYmCSqAMT7gbgBajhMrB8qLkCsoQFQQ0CuOw/EBjgsLIAajmEouvdBhukD8UQgdkASwwXuA7EhNEhwuvQ8iXHSj2Q53FBY7BtADVxIoqEfoQYnYJPEF3bEROZ6WDDBvO+ALcCxJCsBAmpA4SuA7P2PBDQUEOGTDTA1TNCYs6dCRgIlxQswQ0GMB0A8nwgv4gqa+VCXgpMWC1QiEerF9WgaDmJJp/OhkUNIHUHQgJ4ecQHkiMKXXALQIowqpdR8pJi/AA0qvC4lFsyHYqK8zzhaRQ8NQwECDABNaU12xhTp2QAAAABJRU5ErkJggg==';
64   }
65
66   /**
67    * {@inheritdoc}
68    */
69   public function getData() {
70     $data = $this->data;
71
72     if (isset($this->data['performance'])) {
73       $performanceData = new PerformanceTimingData($this->data['performance']);
74       $data['performance']['computed']['DNS lookup time'] = $performanceData->getDNSTiming();
75       $data['performance']['computed']['TCP handshake time'] = $performanceData->getTCPTiming();
76       $data['performance']['computed']['Time to first byte'] = $performanceData->getTtfbTiming();
77       $data['performance']['computed']['Data download time'] = $performanceData->getDataTiming();
78       $data['performance']['computed']['DOM building time'] = $performanceData->getDomTiming();
79     }
80
81     return $data;
82   }
83 }