Home | History | Annotate | Download | only in tracing
      1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 'use strict';
      6 
      7 base.require('tracing.test_utils');
      8 base.require('tracing.timeline_track_view');
      9 base.require('tracing.importer.trace_event_importer');
     10 
     11 base.unittest.testSuite('tracing.timeline_track_view', function() {
     12   var NoCountersFilter = function() {
     13   };
     14 
     15   NoCountersFilter.prototype = {
     16     __proto__: tracing.Filter.prototype,
     17     matchCounter: function(c) {
     18       return false;
     19     }
     20   };
     21 
     22   var NoCpusFilter = function() {
     23   };
     24 
     25   NoCpusFilter.prototype = {
     26     __proto__: tracing.Filter.prototype,
     27     matchCpu: function(c) {
     28       return false;
     29     }
     30   };
     31 
     32   var NoProcessesFilter = function() {
     33   };
     34 
     35   NoProcessesFilter.prototype = {
     36     __proto__: tracing.Filter.prototype,
     37     matchProcess: function(c) {
     38       return false;
     39     }
     40   };
     41 
     42   var NoThreadsFilter = function() {
     43   };
     44 
     45   NoThreadsFilter.prototype = {
     46     __proto__: tracing.Filter.prototype,
     47     matchThread: function(c) {
     48       return false;
     49     }
     50   };
     51 
     52   test('instantiate', function() {
     53     var events = [
     54       {name: 'a', args: {}, pid: 52, ts: 520, cat: 'foo', tid: 53, ph: 'B'},
     55       {name: 'a', args: {}, pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'E'},
     56       {name: 'b', args: {}, pid: 52, ts: 629, cat: 'foo', tid: 53, ph: 'B'},
     57       {name: 'b', args: {}, pid: 52, ts: 631, cat: 'foo', tid: 53, ph: 'E'}
     58     ];
     59     var model = new tracing.TraceModel(events);
     60     var timeline = new tracing.TimelineTrackView();
     61     timeline.model = model;
     62     timeline.focusElement = timeline;
     63     timeline.tabIndex = 0;
     64     this.addHTMLOutput(timeline);
     65   });
     66 
     67   test('addAllObjectsMatchingFilterToSelection', function() {
     68     var model = new tracing.TraceModel();
     69     var p1 = model.getOrCreateProcess(1);
     70     var t1 = p1.getOrCreateThread(1);
     71 
     72     t1.sliceGroup.pushSlice(
     73         new tracing.trace_model.ThreadSlice('', 'a', 0, 1, {}, 3));
     74     t1.sliceGroup.pushSlice(
     75         new tracing.trace_model.ThreadSlice('', 'b', 0, 1.1, {}, 2.8));
     76 
     77     var t1asg = t1.asyncSliceGroup;
     78     t1asg.slices.push(
     79         tracing.test_utils.newAsyncSliceNamed('a', 0, 1, t1, t1));
     80     t1asg.slices.push(
     81         tracing.test_utils.newAsyncSliceNamed('b', 1, 2, t1, t1));
     82 
     83     var timeline = new tracing.TimelineTrackView();
     84     timeline.model = model;
     85 
     86     var expected = [{slice: t1asg.slices[0].subSlices[0]},
     87                     {slice: t1.sliceGroup.slices[0]}];
     88     var result = new tracing.Selection();
     89     timeline.addAllObjectsMatchingFilterToSelection(
     90         new tracing.TitleFilter('a'), result);
     91     assertEquals(2, result.length);
     92     assertEquals(expected[0].slice, result[0].slice);
     93     assertEquals(expected[1].slice, result[1].slice);
     94 
     95     var expected = [{slice: t1asg.slices[1].subSlices[0]},
     96                     {slice: t1.sliceGroup.slices[1]}];
     97     var result = new tracing.Selection();
     98     timeline.addAllObjectsMatchingFilterToSelection(
     99         new tracing.TitleFilter('b'), result);
    100     assertEquals(2, result.length);
    101     assertEquals(expected[0].slice, result[0].slice);
    102     assertEquals(expected[1].slice, result[1].slice);
    103   });
    104 
    105   test('emptyThreadsDeleted', function() {
    106     var model = new tracing.TraceModel();
    107     var p1 = model.getOrCreateProcess(1);
    108     var t1 = p1.getOrCreateThread(1);
    109 
    110     var timeline = new tracing.TimelineTrackView();
    111     timeline.model = model;
    112 
    113     assertFalse(timeline.hasVisibleContent);
    114   });
    115 
    116   test('filteredCounters', function() {
    117     var model = new tracing.TraceModel();
    118     var c1 = model.kernel.getOrCreateCpu(0);
    119     c1.getOrCreateCounter('', 'b');
    120 
    121     var p1 = model.getOrCreateProcess(1);
    122     var ctr = p1.getOrCreateCounter('', 'a');
    123     var series = new tracing.trace_model.CounterSeries('a', 0);
    124     series.addSample(0, 1);
    125     ctr.addSeries(series);
    126 
    127     var timeline = new tracing.TimelineTrackView();
    128     timeline.model = model;
    129 
    130     assertTrue(timeline.hasVisibleContent);
    131 
    132     timeline.categoryFilter = new NoCountersFilter();
    133     assertFalse(timeline.hasVisibleContent);
    134   });
    135 
    136   test('filteredCpus', function() {
    137     var model = new tracing.TraceModel();
    138     var c1 = model.kernel.getOrCreateCpu(1);
    139     c1.getOrCreateCounter('', 'a');
    140 
    141     var timeline = new tracing.TimelineTrackView();
    142     timeline.model = model;
    143 
    144     assertTrue(timeline.hasVisibleContent);
    145 
    146     timeline.categoryFilter = new NoCpusFilter();
    147     assertFalse(timeline.hasVisibleContent);
    148   });
    149 
    150   test('filteredProcesses', function() {
    151     var model = new tracing.TraceModel();
    152     var p1 = model.getOrCreateProcess(1);
    153     p1.getOrCreateCounter('', 'a');
    154 
    155     var timeline = new tracing.TimelineTrackView();
    156     timeline.model = model;
    157 
    158     assertTrue(timeline.hasVisibleContent);
    159 
    160     timeline.categoryFilter = new NoProcessesFilter();
    161     assertFalse(timeline.hasVisibleContent);
    162   });
    163 
    164   test('filteredThreads', function() {
    165     var model = new tracing.TraceModel();
    166     var p1 = model.getOrCreateProcess(1);
    167     var t1 = p1.getOrCreateThread(2);
    168     t1.sliceGroup.pushSlice(tracing.test_utils.newSlice(0, 1));
    169 
    170     var timeline = new tracing.TimelineTrackView();
    171     timeline.model = model;
    172 
    173     assertTrue(timeline.hasVisibleContent);
    174 
    175     timeline.categoryFilter = new NoThreadsFilter();
    176     assertFalse(timeline.hasVisibleContent);
    177   });
    178 });
    179