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

Side by Side 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: Created 5 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 }, 1189 },
1190 1190
1191 /** 1191 /**
1192 * @param {!Blob} file 1192 * @param {!Blob} file
1193 * @param {!WebInspector.Progress} progress 1193 * @param {!WebInspector.Progress} progress
1194 */ 1194 */
1195 loadFromFile: function(file, progress) 1195 loadFromFile: function(file, progress)
1196 { 1196 {
1197 var delegate = new WebInspector.TimelineModelLoadFromFileDelegate(this, progress); 1197 var delegate = new WebInspector.TimelineModelLoadFromFileDelegate(this, progress);
1198 var fileReader = this._createFileReader(file, delegate); 1198 var fileReader = this._createFileReader(file, delegate);
1199 var loader = this.createLoader(fileReader, progress); 1199 var loader = new WebInspector.TracingModelLoader(this, new WebInspector. ProgressStub(), fileReader.cancel.bind(fileReader));
1200 fileReader.start(loader); 1200 fileReader.start(loader);
1201 }, 1201 },
1202 1202
1203 _createFileReader: function(file, delegate) 1203 _createFileReader: function(file, delegate)
1204 { 1204 {
1205 return new WebInspector.ChunkedFileReader(file, WebInspector.TimelineMod el.TransferChunkLengthBytes, delegate); 1205 return new WebInspector.ChunkedFileReader(file, WebInspector.TimelineMod el.TransferChunkLengthBytes, delegate);
1206 }, 1206 },
1207 1207
1208 reset: function() 1208 reset: function()
1209 { 1209 {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1275 1275
1276 /** 1276 /**
1277 * @return {!Array.<!WebInspector.TimelineModel.VirtualThread>} 1277 * @return {!Array.<!WebInspector.TimelineModel.VirtualThread>}
1278 */ 1278 */
1279 virtualThreads: function() 1279 virtualThreads: function()
1280 { 1280 {
1281 return this._virtualThreads; 1281 return this._virtualThreads;
1282 }, 1282 },
1283 1283
1284 /** 1284 /**
1285 * @param {!WebInspector.ChunkedFileReader} fileReader
1286 * @param {!WebInspector.Progress} progress
1287 * @return {!WebInspector.OutputStream}
1288 */
1289 createLoader: function(fileReader, progress)
1290 {
1291 return new WebInspector.TracingModelLoader(this, fileReader, progress);
1292 },
1293
1294 /**
1295 * @return {boolean} 1285 * @return {boolean}
1296 */ 1286 */
1297 isEmpty: function() 1287 isEmpty: function()
1298 { 1288 {
1299 return this.minimumRecordTime() === 0 && this.maximumRecordTime() === 0; 1289 return this.minimumRecordTime() === 0 && this.maximumRecordTime() === 0;
1300 }, 1290 },
1301 1291
1302 /** 1292 /**
1303 * @return {!Array.<!WebInspector.TimelineModel.Record>} 1293 * @return {!Array.<!WebInspector.TimelineModel.Record>}
1304 */ 1294 */
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1532 return !this._eventNames[event.name]; 1522 return !this._eventNames[event.name];
1533 }, 1523 },
1534 1524
1535 __proto__: WebInspector.TraceEventNameFilter.prototype 1525 __proto__: WebInspector.TraceEventNameFilter.prototype
1536 } 1526 }
1537 1527
1538 /** 1528 /**
1539 * @constructor 1529 * @constructor
1540 * @implements {WebInspector.OutputStream} 1530 * @implements {WebInspector.OutputStream}
1541 * @param {!WebInspector.TimelineModel} model 1531 * @param {!WebInspector.TimelineModel} model
1542 * @param {!{cancel: function()}} reader
1543 * @param {!WebInspector.Progress} progress 1532 * @param {!WebInspector.Progress} progress
1533 * @param {function()=} canceledCallback
1544 */ 1534 */
1545 WebInspector.TracingModelLoader = function(model, reader, progress) 1535 WebInspector.TracingModelLoader = function(model, progress, canceledCallback)
1546 { 1536 {
1547 this._model = model; 1537 this._model = model;
1548 this._reader = reader; 1538 this._loader = new WebInspector.TracingModel.Loader(model._tracingModel);
1539
1540 this._canceledCallback = canceledCallback;
1549 this._progress = progress; 1541 this._progress = progress;
1550 this._buffer = ""; 1542 this._progress.setTitle(WebInspector.UIString("Loading"));
1543 this._progress.setTotalWork(100000); // Unknown, will loop the values.
alph 2015/03/01 11:30:14 mind to a define a const for it plz.
pfeldman 2015/03/01 12:18:53 Done.
1544
1551 this._firstChunk = true; 1545 this._firstChunk = true;
1552 this._loader = new WebInspector.TracingModel.Loader(model._tracingModel); 1546 this._wasCanceledOnce = false;
1547
1548 this._loadedBytes = 0;
1549 this._jsonTokenizer = new WebInspector.TextUtils.BalancedJSONTokenizer(this. _writeBalancedJSON.bind(this), true);
1553 } 1550 }
1554 1551
1555 WebInspector.TracingModelLoader.prototype = { 1552 WebInspector.TracingModelLoader.prototype = {
1556 /** 1553 /**
1557 * @override 1554 * @override
1558 * @param {string} chunk 1555 * @param {string} chunk
1559 */ 1556 */
1560 write: function(chunk) 1557 write: function(chunk)
1561 { 1558 {
1562 var data = this._buffer + chunk; 1559 this._loadedBytes += chunk.length;
1563 var lastIndex = 0; 1560 if (this._progress.isCanceled() && !this._wasCanceledOnce) {
1564 var index; 1561 this._wasCanceled = true;
1565 do { 1562 this._reportErrorAndCancelLoading();
1566 index = lastIndex; 1563 return;
1567 lastIndex = WebInspector.TextUtils.findBalancedCurlyBrackets(data, i ndex); 1564 }
1568 } while (lastIndex !== -1); 1565 this._progress.setWorked(this._loadedBytes % 100000, WebInspector.UIStri ng("Loaded %s bytes", Number.bytesToString(this._loadedBytes)));
alph 2015/03/01 11:30:14 Drop extra "bytes" word.
pfeldman 2015/03/01 12:18:54 Done.
1566 this._jsonTokenizer.write(chunk);
1567 },
1569 1568
1570 var json = data.slice(0, index) + "]"; 1569 /**
1571 this._buffer = data.slice(index); 1570 * @param {string} data
1572 1571 */
1573 if (!index) 1572 _writeBalancedJSON: function(data)
1574 return; 1573 {
1574 var json = data + "]";
1575 1575
1576 if (this._firstChunk) { 1576 if (this._firstChunk) {
1577 this._model._startCollectingTraceEvents(true); 1577 this._model._startCollectingTraceEvents(true);
1578 } else { 1578 } else {
1579 var commaIndex = json.indexOf(","); 1579 var commaIndex = json.indexOf(",");
1580 if (commaIndex !== -1) 1580 if (commaIndex !== -1)
1581 json = json.slice(commaIndex + 1); 1581 json = json.slice(commaIndex + 1);
1582 json = "[" + json; 1582 json = "[" + json;
1583 } 1583 }
1584 1584
1585 var items; 1585 var items;
1586 try { 1586 try {
1587 items = /** @type {!Array.<!WebInspector.TracingManager.EventPayload >} */ (JSON.parse(json)); 1587 items = /** @type {!Array.<!WebInspector.TracingManager.EventPayload >} */ (JSON.parse(json));
1588 } catch (e) { 1588 } catch (e) {
1589 this._reportErrorAndCancelLoading("Malformed timeline data: " + e); 1589 this._reportErrorAndCancelLoading(WebInspector.UIString("Malformed t imeline data: " + e));
1590 return; 1590 return;
1591 } 1591 }
1592 1592
1593 if (this._firstChunk) { 1593 if (this._firstChunk) {
1594 this._firstChunk = false; 1594 this._firstChunk = false;
1595 if (this._looksLikeAppVersion(items[0])) { 1595 if (this._looksLikeAppVersion(items[0])) {
1596 this._reportErrorAndCancelLoading("Old Timeline format is not su pported."); 1596 this._reportErrorAndCancelLoading(WebInspector.UIString("Legacy Timeline format is not supported."));
1597 return; 1597 return;
1598 } 1598 }
1599 } 1599 }
1600 1600
1601 try { 1601 try {
1602 this._loader.loadNextChunk(items); 1602 this._loader.loadNextChunk(items);
1603 } catch(e) { 1603 } catch(e) {
1604 this._reportErrorAndCancelLoading("Malformed timeline data: " + e); 1604 this._reportErrorAndCancelLoading(WebInspector.UIString("Malformed t imeline data: " + e));
1605 return; 1605 return;
1606 } 1606 }
1607 }, 1607 },
1608 1608
1609 /**
1610 * @param {string=} messsage
1611 */
1609 _reportErrorAndCancelLoading: function(messsage) 1612 _reportErrorAndCancelLoading: function(messsage)
1610 { 1613 {
1611 WebInspector.console.error(messsage); 1614 if (messsage)
alph 2015/03/01 11:30:14 two 's'-es should be enough
pfeldman 2015/03/01 12:18:53 Done.
1615 WebInspector.console.error(messsage);
1612 this._model.tracingComplete(); 1616 this._model.tracingComplete();
1613 this._model.reset(); 1617 this._model.reset();
1614 this._reader.cancel(); 1618 if (this._canceledCallback)
1619 this._canceledCallback();
1615 this._progress.done(); 1620 this._progress.done();
1616 }, 1621 },
1617 1622
1618 _looksLikeAppVersion: function(item) 1623 _looksLikeAppVersion: function(item)
1619 { 1624 {
1620 return typeof item === "string" && item.indexOf("Chrome") !== -1; 1625 return typeof item === "string" && item.indexOf("Chrome") !== -1;
1621 }, 1626 },
1622 1627
1623 /** 1628 /**
1624 * @override 1629 * @override
1625 */ 1630 */
1626 close: function() 1631 close: function()
alph 2015/03/01 11:30:14 shouldn't there be a check that the remainder is e
pfeldman 2015/03/01 12:18:54 There was not previously.
1627 { 1632 {
1628 this._loader.finish(); 1633 this._loader.finish();
1629 this._model.tracingComplete(); 1634 this._model.tracingComplete();
1635 if (this._progress)
1636 this._progress.done();
1630 } 1637 }
1631 } 1638 }
1632 1639
1633 /** 1640 /**
1634 * @constructor 1641 * @constructor
1635 * @param {!WebInspector.OutputStream} stream 1642 * @param {!WebInspector.OutputStream} stream
1636 * @implements {WebInspector.OutputStreamDelegate} 1643 * @implements {WebInspector.OutputStreamDelegate}
1637 */ 1644 */
1638 WebInspector.TracingTimelineSaver = function(stream) 1645 WebInspector.TracingTimelineSaver = function(stream)
1639 { 1646 {
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
1971 /** @type {!Object.<string, !Array.<!WebInspector.InvalidationTrackingEv ent>>} */ 1978 /** @type {!Object.<string, !Array.<!WebInspector.InvalidationTrackingEv ent>>} */
1972 this._invalidations = {}; 1979 this._invalidations = {};
1973 /** @type {!Object.<number, !Array.<!WebInspector.InvalidationTrackingEv ent>>} */ 1980 /** @type {!Object.<number, !Array.<!WebInspector.InvalidationTrackingEv ent>>} */
1974 this._invalidationsByNodeId = {}; 1981 this._invalidationsByNodeId = {};
1975 1982
1976 this._lastRecalcStyle = undefined; 1983 this._lastRecalcStyle = undefined;
1977 this._lastPaintWithLayer = undefined; 1984 this._lastPaintWithLayer = undefined;
1978 this._didPaint = false; 1985 this._didPaint = false;
1979 } 1986 }
1980 } 1987 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698