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

Unified Diff: Source/devtools/front_end/timeline/TimelineModel.js

Issue 967853002: DevTools: n^2 -> n while loading heap snapshots and timeline files. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fixed the load test. Created 5 years, 10 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/devtools/front_end/heap_snapshot_worker/HeapSnapshotLoader.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/devtools/front_end/timeline/TimelineModel.js
diff --git a/Source/devtools/front_end/timeline/TimelineModel.js b/Source/devtools/front_end/timeline/TimelineModel.js
index 5a89c30ce9720acb3016b4e2ea07a8c84a1fb9ce..60e4220eb7a1fa9ba2f5f57a501b8e4eaa0df745 100644
--- a/Source/devtools/front_end/timeline/TimelineModel.js
+++ b/Source/devtools/front_end/timeline/TimelineModel.js
@@ -1196,7 +1196,7 @@ WebInspector.TimelineModel.prototype = {
{
var delegate = new WebInspector.TimelineModelLoadFromFileDelegate(this, progress);
var fileReader = this._createFileReader(file, delegate);
- var loader = this.createLoader(fileReader, progress);
+ var loader = new WebInspector.TracingModelLoader(this, new WebInspector.ProgressStub(), fileReader.cancel.bind(fileReader));
fileReader.start(loader);
},
@@ -1282,16 +1282,6 @@ WebInspector.TimelineModel.prototype = {
},
/**
- * @param {!WebInspector.ChunkedFileReader} fileReader
- * @param {!WebInspector.Progress} progress
- * @return {!WebInspector.OutputStream}
- */
- createLoader: function(fileReader, progress)
- {
- return new WebInspector.TracingModelLoader(this, fileReader, progress);
- },
-
- /**
* @return {boolean}
*/
isEmpty: function()
@@ -1539,19 +1529,28 @@ WebInspector.ExclusiveTraceEventNameFilter.prototype = {
* @constructor
* @implements {WebInspector.OutputStream}
* @param {!WebInspector.TimelineModel} model
- * @param {!{cancel: function()}} reader
* @param {!WebInspector.Progress} progress
+ * @param {function()=} canceledCallback
*/
-WebInspector.TracingModelLoader = function(model, reader, progress)
+WebInspector.TracingModelLoader = function(model, progress, canceledCallback)
{
this._model = model;
- this._reader = reader;
+ this._loader = new WebInspector.TracingModel.Loader(model._tracingModel);
+
+ this._canceledCallback = canceledCallback;
this._progress = progress;
- this._buffer = "";
+ this._progress.setTitle(WebInspector.UIString("Loading"));
+ this._progress.setTotalWork(WebInspector.TracingModelLoader._totalProgress); // Unknown, will loop the values.
+
this._firstChunk = true;
- this._loader = new WebInspector.TracingModel.Loader(model._tracingModel);
+ this._wasCanceledOnce = false;
+
+ this._loadedBytes = 0;
+ this._jsonTokenizer = new WebInspector.TextUtils.BalancedJSONTokenizer(this._writeBalancedJSON.bind(this), true);
}
+WebInspector.TracingModelLoader._totalProgress = 100000;
+
WebInspector.TracingModelLoader.prototype = {
/**
* @override
@@ -1559,19 +1558,23 @@ WebInspector.TracingModelLoader.prototype = {
*/
write: function(chunk)
{
- var data = this._buffer + chunk;
- var lastIndex = 0;
- var index;
- do {
- index = lastIndex;
- lastIndex = WebInspector.TextUtils.findBalancedCurlyBrackets(data, index);
- } while (lastIndex !== -1);
-
- var json = data.slice(0, index) + "]";
- this._buffer = data.slice(index);
-
- if (!index)
+ this._loadedBytes += chunk.length;
+ if (this._progress.isCanceled() && !this._wasCanceledOnce) {
+ this._wasCanceled = true;
+ this._reportErrorAndCancelLoading();
return;
+ }
+ this._progress.setWorked(this._loadedBytes % WebInspector.TracingModelLoader._totalProgress,
+ WebInspector.UIString("Loaded %s", Number.bytesToString(this._loadedBytes)));
+ this._jsonTokenizer.write(chunk);
+ },
+
+ /**
+ * @param {string} data
+ */
+ _writeBalancedJSON: function(data)
+ {
+ var json = data + "]";
if (this._firstChunk) {
this._model._startCollectingTraceEvents(true);
@@ -1586,14 +1589,14 @@ WebInspector.TracingModelLoader.prototype = {
try {
items = /** @type {!Array.<!WebInspector.TracingManager.EventPayload>} */ (JSON.parse(json));
} catch (e) {
- this._reportErrorAndCancelLoading("Malformed timeline data: " + e);
+ this._reportErrorAndCancelLoading(WebInspector.UIString("Malformed timeline data: " + e));
return;
}
if (this._firstChunk) {
this._firstChunk = false;
if (this._looksLikeAppVersion(items[0])) {
- this._reportErrorAndCancelLoading("Old Timeline format is not supported.");
+ this._reportErrorAndCancelLoading(WebInspector.UIString("Legacy Timeline format is not supported."));
return;
}
}
@@ -1601,17 +1604,22 @@ WebInspector.TracingModelLoader.prototype = {
try {
this._loader.loadNextChunk(items);
} catch(e) {
- this._reportErrorAndCancelLoading("Malformed timeline data: " + e);
+ this._reportErrorAndCancelLoading(WebInspector.UIString("Malformed timeline data: " + e));
return;
}
},
- _reportErrorAndCancelLoading: function(messsage)
+ /**
+ * @param {string=} message
+ */
+ _reportErrorAndCancelLoading: function(message)
{
- WebInspector.console.error(messsage);
+ if (message)
+ WebInspector.console.error(message);
this._model.tracingComplete();
this._model.reset();
- this._reader.cancel();
+ if (this._canceledCallback)
+ this._canceledCallback();
this._progress.done();
},
@@ -1627,6 +1635,8 @@ WebInspector.TracingModelLoader.prototype = {
{
this._loader.finish();
this._model.tracingComplete();
+ if (this._progress)
+ this._progress.done();
}
}
« no previous file with comments | « Source/devtools/front_end/heap_snapshot_worker/HeapSnapshotLoader.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698