Home | History | Annotate | Download | only in helpers
      1 <!DOCTYPE html>
      2 <!--
      3 Copyright (c) 2014 The Chromium Authors. All rights reserved.
      4 Use of this source code is governed by a BSD-style license that can be
      5 found in the LICENSE file.
      6 -->
      7 
      8 <link rel="import" href="/tracing/core/test_utils.html">
      9 <link rel="import" href="/tracing/extras/chrome/chrome_test_utils.html">
     10 <link rel="import" href="/tracing/extras/importer/trace_event_importer.html">
     11 <link rel="import" href="/tracing/model/helpers/chrome_browser_helper.html">
     12 <link rel="import" href="/tracing/model/helpers/chrome_model_helper.html">
     13 <link rel="import" href="/tracing/model/model.html">
     14 
     15 <script>
     16 'use strict';
     17 
     18 tr.b.unittest.testSuite(function() {
     19   var newAsyncSliceEx = tr.c.TestUtils.newAsyncSliceEx;
     20 
     21   test('getLatencyData', function() {
     22     var m = tr.e.chrome.ChromeTestUtils.newChromeModel(function(m) {
     23       m.browserMain.asyncSliceGroup.push(newAsyncSliceEx({
     24         title: 'InputLatency::GestureScrollUpdate',
     25         cat: 'benchmark',
     26         start: 0,
     27         end: 10,
     28         id: '0x100',
     29         isTopLevel: true,
     30         args: {
     31           data: {
     32             INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT: {'time' : 0},
     33             INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT: {time: 10}
     34           }
     35         }
     36       }));
     37     });
     38 
     39     var modelHelper = m.getOrCreateHelper(tr.model.helpers.ChromeModelHelper);
     40     var latencyEvents = modelHelper.browserHelper.getLatencyEventsInRange(
     41       m.bounds);
     42     assert.equal(latencyEvents.length, 1);
     43   });
     44 
     45   test('getFrametime', function() {
     46     var frame_ts;
     47     var events = [];
     48     // Browser process 3507
     49     events.push({'cat' : '__metadata', 'pid' : 3507, 'tid' : 3507, 'ts' : 0, 'ph' : 'M', 'name' : 'thread_name', 'args' : {'name' : 'CrBrowserMain'}}); // @suppress longLineCheck
     50 
     51     // Renderer process 3508
     52     events.push({'cat' : '__metadata', 'pid' : 3508, 'tid' : 3508, 'ts' : 0, 'ph' : 'M', 'name' : 'thread_name', 'args' : {'name' : 'CrRendererMain'}}); // @suppress longLineCheck
     53     // Compositor thread 3510
     54     events.push({'cat' : '__metadata', 'pid' : 3508, 'tid' : 3510, 'ts' : 0, 'ph' : 'M', 'name' : 'thread_name', 'args' : {'name' : 'Compositor'}}); // @suppress longLineCheck
     55 
     56     // Renderer process 3509
     57     events.push({'cat' : '__metadata', 'pid' : 3509, 'tid' : 3509, 'ts' : 0, 'ph' : 'M', 'name' : 'thread_name', 'args' : {'name' : 'CrRendererMain'}}); // @suppress longLineCheck
     58 
     59     // Compositor thread 3511
     60     events.push({'cat' : '__metadata', 'pid' : 3509, 'tid' : 3511, 'ts' : 0, 'ph' : 'M', 'name' : 'thread_name', 'args' : {'name' : 'Compositor'}}); // @suppress longLineCheck
     61 
     62     frame_ts = 0;
     63     // Add impl rendering stats for browser process 3507
     64     for (var i = 0; i < 10; i++) {
     65       events.push({'cat' : 'benchmark', 'pid' : 3507, 'tid' : 3507, 'ts' : frame_ts, 'ph' : 'i', 'name' : 'BenchmarkInstrumentation::ImplThreadRenderingStats', 's' : 't'}); // @suppress longLineCheck
     66       frame_ts += 16000 + 1000 * (i % 2);
     67     }
     68 
     69     frame_ts = 0;
     70     // Add main rendering stats for renderer process 3508
     71     for (var i = 0; i < 10; i++) {
     72       events.push({'cat' : 'benchmark', 'pid' : 3508, 'tid' : 3508, 'ts' : frame_ts, 'ph' : 'i', 'name' : 'BenchmarkInstrumentation::MainThreadRenderingStats', 's' : 't'}); // @suppress longLineCheck
     73       frame_ts += 16000 + 1000 * (i % 2);
     74     }
     75     events.push({'cat' : 'benchmark', 'pid' : 3508, 'tid' : 3510, 'ts' : 1600, 'ph' : 'i', 'name' : 'KeepAlive', 's' : 't'}); // @suppress longLineCheck
     76 
     77     frame_ts = 0;
     78     // Add impl and main rendering stats for renderer process 3509
     79     for (var i = 0; i < 10; i++) {
     80       events.push({'cat' : 'benchmark', 'pid' : 3509, 'tid' : 3511, 'ts' : frame_ts, 'ph' : 'i', 'name' : 'BenchmarkInstrumentation::ImplThreadRenderingStats', 's' : 't'}); // @suppress longLineCheck
     81       events.push({'cat' : 'benchmark', 'pid' : 3509, 'tid' : 3509, 'ts' : frame_ts, 'ph' : 'i', 'name' : 'BenchmarkInstrumentation::MainThreadRenderingStats', 's' : 't'}); // @suppress longLineCheck
     82       frame_ts += 16000 + 1000 * (i % 2);
     83     }
     84 
     85     var m = tr.c.TestUtils.newModelWithEvents([events]);
     86     var modelHelper = m.getOrCreateHelper(tr.model.helpers.ChromeModelHelper);
     87 
     88     // Testing browser impl and main rendering stats.
     89     var frameEvents = modelHelper.browserHelper.getFrameEventsInRange(
     90         tr.model.helpers.IMPL_FRAMETIME_TYPE, m.bounds);
     91     var frametimeData = tr.model.helpers.getFrametimeDataFromEvents(
     92         frameEvents);
     93     assert.equal(frametimeData.length, 9);
     94     for (var i = 0; i < frametimeData.length; i++) {
     95       assert.equal(frametimeData[i].frametime, 16 + i % 2);
     96     }
     97     // No main rendering stats.
     98     frameEvents = modelHelper.browserHelper.getFrameEventsInRange(
     99         tr.model.helpers.MAIN_FRAMETIME_TYPE, m.bounds);
    100     assert.equal(frameEvents.length, 0);
    101 
    102 
    103     // Testing renderer 3508 impl and main rendering stats.
    104     frameEvents = modelHelper.rendererHelpers[3508].getFrameEventsInRange(
    105         tr.model.helpers.MAIN_FRAMETIME_TYPE, m.bounds);
    106     frametimeData = tr.model.helpers.getFrametimeDataFromEvents(frameEvents);
    107     assert.equal(frametimeData.length, 9);
    108     for (var i = 0; i < frametimeData.length; i++) {
    109       assert.equal(frametimeData[i].frametime, 16 + i % 2);
    110     }
    111 
    112     // No impl rendering stats.
    113     frameEvents = modelHelper.rendererHelpers[3508].getFrameEventsInRange(
    114         tr.model.helpers.IMPL_FRAMETIME_TYPE, m.bounds);
    115     assert.equal(frameEvents.length, 0);
    116 
    117 
    118     // Testing renderer 3509 impl and main rendering stats.
    119     frameEvents = modelHelper.rendererHelpers[3509].getFrameEventsInRange(
    120         tr.model.helpers.IMPL_FRAMETIME_TYPE, m.bounds);
    121     frametimeData = tr.model.helpers.getFrametimeDataFromEvents(frameEvents);
    122     assert.equal(frametimeData.length, 9);
    123     for (var i = 0; i < frametimeData.length; i++) {
    124       assert.equal(frametimeData[i].frametime, 16 + i % 2);
    125     }
    126 
    127     frameEvents = modelHelper.rendererHelpers[3509].getFrameEventsInRange(
    128         tr.model.helpers.MAIN_FRAMETIME_TYPE, m.bounds);
    129     frametimeData = tr.model.helpers.getFrametimeDataFromEvents(frameEvents);
    130     assert.equal(frametimeData.length, 9);
    131     for (var i = 0; i < frametimeData.length; i++) {
    132       assert.equal(frametimeData[i].frametime, 16 + i % 2);
    133     }
    134 
    135   });
    136 
    137   test('multipleBrowsers', function() {
    138     var m = tr.c.TestUtils.newModel(function(model) {
    139       var browserProcess1 = model.getOrCreateProcess(1);
    140       browserProcess1.getOrCreateThread(2).name = 'CrBrowserMain';
    141 
    142       var browserProcess2 = model.getOrCreateProcess(3);
    143       browserProcess2.getOrCreateThread(4);
    144       browserProcess2.getOrCreateThread(5).name = 'CrBrowserMain';
    145 
    146       var nonBrowserProcess = model.getOrCreateProcess(6);
    147       nonBrowserProcess.getOrCreateThread(7);
    148 
    149       var browserProcess3 = model.getOrCreateProcess(8);
    150       browserProcess3.getOrCreateThread(9).name = 'CrBrowserMain';
    151       browserProcess3.getOrCreateThread(10);
    152     });
    153 
    154     var modelHelper = m.getOrCreateHelper(tr.model.helpers.ChromeModelHelper);
    155     var browserHelpers = modelHelper.browserHelpers;
    156 
    157     // Check that the correct processes were marked as Chrome browser processes.
    158     assert.sameMembers(browserHelpers.map(h => h.process.pid), [1, 3, 8]);
    159 
    160     // Check that the browser helpers have the correct structure.
    161     browserHelpers.forEach(function(helper) {
    162       assert.instanceOf(helper, tr.model.helpers.ChromeBrowserHelper);
    163       assert.strictEqual(helper.modelHelper, modelHelper);
    164     });
    165   });
    166 });
    167 </script>
    168