def testThreadBusyness(self):
   raw_events =  [
       {u'args': {},
        u'cat': u'toplevel',
        u'dur': 200 * 1000,
        u'name': u'MessageLoop::RunTask',
        u'ph': u'X',
        u'pid': 123,
        u'tid': 123,
        u'ts': 0,
        u'tts': 56485},
       {u'args': {},
        u'cat': u'toplevel',
        u'dur': 8 * 200,
        u'name': u'MessageLoop::NestedSomething',
        u'ph': u'X',
        u'pid': 123,
        u'tid': 123,
        u'ts': 0,
        u'tts': 0}]
   events = self._EventsFromRawEvents(raw_events)
   self.assertEquals(200, ActivityLens._ThreadBusyness(events, 0, 1000))
   # Clamping duration.
   self.assertEquals(100, ActivityLens._ThreadBusyness(events, 0, 100))
   self.assertEquals(50, ActivityLens._ThreadBusyness(events, 25, 75))
Example #2
0
 def testThreadBusyness(self):
     raw_events = [{
         u'args': {},
         u'cat': u'toplevel',
         u'dur': 200 * 1000,
         u'name': u'MessageLoop::RunTask',
         u'ph': u'X',
         u'pid': 123,
         u'tid': 123,
         u'ts': 0,
         u'tts': 56485
     }, {
         u'args': {},
         u'cat': u'toplevel',
         u'dur': 8 * 200,
         u'name': u'MessageLoop::NestedSomething',
         u'ph': u'X',
         u'pid': 123,
         u'tid': 123,
         u'ts': 0,
         u'tts': 0
     }]
     events = self._EventsFromRawEvents(raw_events)
     self.assertEquals(200, ActivityLens._ThreadBusyness(events, 0, 1000))
     # Clamping duration.
     self.assertEquals(100, ActivityLens._ThreadBusyness(events, 0, 100))
     self.assertEquals(50, ActivityLens._ThreadBusyness(events, 25, 75))
 def testParsing(self):
   css_url = u'http://example.com/style.css'
   html_url = u'http://example.com/yeah.htnl'
   raw_events = [
       {u'args': {u'data': {u'styleSheetUrl': css_url}},
        u'cat': u'blink,devtools.timeline',
        u'dur': 400 * 1000,
        u'name': u'ParseAuthorStyleSheet',
        u'ph': u'X',
        u'pid': 32723,
        u'tdur': 49721,
        u'tid': 32738,
        u'ts': 0,
        u'tts': 216148},
       {u'args': {u'beginData': {u'url': html_url}},
        u'cat': u'devtools.timeline',
        u'dur': 42 * 1000,
        u'name': u'ParseHTML',
        u'ph': u'X',
        u'pid': 32723,
        u'tdur': 49721,
        u'tid': 32738,
        u'ts': 0,
        u'tts': 5032310},]
   events = self._EventsFromRawEvents(raw_events)
   self.assertEquals(2, len(ActivityLens._Parsing(events, 0, 1000)))
   self.assertTrue(css_url in ActivityLens._Parsing(events, 0, 1000))
   self.assertEquals(400, ActivityLens._Parsing(events, 0, 1000)[css_url])
   self.assertTrue(html_url in ActivityLens._Parsing(events, 0, 1000))
   self.assertEquals(42, ActivityLens._Parsing(events, 0, 1000)[html_url])
