| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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(WebInspector.TracingModelLoader._totalProgress);
// Unknown, will loop the values. |
| 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 |
| 1552 WebInspector.TracingModelLoader._totalProgress = 100000; |
| 1553 |
| 1555 WebInspector.TracingModelLoader.prototype = { | 1554 WebInspector.TracingModelLoader.prototype = { |
| 1556 /** | 1555 /** |
| 1557 * @override | 1556 * @override |
| 1558 * @param {string} chunk | 1557 * @param {string} chunk |
| 1559 */ | 1558 */ |
| 1560 write: function(chunk) | 1559 write: function(chunk) |
| 1561 { | 1560 { |
| 1562 var data = this._buffer + chunk; | 1561 this._loadedBytes += chunk.length; |
| 1563 var lastIndex = 0; | 1562 if (this._progress.isCanceled() && !this._wasCanceledOnce) { |
| 1564 var index; | 1563 this._wasCanceled = true; |
| 1565 do { | 1564 this._reportErrorAndCancelLoading(); |
| 1566 index = lastIndex; | 1565 return; |
| 1567 lastIndex = WebInspector.TextUtils.findBalancedCurlyBrackets(data, i
ndex); | 1566 } |
| 1568 } while (lastIndex !== -1); | 1567 this._progress.setWorked(this._loadedBytes % WebInspector.TracingModelLo
ader._totalProgress, |
| 1568 WebInspector.UIString("Loaded %s", Number.bytes
ToString(this._loadedBytes))); |
| 1569 this._jsonTokenizer.write(chunk); |
| 1570 }, |
| 1569 | 1571 |
| 1570 var json = data.slice(0, index) + "]"; | 1572 /** |
| 1571 this._buffer = data.slice(index); | 1573 * @param {string} data |
| 1572 | 1574 */ |
| 1573 if (!index) | 1575 _writeBalancedJSON: function(data) |
| 1574 return; | 1576 { |
| 1577 var json = data + "]"; |
| 1575 | 1578 |
| 1576 if (this._firstChunk) { | 1579 if (this._firstChunk) { |
| 1577 this._model._startCollectingTraceEvents(true); | 1580 this._model._startCollectingTraceEvents(true); |
| 1578 } else { | 1581 } else { |
| 1579 var commaIndex = json.indexOf(","); | 1582 var commaIndex = json.indexOf(","); |
| 1580 if (commaIndex !== -1) | 1583 if (commaIndex !== -1) |
| 1581 json = json.slice(commaIndex + 1); | 1584 json = json.slice(commaIndex + 1); |
| 1582 json = "[" + json; | 1585 json = "[" + json; |
| 1583 } | 1586 } |
| 1584 | 1587 |
| 1585 var items; | 1588 var items; |
| 1586 try { | 1589 try { |
| 1587 items = /** @type {!Array.<!WebInspector.TracingManager.EventPayload
>} */ (JSON.parse(json)); | 1590 items = /** @type {!Array.<!WebInspector.TracingManager.EventPayload
>} */ (JSON.parse(json)); |
| 1588 } catch (e) { | 1591 } catch (e) { |
| 1589 this._reportErrorAndCancelLoading("Malformed timeline data: " + e); | 1592 this._reportErrorAndCancelLoading(WebInspector.UIString("Malformed t
imeline data: " + e)); |
| 1590 return; | 1593 return; |
| 1591 } | 1594 } |
| 1592 | 1595 |
| 1593 if (this._firstChunk) { | 1596 if (this._firstChunk) { |
| 1594 this._firstChunk = false; | 1597 this._firstChunk = false; |
| 1595 if (this._looksLikeAppVersion(items[0])) { | 1598 if (this._looksLikeAppVersion(items[0])) { |
| 1596 this._reportErrorAndCancelLoading("Old Timeline format is not su
pported."); | 1599 this._reportErrorAndCancelLoading(WebInspector.UIString("Legacy
Timeline format is not supported.")); |
| 1597 return; | 1600 return; |
| 1598 } | 1601 } |
| 1599 } | 1602 } |
| 1600 | 1603 |
| 1601 try { | 1604 try { |
| 1602 this._loader.loadNextChunk(items); | 1605 this._loader.loadNextChunk(items); |
| 1603 } catch(e) { | 1606 } catch(e) { |
| 1604 this._reportErrorAndCancelLoading("Malformed timeline data: " + e); | 1607 this._reportErrorAndCancelLoading(WebInspector.UIString("Malformed t
imeline data: " + e)); |
| 1605 return; | 1608 return; |
| 1606 } | 1609 } |
| 1607 }, | 1610 }, |
| 1608 | 1611 |
| 1609 _reportErrorAndCancelLoading: function(messsage) | 1612 /** |
| 1613 * @param {string=} message |
| 1614 */ |
| 1615 _reportErrorAndCancelLoading: function(message) |
| 1610 { | 1616 { |
| 1611 WebInspector.console.error(messsage); | 1617 if (message) |
| 1618 WebInspector.console.error(message); |
| 1612 this._model.tracingComplete(); | 1619 this._model.tracingComplete(); |
| 1613 this._model.reset(); | 1620 this._model.reset(); |
| 1614 this._reader.cancel(); | 1621 if (this._canceledCallback) |
| 1622 this._canceledCallback(); |
| 1615 this._progress.done(); | 1623 this._progress.done(); |
| 1616 }, | 1624 }, |
| 1617 | 1625 |
| 1618 _looksLikeAppVersion: function(item) | 1626 _looksLikeAppVersion: function(item) |
| 1619 { | 1627 { |
| 1620 return typeof item === "string" && item.indexOf("Chrome") !== -1; | 1628 return typeof item === "string" && item.indexOf("Chrome") !== -1; |
| 1621 }, | 1629 }, |
| 1622 | 1630 |
| 1623 /** | 1631 /** |
| 1624 * @override | 1632 * @override |
| 1625 */ | 1633 */ |
| 1626 close: function() | 1634 close: function() |
| 1627 { | 1635 { |
| 1628 this._loader.finish(); | 1636 this._loader.finish(); |
| 1629 this._model.tracingComplete(); | 1637 this._model.tracingComplete(); |
| 1638 if (this._progress) |
| 1639 this._progress.done(); |
| 1630 } | 1640 } |
| 1631 } | 1641 } |
| 1632 | 1642 |
| 1633 /** | 1643 /** |
| 1634 * @constructor | 1644 * @constructor |
| 1635 * @param {!WebInspector.OutputStream} stream | 1645 * @param {!WebInspector.OutputStream} stream |
| 1636 * @implements {WebInspector.OutputStreamDelegate} | 1646 * @implements {WebInspector.OutputStreamDelegate} |
| 1637 */ | 1647 */ |
| 1638 WebInspector.TracingTimelineSaver = function(stream) | 1648 WebInspector.TracingTimelineSaver = function(stream) |
| 1639 { | 1649 { |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1971 /** @type {!Object.<string, !Array.<!WebInspector.InvalidationTrackingEv
ent>>} */ | 1981 /** @type {!Object.<string, !Array.<!WebInspector.InvalidationTrackingEv
ent>>} */ |
| 1972 this._invalidations = {}; | 1982 this._invalidations = {}; |
| 1973 /** @type {!Object.<number, !Array.<!WebInspector.InvalidationTrackingEv
ent>>} */ | 1983 /** @type {!Object.<number, !Array.<!WebInspector.InvalidationTrackingEv
ent>>} */ |
| 1974 this._invalidationsByNodeId = {}; | 1984 this._invalidationsByNodeId = {}; |
| 1975 | 1985 |
| 1976 this._lastRecalcStyle = undefined; | 1986 this._lastRecalcStyle = undefined; |
| 1977 this._lastPaintWithLayer = undefined; | 1987 this._lastPaintWithLayer = undefined; |
| 1978 this._didPaint = false; | 1988 this._didPaint = false; |
| 1979 } | 1989 } |
| 1980 } | 1990 } |
| OLD | NEW |