Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/timeline/TimelineLoader.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/timeline/TimelineLoader.js b/third_party/WebKit/Source/devtools/front_end/timeline/TimelineLoader.js |
| index 395654428ca11c74ce856241b77e4ea6ad5d8563..0695950baabaca4e5b8a2327787aefb1c69c8a01 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/timeline/TimelineLoader.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/timeline/TimelineLoader.js |
| @@ -79,11 +79,15 @@ Timeline.TimelineLoader = class { |
| if (!this._client) |
| return; |
| this._loadedBytes += chunk.length; |
| - if (!this._firstChunk) |
| + if (this._firstChunk) |
| + this._client.loadingStarted(); |
| + else |
| this._client.loadingProgress(this._totalSize ? this._loadedBytes / this._totalSize : undefined); |
| if (this._state === Timeline.TimelineLoader.State.Initial) { |
| - if (chunk[0] === '{') { |
| + if (chunk.startsWith('{"nodes":[')) { |
| + this._state = Timeline.TimelineLoader.State.LoadingCPUProfileFormat; |
| + } else if (chunk[0] === '{') { |
| this._state = Timeline.TimelineLoader.State.LookingForEvents; |
| } else if (chunk[0] === '[') { |
| this._state = Timeline.TimelineLoader.State.ReadingEvents; |
| @@ -93,6 +97,11 @@ Timeline.TimelineLoader = class { |
| } |
| } |
| + if (this._state === Timeline.TimelineLoader.State.LoadingCPUProfileFormat) { |
| + this._buffer += chunk; |
| + return; |
| + } |
| + |
| if (this._state === Timeline.TimelineLoader.State.LookingForEvents) { |
| var objectName = '"traceEvents":'; |
| var startPos = this._buffer.length - objectName.length; |
| @@ -121,9 +130,7 @@ Timeline.TimelineLoader = class { |
| _writeBalancedJSON(data) { |
| var json = data + ']'; |
| - if (this._firstChunk) { |
| - this._client.loadingStarted(); |
| - } else { |
| + if (!this._firstChunk) { |
| var commaIndex = json.indexOf(','); |
| if (commaIndex !== -1) |
| json = json.slice(commaIndex + 1); |
| @@ -150,7 +157,6 @@ Timeline.TimelineLoader = class { |
| this._tracingModel.addEvents(items); |
| } catch (e) { |
| this._reportErrorAndCancelLoading(Common.UIString('Malformed timeline data: %s', e.toString())); |
| - return; |
| } |
| } |
| @@ -182,6 +188,10 @@ Timeline.TimelineLoader = class { |
| } |
| _finalizeTrace() { |
| + if (this._state === Timeline.TimelineLoader.State.LoadingCPUProfileFormat) { |
| + this._parseCPUProfileFormat(this._buffer); |
| + this._buffer = ''; |
| + } |
| this._tracingModel.tracingComplete(); |
| this._client.loadingComplete(this._tracingModel, this._backingStorage); |
| } |
| @@ -225,6 +235,19 @@ Timeline.TimelineLoader = class { |
| Common.UIString('An error occurred while reading the file "%s"', reader.fileName())); |
| } |
| } |
| + |
| + /** |
| + * @param {string} text |
| + */ |
| + _parseCPUProfileFormat(text) { |
| + try { |
| + var profile = JSON.parse(text); |
| + var traceEvents = TimelineModel.TimelineJSProfileProcessor.buildTraceProfileFromCpuProfile(profile); |
| + this._tracingModel.addEvents(traceEvents); |
|
caseq
2017/03/02 21:27:05
this one could be out of try {}
alph
2017/03/02 22:17:25
Done.
|
| + } catch (e) { |
| + this._reportErrorAndCancelLoading(Common.UIString('Malformed CPU profile format')); |
| + } |
| + } |
| }; |
| @@ -259,7 +282,8 @@ Timeline.TimelineLoader.State = { |
| Initial: Symbol('Initial'), |
| LookingForEvents: Symbol('LookingForEvents'), |
| ReadingEvents: Symbol('ReadingEvents'), |
| - SkippingTail: Symbol('SkippingTail') |
| + SkippingTail: Symbol('SkippingTail'), |
| + LoadingCPUProfileFormat: Symbol('LoadingCPUProfileFormat') |
| }; |
| /** |