OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * @constructor | 6 * @constructor |
| 7 * @param {!WebInspector.TracingManager} tracingManager |
7 * @param {!WebInspector.TracingModel} tracingModel | 8 * @param {!WebInspector.TracingModel} tracingModel |
8 * @param {!WebInspector.TimelineModel.Filter} recordFilter | 9 * @param {!WebInspector.TimelineModel.Filter} recordFilter |
9 * @extends {WebInspector.TimelineModel} | 10 * @extends {WebInspector.TimelineModel} |
10 */ | 11 */ |
11 WebInspector.TracingTimelineModel = function(tracingModel, recordFilter) | 12 WebInspector.TracingTimelineModel = function(tracingManager, tracingModel, recor
dFilter) |
12 { | 13 { |
13 WebInspector.TimelineModel.call(this); | 14 WebInspector.TimelineModel.call(this); |
| 15 |
| 16 this._tracingManager = tracingManager; |
14 this._tracingModel = tracingModel; | 17 this._tracingModel = tracingModel; |
15 this._recordFilter = recordFilter; | 18 this._recordFilter = recordFilter; |
16 this._tracingModel.addEventListener(WebInspector.TracingModel.Events.Tracing
Started, this._onTracingStarted, this); | 19 this._tracingManager.addEventListener(WebInspector.TracingManager.Events.Tra
cingStarted, this._onTracingStarted, this); |
17 this._tracingModel.addEventListener(WebInspector.TracingModel.Events.Tracing
Complete, this._onTracingComplete, this); | 20 this._tracingManager.addEventListener(WebInspector.TracingManager.Events.Eve
ntsCollected, this._onEventsCollected, this); |
| 21 this._tracingManager.addEventListener(WebInspector.TracingManager.Events.Tra
cingComplete, this._onTracingComplete, this); |
18 this.reset(); | 22 this.reset(); |
19 } | 23 } |
20 | 24 |
21 WebInspector.TracingTimelineModel.RecordType = { | 25 WebInspector.TracingTimelineModel.RecordType = { |
22 Program: "Program", | 26 Program: "Program", |
23 EventDispatch: "EventDispatch", | 27 EventDispatch: "EventDispatch", |
24 | 28 |
25 GPUTask: "GPUTask", | 29 GPUTask: "GPUTask", |
26 | 30 |
27 RequestMainThreadFrame: "RequestMainThreadFrame", | 31 RequestMainThreadFrame: "RequestMainThreadFrame", |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 this._startRecordingWithCategories(categories); | 152 this._startRecordingWithCategories(categories); |
149 }, | 153 }, |
150 | 154 |
151 stopRecording: function() | 155 stopRecording: function() |
152 { | 156 { |
153 this._stopCallbackBarrier = new CallbackBarrier(); | 157 this._stopCallbackBarrier = new CallbackBarrier(); |
154 if (this._jsProfilerStarted) { | 158 if (this._jsProfilerStarted) { |
155 this._currentTarget.profilerAgent().stop(this._stopCallbackBarrier.c
reateCallback(this._didStopRecordingJSSamples.bind(this))); | 159 this._currentTarget.profilerAgent().stop(this._stopCallbackBarrier.c
reateCallback(this._didStopRecordingJSSamples.bind(this))); |
156 this._jsProfilerStarted = false; | 160 this._jsProfilerStarted = false; |
157 } | 161 } |
158 this._tracingModel.stop(); | 162 this._tracingManager.stop(); |
159 }, | 163 }, |
160 | 164 |
161 /** | 165 /** |
162 * @param {!Array.<!WebInspector.TracingModel.EventPayload>} events | 166 * @param {!Array.<!WebInspector.TracingManager.EventPayload>} events |
163 */ | 167 */ |
164 setEventsForTest: function(events) | 168 setEventsForTest: function(events) |
165 { | 169 { |
166 this._tracingModel.setEventsForTest(events); | 170 this._onTracingStarted(); |
| 171 this._tracingModel.addEvents(events); |
| 172 this._onTracingComplete(); |
167 }, | 173 }, |
168 | 174 |
169 _configureCpuProfilerSamplingInterval: function() | 175 _configureCpuProfilerSamplingInterval: function() |
170 { | 176 { |
171 var intervalUs = WebInspector.settings.highResolutionCpuProfiling.get()
? 100 : 1000; | 177 var intervalUs = WebInspector.settings.highResolutionCpuProfiling.get()
? 100 : 1000; |
172 this._currentTarget.profilerAgent().setSamplingInterval(intervalUs, didC
hangeInterval); | 178 this._currentTarget.profilerAgent().setSamplingInterval(intervalUs, didC
hangeInterval); |
173 | 179 |
174 function didChangeInterval(error) | 180 function didChangeInterval(error) |
175 { | 181 { |
176 if (error) | 182 if (error) |
177 WebInspector.console.error(error); | 183 WebInspector.console.error(error); |
178 } | 184 } |
179 }, | 185 }, |
180 | 186 |
181 /** | 187 /** |
182 * @param {string} categories | 188 * @param {string} categories |
183 */ | 189 */ |
184 _startRecordingWithCategories: function(categories) | 190 _startRecordingWithCategories: function(categories) |
185 { | 191 { |
186 this.reset(); | 192 this._tracingManager.start(categories, ""); |
187 this._tracingModel.start(categories, ""); | |
188 }, | 193 }, |
189 | 194 |
190 _onTracingStarted: function() | 195 _onTracingStarted: function() |
191 { | 196 { |
192 this.reset(); | 197 this.reset(); |
| 198 this._tracingModel.reset(); |
193 this.dispatchEventToListeners(WebInspector.TimelineModel.Events.Recordin
gStarted); | 199 this.dispatchEventToListeners(WebInspector.TimelineModel.Events.Recordin
gStarted); |
194 }, | 200 }, |
195 | 201 |
| 202 /** |
| 203 * @param {!WebInspector.Event} event |
| 204 */ |
| 205 _onEventsCollected: function(event) |
| 206 { |
| 207 var traceEvents = /** @type {!Array.<!WebInspector.TracingManager.EventP
ayload>} */ (event.data); |
| 208 this._tracingModel.addEvents(traceEvents); |
| 209 }, |
| 210 |
196 _onTracingComplete: function() | 211 _onTracingComplete: function() |
197 { | 212 { |
| 213 this._tracingModel.tracingComplete(); |
198 if (this._stopCallbackBarrier) | 214 if (this._stopCallbackBarrier) |
199 this._stopCallbackBarrier.callWhenDone(this._didStopRecordingTraceEv
ents.bind(this)); | 215 this._stopCallbackBarrier.callWhenDone(this._didStopRecordingTraceEv
ents.bind(this)); |
200 else | 216 else |
201 this._didStopRecordingTraceEvents(); | 217 this._didStopRecordingTraceEvents(); |
202 }, | 218 }, |
203 | 219 |
204 /** | 220 /** |
205 * @param {?Protocol.Error} error | 221 * @param {?Protocol.Error} error |
206 * @param {?ProfilerAgent.CPUProfile} cpuProfile | 222 * @param {?ProfilerAgent.CPUProfile} cpuProfile |
207 */ | 223 */ |
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 lastIndex = WebInspector.TextUtils.findBalancedCurlyBrackets(data, i
ndex); | 956 lastIndex = WebInspector.TextUtils.findBalancedCurlyBrackets(data, i
ndex); |
941 } while (lastIndex !== -1) | 957 } while (lastIndex !== -1) |
942 | 958 |
943 var json = data.slice(0, index) + "]"; | 959 var json = data.slice(0, index) + "]"; |
944 this._buffer = data.slice(index); | 960 this._buffer = data.slice(index); |
945 | 961 |
946 if (!index) | 962 if (!index) |
947 return; | 963 return; |
948 | 964 |
949 if (this._firstChunk) { | 965 if (this._firstChunk) { |
950 this._model.reset(); | 966 this._model._onTracingStarted(); |
951 } else { | 967 } else { |
952 var commaIndex = json.indexOf(","); | 968 var commaIndex = json.indexOf(","); |
953 if (commaIndex !== -1) | 969 if (commaIndex !== -1) |
954 json = json.slice(commaIndex + 1); | 970 json = json.slice(commaIndex + 1); |
955 json = "[" + json; | 971 json = "[" + json; |
956 } | 972 } |
957 | 973 |
958 var items; | 974 var items; |
959 try { | 975 try { |
960 items = /** @type {!Array.<!WebInspector.TracingModel.EventPayload>}
*/ (JSON.parse(json)); | 976 items = /** @type {!Array.<!WebInspector.TracingManager.EventPayload
>} */ (JSON.parse(json)); |
961 } catch (e) { | 977 } catch (e) { |
962 this._reportErrorAndCancelLoading("Malformed timeline data: " + e); | 978 this._reportErrorAndCancelLoading("Malformed timeline data: " + e); |
963 return; | 979 return; |
964 } | 980 } |
965 | 981 |
966 if (this._firstChunk) { | 982 if (this._firstChunk) { |
967 this._firstChunk = false; | 983 this._firstChunk = false; |
968 if (this._looksLikeAppVersion(items[0])) { | 984 if (this._looksLikeAppVersion(items[0])) { |
969 this._reportErrorAndCancelLoading("Old Timeline format is not su
pported."); | 985 this._reportErrorAndCancelLoading("Old Timeline format is not su
pported."); |
970 return; | 986 return; |
971 } | 987 } |
972 } | 988 } |
973 | 989 |
974 try { | 990 try { |
975 this._loader.loadNextChunk(items); | 991 this._loader.loadNextChunk(items); |
976 } catch(e) { | 992 } catch(e) { |
977 this._reportErrorAndCancelLoading("Malformed timeline data: " + e); | 993 this._reportErrorAndCancelLoading("Malformed timeline data: " + e); |
978 return; | 994 return; |
979 } | 995 } |
980 }, | 996 }, |
981 | 997 |
982 _reportErrorAndCancelLoading: function(messsage) | 998 _reportErrorAndCancelLoading: function(messsage) |
983 { | 999 { |
984 WebInspector.console.error(messsage); | 1000 WebInspector.console.error(messsage); |
| 1001 this._model._onTracingComplete(); |
985 this._model.reset(); | 1002 this._model.reset(); |
986 this._reader.cancel(); | 1003 this._reader.cancel(); |
987 this._progress.done(); | 1004 this._progress.done(); |
988 }, | 1005 }, |
989 | 1006 |
990 _looksLikeAppVersion: function(item) | 1007 _looksLikeAppVersion: function(item) |
991 { | 1008 { |
992 return typeof item === "string" && item.indexOf("Chrome") !== -1; | 1009 return typeof item === "string" && item.indexOf("Chrome") !== -1; |
993 }, | 1010 }, |
994 | 1011 |
995 close: function() | 1012 close: function() |
996 { | 1013 { |
997 this._loader.finish(); | 1014 this._loader.finish(); |
| 1015 this._model._onTracingComplete(); |
998 } | 1016 } |
999 } | 1017 } |
1000 | 1018 |
1001 /** | 1019 /** |
1002 * @constructor | 1020 * @constructor |
1003 * @param {!WebInspector.OutputStream} stream | 1021 * @param {!WebInspector.OutputStream} stream |
1004 */ | 1022 */ |
1005 WebInspector.TracingTimelineSaver = function(stream) | 1023 WebInspector.TracingTimelineSaver = function(stream) |
1006 { | 1024 { |
1007 this._stream = stream; | 1025 this._stream = stream; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1043 }, | 1061 }, |
1044 | 1062 |
1045 _didWriteNextChunk: function(stream) | 1063 _didWriteNextChunk: function(stream) |
1046 { | 1064 { |
1047 if (this._recordIndex === this._payloads.length) | 1065 if (this._recordIndex === this._payloads.length) |
1048 stream.close(); | 1066 stream.close(); |
1049 else | 1067 else |
1050 this._writeNextChunk(stream); | 1068 this._writeNextChunk(stream); |
1051 } | 1069 } |
1052 } | 1070 } |
OLD | NEW |