Example #4
0
 def testParsing(self):
   css_url = u'http://example.com/style.css'
   html_url = u'http://example.com/yeah.htnl'
   raw_events = [
       {u'args': {u'data': {u'styleSheetUrl': css_url}},
        u'cat': u'blink,devtools.timeline',
        u'dur': 400 * 1000,
        u'name': u'ParseAuthorStyleSheet',
        u'ph': u'X',
        u'pid': 32723,
        u'tdur': 49721,
        u'tid': 32738,
        u'ts': 0,
        u'tts': 216148},
       {u'args': {u'beginData': {u'url': html_url}},
        u'cat': u'devtools.timeline',
        u'dur': 42 * 1000,
        u'name': u'ParseHTML',
        u'ph': u'X',
        u'pid': 32723,
        u'tdur': 49721,
        u'tid': 32738,
        u'ts': 0,
        u'tts': 5032310},]
   events = self._EventsFromRawEvents(raw_events)
   self.assertEquals(2, len(ActivityLens._Parsing(events, 0, 1000)))
   self.assertTrue(css_url in ActivityLens._Parsing(events, 0, 1000))
   self.assertEquals(400, ActivityLens._Parsing(events, 0, 1000)[css_url])
   self.assertTrue(html_url in ActivityLens._Parsing(events, 0, 1000))
   self.assertEquals(42, ActivityLens._Parsing(events, 0, 1000)[html_url])
 def testGetRendererMainThread(self):
   first_renderer_tid = 12345
   second_renderer_tid = 123456
   raw_events =  [
       {u'args': {u'name': u'CrBrowserMain'},
        u'cat': u'__metadata',
        u'name': u'thread_name',
        u'ph': u'M',
        u'pid': 1,
        u'tid': 123,
        u'ts': 0},
       {u'args': {u'name': u'CrRendererMain'},
        u'cat': u'__metadata',
        u'name': u'thread_name',
        u'ph': u'M',
        u'pid': 1,
        u'tid': first_renderer_tid,
        u'ts': 0},
       {u'args': {u'name': u'CrRendererMain'},
        u'cat': u'__metadata',
        u'name': u'thread_name',
        u'ph': u'M',
        u'pid': 1,
        u'tid': second_renderer_tid,
        u'ts': 0}]
   raw_events += [
       {u'args': {u'data': {}},
        u'cat': u'devtools.timeline,v8',
        u'name': u'FunctionCall',
        u'ph': u'X',
        u'pid': 1,
        u'tdur': 0,
        u'tid': first_renderer_tid,
        u'ts': 251427174674,
        u'tts': 5107725}] * 100
   raw_events += [
       {u'args': {u'data': {}},
        u'cat': u'devtools.timeline,v8',
        u'name': u'FunctionCall',
        u'ph': u'X',
        u'pid': 1,
        u'tdur': 0,
        u'tid': second_renderer_tid,
        u'ts': 251427174674,
        u'tts': 5107725}] * 150
   # There are more events from first_renderer_tid when (incorrectly) ignoring
   # the PID.
   raw_events += [
       {u'args': {u'data': {}},
        u'cat': u'devtools.timeline,v8',
        u'name': u'FunctionCall',
        u'ph': u'X',
        u'pid': 12,
        u'tdur': 0,
        u'tid': first_renderer_tid,
        u'ts': 251427174674,
        u'tts': 5107725}] * 100
   events = self._EventsFromRawEvents(raw_events)
   self.assertEquals((1, second_renderer_tid),
                     ActivityLens._GetRendererMainThreadId(events))
Example #6
0
 def testGetRendererMainThread(self):
   first_renderer_tid = 12345
   second_renderer_tid = 123456
   raw_events =  [
       {u'args': {u'name': u'CrBrowserMain'},
        u'cat': u'__metadata',
        u'name': u'thread_name',
        u'ph': u'M',
        u'pid': 1,
        u'tid': 123,
        u'ts': 0},
       {u'args': {u'name': u'CrRendererMain'},
        u'cat': u'__metadata',
        u'name': u'thread_name',
        u'ph': u'M',
        u'pid': 1,
        u'tid': first_renderer_tid,
        u'ts': 0},
       {u'args': {u'name': u'CrRendererMain'},
        u'cat': u'__metadata',
        u'name': u'thread_name',
        u'ph': u'M',
        u'pid': 1,
        u'tid': second_renderer_tid,
        u'ts': 0}]
   raw_events += [
       {u'args': {u'data': {}},
        u'cat': u'devtools.timeline,v8',
        u'name': u'FunctionCall',
        u'ph': u'X',
        u'pid': 1,
        u'tdur': 0,
        u'tid': first_renderer_tid,
        u'ts': 251427174674,
        u'tts': 5107725}] * 100
   raw_events += [
       {u'args': {u'data': {}},
        u'cat': u'devtools.timeline,v8',
        u'name': u'FunctionCall',
        u'ph': u'X',
        u'pid': 1,
        u'tdur': 0,
        u'tid': second_renderer_tid,
        u'ts': 251427174674,
        u'tts': 5107725}] * 150
   # There are more events from first_renderer_tid when (incorrectly) ignoring
   # the PID.
   raw_events += [
       {u'args': {u'data': {}},
        u'cat': u'devtools.timeline,v8',
        u'name': u'FunctionCall',
        u'ph': u'X',
        u'pid': 12,
        u'tdur': 0,
        u'tid': first_renderer_tid,
        u'ts': 251427174674,
        u'tts': 5107725}] * 100
   events = self._EventsFromRawEvents(raw_events)
   self.assertEquals((1, second_renderer_tid),
                     ActivityLens._GetRendererMainThreadId(events))
