summaryrefslogtreecommitdiff
path: root/chromium/third_party/catapult/tracing/tracing/model/process_test.html
blob: 46c2ca802a378ad6b17775f5f2a87036ebe07e96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!DOCTYPE html>
<!--
Copyright (c) 2013 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="/tracing/core/test_utils.html">
<link rel="import" href="/tracing/model/frame.html">
<link rel="import" href="/tracing/model/global_memory_dump.html">
<link rel="import" href="/tracing/model/instant_event.html">
<link rel="import" href="/tracing/model/model.html">
<link rel="import" href="/tracing/model/process.html">
<link rel="import" href="/tracing/model/thread_slice.html">

<script>
'use strict';

tr.b.unittest.testSuite(function() {
  test('getOrCreateCounter', function() {
    var model = new tr.Model();
    var process = new tr.model.Process(model, 7);
    var ctrBar = process.getOrCreateCounter('foo', 'bar');
    var ctrBar2 = process.getOrCreateCounter('foo', 'bar');
    assert.equal(ctrBar2, ctrBar);
  });

  test('shiftTimestampsForward', function() {
    var model = new tr.Model();
    var process = new tr.model.Process(model, 7);
    var ctr = process.getOrCreateCounter('foo', 'bar');
    var thread = process.getOrCreateThread(1);

    var instantEvent = new tr.model.InstantEvent('cat', 'event1', 1, 100);
    process.instantEvents.push(instantEvent);

    var slice = new tr.model.ThreadSlice('', 'a', 0, 1, {}, 4);
    var frame =
        new tr.model.Frame([slice], [{thread: thread, start: 100, end: 200}]);
    process.frames.push(frame);

    var memoryDump = new tr.model.GlobalMemoryDump(model, 100);
    process.memoryDumps.push(memoryDump);

    var shiftCount = 0;
    thread.shiftTimestampsForward = function(ts) {
      if (ts == 0.32)
        shiftCount++;
    };
    ctr.shiftTimestampsForward = function(ts) {
      if (ts == 0.32)
        shiftCount++;
    };

    process.shiftTimestampsForward(0.32);
    assert.equal(shiftCount, 2);
    assert.equal(instantEvent.start, 100.32);
    assert.equal(frame.start, 100.32);
    assert.equal(frame.end, 200.32);
    assert.equal(memoryDump.start, 100.32);
  });

  test('compareOnPID', function() {
    var model = new tr.Model();
    var p1 = new tr.model.Process(model, 1);
    p1.name = 'Renderer';

    var model = new tr.Model();
    var p2 = new tr.model.Process(model, 2);
    p2.name = 'Renderer';

    assert.isBelow(p1.compareTo(p2), 0);
  });

  test('compareOnSortIndex', function() {
    var model = new tr.Model();
    var p1 = new tr.model.Process(model, 1);
    p1.name = 'Renderer';
    p1.sortIndex = 1;

    var p2 = new tr.model.Process(model, 2);
    p2.name = 'Renderer';

    assert.isAbove(p1.compareTo(p2), 0);
  });

  test('compareOnName', function() {
    var model = new tr.Model();
    var p1 = new tr.model.Process(model, 1);
    p1.name = 'Browser';

    var p2 = new tr.model.Process(model, 2);
    p2.name = 'Renderer';

    assert.isBelow(p1.compareTo(p2), 0);
  });

  test('compareOnLabels', function() {
    var model = new tr.Model();
    var p1 = new tr.model.Process(model, 1);
    p1.name = 'Renderer';
    p1.labels = ['a'];

    var p2 = new tr.model.Process(model, 2);
    p2.name = 'Renderer';
    p2.labels = ['b'];

    assert.isBelow(p1.compareTo(p2), 0);
  });
});
</script>