blob: 4863be19febfed4a2ba51ce9f0fed7fdc89a43e6 [file] [log] [blame]
Chris Craikb122baf2015-03-05 13:58:42 -08001<!DOCTYPE html>
2<!--
3Copyright (c) 2013 The Chromium Authors. All rights reserved.
4Use of this source code is governed by a BSD-style license that can be
5found 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 Craikbeca7ae2015-04-07 13:29:55 -070010<link rel="import" href="/core/trace_model/timed_event.html">
Chris Craikb122baf2015-03-05 13:58:42 -080011
12<script>
13'use strict';
14
15/**
16 * @fileoverview Provides the AsyncSlice class.
17 */
18tv.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 Craik44c28202015-05-12 17:25:16 -070027 opt_isTopLevel, opt_cpuStart, opt_cpuDuration) {
Chris Craikbeca7ae2015-04-07 13:29:55 -070028 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 Craik44c28202015-05-12 17:25:16 -070043 this.cpuStart = undefined;
44 this.cpuDuration = undefined;
Chris Craikbeca7ae2015-04-07 13:29:55 -070045
46 this.duration = duration;
Chris Craikb122baf2015-03-05 13:58:42 -080047
48 // TODO(nduca): Forgive me for what I must do.
Chris Craikb122baf2015-03-05 13:58:42 -080049 this.isTopLevel = (opt_isTopLevel === true);
Chris Craik44c28202015-05-12 17:25:16 -070050
51 if (opt_cpuStart !== undefined)
52 this.cpuStart = opt_cpuStart;
53
54 if (opt_cpuDuration !== undefined)
55 this.cpuDuration = opt_cpuDuration;
Chris Craikb122baf2015-03-05 13:58:42 -080056 };
57
58 AsyncSlice.prototype = {
Chris Craikbeca7ae2015-04-07 13:29:55 -070059 __proto__: tv.c.trace_model.TimedEvent.prototype,
Chris Craikb122baf2015-03-05 13:58:42 -080060
Chris Craikbeca7ae2015-04-07 13:29:55 -070061 get analysisTypeName() {
62 return this.title;
63 },
Chris Craikb122baf2015-03-05 13:58:42 -080064
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 Craik44c28202015-05-12 17:25:16 -070072 },
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 Craikb122baf2015-03-05 13:58:42 -080096 }
97 };
98
99 tv.c.trace_model.EventRegistry.register(
100 AsyncSlice,
101 {
102 name: 'asyncSlice',
103 pluralName: 'asyncSlices',
Chris Craikbeca7ae2015-04-07 13:29:55 -0700104 singleViewElementName: 'tv-c-a-single-async-slice-sub-view',
105 multiViewElementName: 'tv-c-a-multi-async-slice-sub-view'
Chris Craikb122baf2015-03-05 13:58:42 -0800106 });
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>