Example #7
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))
 def testScriptExecuting(self):
   url = u'http://example.com/script.js'
   raw_events = [
       {u'args': {u'data': {u'scriptName': url}},
        u'cat': u'devtools.timeline,v8',
        u'dur': 250 * 1000,
        u'name': u'FunctionCall',
        u'ph': u'X',
        u'pid': 123,
        u'tdur': 247,
        u'tid': 123,
        u'ts': 0,
        u'tts': 0},
       {u'args': {u'data': {}},
        u'cat': u'devtools.timeline,v8',
        u'dur': 350 * 1000,
        u'name': u'EvaluateScript',
        u'ph': u'X',
        u'pid': 123,
        u'tdur': 247,
        u'tid': 123,
        u'ts': 0,
        u'tts': 0}]
   events = self._EventsFromRawEvents(raw_events)
   self.assertEquals(2, len(ActivityLens._ScriptsExecuting(events, 0, 1000)))
   self.assertTrue(None in ActivityLens._ScriptsExecuting(events, 0, 1000))
   self.assertEquals(
       350, ActivityLens._ScriptsExecuting(events, 0, 1000)[None])
   self.assertTrue(url in ActivityLens._ScriptsExecuting(events, 0, 1000))
   self.assertEquals(250, ActivityLens._ScriptsExecuting(events, 0, 1000)[url])
   # Aggreagates events.
   raw_events.append({u'args': {u'data': {}},
                      u'cat': u'devtools.timeline,v8',
                      u'dur': 50 * 1000,
                      u'name': u'EvaluateScript',
                      u'ph': u'X',
                      u'pid': 123,
                      u'tdur': 247,
                      u'tid': 123,
                      u'ts': 0,
                      u'tts': 0})
   events = self._EventsFromRawEvents(raw_events)
   self.assertEquals(
       350 + 50, ActivityLens._ScriptsExecuting(events, 0, 1000)[None])
Example #9
0
 def testScriptExecuting(self):
   url = u'http://example.com/script.js'
   raw_events = [
       {u'args': {u'data': {u'scriptName': url}},
        u'cat': u'devtools.timeline,v8',
        u'dur': 250 * 1000,
        u'name': u'FunctionCall',
        u'ph': u'X',
        u'pid': 123,
        u'tdur': 247,
        u'tid': 123,
        u'ts': 0,
        u'tts': 0},
       {u'args': {u'data': {}},
        u'cat': u'devtools.timeline,v8',
        u'dur': 350 * 1000,
        u'name': u'EvaluateScript',
        u'ph': u'X',
        u'pid': 123,
        u'tdur': 247,
        u'tid': 123,
        u'ts': 0,
        u'tts': 0}]
   events = self._EventsFromRawEvents(raw_events)
   self.assertEquals(2, len(ActivityLens._ScriptsExecuting(events, 0, 1000)))
   self.assertTrue(None in ActivityLens._ScriptsExecuting(events, 0, 1000))
   self.assertEquals(
       350, ActivityLens._ScriptsExecuting(events, 0, 1000)[None])
   self.assertTrue(url in ActivityLens._ScriptsExecuting(events, 0, 1000))
   self.assertEquals(250, ActivityLens._ScriptsExecuting(events, 0, 1000)[url])
   # Aggreagates events.
   raw_events.append({u'args': {u'data': {}},
                      u'cat': u'devtools.timeline,v8',
                      u'dur': 50 * 1000,
                      u'name': u'EvaluateScript',
                      u'ph': u'X',
                      u'pid': 123,
                      u'tdur': 247,
                      u'tid': 123,
                      u'ts': 0,
                      u'tts': 0})
   events = self._EventsFromRawEvents(raw_events)
   self.assertEquals(
       350 + 50, ActivityLens._ScriptsExecuting(events, 0, 1000)[None])
Example #10
0
 def _ActivityLens(self, requests, raw_events):
     loading_trace = test_utils.LoadingTraceFromEvents(
         requests, None, raw_events)
     return ActivityLens(loading_trace)