Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1148)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sdk/TracingManager.js

Issue 2466123002: DevTools: reformat front-end code to match chromium style. (Closed)
Patch Set: all done Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2014 The Chromium Authors. All rights reserved. 2 * Copyright 2014 The Chromium Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6
7 /** 6 /**
8 * @interface 7 * @interface
9 */ 8 */
10 WebInspector.TracingManagerClient = function() 9 WebInspector.TracingManagerClient = function() {};
11 {
12 };
13 10
14 WebInspector.TracingManagerClient.prototype = { 11 WebInspector.TracingManagerClient.prototype = {
15 tracingStarted: function() { }, 12 tracingStarted: function() {},
16 /** 13 /**
17 * @param {!Array.<!WebInspector.TracingManager.EventPayload>} events 14 * @param {!Array.<!WebInspector.TracingManager.EventPayload>} events
18 */ 15 */
19 traceEventsCollected: function(events) { }, 16 traceEventsCollected: function(events) {},
20 tracingComplete: function() { }, 17 tracingComplete: function() {},
21 /** 18 /**
22 * @param {number} usage 19 * @param {number} usage
23 */ 20 */
24 tracingBufferUsage: function(usage) { }, 21 tracingBufferUsage: function(usage) {},
25 /** 22 /**
26 * @param {number} progress 23 * @param {number} progress
27 */ 24 */
28 eventsRetrievalProgress: function(progress) { } 25 eventsRetrievalProgress: function(progress) {}
29 }; 26 };
30 27
31 /** 28 /**
32 * @constructor 29 * @unrestricted
33 * @param {!WebInspector.Target} target
34 */ 30 */
35 WebInspector.TracingManager = function(target) 31 WebInspector.TracingManager = class {
36 { 32 /**
33 * @param {!WebInspector.Target} target
34 */
35 constructor(target) {
37 this._target = target; 36 this._target = target;
38 target.registerTracingDispatcher(new WebInspector.TracingDispatcher(this)); 37 target.registerTracingDispatcher(new WebInspector.TracingDispatcher(this));
39 38
40 /** @type {?WebInspector.TracingManagerClient} */ 39 /** @type {?WebInspector.TracingManagerClient} */
41 this._activeClient = null; 40 this._activeClient = null;
42 this._eventBufferSize = 0; 41 this._eventBufferSize = 0;
43 this._eventsRetrieved = 0; 42 this._eventsRetrieved = 0;
43 }
44
45 /**
46 * @return {?WebInspector.Target}
47 */
48 target() {
49 return this._target;
50 }
51
52 /**
53 * @param {number=} usage
54 * @param {number=} eventCount
55 * @param {number=} percentFull
56 */
57 _bufferUsage(usage, eventCount, percentFull) {
58 this._eventBufferSize = eventCount;
59 this._activeClient.tracingBufferUsage(usage || percentFull || 0);
60 }
61
62 /**
63 * @param {!Array.<!WebInspector.TracingManager.EventPayload>} events
64 */
65 _eventsCollected(events) {
66 this._activeClient.traceEventsCollected(events);
67 this._eventsRetrieved += events.length;
68 if (!this._eventBufferSize)
69 return;
70 if (this._eventsRetrieved > this._eventBufferSize)
71 this._eventsRetrieved = this._eventBufferSize;
72 this._activeClient.eventsRetrievalProgress(this._eventsRetrieved / this._eve ntBufferSize);
73 }
74
75 _tracingComplete() {
76 this._eventBufferSize = 0;
77 this._eventsRetrieved = 0;
78 this._activeClient.tracingComplete();
79 this._activeClient = null;
80 this._finishing = false;
81 }
82
83 /**
84 * @param {!WebInspector.TracingManagerClient} client
85 * @param {string} categoryFilter
86 * @param {string} options
87 * @param {function(?string)=} callback
88 */
89 start(client, categoryFilter, options, callback) {
90 if (this._activeClient)
91 throw new Error('Tracing is already started');
92 var bufferUsageReportingIntervalMs = 500;
93 this._activeClient = client;
94 this._target.tracingAgent().start(
95 categoryFilter, options, bufferUsageReportingIntervalMs, WebInspector.Tr acingManager.TransferMode.ReportEvents,
96 callback);
97 this._activeClient.tracingStarted();
98 }
99
100 stop() {
101 if (!this._activeClient)
102 throw new Error('Tracing is not started');
103 if (this._finishing)
104 throw new Error('Tracing is already being stopped');
105 this._finishing = true;
106 this._target.tracingAgent().end();
107 }
44 }; 108 };
45 109
46 /** @typedef {!{ 110 /** @typedef {!{
47 cat: string, 111 cat: string,
48 pid: number, 112 pid: number,
49 tid: number, 113 tid: number,
50 ts: number, 114 ts: number,
51 ph: string, 115 ph: string,
52 name: string, 116 name: string,
53 args: !Object, 117 args: !Object,
54 dur: number, 118 dur: number,
55 id: string, 119 id: string,
56 id2: (!{global: (string|undefined), local: (string|undefined)}|undefined ), 120 id2: (!{global: (string|undefined), local: (string|undefined)}|undefined ),
57 scope: string, 121 scope: string,
58 bind_id: string, 122 bind_id: string,
59 s: string 123 s: string
60 }} 124 }}
61 */ 125 */
62 WebInspector.TracingManager.EventPayload; 126 WebInspector.TracingManager.EventPayload;
63 127
64 WebInspector.TracingManager.TransferMode = { 128 WebInspector.TracingManager.TransferMode = {
65 ReportEvents: "ReportEvents", 129 ReportEvents: 'ReportEvents',
66 ReturnAsStream: "ReturnAsStream" 130 ReturnAsStream: 'ReturnAsStream'
67 };
68
69 WebInspector.TracingManager.prototype = {
70 /**
71 * @return {?WebInspector.Target}
72 */
73 target: function()
74 {
75 return this._target;
76 },
77
78 /**
79 * @param {number=} usage
80 * @param {number=} eventCount
81 * @param {number=} percentFull
82 */
83 _bufferUsage: function(usage, eventCount, percentFull)
84 {
85 this._eventBufferSize = eventCount;
86 this._activeClient.tracingBufferUsage(usage || percentFull || 0);
87 },
88
89 /**
90 * @param {!Array.<!WebInspector.TracingManager.EventPayload>} events
91 */
92 _eventsCollected: function(events)
93 {
94 this._activeClient.traceEventsCollected(events);
95 this._eventsRetrieved += events.length;
96 if (!this._eventBufferSize)
97 return;
98 if (this._eventsRetrieved > this._eventBufferSize)
99 this._eventsRetrieved = this._eventBufferSize;
100 this._activeClient.eventsRetrievalProgress(this._eventsRetrieved / this. _eventBufferSize);
101 },
102
103 _tracingComplete: function()
104 {
105 this._eventBufferSize = 0;
106 this._eventsRetrieved = 0;
107 this._activeClient.tracingComplete();
108 this._activeClient = null;
109 this._finishing = false;
110 },
111
112 /**
113 * @param {!WebInspector.TracingManagerClient} client
114 * @param {string} categoryFilter
115 * @param {string} options
116 * @param {function(?string)=} callback
117 */
118 start: function(client, categoryFilter, options, callback)
119 {
120 if (this._activeClient)
121 throw new Error("Tracing is already started");
122 var bufferUsageReportingIntervalMs = 500;
123 this._activeClient = client;
124 this._target.tracingAgent().start(categoryFilter, options, bufferUsageRe portingIntervalMs, WebInspector.TracingManager.TransferMode.ReportEvents, callba ck);
125 this._activeClient.tracingStarted();
126 },
127
128 stop: function()
129 {
130 if (!this._activeClient)
131 throw new Error("Tracing is not started");
132 if (this._finishing)
133 throw new Error("Tracing is already being stopped");
134 this._finishing = true;
135 this._target.tracingAgent().end();
136 }
137 }; 131 };
138 132
139 /** 133 /**
140 * @constructor
141 * @implements {TracingAgent.Dispatcher} 134 * @implements {TracingAgent.Dispatcher}
142 * @param {!WebInspector.TracingManager} tracingManager 135 * @unrestricted
143 */ 136 */
144 WebInspector.TracingDispatcher = function(tracingManager) 137 WebInspector.TracingDispatcher = class {
145 { 138 /**
139 * @param {!WebInspector.TracingManager} tracingManager
140 */
141 constructor(tracingManager) {
146 this._tracingManager = tracingManager; 142 this._tracingManager = tracingManager;
143 }
144
145 /**
146 * @override
147 * @param {number=} usage
148 * @param {number=} eventCount
149 * @param {number=} percentFull
150 */
151 bufferUsage(usage, eventCount, percentFull) {
152 this._tracingManager._bufferUsage(usage, eventCount, percentFull);
153 }
154
155 /**
156 * @override
157 * @param {!Array.<!WebInspector.TracingManager.EventPayload>} data
158 */
159 dataCollected(data) {
160 this._tracingManager._eventsCollected(data);
161 }
162
163 /**
164 * @override
165 */
166 tracingComplete() {
167 this._tracingManager._tracingComplete();
168 }
147 }; 169 };
148
149 WebInspector.TracingDispatcher.prototype = {
150 /**
151 * @override
152 * @param {number=} usage
153 * @param {number=} eventCount
154 * @param {number=} percentFull
155 */
156 bufferUsage: function(usage, eventCount, percentFull)
157 {
158 this._tracingManager._bufferUsage(usage, eventCount, percentFull);
159 },
160
161 /**
162 * @override
163 * @param {!Array.<!WebInspector.TracingManager.EventPayload>} data
164 */
165 dataCollected: function(data)
166 {
167 this._tracingManager._eventsCollected(data);
168 },
169
170 /**
171 * @override
172 */
173 tracingComplete: function()
174 {
175 this._tracingManager._tracingComplete();
176 }
177 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698