Exemplo n.º 1
0
    def __init__(self, trace, ad_rules=None, tracking_rules=None):
        """Constructor.

    Args:
      trace: (LoadingTrace) a loading trace.
      ad_rules: ([str]) List of ad filtering rules.
      tracking_rules: ([str]) List of tracking filtering rules.
    """
        self.trace = trace

        navigation_start_events = trace.tracing_track.GetMatchingEvents(
            'blink.user_timing', 'navigationStart')
        self._navigation_start_msec = min(e.start_msec
                                          for e in navigation_start_events)

        self._dns_requests, self._dns_cost_msec = metrics.DnsRequestsAndCost(
            trace)
        self._connection_stats = metrics.ConnectionMetrics(trace)

        self._user_lens_reports = {}
        plt_lens = PLTLens(self.trace)
        first_text_paint_lens = FirstTextPaintLens(self.trace)
        first_contentful_paint_lens = FirstContentfulPaintLens(self.trace)
        first_significant_paint_lens = FirstSignificantPaintLens(self.trace)
        activity = ActivityLens(trace)
        network_lens = NetworkActivityLens(self.trace)
        for key, user_lens in [['plt', plt_lens],
                               ['first_text', first_text_paint_lens],
                               ['contentful', first_contentful_paint_lens],
                               ['significant', first_significant_paint_lens]]:
            self._user_lens_reports[key] = PerUserLensReport(
                self.trace, user_lens, activity, network_lens,
                self._navigation_start_msec)

        self._transfer_size = metrics.TotalTransferSize(trace)[1]
        self._request_count = len(trace.request_track.GetEvents())

        content_lens = ContentClassificationLens(trace, ad_rules or [],
                                                 tracking_rules or [])
        has_ad_rules = bool(ad_rules)
        has_tracking_rules = bool(tracking_rules)
        self._ad_report = self._AdRequestsReport(trace, content_lens,
                                                 has_ad_rules,
                                                 has_tracking_rules)
        self._ads_cost = self._AdsAndTrackingCpuCost(
            self._navigation_start_msec,
            (self._navigation_start_msec +
             self._user_lens_reports['plt'].GenerateReport()['ms']),
            content_lens, activity, has_tracking_rules or has_ad_rules)

        self._queue_stats = self._ComputeQueueStats(QueuingLens(trace))
Exemplo n.º 2
0
 def _ActivityLens(self, requests, raw_events):
     loading_trace = test_utils.LoadingTraceFromEvents(
         requests, None, raw_events)
     return ActivityLens(loading_trace)