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 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 { | 544 { |
545 // FIXME: Consider returning null for loaded traces. | 545 // FIXME: Consider returning null for loaded traces. |
546 return this._targets[0]; | 546 return this._targets[0]; |
547 }, | 547 }, |
548 | 548 |
549 /** | 549 /** |
550 * @param {!Array.<!WebInspector.TracingManager.EventPayload>} events | 550 * @param {!Array.<!WebInspector.TracingManager.EventPayload>} events |
551 */ | 551 */ |
552 setEventsForTest: function(events) | 552 setEventsForTest: function(events) |
553 { | 553 { |
554 this.startCollectingTraceEvents(false); | 554 this._startCollectingTraceEvents(false); |
555 this._tracingModel.addEvents(events); | 555 this._tracingModel.addEvents(events); |
556 this.tracingComplete(); | 556 this.tracingComplete(); |
557 }, | 557 }, |
558 | 558 |
559 /** | 559 /** |
560 * @override | 560 * @override |
561 * @param {!WebInspector.Target} target | 561 * @param {!WebInspector.Target} target |
562 */ | 562 */ |
563 targetAdded: function(target) | 563 targetAdded: function(target) |
564 { | 564 { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 { | 651 { |
652 mainTarget.resourceTreeModel.resumeReload(); | 652 mainTarget.resourceTreeModel.resumeReload(); |
653 if (callback) | 653 if (callback) |
654 callback(error); | 654 callback(error); |
655 } | 655 } |
656 }, | 656 }, |
657 | 657 |
658 /** | 658 /** |
659 * @param {boolean} fromFile | 659 * @param {boolean} fromFile |
660 */ | 660 */ |
661 startCollectingTraceEvents: function(fromFile) | 661 _startCollectingTraceEvents: function(fromFile) |
662 { | 662 { |
663 this._tracingModel.reset(); | 663 this._tracingModel.reset(); |
664 this.reset(); | 664 this.reset(); |
665 this.dispatchEventToListeners(WebInspector.TimelineModel.Events.Recordin
gStarted, { fromFile: fromFile }); | 665 this.dispatchEventToListeners(WebInspector.TimelineModel.Events.Recordin
gStarted, { fromFile: fromFile }); |
666 }, | 666 }, |
667 | 667 |
668 /** | 668 /** |
669 * @override | 669 * @override |
670 */ | 670 */ |
671 tracingStarted: function() | 671 tracingStarted: function() |
672 { | 672 { |
673 this.startCollectingTraceEvents(false); | 673 this._startCollectingTraceEvents(false); |
674 }, | 674 }, |
675 | 675 |
676 /** | 676 /** |
677 * @param {!Array.<!WebInspector.TracingManager.EventPayload>} events | 677 * @param {!Array.<!WebInspector.TracingManager.EventPayload>} events |
678 * @override | 678 * @override |
679 */ | 679 */ |
680 traceEventsCollected: function(events) | 680 traceEventsCollected: function(events) |
681 { | 681 { |
682 this._tracingModel.addEvents(events); | 682 this._tracingModel.addEvents(events); |
683 }, | 683 }, |
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1341 */ | 1341 */ |
1342 _mergeAsyncEvents: function(target, source) | 1342 _mergeAsyncEvents: function(target, source) |
1343 { | 1343 { |
1344 for (var group of source.keys()) { | 1344 for (var group of source.keys()) { |
1345 var events = target.get(group) || []; | 1345 var events = target.get(group) || []; |
1346 events = events.mergeOrdered(source.get(group) || [], WebInspector.T
racingModel.Event.compareStartAndEndTime); | 1346 events = events.mergeOrdered(source.get(group) || [], WebInspector.T
racingModel.Event.compareStartAndEndTime); |
1347 target.set(group, events); | 1347 target.set(group, events); |
1348 } | 1348 } |
1349 }, | 1349 }, |
1350 | 1350 |
| 1351 /** |
| 1352 * @param {!Blob} file |
| 1353 * @param {!WebInspector.Progress} progress |
| 1354 */ |
| 1355 loadFromFile: function(file, progress) |
| 1356 { |
| 1357 var delegate = new WebInspector.TimelineModelLoadFromFileDelegate(this,
progress); |
| 1358 var fileReader = this._createFileReader(file, delegate); |
| 1359 var loader = new WebInspector.TracingModelLoader(this, new WebInspector.
ProgressProxy(null), fileReader.cancel.bind(fileReader)); |
| 1360 fileReader.start(loader); |
| 1361 }, |
| 1362 |
| 1363 /** |
| 1364 * @param {string} url |
| 1365 * @param {!WebInspector.Progress} progress |
| 1366 */ |
| 1367 loadFromURL: function(url, progress) |
| 1368 { |
| 1369 var stream = new WebInspector.TracingModelLoader(this, progress); |
| 1370 WebInspector.ResourceLoader.loadAsStream(url, null, stream); |
| 1371 }, |
| 1372 |
| 1373 _createFileReader: function(file, delegate) |
| 1374 { |
| 1375 return new WebInspector.ChunkedFileReader(file, WebInspector.TimelineMod
el.TransferChunkLengthBytes, delegate); |
| 1376 }, |
| 1377 |
1351 reset: function() | 1378 reset: function() |
1352 { | 1379 { |
1353 this._virtualThreads = []; | 1380 this._virtualThreads = []; |
1354 /** @type {!Array.<!WebInspector.TracingModel.Event>} */ | 1381 /** @type {!Array.<!WebInspector.TracingModel.Event>} */ |
1355 this._mainThreadEvents = []; | 1382 this._mainThreadEvents = []; |
1356 /** @type {!Map<!WebInspector.AsyncEventGroup, !Array<!WebInspector.Trac
ingModel.AsyncEvent>>} */ | 1383 /** @type {!Map<!WebInspector.AsyncEventGroup, !Array<!WebInspector.Trac
ingModel.AsyncEvent>>} */ |
1357 this._mainThreadAsyncEventsByGroup = new Map(); | 1384 this._mainThreadAsyncEventsByGroup = new Map(); |
1358 /** @type {!Array.<!WebInspector.TracingModel.Event>} */ | 1385 /** @type {!Array.<!WebInspector.TracingModel.Event>} */ |
1359 this._inspectedTargetEvents = []; | 1386 this._inspectedTargetEvents = []; |
1360 /** @type {!Array.<!WebInspector.TimelineModel.Record>} */ | 1387 /** @type {!Array.<!WebInspector.TimelineModel.Record>} */ |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1593 accept: function(event) | 1620 accept: function(event) |
1594 { | 1621 { |
1595 return this._visibleTypes.has(WebInspector.TimelineModel._eventType(even
t)); | 1622 return this._visibleTypes.has(WebInspector.TimelineModel._eventType(even
t)); |
1596 }, | 1623 }, |
1597 | 1624 |
1598 __proto__: WebInspector.TimelineModel.Filter.prototype | 1625 __proto__: WebInspector.TimelineModel.Filter.prototype |
1599 } | 1626 } |
1600 | 1627 |
1601 /** | 1628 /** |
1602 * @constructor | 1629 * @constructor |
| 1630 * @implements {WebInspector.OutputStreamDelegate} |
| 1631 * @param {!WebInspector.TimelineModel} model |
| 1632 * @param {!WebInspector.Progress} progress |
| 1633 */ |
| 1634 WebInspector.TimelineModelLoadFromFileDelegate = function(model, progress) |
| 1635 { |
| 1636 this._model = model; |
| 1637 this._progress = progress; |
| 1638 } |
| 1639 |
| 1640 WebInspector.TimelineModelLoadFromFileDelegate.prototype = { |
| 1641 /** |
| 1642 * @override |
| 1643 */ |
| 1644 onTransferStarted: function() |
| 1645 { |
| 1646 this._progress.setTitle(WebInspector.UIString("Loading\u2026")); |
| 1647 }, |
| 1648 |
| 1649 /** |
| 1650 * @override |
| 1651 * @param {!WebInspector.ChunkedReader} reader |
| 1652 */ |
| 1653 onChunkTransferred: function(reader) |
| 1654 { |
| 1655 if (this._progress.isCanceled()) { |
| 1656 reader.cancel(); |
| 1657 this._progress.done(); |
| 1658 this._model.reset(); |
| 1659 return; |
| 1660 } |
| 1661 |
| 1662 var totalSize = reader.fileSize(); |
| 1663 if (totalSize) { |
| 1664 this._progress.setTotalWork(totalSize); |
| 1665 this._progress.setWorked(reader.loadedSize()); |
| 1666 } |
| 1667 }, |
| 1668 |
| 1669 /** |
| 1670 * @override |
| 1671 */ |
| 1672 onTransferFinished: function() |
| 1673 { |
| 1674 this._progress.done(); |
| 1675 }, |
| 1676 |
| 1677 /** |
| 1678 * @override |
| 1679 * @param {!WebInspector.ChunkedReader} reader |
| 1680 * @param {!Event} event |
| 1681 */ |
| 1682 onError: function(reader, event) |
| 1683 { |
| 1684 this._progress.done(); |
| 1685 this._model.reset(); |
| 1686 switch (event.target.error.code) { |
| 1687 case FileError.NOT_FOUND_ERR: |
| 1688 WebInspector.console.error(WebInspector.UIString("File \"%s\" not fo
und.", reader.fileName())); |
| 1689 break; |
| 1690 case FileError.NOT_READABLE_ERR: |
| 1691 WebInspector.console.error(WebInspector.UIString("File \"%s\" is not
readable", reader.fileName())); |
| 1692 break; |
| 1693 case FileError.ABORT_ERR: |
| 1694 break; |
| 1695 default: |
| 1696 WebInspector.console.error(WebInspector.UIString("An error occurred
while reading the file \"%s\"", reader.fileName())); |
| 1697 } |
| 1698 } |
| 1699 } |
| 1700 |
| 1701 /** |
| 1702 * @constructor |
1603 * @extends {WebInspector.TimelineModel.Filter} | 1703 * @extends {WebInspector.TimelineModel.Filter} |
1604 * @param {!Array<string>} excludeNames | 1704 * @param {!Array<string>} excludeNames |
1605 */ | 1705 */ |
1606 WebInspector.ExclusiveNameFilter = function(excludeNames) | 1706 WebInspector.ExclusiveNameFilter = function(excludeNames) |
1607 { | 1707 { |
1608 WebInspector.TimelineModel.Filter.call(this); | 1708 WebInspector.TimelineModel.Filter.call(this); |
1609 this._excludeNames = new Set(excludeNames); | 1709 this._excludeNames = new Set(excludeNames); |
1610 } | 1710 } |
1611 | 1711 |
1612 WebInspector.ExclusiveNameFilter.prototype = { | 1712 WebInspector.ExclusiveNameFilter.prototype = { |
(...skipping 27 matching lines...) Expand all Loading... |
1640 */ | 1740 */ |
1641 accept: function(event) | 1741 accept: function(event) |
1642 { | 1742 { |
1643 return !WebInspector.TracingModel.isTopLevelEvent(event); | 1743 return !WebInspector.TracingModel.isTopLevelEvent(event); |
1644 }, | 1744 }, |
1645 | 1745 |
1646 __proto__: WebInspector.TimelineModel.Filter.prototype | 1746 __proto__: WebInspector.TimelineModel.Filter.prototype |
1647 } | 1747 } |
1648 | 1748 |
1649 /** | 1749 /** |
| 1750 * @constructor |
| 1751 * @implements {WebInspector.OutputStream} |
| 1752 * @param {!WebInspector.TimelineModel} model |
| 1753 * @param {!WebInspector.Progress} progress |
| 1754 * @param {function()=} canceledCallback |
| 1755 */ |
| 1756 WebInspector.TracingModelLoader = function(model, progress, canceledCallback) |
| 1757 { |
| 1758 this._model = model; |
| 1759 |
| 1760 this._canceledCallback = canceledCallback; |
| 1761 this._progress = progress; |
| 1762 this._progress.setTitle(WebInspector.UIString("Loading")); |
| 1763 this._progress.setTotalWork(WebInspector.TracingModelLoader._totalProgress);
// Unknown, will loop the values. |
| 1764 |
| 1765 this._state = WebInspector.TracingModelLoader.State.Initial; |
| 1766 this._buffer = ""; |
| 1767 this._firstChunk = true; |
| 1768 this._wasCanceledOnce = false; |
| 1769 |
| 1770 this._loadedBytes = 0; |
| 1771 this._jsonTokenizer = new WebInspector.TextUtils.BalancedJSONTokenizer(this.
_writeBalancedJSON.bind(this), true); |
| 1772 } |
| 1773 |
| 1774 WebInspector.TracingModelLoader._totalProgress = 100000; |
| 1775 |
| 1776 WebInspector.TracingModelLoader.State = { |
| 1777 Initial: "Initial", |
| 1778 LookingForEvents: "LookingForEvents", |
| 1779 ReadingEvents: "ReadingEvents" |
| 1780 } |
| 1781 |
| 1782 WebInspector.TracingModelLoader.prototype = { |
| 1783 /** |
| 1784 * @override |
| 1785 * @param {string} chunk |
| 1786 */ |
| 1787 write: function(chunk) |
| 1788 { |
| 1789 this._loadedBytes += chunk.length; |
| 1790 if (this._progress.isCanceled() && !this._wasCanceledOnce) { |
| 1791 this._wasCanceled = true; |
| 1792 this._reportErrorAndCancelLoading(); |
| 1793 return; |
| 1794 } |
| 1795 this._progress.setWorked(this._loadedBytes % WebInspector.TracingModelLo
ader._totalProgress, |
| 1796 WebInspector.UIString("Loaded %s", Number.bytes
ToString(this._loadedBytes))); |
| 1797 if (this._state === WebInspector.TracingModelLoader.State.Initial) { |
| 1798 if (chunk[0] === "{") |
| 1799 this._state = WebInspector.TracingModelLoader.State.LookingForEv
ents; |
| 1800 else if (chunk[0] === "[") |
| 1801 this._state = WebInspector.TracingModelLoader.State.ReadingEvent
s; |
| 1802 else { |
| 1803 this._reportErrorAndCancelLoading(WebInspector.UIString("Malform
ed timeline data: Unknown JSON format")); |
| 1804 return; |
| 1805 } |
| 1806 } |
| 1807 |
| 1808 if (this._state === WebInspector.TracingModelLoader.State.LookingForEven
ts) { |
| 1809 var objectName = "\"traceEvents\":"; |
| 1810 var startPos = this._buffer.length - objectName.length; |
| 1811 this._buffer += chunk; |
| 1812 var pos = this._buffer.indexOf(objectName, startPos); |
| 1813 if (pos === -1) |
| 1814 return; |
| 1815 chunk = this._buffer.slice(pos + objectName.length) |
| 1816 this._state = WebInspector.TracingModelLoader.State.ReadingEvents; |
| 1817 } |
| 1818 |
| 1819 this._jsonTokenizer.write(chunk); |
| 1820 }, |
| 1821 |
| 1822 /** |
| 1823 * @param {string} data |
| 1824 */ |
| 1825 _writeBalancedJSON: function(data) |
| 1826 { |
| 1827 var json = data + "]"; |
| 1828 |
| 1829 if (this._firstChunk) { |
| 1830 this._model._startCollectingTraceEvents(true); |
| 1831 } else { |
| 1832 var commaIndex = json.indexOf(","); |
| 1833 if (commaIndex !== -1) |
| 1834 json = json.slice(commaIndex + 1); |
| 1835 json = "[" + json; |
| 1836 } |
| 1837 |
| 1838 var items; |
| 1839 try { |
| 1840 items = /** @type {!Array.<!WebInspector.TracingManager.EventPayload
>} */ (JSON.parse(json)); |
| 1841 } catch (e) { |
| 1842 this._reportErrorAndCancelLoading(WebInspector.UIString("Malformed t
imeline data: %s", e.toString())); |
| 1843 return; |
| 1844 } |
| 1845 |
| 1846 if (this._firstChunk) { |
| 1847 this._firstChunk = false; |
| 1848 if (this._looksLikeAppVersion(items[0])) { |
| 1849 this._reportErrorAndCancelLoading(WebInspector.UIString("Legacy
Timeline format is not supported.")); |
| 1850 return; |
| 1851 } |
| 1852 } |
| 1853 |
| 1854 try { |
| 1855 this._model._tracingModel.addEvents(items); |
| 1856 } catch(e) { |
| 1857 this._reportErrorAndCancelLoading(WebInspector.UIString("Malformed t
imeline data: %s", e.toString())); |
| 1858 return; |
| 1859 } |
| 1860 }, |
| 1861 |
| 1862 /** |
| 1863 * @param {string=} message |
| 1864 */ |
| 1865 _reportErrorAndCancelLoading: function(message) |
| 1866 { |
| 1867 if (message) |
| 1868 WebInspector.console.error(message); |
| 1869 this._model.tracingComplete(); |
| 1870 this._model.reset(); |
| 1871 if (this._canceledCallback) |
| 1872 this._canceledCallback(); |
| 1873 this._progress.done(); |
| 1874 }, |
| 1875 |
| 1876 _looksLikeAppVersion: function(item) |
| 1877 { |
| 1878 return typeof item === "string" && item.indexOf("Chrome") !== -1; |
| 1879 }, |
| 1880 |
| 1881 /** |
| 1882 * @override |
| 1883 */ |
| 1884 close: function() |
| 1885 { |
| 1886 this._model._loadedFromFile = true; |
| 1887 this._model.tracingComplete(); |
| 1888 if (this._progress) |
| 1889 this._progress.done(); |
| 1890 } |
| 1891 } |
| 1892 |
| 1893 /** |
| 1894 * @constructor |
| 1895 * @param {!WebInspector.OutputStream} stream |
| 1896 * @implements {WebInspector.OutputStreamDelegate} |
| 1897 */ |
| 1898 WebInspector.TracingTimelineSaver = function(stream) |
| 1899 { |
| 1900 this._stream = stream; |
| 1901 } |
| 1902 |
| 1903 WebInspector.TracingTimelineSaver.prototype = { |
| 1904 /** |
| 1905 * @override |
| 1906 */ |
| 1907 onTransferStarted: function() |
| 1908 { |
| 1909 this._stream.write("["); |
| 1910 }, |
| 1911 |
| 1912 /** |
| 1913 * @override |
| 1914 */ |
| 1915 onTransferFinished: function() |
| 1916 { |
| 1917 this._stream.write("]"); |
| 1918 }, |
| 1919 |
| 1920 /** |
| 1921 * @override |
| 1922 * @param {!WebInspector.ChunkedReader} reader |
| 1923 */ |
| 1924 onChunkTransferred: function(reader) { }, |
| 1925 |
| 1926 /** |
| 1927 * @override |
| 1928 * @param {!WebInspector.ChunkedReader} reader |
| 1929 * @param {!Event} event |
| 1930 */ |
| 1931 onError: function(reader, event) { } |
| 1932 } |
| 1933 |
| 1934 /** |
1650 * @constructor | 1935 * @constructor |
1651 * @param {!WebInspector.TracingModel.Event} event | 1936 * @param {!WebInspector.TracingModel.Event} event |
1652 */ | 1937 */ |
1653 WebInspector.InvalidationTrackingEvent = function(event) | 1938 WebInspector.InvalidationTrackingEvent = function(event) |
1654 { | 1939 { |
1655 /** @type {string} */ | 1940 /** @type {string} */ |
1656 this.type = event.name; | 1941 this.type = event.name; |
1657 /** @type {number} */ | 1942 /** @type {number} */ |
1658 this.startTime = event.startTime; | 1943 this.startTime = event.startTime; |
1659 /** @type {!WebInspector.TracingModel.Event} */ | 1944 /** @type {!WebInspector.TracingModel.Event} */ |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2007 if (!id) | 2292 if (!id) |
2008 return; | 2293 return; |
2009 /** @type {!Map<string, !WebInspector.TracingModel.Event>|undefined} */ | 2294 /** @type {!Map<string, !WebInspector.TracingModel.Event>|undefined} */ |
2010 var initiatorMap = this._initiatorByType.get(initiatorType); | 2295 var initiatorMap = this._initiatorByType.get(initiatorType); |
2011 if (isInitiator) | 2296 if (isInitiator) |
2012 initiatorMap.set(id, event); | 2297 initiatorMap.set(id, event); |
2013 else | 2298 else |
2014 event.initiator = initiatorMap.get(id) || null; | 2299 event.initiator = initiatorMap.get(id) || null; |
2015 } | 2300 } |
2016 } | 2301 } |
OLD | NEW |