Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <!-- |
| 3 | Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 4 | Use of this source code is governed by a BSD-style license that can be |
| 5 | found in the LICENSE file. |
| 6 | --> |
| 7 | |
| 8 | <link rel="import" href="/base/extension_registry.html"> |
| 9 | <link rel="import" href="/core/analysis/util.html"> |
Chris Craik | beca7ae | 2015-04-07 13:29:55 -0700 | [diff] [blame] | 10 | <link rel="import" href="/core/trace_model/timed_event.html"> |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 11 | |
| 12 | <script> |
| 13 | 'use strict'; |
| 14 | |
| 15 | /** |
| 16 | * @fileoverview Provides the AsyncSlice class. |
| 17 | */ |
| 18 | tv.exportTo('tv.c.trace_model', function() { |
| 19 | /** |
| 20 | * A AsyncSlice represents an interval of time during which an |
| 21 | * asynchronous operation is in progress. An AsyncSlice consumes no CPU time |
| 22 | * itself and so is only associated with Threads at its start and end point. |
| 23 | * |
| 24 | * @constructor |
| 25 | */ |
| 26 | function AsyncSlice(category, title, colorId, start, args, duration, |
Chris Craik | 44c2820 | 2015-05-12 17:25:16 -0700 | [diff] [blame^] | 27 | opt_isTopLevel, opt_cpuStart, opt_cpuDuration) { |
Chris Craik | beca7ae | 2015-04-07 13:29:55 -0700 | [diff] [blame] | 28 | tv.c.trace_model.TimedEvent.call(this, start); |
| 29 | |
| 30 | this.category = category || ''; |
| 31 | this.title = title; |
| 32 | this.colorId = colorId; |
| 33 | this.args = args; |
| 34 | this.startStackFrame = undefined; |
| 35 | this.endStackFrame = undefined; |
| 36 | this.didNotFinish = false; |
| 37 | this.important = false; |
| 38 | this.subSlices = []; |
| 39 | |
| 40 | this.id = undefined; |
| 41 | this.startThread = undefined; |
| 42 | this.endThread = undefined; |
Chris Craik | 44c2820 | 2015-05-12 17:25:16 -0700 | [diff] [blame^] | 43 | this.cpuStart = undefined; |
| 44 | this.cpuDuration = undefined; |
Chris Craik | beca7ae | 2015-04-07 13:29:55 -0700 | [diff] [blame] | 45 | |
| 46 | this.duration = duration; |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 47 | |
| 48 | // TODO(nduca): Forgive me for what I must do. |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 49 | this.isTopLevel = (opt_isTopLevel === true); |
Chris Craik | 44c2820 | 2015-05-12 17:25:16 -0700 | [diff] [blame^] | 50 | |
| 51 | if (opt_cpuStart !== undefined) |
| 52 | this.cpuStart = opt_cpuStart; |
| 53 | |
| 54 | if (opt_cpuDuration !== undefined) |
| 55 | this.cpuDuration = opt_cpuDuration; |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | AsyncSlice.prototype = { |
Chris Craik | beca7ae | 2015-04-07 13:29:55 -0700 | [diff] [blame] | 59 | __proto__: tv.c.trace_model.TimedEvent.prototype, |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 60 | |
Chris Craik | beca7ae | 2015-04-07 13:29:55 -0700 | [diff] [blame] | 61 | get analysisTypeName() { |
| 62 | return this.title; |
| 63 | }, |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 64 | |
| 65 | get viewSubGroupTitle() { |
| 66 | return this.title; |
| 67 | }, |
| 68 | |
| 69 | get userFriendlyName() { |
| 70 | return 'Async slice ' + this.title + ' at ' + |
| 71 | tv.c.analysis.tsString(this.start); |
Chris Craik | 44c2820 | 2015-05-12 17:25:16 -0700 | [diff] [blame^] | 72 | }, |
| 73 | |
| 74 | findDescendentSlice: function(targetTitle) { |
| 75 | if (!this.subSlices) |
| 76 | return undefined; |
| 77 | |
| 78 | for (var i = 0; i < this.subSlices.length; i++) { |
| 79 | if (this.subSlices[i].title == targetTitle) |
| 80 | return this.subSlices[i]; |
| 81 | var slice = this.subSlices[i].findDescendentSlice(targetTitle); |
| 82 | if (slice) return slice; |
| 83 | } |
| 84 | return undefined; |
| 85 | }, |
| 86 | |
| 87 | iterateAllDescendents: function(callback, opt_this) { |
| 88 | this.subSlices.forEach(callback, opt_this); |
| 89 | this.subSlices.forEach(function(subSlice) { |
| 90 | subSlice.iterateAllDescendents(callback, opt_this); |
| 91 | }, opt_this); |
| 92 | }, |
| 93 | |
| 94 | compareTo: function(that) { |
| 95 | return this.title.localeCompare(that.title); |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 96 | } |
| 97 | }; |
| 98 | |
| 99 | tv.c.trace_model.EventRegistry.register( |
| 100 | AsyncSlice, |
| 101 | { |
| 102 | name: 'asyncSlice', |
| 103 | pluralName: 'asyncSlices', |
Chris Craik | beca7ae | 2015-04-07 13:29:55 -0700 | [diff] [blame] | 104 | singleViewElementName: 'tv-c-a-single-async-slice-sub-view', |
| 105 | multiViewElementName: 'tv-c-a-multi-async-slice-sub-view' |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 106 | }); |
| 107 | |
| 108 | |
| 109 | var options = new tv.b.ExtensionRegistryOptions( |
| 110 | tv.b.TYPE_BASED_REGISTRY_MODE); |
| 111 | options.mandatoryBaseClass = AsyncSlice; |
| 112 | options.defaultConstructor = AsyncSlice; |
| 113 | tv.b.decorateExtensionRegistry(AsyncSlice, options); |
| 114 | |
| 115 | return { |
| 116 | AsyncSlice: AsyncSlice |
| 117 | }; |
| 118 | }); |
| 119 | </script> |