OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <!-- | 3 <!-- |
4 Copyright (c) 2012 The Chromium Authors. All rights reserved. | 4 Copyright (c) 2012 The Chromium Authors. All rights reserved. |
5 Use of this source code is governed by a BSD-style license that can be | 5 Use of this source code is governed by a BSD-style license that can be |
6 found in the LICENSE file. | 6 found in the LICENSE file. |
7 --> | 7 --> |
8 <head> | 8 <head> |
9 <title>TimelineModel tests</title> | 9 <title>TimelineModel tests</title> |
10 <script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.j
s"></script> | 10 <script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.j
s"></script> |
11 <script src="../shared/js/cr.js"></script> | 11 <script src="../shared/js/cr.js"></script> |
12 <script src="../shared/js/cr/event_target.js"></script> | 12 <script src="../shared/js/cr/event_target.js"></script> |
13 <script src="timeline_model.js"></script> | 13 <script src="timeline_model.js"></script> |
14 <script> | 14 <script> |
15 goog.require('goog.testing.jsunit'); | 15 goog.require('goog.testing.jsunit'); |
16 </script> | 16 </script> |
17 | 17 |
18 </head> | 18 </head> |
19 <body> | 19 <body> |
20 <script> | 20 <script> |
| 21 'use strict'; |
21 var TimelineCpu = tracing.TimelineCpu; | 22 var TimelineCpu = tracing.TimelineCpu; |
22 var TimelineSlice = tracing.TimelineSlice; | 23 var TimelineSlice = tracing.TimelineSlice; |
| 24 var TimelineThreadSlice = tracing.TimelineThreadSlice; |
23 var TimelineProcess = tracing.TimelineProcess; | 25 var TimelineProcess = tracing.TimelineProcess; |
24 var TimelineThread = tracing.TimelineThread; | 26 var TimelineThread = tracing.TimelineThread; |
25 var TimelineModel = tracing.TimelineModel; | 27 var TimelineModel = tracing.TimelineModel; |
| 28 var TimelineAsyncSlice = tracing.TimelineAsyncSlice; |
| 29 var TimelineAsyncSliceGroup = tracing.TimelineAsyncSliceGroup; |
| 30 |
| 31 // Helper function to create a slice. |
| 32 function newAsyncSlice(start, duration, startThread, endThread) { |
| 33 var s = new TimelineAsyncSlice('a', 0, start); |
| 34 s.duration = duration; |
| 35 s.startThread = startThread; |
| 36 s.endThread = endThread; |
| 37 return s; |
| 38 } |
26 | 39 |
27 function testThreadBounds_Empty() { | 40 function testThreadBounds_Empty() { |
28 var t = new TimelineThread(undefined, 1); | 41 var t = new TimelineThread(new TimelineProcess(7), 1); |
29 t.updateBounds(); | 42 t.updateBounds(); |
30 assertEquals(undefined, t.minTimestamp); | 43 assertEquals(undefined, t.minTimestamp); |
31 assertEquals(undefined, t.maxTimestamp); | 44 assertEquals(undefined, t.maxTimestamp); |
32 } | 45 } |
33 | 46 |
34 function testThreadBounds_SubRow() { | 47 function testThreadBounds_SubRow() { |
35 var t = new TimelineThread(undefined, 1); | 48 var t = new TimelineThread(new TimelineProcess(7), 1); |
36 t.subRows[0].push(new TimelineSlice('a', 0, 1, {}, 3)); | 49 t.subRows[0].push(new TimelineThreadSlice('a', 0, 1, {}, 3)); |
37 t.updateBounds(); | 50 t.updateBounds(); |
38 assertEquals(1, t.minTimestamp); | 51 assertEquals(1, t.minTimestamp); |
39 assertEquals(4, t.maxTimestamp); | 52 assertEquals(4, t.maxTimestamp); |
40 } | 53 } |
41 | 54 |
42 function testThreadBounds_NestedSubrow() { | 55 function testThreadBounds_AsyncSliceGroup() { |
43 var t = new TimelineThread(undefined, 1); | 56 var t = new TimelineThread(new TimelineProcess(7), 1); |
44 t.nonNestedSubRows.push([]); | 57 t.subRows[0].push(new TimelineThreadSlice('a', 0, 1, {}, 3)); |
45 t.nonNestedSubRows[0].push(new TimelineSlice('a', 0, 1, {}, 3)); | 58 t.asyncSlices.push(newAsyncSlice(0.1, 5, t, t)); |
46 t.updateBounds(); | 59 t.updateBounds(); |
47 assertEquals(1, t.minTimestamp); | 60 assertEquals(0.1, t.minTimestamp); |
48 assertEquals(4, t.maxTimestamp); | 61 assertEquals(5.1, t.maxTimestamp); |
49 } | |
50 | |
51 function testThreadBounds_SubRowAndNonNestedSubRow() { | |
52 var t = new TimelineThread(undefined, 1); | |
53 t.subRows[0].push(new TimelineSlice('a', 0, 0.5, {}, 3)); | |
54 t.nonNestedSubRows.push([]); | |
55 t.nonNestedSubRows[0].push(new TimelineSlice('b', 0, 1, {}, 4.5)); | |
56 t.updateBounds(); | |
57 assertEquals(0.5, t.minTimestamp); | |
58 assertEquals(5.5, t.maxTimestamp); | |
59 } | 62 } |
60 | 63 |
61 function testModelBounds_EmptyModel() { | 64 function testModelBounds_EmptyModel() { |
62 var m = new TimelineModel(); | 65 var m = new TimelineModel(); |
63 m.updateBounds(); | 66 m.updateBounds(); |
64 assertEquals(undefined, m.minTimestamp); | 67 assertEquals(undefined, m.minTimestamp); |
65 assertEquals(undefined, m.maxTimestamp); | 68 assertEquals(undefined, m.maxTimestamp); |
66 } | 69 } |
67 | 70 |
68 function testModelBounds_OneEmptyThread() { | 71 function testModelBounds_OneEmptyThread() { |
69 var m = new TimelineModel(); | 72 var m = new TimelineModel(); |
70 var t = m.getOrCreateProcess(1).getOrCreateThread(1); | 73 var t = m.getOrCreateProcess(1).getOrCreateThread(1); |
71 m.updateBounds(); | 74 m.updateBounds(); |
72 assertEquals(undefined, m.minTimestamp); | 75 assertEquals(undefined, m.minTimestamp); |
73 assertEquals(undefined, m.maxTimestamp); | 76 assertEquals(undefined, m.maxTimestamp); |
74 } | 77 } |
75 | 78 |
76 function testModelBounds_OneThrad() { | 79 function testModelBounds_OneThread() { |
77 var m = new TimelineModel(); | 80 var m = new TimelineModel(); |
78 var t = m.getOrCreateProcess(1).getOrCreateThread(1); | 81 var t = m.getOrCreateProcess(1).getOrCreateThread(1); |
79 t.subRows[0].push(new TimelineSlice('a', 0, 1, {}, 3)); | 82 t.subRows[0].push(new TimelineThreadSlice('a', 0, 1, {}, 3)); |
80 m.updateBounds(); | 83 m.updateBounds(); |
81 assertEquals(1, m.minTimestamp); | 84 assertEquals(1, m.minTimestamp); |
82 assertEquals(4, m.maxTimestamp); | 85 assertEquals(4, m.maxTimestamp); |
83 } | 86 } |
84 | 87 |
85 function testModelBounds_OneThreadAndOneEmptyThread() { | 88 function testModelBounds_OneThreadAndOneEmptyThread() { |
86 var m = new TimelineModel(); | 89 var m = new TimelineModel(); |
87 var t1 = m.getOrCreateProcess(1).getOrCreateThread(1); | 90 var t1 = m.getOrCreateProcess(1).getOrCreateThread(1); |
88 t1.subRows[0].push(new TimelineSlice('a', 0, 1, {}, 3)); | 91 t1.subRows[0].push(new TimelineThreadSlice('a', 0, 1, {}, 3)); |
89 var t2 = m.getOrCreateProcess(1).getOrCreateThread(1); | 92 var t2 = m.getOrCreateProcess(1).getOrCreateThread(1); |
90 m.updateBounds(); | 93 m.updateBounds(); |
91 assertEquals(1, m.minTimestamp); | 94 assertEquals(1, m.minTimestamp); |
92 assertEquals(4, m.maxTimestamp); | 95 assertEquals(4, m.maxTimestamp); |
93 } | 96 } |
94 | 97 |
95 function testCpuBounds_Empty() { | 98 function testCpuBounds_Empty() { |
96 var cpu = new TimelineCpu(undefined, 1); | 99 var cpu = new TimelineCpu(undefined, 1); |
97 cpu.updateBounds(); | 100 cpu.updateBounds(); |
98 assertEquals(undefined, cpu.minTimestamp); | 101 assertEquals(undefined, cpu.minTimestamp); |
99 assertEquals(undefined, cpu.maxTimestamp); | 102 assertEquals(undefined, cpu.maxTimestamp); |
100 } | 103 } |
101 | 104 |
102 | |
103 function testCpuBounds_OneSlice() { | 105 function testCpuBounds_OneSlice() { |
104 var cpu = new TimelineCpu(undefined, 1); | 106 var cpu = new TimelineCpu(undefined, 1); |
105 cpu.slices.push(new TimelineSlice('a', 0, 1, {}, 3)); | 107 cpu.slices.push(new TimelineSlice('a', 0, 1, {}, 3)); |
106 cpu.updateBounds(); | 108 cpu.updateBounds(); |
107 assertEquals(1, cpu.minTimestamp); | 109 assertEquals(1, cpu.minTimestamp); |
108 assertEquals(4, cpu.maxTimestamp); | 110 assertEquals(4, cpu.maxTimestamp); |
109 } | 111 } |
110 | 112 |
111 function testModelBounds_OneCpu() { | 113 function testModelBounds_OneCpu() { |
| 114 var m = new TimelineModel(); |
| 115 var cpu = m.getOrCreateCpu(1); |
| 116 cpu.slices.push(new TimelineSlice('a', 0, 1, {}, 3)); |
| 117 m.updateBounds(); |
| 118 assertEquals(1, m.minTimestamp); |
| 119 assertEquals(4, m.maxTimestamp); |
112 } | 120 } |
113 | 121 |
114 | 122 |
115 function testModelBounds_OneCpuOneThread() { | 123 function testModelBounds_OneCpuOneThread() { |
| 124 var m = new TimelineModel(); |
| 125 var cpu = m.getOrCreateCpu(1); |
| 126 cpu.slices.push(new TimelineSlice('a', 0, 1, {}, 3)); |
| 127 |
| 128 var t = m.getOrCreateProcess(1).getOrCreateThread(1); |
| 129 t.subRows[0].push(new TimelineThreadSlice('a', 0, 1, {}, 4)); |
| 130 |
| 131 m.updateBounds(); |
| 132 assertEquals(1, m.minTimestamp); |
| 133 assertEquals(5, m.maxTimestamp); |
| 134 } |
| 135 |
| 136 function testPTIDFromPidAndTid() { |
| 137 assertEquals('1:2', TimelineThread.getPTIDFromPidAndTid(1, 2)); |
| 138 } |
| 139 |
| 140 function testAsyncSliceGroupBounds_Empty() { |
| 141 var g = new TimelineAsyncSliceGroup(name); |
| 142 g.updateBounds(); |
| 143 assertEquals(undefined, g.minTimestamp); |
| 144 assertEquals(undefined, g.maxTimestamp); |
| 145 } |
| 146 |
| 147 function testAsyncSliceGroupBounds_Basic() { |
| 148 var p1 = new TimelineProcess(1); |
| 149 var t1 = new TimelineThread(p1, 1); |
| 150 var g = new TimelineAsyncSliceGroup('a'); |
| 151 g.push(newAsyncSlice(0, 1, t1, t1)); |
| 152 g.push(newAsyncSlice(1, 1.5, t1, t1)); |
| 153 assertEquals(2, g.length); |
| 154 g.updateBounds(); |
| 155 assertEquals(0, g.minTimestamp); |
| 156 assertEquals(2.5, g.maxTimestamp); |
| 157 } |
| 158 |
| 159 function testAsyncSliceGroup_rebuildSubRows_twoNonOverlappingSlices() { |
| 160 var p1 = new TimelineProcess(1); |
| 161 var t1 = new TimelineThread(p1, 1); |
| 162 var g = new TimelineAsyncSliceGroup('a'); |
| 163 g.slices.push(newAsyncSlice(0, 1, t1, t1)); |
| 164 g.slices.push(newAsyncSlice(1, 1, t1, t1)); |
| 165 |
| 166 assertEquals(1, g.subRows.length); |
| 167 assertEquals(2, g.subRows[0].length); |
| 168 assertEquals(g.slices[0], g.subRows[0][0]); |
| 169 assertEquals(g.slices[1], g.subRows[0][1]); |
| 170 } |
| 171 |
| 172 function testAsyncSliceGroup_rebuildSubRows_twoOverlappingSlices() { |
| 173 var p1 = new TimelineProcess(1); |
| 174 var t1 = new TimelineThread(p1, 1); |
| 175 var g = new TimelineAsyncSliceGroup('a'); |
| 176 g.slices.push(newAsyncSlice(0, 1, t1, t1)); |
| 177 g.slices.push(newAsyncSlice(0, 1.5, t1, t1)); |
| 178 g.updateBounds(); |
| 179 |
| 180 assertEquals(2, g.subRows.length); |
| 181 assertEquals(1, g.subRows[0].length); |
| 182 assertEquals(g.slices[0], g.subRows[0][0]); |
| 183 assertEquals(1, g.subRows[1].length); |
| 184 assertEquals(g.slices[1], g.subRows[1][0]); |
| 185 } |
| 186 |
| 187 function testAsyncSliceGroup_rebuildSubRows_threePartlyOverlappingSlices() { |
| 188 var p1 = new TimelineProcess(1); |
| 189 var t1 = new TimelineThread(p1, 1); |
| 190 var g = new TimelineAsyncSliceGroup('a'); |
| 191 g.slices.push(newAsyncSlice(0, 1, t1, t1)); |
| 192 g.slices.push(newAsyncSlice(0, 1.5, t1, t1)); |
| 193 g.slices.push(newAsyncSlice(1, 1.5, t1, t1)); |
| 194 g.updateBounds(); |
| 195 |
| 196 assertEquals(2, g.subRows.length); |
| 197 assertEquals(2, g.subRows[0].length); |
| 198 assertEquals(g.slices[0], g.subRows[0][0]); |
| 199 assertEquals(g.slices[2], g.subRows[0][1]); |
| 200 assertEquals(1, g.subRows[1].length); |
| 201 assertEquals(g.slices[1], g.subRows[1][0]); |
| 202 } |
| 203 |
| 204 function testAsyncSliceGroup_computeSubGroups_twoThreadSpecificSlices() { |
| 205 var p1 = new TimelineProcess(1); |
| 206 var t1 = new TimelineThread(p1, 1); |
| 207 var t2 = new TimelineThread(p1, 2); |
| 208 var g = new TimelineAsyncSliceGroup('a'); |
| 209 g.slices.push(newAsyncSlice(0, 1, t1, t1)); |
| 210 g.slices.push(newAsyncSlice(0, 1, t2, t2)); |
| 211 |
| 212 var subGroups = g.computeSubGroups(); |
| 213 assertEquals(2, subGroups.length); |
| 214 |
| 215 assertEquals(g.name, subGroups[0].name); |
| 216 assertEquals(1, subGroups[0].slices.length); |
| 217 assertEquals(g.slices[0], subGroups[0].slices[0]); |
| 218 |
| 219 assertEquals(g.name, subGroups[1].name); |
| 220 assertEquals(1, subGroups[1].slices.length); |
| 221 assertEquals(g.slices[1], subGroups[1].slices[0]); |
116 } | 222 } |
117 | 223 |
118 function testModelCanImportEmpty() { | 224 function testModelCanImportEmpty() { |
119 var m; | 225 var m; |
120 m = new TimelineModel([]); | 226 m = new TimelineModel([]); |
121 m = new TimelineModel(""); | 227 m = new TimelineModel(''); |
122 } | 228 } |
123 </script> | 229 </script> |
124 </body> | 230 </body> |
125 </html> | 231 </html> |
OLD | NEW |