Commit d75decea authored by lizeb's avatar lizeb Committed by Commit bot

clovis: Report the number and cost of DNS requests.

Review-Url: https://codereview.chromium.org/2021093002
Cr-Commit-Position: refs/heads/master@{#396804}
parent 47d6f9ab
......@@ -106,6 +106,16 @@ def AdsAndTrackingTransferSize(trace, ad_rules_filename,
return TransferSize(requests)
def DnsRequestsAndCost(trace):
"""Returns the number and cost of DNS requests for a trace."""
requests = trace.request_track.GetEvents()
requests_with_dns = [r for r in requests if r.timing.dns_start != -1]
dns_requests_count = len(requests_with_dns)
dns_cost = sum(r.timing.dns_end - r.timing.dns_start
for r in requests_with_dns)
return (dns_requests_count, dns_cost)
def PlotTransferSizeVsTimeBetweenVisits(trace):
times = [10, 60, 300, 600, 3600, 4 * 3600, 12 * 3600, 24 * 3600]
labels = ['10s', '1m', '10m', '1h', '4h', '12h', '1d']
......
......@@ -72,6 +72,18 @@ class MetricsTestCase(unittest.TestCase):
self.assertEqual(self._BODY_SIZE + self._RESPONSE_HEADERS_SIZE,
downloaded)
def testDnsRequestsAndCost(self):
trace = self._MakeTrace()
(count, cost) = metrics.DnsRequestsAndCost(trace)
self.assertEqual(0, count)
self.assertEqual(0, cost)
r = trace.request_track.GetEvents()[0]
r.timing.dns_end = 12
r.timing.dns_start = 4
(count, cost) = metrics.DnsRequestsAndCost(trace)
self.assertEqual(1, count)
self.assertEqual(8, cost)
@classmethod
def _MakeTrace(cls):
request = request_track.Request.FromJsonDict(copy.deepcopy(cls._REQUEST))
......
......@@ -107,6 +107,7 @@ class LoadingReport(object):
requests[0], dependencies_lens, self.trace)
self._requests = len(requests)
self._preloaded_requests = len(preloaded_requests)
self._dns_requests, self._dns_cost_msec = metrics.DnsRequestsAndCost(trace)
self._user_lens_reports = {}
first_text_paint_lens = FirstTextPaintLens(self.trace)
......@@ -144,7 +145,9 @@ class LoadingReport(object):
'plt_ms': self._load_end_msec - self._navigation_start_msec,
'requests': self._requests,
'preloaded_requests': self._preloaded_requests,
'transfer_size': self._transfer_size}
'transfer_size': self._transfer_size,
'dns_requests': self._dns_requests,
'dns_cost_ms': self._dns_cost_msec}
for user_lens_type, user_lens_report in self._user_lens_reports.iteritems():
for key, value in user_lens_report.GenerateReport().iteritems():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment