OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 /** | 6 /** |
7 * @fileoverview TimelineModel is a parsed representation of the | 7 * @fileoverview TimelineModel is a parsed representation of the |
8 * TraceEvents obtained from base/trace_event in which the begin-end | 8 * TraceEvents obtained from base/trace_event in which the begin-end |
9 * tokens are converted into a hierarchy of processes, threads, | 9 * tokens are converted into a hierarchy of processes, threads, |
10 * subrows, and slices. | 10 * subrows, and slices. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 * @constructor | 58 * @constructor |
59 */ | 59 */ |
60 function TimelineThread(parent, tid) { | 60 function TimelineThread(parent, tid) { |
61 this.parent = parent; | 61 this.parent = parent; |
62 this.tid = tid; | 62 this.tid = tid; |
63 this.subRows = [[]]; | 63 this.subRows = [[]]; |
64 this.nonNestedSubRows = []; | 64 this.nonNestedSubRows = []; |
65 } | 65 } |
66 | 66 |
67 TimelineThread.prototype = { | 67 TimelineThread.prototype = { |
| 68 name: undefined, |
| 69 |
68 getSubrow: function(i) { | 70 getSubrow: function(i) { |
69 while (i >= this.subRows.length) | 71 while (i >= this.subRows.length) |
70 this.subRows.push([]); | 72 this.subRows.push([]); |
71 return this.subRows[i]; | 73 return this.subRows[i]; |
72 }, | 74 }, |
73 | 75 |
74 addNonNestedSlice: function(slice) { | 76 addNonNestedSlice: function(slice) { |
75 for (var i = 0; i < this.nonNestedSubRows.length; i++) { | 77 for (var i = 0; i < this.nonNestedSubRows.length; i++) { |
76 var currSubRow = this.nonNestedSubRows[i]; | 78 var currSubRow = this.nonNestedSubRows[i]; |
77 var lastSlice = currSubRow[currSubRow.length - 1]; | 79 var lastSlice = currSubRow[currSubRow.length - 1]; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 | 224 |
223 // Add the slice to the subSlices array of its parent. | 225 // Add the slice to the subSlices array of its parent. |
224 if (state.openSlices.length) { | 226 if (state.openSlices.length) { |
225 var parentSlice = state.openSlices[state.openSlices.length - 1]; | 227 var parentSlice = state.openSlices[state.openSlices.length - 1]; |
226 parentSlice.slice.subSlices.push(slice); | 228 parentSlice.slice.subSlices.push(slice); |
227 } | 229 } |
228 } | 230 } |
229 } else if (event.ph == 'I') { | 231 } else if (event.ph == 'I') { |
230 // TODO(nduca): Implement parsing of immediate events. | 232 // TODO(nduca): Implement parsing of immediate events. |
231 console.log('Parsing of I-type events not implemented.'); | 233 console.log('Parsing of I-type events not implemented.'); |
| 234 } else if (event.ph == 'M') { |
| 235 if (event.name == 'thread_name') { |
| 236 var thread = this.getProcess(event.pid).getThread(event.tid); |
| 237 thread.name = event.args.name; |
| 238 } else { |
| 239 console.log('Unrecognized metadata name: ' + event.name); |
| 240 } |
232 } else { | 241 } else { |
233 throw new Error('Unrecognized event phase: ' + event.ph + | 242 console.log('Unrecognized event phase: ' + event.ph + |
234 '(' + event.name + ')'); | 243 '(' + event.name + ')'); |
235 } | 244 } |
236 } | 245 } |
237 | 246 this.pruneEmptyThreads(); |
238 this.updateBounds(); | 247 this.updateBounds(); |
239 | 248 |
240 // Add end events for any events that are still on the stack. These | 249 // Add end events for any events that are still on the stack. These |
241 // are events that were still open when trace was ended, and can often | 250 // are events that were still open when trace was ended, and can often |
242 // indicate deadlock behavior. | 251 // indicate deadlock behavior. |
243 for (var ptid in threadStateByPTID) { | 252 for (var ptid in threadStateByPTID) { |
244 var state = threadStateByPTID[ptid]; | 253 var state = threadStateByPTID[ptid]; |
245 while (state.openSlices.length > 0) { | 254 while (state.openSlices.length > 0) { |
246 var slice = state.openSlices.pop(); | 255 var slice = state.openSlices.pop(); |
247 slice.slice.duration = this.maxTimestamp - slice.slice.start; | 256 slice.slice.duration = this.maxTimestamp - slice.slice.start; |
(...skipping 13 matching lines...) Expand all Loading... |
261 } | 270 } |
262 } | 271 } |
263 | 272 |
264 this.shiftWorldToMicroseconds(); | 273 this.shiftWorldToMicroseconds(); |
265 | 274 |
266 var boost = (this.maxTimestamp - this.minTimestamp) * 0.15; | 275 var boost = (this.maxTimestamp - this.minTimestamp) * 0.15; |
267 this.minTimestamp = this.minTimestamp - boost; | 276 this.minTimestamp = this.minTimestamp - boost; |
268 this.maxTimestamp = this.maxTimestamp + boost; | 277 this.maxTimestamp = this.maxTimestamp + boost; |
269 }, | 278 }, |
270 | 279 |
| 280 pruneEmptyThreads: function() { |
| 281 for (var pid in this.processes) { |
| 282 var process = this.processes[pid]; |
| 283 var prunedThreads = []; |
| 284 for (var tid in process.threads) { |
| 285 var thread = process.threads[tid]; |
| 286 if (thread.subRows[0].length) |
| 287 prunedThreads.push(thread); |
| 288 } |
| 289 process.threads = prunedThreads; |
| 290 } |
| 291 }, |
| 292 |
271 updateBounds: function() { | 293 updateBounds: function() { |
272 var wmin = Infinity; | 294 var wmin = Infinity; |
273 var wmax = -wmin; | 295 var wmax = -wmin; |
274 var threads = this.getAllThreads(); | 296 var threads = this.getAllThreads(); |
275 for (var tI = 0; tI < threads.length; tI++) { | 297 for (var tI = 0; tI < threads.length; tI++) { |
276 var thread = threads[tI]; | 298 var thread = threads[tI]; |
277 thread.updateBounds(); | 299 thread.updateBounds(); |
278 if (thread.minTimestamp && thread.maxTimestamp) { | 300 if (thread.minTimestamp != undefined && |
| 301 thread.maxTimestamp != undefined) { |
279 wmin = Math.min(wmin, thread.minTimestamp); | 302 wmin = Math.min(wmin, thread.minTimestamp); |
280 wmax = Math.max(wmax, thread.maxTimestamp); | 303 wmax = Math.max(wmax, thread.maxTimestamp); |
281 } | 304 } |
282 } | 305 } |
283 this.minTimestamp = wmin; | 306 this.minTimestamp = wmin; |
284 this.maxTimestamp = wmax; | 307 this.maxTimestamp = wmax; |
285 }, | 308 }, |
286 | 309 |
287 shiftWorldToMicroseconds: function() { | 310 shiftWorldToMicroseconds: function() { |
288 var timeBase = this.minTimestamp; | 311 var timeBase = this.minTimestamp; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 | 343 |
321 }; | 344 }; |
322 | 345 |
323 return { | 346 return { |
324 TimelineSlice: TimelineSlice, | 347 TimelineSlice: TimelineSlice, |
325 TimelineThread: TimelineThread, | 348 TimelineThread: TimelineThread, |
326 TimelineProcess: TimelineProcess, | 349 TimelineProcess: TimelineProcess, |
327 TimelineModel: TimelineModel | 350 TimelineModel: TimelineModel |
328 }; | 351 }; |
329 }); | 352 }); |
OLD | NEW |