3 namespace Drupal\webprofiler\DataCollector;
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;
13 * Collects data about frontend performance.
15 class PerformanceTimingDataCollector extends DataCollector implements DrupalDataCollectorInterface {
17 use StringTranslationTrait, DrupalDataCollectorTrait;
22 public function collect(Request $request, Response $response, \Exception $exception = NULL) {
29 public function setData($data) {
30 $this->data['performance'] = $data;
36 public function getName() {
37 return 'performance_timing';
43 public function getTitle() {
44 return $this->t('Performance Timing');
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())]);
62 public function getIcon() {
63 return 'iVBORw0KGgoAAAANSUhEUgAAABUAAAAcCAYAAACOGPReAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQJJREFUeNpi/P//PwO1ARMDDcCooUPEUEYi1AgAcQIQ+0P5H4B4IxAvwKaYmCSqAMT7gbgBajhMrB8qLkCsoQFQQ0CuOw/EBjgsLIAajmEouvdBhukD8UQgdkASwwXuA7EhNEhwuvQ8iXHSj2Q53FBY7BtADVxIoqEfoQYnYJPEF3bEROZ6WDDBvO+ALcCxJCsBAmpA4SuA7P2PBDQUEOGTDTA1TNCYs6dCRgIlxQswQ0GMB0A8nwgv4gqa+VCXgpMWC1QiEerF9WgaDmJJp/OhkUNIHUHQgJ4ecQHkiMKXXALQIowqpdR8pJi/AA0qvC4lFsyHYqK8zzhaRQ8NQwECDABNaU12xhTp2QAAAABJRU5ErkJggg==';
69 public function getData() {
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();