| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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 cr.define('tracing', function() { | |
| 5 var dataSets = [ | |
| 6 { | |
| 7 name: 'big_trace', | |
| 8 events_url: './tests/big_trace.json' | |
| 9 }, | |
| 10 { | |
| 11 name: 'trivial_trace', | |
| 12 events: [ | |
| 13 {'name': 'a', 'args': {},'pid': 52, 'ts': 9524, 'cat': 'foo', 'tid': 53, | |
| 14 'ph': 'B'}, | |
| 15 {'name': 'a', 'args': {},'pid': 52, 'ts': 9560, 'cat': 'foo', 'tid': 53, | |
| 16 'ph': 'E'}, | |
| 17 {'name': 'b', 'args': {},'pid': 52, 'ts': 9629, 'cat': 'foo', 'tid': 53, | |
| 18 'ph': 'B'}, | |
| 19 {'name': 'b', 'args': {},'pid': 52, 'ts': 9631, 'cat': 'foo', 'tid': 53, | |
| 20 'ph': 'E'} | |
| 21 ] | |
| 22 }, | |
| 23 { | |
| 24 name: 'simple_trace', | |
| 25 events: [ | |
| 26 {'cat': 'PERF', 'pid': 22630, 'tid': 22630, 'ts': 826, 'ph': 'B', | |
| 27 'name': 'A long name that doesnt fit but is exceedingly informative', | |
| 28 'args': {}}, | |
| 29 {'cat': 'PERF', 'pid': 22630, 'tid': 22630, 'ts': 827, 'ph': 'B', | |
| 30 'name': 'Asub with a name that wont fit', 'args': {}}, | |
| 31 {'cat': 'PERF', 'pid': 22630, 'tid': 22630, 'ts': 828, 'ph': 'E', | |
| 32 'name': 'Asub', 'args': {}}, | |
| 33 {'cat': 'PERF', 'pid': 22630, 'tid': 22630, 'ts': 829, 'ph': 'B', | |
| 34 'name': 'Asub', 'args': {}}, | |
| 35 {'cat': 'PERF', 'pid': 22630, 'tid': 22630, 'ts': 832, 'ph': 'E', | |
| 36 'name': 'Asub', 'args': {}}, | |
| 37 {'cat': 'PERF', 'pid': 22630, 'tid': 22630, 'ts': 833, 'ph': 'E', | |
| 38 'name': '', 'args': {}}, | |
| 39 | |
| 40 {'cat': 'PERF', 'pid': 22630, 'tid': 22630, 'ts': 835, 'ph': 'I', | |
| 41 'name': 'I1', 'args': {}}, | |
| 42 {'cat': 'PERF', 'pid': 22630, 'tid': 22630, 'ts': 837, 'ph': 'I', | |
| 43 'name': 'I2', 'args': {}}, | |
| 44 | |
| 45 {'cat': 'PERF', 'pid': 22630, 'tid': 22630, 'ts': 840, 'ph': 'B', | |
| 46 'name': 'A not as long a name', 'args': {}}, | |
| 47 {'cat': 'PERF', 'pid': 22630, 'tid': 22630, 'ts': 848, 'ph': 'E', | |
| 48 'name': 'A not as long a name', 'args': {}}, | |
| 49 | |
| 50 {'cat': 'PERF', 'pid': 22630, 'tid': 22630, 'ts': 850, 'ph': 'B', | |
| 51 'name': 'B', 'args': {}}, | |
| 52 {'cat': 'PERF', 'pid': 22630, 'tid': 22630, 'ts': 854, 'ph': 'E', | |
| 53 'name': 'B', 'args': {}}, | |
| 54 | |
| 55 {'cat': 'PERF', 'pid': 22630, 'tid': 22631, 'ts': 827, 'ph': 'B', | |
| 56 'name': 'A', 'args': {}}, | |
| 57 {'cat': 'PERF', 'pid': 22630, 'tid': 22631, 'ts': 835, 'ph': 'I', | |
| 58 'name': 'Immediate Three', 'args': {}}, | |
| 59 {'cat': 'PERF', 'pid': 22630, 'tid': 22631, 'ts': 845, 'ph': 'I', | |
| 60 'name': 'I4', 'args': {}}, | |
| 61 {'cat': 'PERF', 'pid': 22630, 'tid': 22631, 'ts': 854, 'ph': 'E', | |
| 62 'name': 'A', 'args': {}}, | |
| 63 | |
| 64 {'cat': '__metadata', 'pid': 22630, 'tid': 22630, 'ts': 0, 'ph': 'M', | |
| 65 'name': 'thread_name', 'args': {'name': 'threadA'}}, | |
| 66 {'cat': '__metadata', 'pid': 22630, 'tid': 22631, 'ts': 0, 'ph': 'M', | |
| 67 'name': 'thread_name', 'args': {'name': 'threadB'}}, | |
| 68 {'cat': '__metadata', 'pid': 22630, 'tid': 22632, 'ts': 0, 'ph': 'M', | |
| 69 'name': 'thread_name', 'args': {'name': 'threadC'}} | |
| 70 ] | |
| 71 }, | |
| 72 { | |
| 73 name: 'nonnested_trace', | |
| 74 events: [ | |
| 75 {'cat': 'PERF', 'pid': 22630, 'tid': 22630, 'ts': 826, 'ph': 'B', | |
| 76 'name': 'A', 'args': {}}, | |
| 77 {'cat': 'PERF', 'pid': 22630, 'tid': 22630, 'ts': 827, 'ph': 'B', | |
| 78 'name': 'Asub', 'args': {}}, | |
| 79 {'cat': 'PERF', 'pid': 22630, 'tid': 22630, 'ts': 829, 'ph': 'B', | |
| 80 'name': 'NonNest', 'args': {'id': '1', 'ui-nest': '0'}}, | |
| 81 {'cat': 'PERF', 'pid': 22630, 'tid': 22630, 'ts': 830, 'ph': 'B', | |
| 82 'name': 'NonNest', 'args': {'id': '2', 'ui-nest': '0'}}, | |
| 83 {'cat': 'PERF', 'pid': 22630, 'tid': 22630, 'ts': 831, 'ph': 'E', | |
| 84 'name': 'Asub', 'args': {}}, | |
| 85 {'cat': 'PERF', 'pid': 22630, 'tid': 22630, 'ts': 832, 'ph': 'E', | |
| 86 'name': 'NonNest', 'args': {'id': '1', 'ui-nest': '0'}}, | |
| 87 {'cat': 'PERF', 'pid': 22630, 'tid': 22630, 'ts': 833, 'ph': 'E', | |
| 88 'name': 'NonNest', 'args': {'id': '2', 'ui-nest': '0'}}, | |
| 89 {'cat': 'PERF', 'pid': 22630, 'tid': 22630, 'ts': 834, 'ph': 'E', | |
| 90 'name': 'A', 'args': {}}, | |
| 91 | |
| 92 {'cat': 'PERF', 'pid': 22630, 'tid': 22631, 'ts': 827, 'ph': 'B', | |
| 93 'name': 'A', 'args': {}}, | |
| 94 {'cat': 'PERF', 'pid': 22630, 'tid': 22631, 'ts': 854, 'ph': 'E', | |
| 95 'name': 'A', 'args': {}} | |
| 96 ] | |
| 97 }, | |
| 98 { | |
| 99 name: 'tall_trace', | |
| 100 events: [ | |
| 101 {'cat': 'X', 'pid': 30, 'tid': 30, 'ts': 826, 'ph': 'B', 'name': 'A', | |
| 102 'args': {}}, | |
| 103 {'cat': 'X', 'pid': 30, 'tid': 30, 'ts': 827, 'ph': 'B', 'name': 'Asub', | |
| 104 'args': {}}, | |
| 105 {'cat': 'X', 'pid': 30, 'tid': 30, 'ts': 828, 'ph': 'E', 'name': 'Asub', | |
| 106 'args': {}}, | |
| 107 {'cat': 'X', 'pid': 30, 'tid': 30, 'ts': 829, 'ph': 'B', 'name': 'Asub', | |
| 108 'args': {}}, | |
| 109 {'cat': 'X', 'pid': 30, 'tid': 30, 'ts': 832, 'ph': 'E', 'name': 'Asub', | |
| 110 'args': {}}, | |
| 111 {'cat': 'X', 'pid': 30, 'tid': 30, 'ts': 833, 'ph': 'E', 'name': '', | |
| 112 'args': {}}, | |
| 113 | |
| 114 {'cat': 'X', 'pid': 30, 'tid': 31, 'ts': 840, 'ph': 'B', 'name': 'A', | |
| 115 'args': {}}, | |
| 116 {'cat': 'X', 'pid': 30, 'tid': 31, 'ts': 848, 'ph': 'E', 'name': 'A', | |
| 117 'args': {}}, | |
| 118 | |
| 119 {'cat': 'X', 'pid': 30, 'tid': 32, 'ts': 840, 'ph': 'B', 'name': 'A', | |
| 120 'args': {}}, | |
| 121 {'cat': 'X', 'pid': 30, 'tid': 32, 'ts': 848, 'ph': 'E', 'name': 'A', | |
| 122 'args': {}}, | |
| 123 | |
| 124 {'cat': 'X', 'pid': 30, 'tid': 33, 'ts': 840, 'ph': 'B', 'name': 'A', | |
| 125 'args': {}}, | |
| 126 {'cat': 'X', 'pid': 30, 'tid': 33, 'ts': 848, 'ph': 'E', 'name': 'A', | |
| 127 'args': {}}, | |
| 128 | |
| 129 {'cat': 'X', 'pid': 30, 'tid': 34, 'ts': 840, 'ph': 'B', 'name': 'A', | |
| 130 'args': {}}, | |
| 131 {'cat': 'X', 'pid': 30, 'tid': 34, 'ts': 848, 'ph': 'E', 'name': 'A', | |
| 132 'args': {}}, | |
| 133 | |
| 134 {'cat': 'X', 'pid': 30, 'tid': 35, 'ts': 840, 'ph': 'B', 'name': 'A', | |
| 135 'args': {}}, | |
| 136 {'cat': 'X', 'pid': 30, 'tid': 35, 'ts': 848, 'ph': 'E', 'name': 'A', | |
| 137 'args': {}}, | |
| 138 | |
| 139 {'cat': 'X', 'pid': 30, 'tid': 36, 'ts': 840, 'ph': 'B', 'name': 'A', | |
| 140 'args': {}}, | |
| 141 {'cat': 'X', 'pid': 30, 'tid': 36, 'ts': 848, 'ph': 'E', 'name': 'A', | |
| 142 'args': {}}, | |
| 143 | |
| 144 {'cat': 'X', 'pid': 30, 'tid': 37, 'ts': 840, 'ph': 'B', 'name': 'A', | |
| 145 'args': {}}, | |
| 146 {'cat': 'X', 'pid': 30, 'tid': 37, 'ts': 848, 'ph': 'E', 'name': 'A', | |
| 147 'args': {}}, | |
| 148 | |
| 149 {'cat': 'X', 'pid': 30, 'tid': 38, 'ts': 840, 'ph': 'B', 'name': 'A', | |
| 150 'args': {}}, | |
| 151 {'cat': 'X', 'pid': 30, 'tid': 38, 'ts': 848, 'ph': 'E', 'name': 'A', | |
| 152 'args': {}}, | |
| 153 | |
| 154 {'cat': 'X', 'pid': 30, 'tid': 39, 'ts': 840, 'ph': 'B', 'name': 'A', | |
| 155 'args': {}}, | |
| 156 {'cat': 'X', 'pid': 30, 'tid': 39, 'ts': 848, 'ph': 'E', 'name': 'A', | |
| 157 'args': {}}, | |
| 158 | |
| 159 {'cat': 'X', 'pid': 30, 'tid': 10, 'ts': 840, 'ph': 'B', 'name': 'A', | |
| 160 'args': {}}, | |
| 161 {'cat': 'X', 'pid': 30, 'tid': 10, 'ts': 848, 'ph': 'E', 'name': 'A', | |
| 162 'args': {}}, | |
| 163 | |
| 164 {'cat': 'X', 'pid': 31, 'tid': 11, 'ts': 840, 'ph': 'B', 'name': 'A', | |
| 165 'args': {}}, | |
| 166 {'cat': 'X', 'pid': 31, 'tid': 11, 'ts': 848, 'ph': 'E', 'name': 'A', | |
| 167 'args': {}}, | |
| 168 | |
| 169 {'cat': 'X', 'pid': 30, 'tid': 12, 'ts': 840, 'ph': 'B', 'name': 'A', | |
| 170 'args': {}}, | |
| 171 {'cat': 'X', 'pid': 30, 'tid': 12, 'ts': 848, 'ph': 'E', 'name': 'A', | |
| 172 'args': {}}, | |
| 173 | |
| 174 {'cat': 'X', 'pid': 30, 'tid': 13, 'ts': 840, 'ph': 'B', 'name': 'A', | |
| 175 'args': {}}, | |
| 176 {'cat': 'X', 'pid': 30, 'tid': 13, 'ts': 848, 'ph': 'E', 'name': 'A', | |
| 177 'args': {}}, | |
| 178 | |
| 179 {'cat': 'X', 'pid': 30, 'tid': 14, 'ts': 840, 'ph': 'B', 'name': 'A', | |
| 180 'args': {}}, | |
| 181 {'cat': 'X', 'pid': 30, 'tid': 14, 'ts': 848, 'ph': 'E', 'name': 'A', | |
| 182 'args': {}}, | |
| 183 | |
| 184 {'cat': 'X', 'pid': 30, 'tid': 15, 'ts': 840, 'ph': 'B', 'name': 'A', | |
| 185 'args': {}}, | |
| 186 {'cat': 'X', 'pid': 30, 'tid': 15, 'ts': 848, 'ph': 'E', 'name': 'A', | |
| 187 'args': {}}, | |
| 188 | |
| 189 {'cat': '__metadata', 'pid': 30, 'tid': 14, 'ts': 0, 'ph': 'M', | |
| 190 'name': 'thread_name', 'args': {'name': 'threadB'}}, | |
| 191 {'cat': '__metadata', 'pid': 30, 'tid': 15, 'ts': 0, 'ph': 'M', | |
| 192 'name': 'thread_name', 'args': {'name': 'threadA'}} | |
| 193 ] | |
| 194 }, | |
| 195 { | |
| 196 name: 'huge_trace', | |
| 197 events_url: './tests/huge_trace.json' | |
| 198 } | |
| 199 ]; | |
| 200 | |
| 201 // Create UI for controlling the test harness | |
| 202 var selectEl = document.createElement('select'); | |
| 203 for (var i = 0; i < dataSets.length; ++i) { | |
| 204 var optionEl = document.createElement('option'); | |
| 205 optionEl.textContent = dataSets[i].name; | |
| 206 optionEl.dataSet = dataSets[i]; | |
| 207 selectEl.appendChild(optionEl); | |
| 208 } | |
| 209 selectEl.addEventListener('change', function() { | |
| 210 tracingController.beginTracing(); | |
| 211 }); | |
| 212 selectEl.addEventListener('keydown', function() { | |
| 213 window.setTimeout(function() { | |
| 214 tracingController.beginTracing(); | |
| 215 }, 0); | |
| 216 }); | |
| 217 | |
| 218 var controlEl = document.createElement('div'); | |
| 219 var textEl = document.createElement('span'); | |
| 220 textEl.textContent = 'Trace:'; | |
| 221 controlEl.appendChild(textEl); | |
| 222 controlEl.appendChild(selectEl); | |
| 223 | |
| 224 document.querySelector('#debug-div').appendChild(controlEl, | |
| 225 document.body.firstChild); | |
| 226 | |
| 227 return { | |
| 228 tracingControllerTestHarness: { | |
| 229 beginTracing: function() { | |
| 230 var dataSet = dataSets[selectEl.selectedIndex]; | |
| 231 if (dataSet.events) { | |
| 232 window.setTimeout(function() { | |
| 233 tracingController.onTraceDataCollected(dataSet.events); | |
| 234 tracingController.endTracing(); | |
| 235 window.setTimeout(function() { | |
| 236 tracingController.onEndTracingComplete(); | |
| 237 },0); | |
| 238 }, 0); | |
| 239 } else { | |
| 240 var req = new XMLHttpRequest(); | |
| 241 req.open('GET', './tracing/' + dataSet.events_url, true); | |
| 242 req.onreadystatechange = function(aEvt) { | |
| 243 if (req.readyState == 4) { | |
| 244 tracingController.endTracing(); | |
| 245 window.setTimeout(function() { | |
| 246 if (req.status == 200) { | |
| 247 var resp = JSON.parse(req.responseText); | |
| 248 if (resp.traceEvents) | |
| 249 tracingController.onTraceDataCollected(resp.traceEvents); | |
| 250 else | |
| 251 tracingController.onTraceDataCollected(resp); | |
| 252 } else { | |
| 253 console.log('collection failed.'); | |
| 254 } | |
| 255 tracingController.onEndTracingComplete(); | |
| 256 }, 0); | |
| 257 } | |
| 258 }; | |
| 259 req.send(null); | |
| 260 } | |
| 261 }, | |
| 262 | |
| 263 endTracing: function() { | |
| 264 } | |
| 265 } | |
| 266 }; | |
| 267 }); | |
| OLD | NEW |