function getCalculatedStats()

in fusion-plugin-browser-performance-emitter/src/server.js [65:136]


      function getCalculatedStats(timing, resourceEntries, paintTimes) {
        let calculated = {};
        if (!isEmpty(timing)) {
          calculated = {
            // time spent following redirects
            redirection_time: timing.fetchStart - timing.navigationStart,
            // time from the initial navigation to getting a response from the server
            time_to_first_byte: timing.responseStart - timing.navigationStart,
            // time from the initial request to having all blocking assets loaded
            dom_content_loaded:
              timing.domContentLoadedEventEnd - timing.fetchStart,
            // time from initial request to having all assets (blocking and nonblocking) loaded
            full_page_load: timing.loadEventEnd - timing.fetchStart,
            // dns lookup time
            dns: timing.domainLookupEnd - timing.domainLookupStart,
            // time to open tcp connection
            tcp_connection_time: timing.connectEnd - timing.connectStart,
            // time for browser to get back full html response from server
            browser_request_time: timing.responseEnd - timing.requestStart,
            // time for browser to receive initial response from server
            browser_request_first_byte:
              timing.responseStart - timing.requestStart,
            // time from receiving first byte to receiving full response
            browser_request_response_time:
              timing.responseEnd - timing.responseStart,
            // time to parse the html response into a DOM tree + load blocking resources
            dom_interactive_time: timing.domInteractive - timing.responseEnd,
            // time from having fully parsed html to having all assets loaded
            total_resource_load_time:
              timing.loadEventStart - timing.responseEnd,
            // time from having fully parsed html to having all blocking assets loaded
            total_blocking_resource_load_time:
              timing.domContentLoadedEventStart - timing.responseEnd,
          };
          if (paintTimes) {
            // $FlowFixMe
            calculated.first_paint_time = paintTimes.firstPaint;
            // $FlowFixMe
            calculated.first_contentful_paint_time =
              paintTimes.firstContentfulPaint;
          }
        }

        if (!isEmpty(resourceEntries)) {
          // $FlowFixMe
          calculated.resources_avg_load_time = {};
          // all of the values are on the prototype so we need to extract them
          const resourceLoadTimes = resourceEntries.reduce((memo, entry) => {
            const type = extractResourceType(entry.name);
            if (type) {
              if (!memo[type]) {
                memo[type] = [];
              }
              memo[type].push(entry.duration);
            }
            return memo;
          }, {});

          if (!isEmpty(resourceLoadTimes)) {
            Object.keys(resourceLoadTimes).forEach(resourceType => {
              const avgTime = parseInt(
                mean(resourceLoadTimes[resourceType]),
                10
              );
              // $FlowFixMe
              calculated.resources_avg_load_time[resourceType] = avgTime;
            });
          }
        }

        return calculated;
      }